Other functions in sd-login generally allow the output parameter to be NULL, in
which case only the number of items that would be stored in the array is returned.
Be nice and do the same here.
}
_public_ int sd_get_machine_names(char ***machines) {
}
_public_ int sd_get_machine_names(char ***machines) {
- char **l = NULL, **a, **b;
- assert_return(machines, -EINVAL);
-
r = get_files_in_directory("/run/systemd/machines/", &l);
if (r == -ENOENT) {
r = get_files_in_directory("/run/systemd/machines/", &l);
if (r == -ENOENT) {
+ if (machines)
+ *machines = NULL;
r = 0;
/* Filter out the unit: symlinks */
r = 0;
/* Filter out the unit: symlinks */
- for (a = l, b = l; *a; a++) {
+ for (a = b = l; *a; a++) {
if (startswith(*a, "unit:") || !machine_name_is_valid(*a))
free(*a);
else {
if (startswith(*a, "unit:") || !machine_name_is_valid(*a))
free(*a);
else {
+ if (machines)
+ *machines = l;
assert_se(r >= 0);
assert_se(r == (int) strv_length(machines));
assert_se(buf = strv_join(machines, " "));
assert_se(r >= 0);
assert_se(r == (int) strv_length(machines));
assert_se(buf = strv_join(machines, " "));
log_info("sd_get_machines(…) → [%i] \"%s\"", r, buf);
log_info("sd_get_machines(…) → [%i] \"%s\"", r, buf);
+
+ assert_se(sd_get_machine_names(NULL) == r);