chiark / gitweb /
shutdown: drop -f/-F switches again, simply because we don't want to condone non...
[elogind.git] / src / systemctl.c
index 2b34798d060b35fb3e4531bb9ffcabe32076dbc5..a8a5e0c20745eefffb00c27629fa406860a4ef79 100644 (file)
@@ -70,8 +70,6 @@ static bool arg_force = false;
 static bool arg_defaults = false;
 static char **arg_wall = NULL;
 static usec_t arg_when = 0;
 static bool arg_defaults = false;
 static char **arg_wall = NULL;
 static usec_t arg_when = 0;
-static bool arg_skip_fsck = false;
-static bool arg_force_fsck = false;
 static enum action {
         ACTION_INVALID,
         ACTION_SYSTEMCTL,
 static enum action {
         ACTION_INVALID,
         ACTION_SYSTEMCTL,
@@ -216,11 +214,11 @@ static int compare_unit_info(const void *a, const void *b) {
         if (d1 && d2) {
                 int r;
 
         if (d1 && d2) {
                 int r;
 
-                if ((r = strcmp(d1, d2)) != 0)
+                if ((r = strcasecmp(d1, d2)) != 0)
                         return r;
         }
 
                         return r;
         }
 
-        return strcmp(u->id, v->id);
+        return strcasecmp(u->id, v->id);
 }
 
 static int list_units(DBusConnection *bus, char **args, unsigned n) {
 }
 
 static int list_units(DBusConnection *bus, char **args, unsigned n) {
@@ -3829,7 +3827,7 @@ static int halt_help(void) {
 
 static int shutdown_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"
                "Shut down the system.\n\n"
                "     --help      Show this help\n"
                "  -H --halt      Halt the machine\n"
@@ -3838,8 +3836,6 @@ static int shutdown_help(void) {
                "  -h             Equivalent to --poweroff, overriden by --halt\n"
                "  -k             Don't halt/power-off/reboot, just send warnings\n"
                "     --no-wall   Don't send wall message before halt/power-off/reboot\n"
                "  -h             Equivalent to --poweroff, overriden by --halt\n"
                "  -k             Don't halt/power-off/reboot, just send warnings\n"
                "     --no-wall   Don't send wall message before halt/power-off/reboot\n"
-               "  -f             Skip fsck on reboot\n"
-               "  -F             Force fsck on reboot\n"
                "  -c             Cancel a pending shutdown\n",
                program_invocation_short_name);
 
                "  -c             Cancel a pending shutdown\n",
                program_invocation_short_name);
 
@@ -4137,11 +4133,14 @@ static int parse_time_spec(const char *t, usec_t *_u) {
                         return -EINVAL;
 
                 n = now(CLOCK_REALTIME);
                         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;
                 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));
 
 
                 assert_se(s = mktime(&tm));
 
@@ -4212,14 +4211,6 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
                         /* Compatibility nops */
                         break;
 
                         /* Compatibility nops */
                         break;
 
-                case 'f':
-                        arg_skip_fsck = true;
-                        break;
-
-                case 'F':
-                        arg_force_fsck = true;
-                        break;
-
                 case 'c':
                         arg_action = ACTION_CANCEL_SHUTDOWN;
                         break;
                 case 'c':
                         arg_action = ACTION_CANCEL_SHUTDOWN;
                         break;
@@ -4239,7 +4230,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
                         return r;
                 }
         } else
                         return r;
                 }
         } else
-                arg_when = USEC_PER_MINUTE;
+                arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE;
 
         /* We skip the time argument */
         if (argc > optind + 1)
 
         /* We skip the time argument */
         if (argc > optind + 1)
@@ -4696,7 +4687,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
         return verbs[i].dispatch(bus, argv + optind, left);
 }
 
         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;
         int fd = -1;
         struct msghdr msghdr;
         struct iovec iovec;
@@ -4711,6 +4702,10 @@ static int send_shutdownd(usec_t t, char mode) {
         zero(c);
         c.elapse = t;
         c.mode = 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;
 
         if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0)
                 return -errno;
@@ -4805,22 +4800,26 @@ static int halt_main(DBusConnection *bus) {
                 return -EPERM;
         }
 
                 return -EPERM;
         }
 
-        if (arg_force_fsck) {
-                if ((r = touch("/forcefsck")) < 0)
-                        log_warning("Failed to create /forcefsck: %s", strerror(-r));
-        } else if (arg_skip_fsck) {
-                if ((r = touch("/fastboot")) < 0)
-                        log_warning("Failed to create /fastboot: %s", strerror(-r));
-        }
-
         if (arg_when > 0) {
         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));
                         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;
                         return 0;
+                }
         }
 
         if (!arg_dry && !arg_immediate)
         }
 
         if (!arg_dry && !arg_immediate)
@@ -4891,6 +4890,7 @@ int main(int argc, char*argv[]) {
         dbus_error_init(&error);
 
         log_parse_environment();
         dbus_error_init(&error);
 
         log_parse_environment();
+        log_open();
 
         if ((r = parse_argv(argc, argv)) < 0)
                 goto finish;
 
         if ((r = parse_argv(argc, argv)) < 0)
                 goto finish;
@@ -4937,7 +4937,7 @@ int main(int argc, char*argv[]) {
                 break;
 
         case ACTION_CANCEL_SHUTDOWN:
                 break;
 
         case ACTION_CANCEL_SHUTDOWN:
-                retval = send_shutdownd(0, 0) < 0;
+                retval = send_shutdownd(0, 0, false, NULL) < 0;
                 break;
 
         case ACTION_INVALID:
                 break;
 
         case ACTION_INVALID: