X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl.c;h=36346eebe86485c4e68168d64899f7f8018eaf48;hb=4bf2bbb6fbfa745fa7e51f85dc59fc008207cb3e;hp=c01a82c9305e8f0ca6733f600b9f36fd1c2a48d8;hpb=69fc152fc133172433d2bacb6a1fb8b97b866e9d;p=elogind.git diff --git a/src/systemctl.c b/src/systemctl.c index c01a82c93..36346eebe 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -2080,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: { @@ -2087,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")) @@ -2246,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); @@ -2345,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); @@ -2498,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); @@ -3840,12 +3731,12 @@ static int remove_marked_symlinks(const char *config_path) { static int create_symlink(const char *verb, const char *orig_old_path, const char *new_path) { int r; - const char *old_path; + const char *old_path; - if (arg_root) - old_path = orig_old_path+strlen(arg_root); - else - old_path = orig_old_path; + if (arg_root) + old_path = orig_old_path+strlen(arg_root); + else + old_path = orig_old_path; assert(old_path); assert(new_path); @@ -4058,22 +3949,22 @@ static int install_info_apply(const char *verb, LookupPaths *paths, InstallInfo STRV_FOREACH(p, paths->unit_path) { int fd; - char *path, *should_free; + char *path, *should_free; - if (arg_root) - should_free = path = strappend(arg_root, *p); - else { - should_free = NULL; - path = *p; - } + if (arg_root) + should_free = path = strappend(arg_root, *p); + else { + should_free = NULL; + path = *p; + } if (!(filename = path_make_absolute(i->name, path))) { log_error("Out of memory"); return -ENOMEM; } - if (should_free) - free(should_free); + if (should_free) + free(should_free); /* Ensure that we don't follow symlinks */ if ((fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOFOLLOW|O_NOCTTY)) >= 0) @@ -4115,7 +4006,7 @@ static int install_info_apply(const char *verb, LookupPaths *paths, InstallInfo tmp_path = strappend (arg_root, sysv); exists = access (tmp_path, F_OK) >= 0; free (tmp_path); - } else + } else exists = access(sysv, F_OK) >= 0; if (exists) { @@ -4139,7 +4030,7 @@ static int install_info_apply(const char *verb, LookupPaths *paths, InstallInfo if (arg_root) argv[3] = strappend("--root=", arg_root); - log_info("Executing %s %s %s %s", argv[0], argv[1], strempty(argv[2]), strempty(argv[3])); + log_info("Executing %s %s %s %s", argv[0], argv[1], strempty(argv[2]), strempty(argv[3])); if ((pid = fork()) < 0) { log_error("Failed to fork: %m"); @@ -4248,7 +4139,7 @@ static int enable_unit(DBusConnection *bus, char **args, unsigned n) { dbus_error_init(&error); zero(paths); - if ((r = lookup_paths_init(&paths, arg_user ? MANAGER_USER : MANAGER_SYSTEM)) < 0) { + if ((r = lookup_paths_init(&paths, arg_user ? MANAGER_USER : MANAGER_SYSTEM, true)) < 0) { log_error("Failed to determine lookup paths: %s", strerror(-r)); goto finish; } @@ -4354,7 +4245,7 @@ static int systemctl_help(void) { " When queueing a new job, ignore all its dependencies\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" @@ -5221,7 +5112,7 @@ static int talk_upstart(void) { goto finish; } - r = 0; + r = 1; finish: if (m)