X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=1c6fef484e47c9113e1201e4d1f44666b00dcc0b;hp=daf7e31de9cf13c99794ec9c1965bf29921a919e;hb=cc19881a694c26af2d941246f72221df7e76ee02;hpb=601185b43da638b1c74153deae01dbd518680889 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index daf7e31de..1c6fef484 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -594,7 +594,7 @@ static int get_unit_list_recursive( assert(_unit_infos); assert(_machines); - replies = set_new(NULL, NULL); + replies = set_new(NULL); if (!replies) return log_oom(); @@ -617,7 +617,7 @@ static int get_unit_list_recursive( return r; STRV_FOREACH(i, machines) { - _cleanup_bus_unref_ sd_bus *container = NULL; + _cleanup_bus_close_unref_ sd_bus *container = NULL; int k; r = sd_bus_open_system_container(&container, *i); @@ -1338,7 +1338,7 @@ static int list_unit_files(sd_bus *bus, char **args) { Iterator i; unsigned n_units; - h = hashmap_new(string_hash_func, string_compare_func); + h = hashmap_new(&string_hash_ops); if (!h) return log_oom(); @@ -1350,8 +1350,9 @@ static int list_unit_files(sd_bus *bus, char **args) { } n_units = hashmap_size(h); + units = new(UnitFileList, n_units); - if (!units) { + if (!units && n_units > 0) { unit_file_list_free(h); return log_oom(); } @@ -1407,14 +1408,13 @@ static int list_unit_files(sd_bus *bus, char **args) { return bus_log_parse_error(r); } - if (c > 0) { - qsort(units, c, sizeof(UnitFileList), compare_unit_file_list); - output_unit_file_list(units, c); - } + qsort_safe(units, c, sizeof(UnitFileList), compare_unit_file_list); + output_unit_file_list(units, c); - if (avoid_bus()) + if (avoid_bus()) { for (unit = units; unit < units + c; unit++) free(unit->path); + } return 0; } @@ -1688,7 +1688,7 @@ static int compare_machine_info(const void *a, const void *b) { } static int get_machine_properties(sd_bus *bus, struct machine_info *mi) { - _cleanup_bus_unref_ sd_bus *container = NULL; + _cleanup_bus_close_unref_ sd_bus *container = NULL; int r; assert(mi); @@ -2351,8 +2351,18 @@ static int check_wait_response(WaitData *d) { log_error("Job for %s canceled.", strna(d->name)); else if (streq(d->result, "dependency")) log_error("A dependency job for %s failed. See 'journalctl -xn' for details.", strna(d->name)); - else if (!streq(d->result, "done") && !streq(d->result, "skipped")) - log_error("Job for %s failed. See 'systemctl status %s' and 'journalctl -xn' for details.", strna(d->name), strna(d->name)); + else if (!streq(d->result, "done") && !streq(d->result, "skipped")) { + if (d->name) { + bool quotes; + + quotes = chars_intersect(d->name, SHELL_NEED_QUOTES); + + log_error("Job for %s failed. See \"systemctl status %s%s%s\" and \"journalctl -xn\" for details.", + d->name, + quotes ? "'" : "", d->name, quotes ? "'" : ""); + } else + log_error("Job failed. See \"journalctl -xn\" for details."); + } } if (streq(d->result, "timeout")) @@ -2382,7 +2392,7 @@ static int wait_for_jobs(sd_bus *bus, Set *s) { while (!set_isempty(s)) { q = bus_process_wait(bus); if (q < 0) { - log_error("Failed to wait for response: %s", strerror(-r)); + log_error("Failed to wait for response: %s", strerror(-q)); return q; } @@ -2736,7 +2746,7 @@ static int start_unit(sd_bus *bus, char **args) { return r; } - s = set_new(string_hash_func, string_compare_func); + s = set_new(&string_hash_ops); if (!s) return log_oom(); } @@ -4439,7 +4449,6 @@ static int show(sd_bus *bus, char **args) { } static int cat(sd_bus *bus, char **args) { - _cleanup_free_ char *unit = NULL; _cleanup_strv_free_ char **names = NULL; char **name; bool first = true; @@ -4457,7 +4466,7 @@ static int cat(sd_bus *bus, char **args) { STRV_FOREACH(name, names) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_strv_free_ char **dropin_paths = NULL; - _cleanup_free_ char *fragment_path = NULL; + _cleanup_free_ char *fragment_path = NULL, *unit = NULL; char **path; unit = unit_dbus_path_from_name(*name); @@ -4827,7 +4836,7 @@ static int switch_root(sd_bus *bus, char **args) { const char *root_systemd_path = NULL, *root_init_path = NULL; root_systemd_path = strappenda(root, "/" SYSTEMD_BINARY_PATH); - root_init_path = strappenda3(root, "/", init); + root_init_path = strappenda(root, "/", init); /* If the passed init is actually the same as the * systemd binary, then let's suppress it. */ @@ -6828,7 +6837,7 @@ static int runlevel_main(void) { } int main(int argc, char*argv[]) { - _cleanup_bus_unref_ sd_bus *bus = NULL; + _cleanup_bus_close_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, "");