X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl.c;h=840e2ffc2d2f235b61983378c298b4265db54524;hp=556070bcbaa688b6d3b92a2d6d65185b89895241;hb=88e3dc903bd543a74b8699c1575b0da9eeab24a2;hpb=abca4822916b85ae5b0b2bef5d458ea2225d25ab diff --git a/src/systemctl.c b/src/systemctl.c index 556070bcb..840e2ffc2 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -80,8 +80,8 @@ static bool arg_failed = false; static char **arg_wall = NULL; static const char *arg_kill_who = NULL; static const char *arg_kill_mode = NULL; -static const char *arg_root = NULL; static int arg_signal = SIGTERM; +static const char *arg_root = NULL; static usec_t arg_when = 0; static enum action { ACTION_INVALID, @@ -122,11 +122,6 @@ static pid_t agent_pid = 0; static int daemon_reload(DBusConnection *bus, char **args, unsigned n); -static void pager_open_if_enabled(void) { - if (!arg_no_pager) - pager_open(); -} - static bool on_tty(void) { static int t = -1; @@ -142,6 +137,13 @@ static bool on_tty(void) { return t; } +static void pager_open_if_enabled(void) { + on_tty(); + + if (!arg_no_pager) + pager_open(); +} + static void spawn_ask_password_agent(void) { pid_t parent; @@ -783,7 +785,7 @@ static int dot(DBusConnection *bus, char **args, unsigned n) { " red = Conflicts\n" " green = After\n"); - if (isatty(fileno(stdout))) + if (on_tty()) log_notice("-- You probably want to process this output with graphviz' dot tool.\n" "-- Try a shell pipeline like 'systemctl dot | dot -Tsvg > systemd.svg'!\n"); @@ -839,7 +841,7 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) { dbus_message_iter_recurse(&iter, &sub); - if (isatty(STDOUT_FILENO)) + if (on_tty()) printf("%4s %-25s %-15s %-7s\n", "JOB", "UNIT", "TYPE", "STATE"); while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { @@ -875,7 +877,7 @@ static int list_jobs(DBusConnection *bus, char **args, unsigned n) { dbus_message_iter_next(&sub); } - if (isatty(STDOUT_FILENO)) + if (on_tty()) printf("\n%u jobs listed.\n", k); r = 0; @@ -2078,6 +2080,10 @@ static void print_status_info(UnitStatusInfo *i) { static int status_property(const char *name, DBusMessageIter *iter, UnitStatusInfo *i) { + assert(name); + assert(iter); + assert(i); + switch (dbus_message_iter_get_arg_type(iter)) { case DBUS_TYPE_STRING: { @@ -2085,7 +2091,7 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn dbus_message_iter_get_basic(iter, &s); - if (s[0]) { + if (!isempty(s)) { if (streq(name, "Id")) i->id = s; else if (streq(name, "LoadState")) @@ -2244,74 +2250,6 @@ static int print_property(const char *name, DBusMessageIter *iter) { switch (dbus_message_iter_get_arg_type(iter)) { - case DBUS_TYPE_STRING: { - const char *s; - dbus_message_iter_get_basic(iter, &s); - - if (arg_all || s[0]) - printf("%s=%s\n", name, s); - - return 0; - } - - case DBUS_TYPE_BOOLEAN: { - dbus_bool_t b; - dbus_message_iter_get_basic(iter, &b); - printf("%s=%s\n", name, yes_no(b)); - - return 0; - } - - case DBUS_TYPE_UINT64: { - uint64_t u; - dbus_message_iter_get_basic(iter, &u); - - /* Yes, heuristics! But we can change this check - * should it turn out to not be sufficient */ - - if (endswith(name, "Timestamp")) { - char timestamp[FORMAT_TIMESTAMP_MAX], *t; - - if ((t = format_timestamp(timestamp, sizeof(timestamp), u)) || arg_all) - printf("%s=%s\n", name, strempty(t)); - } else if (strstr(name, "USec")) { - char timespan[FORMAT_TIMESPAN_MAX]; - - printf("%s=%s\n", name, format_timespan(timespan, sizeof(timespan), u)); - } else - printf("%s=%llu\n", name, (unsigned long long) u); - - return 0; - } - - case DBUS_TYPE_UINT32: { - uint32_t u; - dbus_message_iter_get_basic(iter, &u); - - if (strstr(name, "UMask") || strstr(name, "Mode")) - printf("%s=%04o\n", name, u); - else - printf("%s=%u\n", name, (unsigned) u); - - return 0; - } - - case DBUS_TYPE_INT32: { - int32_t i; - dbus_message_iter_get_basic(iter, &i); - - printf("%s=%i\n", name, (int) i); - return 0; - } - - case DBUS_TYPE_DOUBLE: { - double d; - dbus_message_iter_get_basic(iter, &d); - - printf("%s=%g\n", name, d); - return 0; - } - case DBUS_TYPE_STRUCT: { DBusMessageIter sub; dbus_message_iter_recurse(iter, &sub); @@ -2343,55 +2281,7 @@ static int print_property(const char *name, DBusMessageIter *iter) { case DBUS_TYPE_ARRAY: - if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING) { - DBusMessageIter sub; - bool space = false; - - dbus_message_iter_recurse(iter, &sub); - if (arg_all || - dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { - printf("%s=", name); - - while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { - const char *s; - - assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING); - dbus_message_iter_get_basic(&sub, &s); - printf("%s%s", space ? " " : "", s); - - space = true; - dbus_message_iter_next(&sub); - } - - puts(""); - } - - return 0; - - } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_BYTE) { - DBusMessageIter sub; - - dbus_message_iter_recurse(iter, &sub); - if (arg_all || - dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { - printf("%s=", name); - - while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { - uint8_t u; - - assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_BYTE); - dbus_message_iter_get_basic(&sub, &u); - printf("%02x", u); - - dbus_message_iter_next(&sub); - } - - puts(""); - } - - return 0; - - } else if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) { + if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRUCT && streq(name, "EnvironmentFiles")) { DBusMessageIter sub, sub2; dbus_message_iter_recurse(iter, &sub); @@ -2496,6 +2386,9 @@ static int print_property(const char *name, DBusMessageIter *iter) { break; } + if (generic_print_property(name, iter, arg_all) > 0) + return 0; + if (arg_all) printf("%s=[unprintable]\n", name); @@ -4350,10 +4243,9 @@ static int systemctl_help(void) { " pending\n" " --ignore-dependencies\n" " When queueing a new job, ignore all its dependencies\n" - " --kill-mode=MODE How to send signal\n" " --kill-who=WHO Who to send signal to\n" " -s --signal=SIGNAL Which signal to send\n" - " -H --host=[user@]host\n" + " -H --host=[USER@]HOST\n" " Show information for remote host\n" " -P --privileged Acquire privileges before execution\n" " -q --quiet Suppress output\n" @@ -4361,7 +4253,7 @@ static int systemctl_help(void) { " --no-wall Don't send wall message before halt/power-off/reboot\n" " --no-reload When enabling/disabling unit files, don't reload daemon\n" " configuration\n" - " --no-pager Do not pipe output into a pager.\n" + " --no-pager Do not pipe output into a pager\n" " --no-ask-password\n" " Do not ask for system passwords\n" " --order When generating graph for dot, show only order\n" @@ -4534,7 +4426,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "force", no_argument, NULL, 'f' }, { "no-reload", no_argument, NULL, ARG_NO_RELOAD }, { "defaults", no_argument, NULL, ARG_DEFAULTS }, - { "kill-mode", required_argument, NULL, ARG_KILL_MODE }, + { "kill-mode", required_argument, NULL, ARG_KILL_MODE }, /* undocumented on purpose */ { "kill-who", required_argument, NULL, ARG_KILL_WHO }, { "signal", required_argument, NULL, 's' }, { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },