X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl%2Fsystemctl.c;h=e6bd855c15eb2b0501e193c93d73fe6bafe368ed;hp=f9a03cad0d87c5e2350efa105cc442ecca339c87;hb=571bfc6c56962dfc926e9bbc1600c511fc8565d1;hpb=44a6b1b68029833893f6e9cee35aa27a974038f6 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index f9a03cad0..e6bd855c1 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -132,6 +132,7 @@ static enum transport { static const char *arg_host = NULL; static unsigned arg_lines = 10; static OutputMode arg_output = OUTPUT_SHORT; +static bool arg_plain = false; static bool private_bus = false; @@ -654,11 +655,12 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { } if (cs) { - printf("%-*s %-*.*s%-*s %s\n", - pathlen, "LISTEN", - typelen + arg_show_types, typelen + arg_show_types, "TYPE ", - socklen, "UNIT", - "ACTIVATES"); + if (!arg_no_legend) + printf("%-*s %-*.*s%-*s %s\n", + pathlen, "LISTEN", + typelen + arg_show_types, typelen + arg_show_types, "TYPE ", + socklen, "UNIT", + "ACTIVATES"); for (s = socket_infos; s < socket_infos + cs; s++) { char **a; @@ -677,15 +679,18 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { on = ansi_highlight(true); off = ansi_highlight(false); - printf("\n"); + if (!arg_no_legend) + printf("\n"); } else { on = ansi_highlight_red(true); off = ansi_highlight_red(false); } - printf("%s%u sockets listed.%s\n", on, cs, off); - if (!arg_all) - printf("Pass --all to see loaded but inactive sockets, too.\n"); + if (!arg_no_legend) { + printf("%s%u sockets listed.%s\n", on, cs, off); + if (!arg_all) + printf("Pass --all to see loaded but inactive sockets, too.\n"); + } return 0; } @@ -956,20 +961,22 @@ static int list_dependencies_print(const char *name, int level, unsigned int bra size_t len = 0; size_t max_len = MAX(columns(),20u); - for (i = level - 1; i >= 0; i--) { + if (!arg_plain) { + for (i = level - 1; i >= 0; i--) { + len += 2; + if(len > max_len - 3 && !arg_full) { + printf("%s...\n",max_len % 2 ? "" : " "); + return 0; + } + printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERT : DRAW_TREE_SPACE)); + } len += 2; if(len > max_len - 3 && !arg_full) { printf("%s...\n",max_len % 2 ? "" : " "); return 0; } - printf("%s", draw_special_char(branches & (1 << i) ? DRAW_TREE_VERT : DRAW_TREE_SPACE)); - } - len += 2; - if(len > max_len - 3 && !arg_full) { - printf("%s...\n",max_len % 2 ? "" : " "); - return 0; + printf("%s", draw_special_char(last ? DRAW_TREE_RIGHT : DRAW_TREE_BRANCH)); } - printf("%s", draw_special_char(last ? DRAW_TREE_RIGHT : DRAW_TREE_BRANCH)); if(arg_full){ printf("%s\n", name); @@ -1105,12 +1112,12 @@ static int list_dependencies_compare(const void *_a, const void *_b) { return strcasecmp(*a, *b); } -static int list_dependencies_one(DBusConnection *bus, const char *name, int level, char **units, unsigned int branches) { +static int list_dependencies_one(DBusConnection *bus, const char *name, int level, char ***units, unsigned int branches) { _cleanup_strv_free_ char **deps = NULL, **u; char **c; int r = 0; - u = strv_append(units, name); + u = strv_append(*units, name); if (!u) return log_oom(); @@ -1122,9 +1129,11 @@ static int list_dependencies_one(DBusConnection *bus, const char *name, int leve STRV_FOREACH(c, deps) { if (strv_contains(u, *c)) { - r = list_dependencies_print("...", level + 1, (branches << 1) | (c[1] == NULL ? 0 : 1), 1); - if (r < 0) - return r; + if (!arg_plain) { + r = list_dependencies_print("...", level + 1, (branches << 1) | (c[1] == NULL ? 0 : 1), 1); + if (r < 0) + return r; + } continue; } @@ -1133,17 +1142,22 @@ static int list_dependencies_one(DBusConnection *bus, const char *name, int leve return r; if (arg_all || unit_name_to_type(*c) == UNIT_TARGET) { - r = list_dependencies_one(bus, *c, level + 1, u, (branches << 1) | (c[1] == NULL ? 0 : 1)); + r = list_dependencies_one(bus, *c, level + 1, &u, (branches << 1) | (c[1] == NULL ? 0 : 1)); if(r < 0) return r; } } - + if (arg_plain) { + strv_free(*units); + *units = u; + u = NULL; + } return 0; } static int list_dependencies(DBusConnection *bus, char **args) { _cleanup_free_ char *unit = NULL; + _cleanup_strv_free_ char **units = NULL; const char *u; assert(bus); @@ -1160,7 +1174,7 @@ static int list_dependencies(DBusConnection *bus, char **args) { puts(u); - return list_dependencies_one(bus, u, 0, NULL, 0); + return list_dependencies_one(bus, u, 0, &units, 0); } struct job_info { @@ -1285,8 +1299,7 @@ static int list_jobs(DBusConnection *bus, char **args) { goto finish; } - if (!greedy_realloc((void**) &jobs, &size, - sizeof(struct job_info) * (used + 1))) { + if (!GREEDY_REALLOC(jobs, size, used + 1)) { r = log_oom(); goto finish; } @@ -4717,7 +4730,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_NO_ASK_PASSWORD, ARG_FAILED, ARG_RUNTIME, - ARG_FORCE + ARG_FORCE, + ARG_PLAIN }; static const struct option options[] = { @@ -4755,6 +4769,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "runtime", no_argument, NULL, ARG_RUNTIME }, { "lines", required_argument, NULL, 'n' }, { "output", required_argument, NULL, 'o' }, + { "plain", no_argument, NULL, ARG_PLAIN }, { NULL, 0, NULL, 0 } }; @@ -4982,6 +4997,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) { arg_ignore_inhibitors = true; break; + case ARG_PLAIN: + arg_plain = true; + break; + case '?': return -EINVAL;