X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemctl.c;h=44b884800bdee69708a7acf2bf8d1a6a65543dcf;hb=8630d370239482b6e4913e81011440b173e41b79;hp=e517031ceac0d5af15d65e5838e119014888c776;hpb=f61448083198dc0e4e0d19a916bcd478336cc85d;p=elogind.git diff --git a/src/systemctl.c b/src/systemctl.c index e517031ce..44b884800 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -216,11 +216,11 @@ static int compare_unit_info(const void *a, const void *b) { if (d1 && d2) { int r; - if ((r = strcmp(d1, d2)) != 0) + if ((r = strcasecmp(d1, d2)) != 0) return r; } - return strcmp(u->id, v->id); + return strcasecmp(u->id, v->id); } static int list_units(DBusConnection *bus, char **args, unsigned n) { @@ -3829,7 +3829,7 @@ static int halt_help(void) { static int shutdown_help(void) { - printf("%s [OPTIONS...] [now] [WALL...]\n\n" + printf("%s [OPTIONS...] [TIME] [WALL...]\n\n" "Shut down the system.\n\n" " --help Show this help\n" " -H --halt Halt the machine\n" @@ -4137,11 +4137,14 @@ static int parse_time_spec(const char *t, usec_t *_u) { return -EINVAL; n = now(CLOCK_REALTIME); - s = (time_t) n / USEC_PER_SEC; + s = (time_t) (n / USEC_PER_SEC); + + zero(tm); assert_se(localtime_r(&s, &tm)); tm.tm_hour = (int) hour; tm.tm_min = (int) minute; + tm.tm_sec = 0; assert_se(s = mktime(&tm)); @@ -4233,11 +4236,13 @@ static int shutdown_parse_argv(int argc, char *argv[]) { } } - if (argc > optind) + if (argc > optind) { if ((r = parse_time_spec(argv[optind], &arg_when)) < 0) { log_error("Failed to parse time specification: %s", argv[optind]); return r; } + } else + arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE; /* We skip the time argument */ if (argc > optind + 1) @@ -4694,7 +4699,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError return verbs[i].dispatch(bus, argv + optind, left); } -static int send_shutdownd(usec_t t, char mode) { +static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) { int fd = -1; struct msghdr msghdr; struct iovec iovec; @@ -4709,6 +4714,10 @@ static int send_shutdownd(usec_t t, char mode) { zero(c); c.elapse = t; c.mode = mode; + c.warn_wall = warn; + + if (message) + strncpy(c.wall_message, message, sizeof(c.wall_message)); if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -errno; @@ -4812,13 +4821,25 @@ static int halt_main(DBusConnection *bus) { } if (arg_when > 0) { - if ((r = send_shutdownd(arg_when, - arg_action == ACTION_HALT ? 'H' : - arg_action == ACTION_POWEROFF ? 'P' : - 'r')) < 0) + char *m; + char date[FORMAT_TIMESTAMP_MAX]; + + m = strv_join(arg_wall, " "); + r = send_shutdownd(arg_when, + arg_action == ACTION_HALT ? 'H' : + arg_action == ACTION_POWEROFF ? 'P' : + 'r', + !arg_no_wall, + m); + free(m); + + if (r < 0) log_warning("Failed to talk to shutdownd, proceeding with immediate shutdown: %s", strerror(-r)); - else + else { + log_info("Shutdown scheduled for %s, use 'shutdown -c' to cancel.", + format_timestamp(date, sizeof(date), arg_when)); return 0; + } } if (!arg_dry && !arg_immediate) @@ -4889,6 +4910,7 @@ int main(int argc, char*argv[]) { dbus_error_init(&error); log_parse_environment(); + log_open(); if ((r = parse_argv(argc, argv)) < 0) goto finish; @@ -4935,7 +4957,7 @@ int main(int argc, char*argv[]) { break; case ACTION_CANCEL_SHUTDOWN: - retval = send_shutdownd(0, 0) < 0; + retval = send_shutdownd(0, 0, false, NULL) < 0; break; case ACTION_INVALID: