X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsystemctl.c;h=c8384ff530102b26a03c45ccb88c09d135f4fc3c;hp=1f2b43be032148a7f004af985100946115aa5924;hb=b9c0d4415b8cd6135321185b6febfdd1366a477c;hpb=07459bb6b92268beb2599f65cf195708d88c51cc diff --git a/src/systemctl.c b/src/systemctl.c index 1f2b43be0..c8384ff53 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -53,6 +54,7 @@ #include "exit-status.h" #include "bus-errors.h" #include "build.h" +#include "unit-name.h" static const char *arg_type = NULL; static char **arg_property = NULL; @@ -295,7 +297,8 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) { if (!output_show_job(u)) continue; - if (!streq(u->load_state, "loaded")) { + if (!streq(u->load_state, "loaded") && + !streq(u->load_state, "banned")) { on_loaded = ansi_highlight(true); off_loaded = ansi_highlight(false); } else @@ -1626,7 +1629,8 @@ static void print_status_info(UnitStatusInfo *i) { printf("\n"); - if (streq_ptr(i->load_state, "failed")) { + if (streq_ptr(i->load_state, "failed") || + streq_ptr(i->load_state, "banned")) { on = ansi_highlight(true); off = ansi_highlight(false); } else @@ -3237,28 +3241,16 @@ static void install_info_hashmap_free(Hashmap *m) { hashmap_free(m); } -static bool unit_name_valid(const char *name) { - - /* This is a minimal version of unit_name_valid() from - * unit-name.c */ - - if (!*name) - return false; - - if (ignore_file(name)) - return false; - - return true; -} - static int install_info_add(const char *name) { InstallInfo *i; int r; assert(will_install); - if (!unit_name_valid(name)) + if (!unit_name_is_valid_no_type(name, true)) { + log_warning("Unit name %s is not a valid unit name.", name); return -EINVAL; + } if (hashmap_get(have_installed, name) || hashmap_get(will_install, name)) @@ -3310,11 +3302,13 @@ static int config_parse_also( if (!(n = strndup(w, l))) return -ENOMEM; - r = install_info_add(n); - free(n); - - if (r < 0) + if ((r = install_info_add(n)) < 0) { + log_warning("Cannot install unit %s: %s", n, strerror(-r)); + free(n); return r; + } + + free(n); } return 0; @@ -3639,12 +3633,6 @@ static int install_info_symlink_alias(const char *verb, InstallInfo *i, const ch STRV_FOREACH(s, i->aliases) { - if (!unit_name_valid(*s)) { - log_error("Invalid name %s.", *s); - r = -EINVAL; - goto finish; - } - free(alias_path); if (!(alias_path = path_make_absolute(*s, config_path))) { log_error("Out of memory"); @@ -3658,7 +3646,6 @@ static int install_info_symlink_alias(const char *verb, InstallInfo *i, const ch if (streq(verb, "disable")) rmdir_parents(alias_path, config_path); } - r = 0; finish: @@ -3677,7 +3664,7 @@ static int install_info_symlink_wants(const char *verb, InstallInfo *i, const ch assert(config_path); STRV_FOREACH(s, i->wanted_by) { - if (!unit_name_valid(*s)) { + if (!unit_name_is_valid_no_type(*s, true)) { log_error("Invalid name %s.", *s); r = -EINVAL; goto finish; @@ -3840,8 +3827,10 @@ static int enable_unit(DBusConnection *bus, char **args, unsigned n) { } for (j = 1; j < n; j++) - if ((r = install_info_add(args[j])) < 0) + if ((r = install_info_add(args[j])) < 0) { + log_warning("Cannot install unit %s: %s", args[j], strerror(-r)); goto finish; + } while ((i = hashmap_first(will_install))) { int q; @@ -4883,7 +4872,7 @@ static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) { zero(msghdr); msghdr.msg_name = &sockaddr; - msghdr.msg_namelen = sizeof(sa_family_t) + 1 + sizeof("/org/freedesktop/systemd1/shutdownd") - 1; + msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + 1 + sizeof("/org/freedesktop/systemd1/shutdownd") - 1; msghdr.msg_iov = &iovec; msghdr.msg_iovlen = 1;