X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=599d5907478408e4910880c738dd6f86b0e65b01;hp=1ab4794bd6e52948c28c36e3a295520a32e38f14;hb=0c6ea3a4e2ac3f350dcb58e8f08bb74b030cd624;hpb=b4af5a803aa71a57733ca46fef29b7afb20a626c diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1ab4794bd..599d59074 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -456,7 +456,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { } if (circle_len > 0) - printf("%s%s%s", on_circle, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_circle); + printf("%s%s%s ", on_circle, circle ? draw_special_char(DRAW_BLACK_CIRCLE) : " ", off_circle); printf("%s%-*s%s %s%-*s%s %s%-*s %-*s%s %-*s", on_active, id_len, id, off_active, @@ -3503,50 +3503,11 @@ static void show_unit_help(UnitStatusInfo *i) { return; } - STRV_FOREACH(p, i->documentation) { - - if (startswith(*p, "man:")) { - const char *args[4] = { "man", NULL, NULL, NULL }; - _cleanup_free_ char *page = NULL, *section = NULL; - char *e = NULL; - pid_t pid; - size_t k; - - k = strlen(*p); - - if ((*p)[k-1] == ')') - e = strrchr(*p, '('); - - if (e) { - page = strndup((*p) + 4, e - *p - 4); - section = strndup(e + 1, *p + k - e - 2); - if (!page || !section) { - log_oom(); - return; - } - - args[1] = section; - args[2] = page; - } else - args[1] = *p + 4; - - pid = fork(); - if (pid < 0) { - log_error("Failed to fork: %m"); - continue; - } - - if (pid == 0) { - /* Child */ - execvp(args[0], (char**) args); - log_error("Failed to execute man: %m"); - _exit(EXIT_FAILURE); - } - - wait_for_terminate(pid, NULL); - } else + STRV_FOREACH(p, i->documentation) + if (startswith(*p, "man:")) + show_man_page(*p + 4, false); + else log_info("Can't show: %s", *p); - } } static int status_property(const char *name, sd_bus_message *m, UnitStatusInfo *i, const char *contents) { @@ -5037,15 +4998,9 @@ static int enable_sysv_units(const char *verb, char **args) { STRV_FOREACH(k, paths.unit_path) { _cleanup_free_ char *path = NULL; - if (!isempty(arg_root)) - asprintf(&path, "%s/%s/%s", arg_root, *k, name); - else - asprintf(&path, "%s/%s", *k, name); - - if (!path) { - r = log_oom(); - goto finish; - } + path = path_join(arg_root, *k, name); + if (!path) + return log_oom(); found_native = access(path, F_OK) >= 0; if (found_native) @@ -5055,14 +5010,9 @@ static int enable_sysv_units(const char *verb, char **args) { if (found_native) continue; - if (!isempty(arg_root)) - asprintf(&p, "%s/" SYSTEM_SYSVINIT_PATH "/%s", arg_root, name); - else - asprintf(&p, SYSTEM_SYSVINIT_PATH "/%s", name); - if (!p) { - r = log_oom(); - goto finish; - } + p = path_join(arg_root, SYSTEM_SYSVINIT_PATH, name); + if (!p) + return log_oom(); p[strlen(p) - strlen(".service")] = 0; found_sysv = access(p, F_OK) >= 0; @@ -5084,18 +5034,15 @@ static int enable_sysv_units(const char *verb, char **args) { argv[c] = NULL; l = strv_join((char**)argv, " "); - if (!l) { - r = log_oom(); - goto finish; - } + if (!l) + return log_oom(); log_info("Executing %s", l); pid = fork(); if (pid < 0) { log_error("Failed to fork: %m"); - r = -errno; - goto finish; + return -errno; } else if (pid == 0) { /* Child */ @@ -5106,8 +5053,7 @@ static int enable_sysv_units(const char *verb, char **args) { j = wait_for_terminate(pid, &status); if (j < 0) { log_error("Failed to wait for child: %s", strerror(-r)); - r = j; - goto finish; + return j; } if (status.si_code == CLD_EXITED) { @@ -5121,17 +5067,12 @@ static int enable_sysv_units(const char *verb, char **args) { puts("disabled"); } - } else if (status.si_status != 0) { - r = -EINVAL; - goto finish; - } - } else { - r = -EPROTO; - goto finish; - } + } else if (status.si_status != 0) + return -EINVAL; + } else + return -EPROTO; } -finish: /* Drop all SysV units */ for (f = 0, t = 0; args[f]; f++) {