[systemd-commits] 2 commits - src/cgls.c src/cgroups-agent.c src/initctl.c src/log.c src/logger.c src/notify.c src/random-seed.c src/shutdownd.c src/systemctl.c src/update-utmp.c

Lennart Poettering lennart at kemper.freedesktop.org
Mon Aug 16 13:40:27 PDT 2010


 src/cgls.c          |    1 +
 src/cgroups-agent.c |    1 +
 src/initctl.c       |    1 +
 src/log.c           |    6 +++---
 src/logger.c        |    1 +
 src/notify.c        |    1 +
 src/random-seed.c   |    2 ++
 src/shutdownd.c     |   37 +++++++++++++++++++++++++------------
 src/systemctl.c     |   16 ++++++++++++----
 src/update-utmp.c   |    1 +
 10 files changed, 48 insertions(+), 19 deletions(-)

New commits:
commit 08e4b1c5c8aeb52e806b7cf994173660190e61ab
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Aug 16 22:40:11 2010 +0200

    shutdown: various fixes for handling of delayed shutdowns

diff --git a/src/shutdownd.c b/src/shutdownd.c
index 80ff2e9..59439bc 100644
--- a/src/shutdownd.c
+++ b/src/shutdownd.c
@@ -99,30 +99,31 @@ static int read_packet(int fd, struct shutdownd_command *_c) {
         return 1;
 }
 
-static void warn_wall(struct shutdownd_command *c) {
+static void warn_wall(usec_t n, struct shutdownd_command *c) {
 
         assert(c);
         assert(c->warn_wall);
 
+        if (n >= c->elapse)
+                return;
+
         if (c->wall_message[0])
                 utmp_wall(c->wall_message);
         else {
                 char date[FORMAT_TIMESTAMP_MAX];
                 const char* prefix;
-                char *l;
+                char *l = NULL;
 
                 if (c->mode == 'H')
-                        prefix = "The system is going down for system halt at";
+                        prefix = "The system is going down for system halt at ";
                 else if (c->mode == 'P')
-                        prefix = "The system is going down for power-off at";
+                        prefix = "The system is going down for power-off at ";
                 else if (c->mode == 'r')
-                        prefix = "The system is going down for reboot at";
+                        prefix = "The system is going down for reboot at ";
                 else
                         assert_not_reached("Unknown mode!");
 
-                if (asprintf(&l, "%s %s!",
-                             prefix,
-                             format_timestamp(date, sizeof(date), c->elapse)) < 0)
+                if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0)
                         log_error("Failed to allocate wall message");
                 else {
                         utmp_wall(l);
@@ -151,8 +152,10 @@ static usec_t when_wall(usec_t n, usec_t elapse) {
 
         left = elapse - n;
         for (i = 0; i < ELEMENTSOF(table); i++)
-                if (n + table[i].delay >= elapse)
+                if (n + table[i].delay >= elapse) {
                         sub = ((left / table[i].interval) * table[i].interval);
+                        break;
+                }
 
         if (i >= ELEMENTSOF(table))
                 sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR);
@@ -272,7 +275,7 @@ int main(int argc, char *argv[]) {
                                         /* Warn immediately if less than 15 minutes are left */
                                         if (n < c.elapse &&
                                             n + 15*USEC_PER_MINUTE >= c.elapse)
-                                                warn_wall(&c);
+                                                warn_wall(n, &c);
                                 }
 
                                 /* Disallow logins 5 minutes prior to shutdown */
@@ -300,7 +303,7 @@ int main(int argc, char *argv[]) {
                 if (pollfd[FD_WALL_TIMER].revents) {
                         struct itimerspec its;
 
-                        warn_wall(&c);
+                        warn_wall(n, &c);
                         flush_fd(pollfd[FD_WALL_TIMER].fd);
 
                         /* Restart timer */
@@ -315,6 +318,8 @@ int main(int argc, char *argv[]) {
                 if (pollfd[FD_NOLOGIN_TIMER].revents) {
                         int e;
 
+                        log_info("Creating /etc/nologin, blocking further logins...");
+
                         if ((e = touch("/etc/nologin")) < 0)
                                 log_error("Failed to create /etc/nologin: %s", strerror(-e));
                         else
@@ -347,7 +352,14 @@ finish:
                 sw[1] = c.mode;
                 sw[2] = 0;
 
-                execl(SYSTEMCTL_BINARY_PATH, "shutdown", sw, "now", NULL);
+                execl(SYSTEMCTL_BINARY_PATH,
+                      "shutdown",
+                      sw,
+                      "now",
+                      (c.warn_wall && c.wall_message[0]) ? c.wall_message :
+                      (c.warn_wall ? NULL : "--no-wall"),
+                      NULL);
+
                 log_error("Failed to execute /sbin/shutdown: %m");
         }
 
diff --git a/src/systemctl.c b/src/systemctl.c
index 50473a1..44b8848 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -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));
 
@@ -4239,7 +4242,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
                         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)
@@ -4819,6 +4822,7 @@ static int halt_main(DBusConnection *bus) {
 
         if (arg_when > 0) {
                 char *m;
+                char date[FORMAT_TIMESTAMP_MAX];
 
                 m = strv_join(arg_wall, " ");
                 r = send_shutdownd(arg_when,
@@ -4831,8 +4835,11 @@ static int halt_main(DBusConnection *bus) {
 
                 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)
commit 2396fb04f78eaa9842c747e384218f0069446960
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Aug 16 22:39:02 2010 +0200

    log: properly open log target in the various utilities

diff --git a/src/cgls.c b/src/cgls.c
index c60f9ee..2940e37 100644
--- a/src/cgls.c
+++ b/src/cgls.c
@@ -75,6 +75,7 @@ int main(int argc, char *argv[]) {
         int r = 0, retval = 1;
 
         log_parse_environment();
+        log_open();
 
         if ((r = parse_argv(argc, argv)) < 0)
                 goto finish;
diff --git a/src/cgroups-agent.c b/src/cgroups-agent.c
index ed1d43e..92b56c5 100644
--- a/src/cgroups-agent.c
+++ b/src/cgroups-agent.c
@@ -39,6 +39,7 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
         /* If possible we go via the system bus, to make sure that
          * session instances get the messages. If not possible we talk
diff --git a/src/initctl.c b/src/initctl.c
index e1ab3f7..115452e 100644
--- a/src/initctl.c
+++ b/src/initctl.c
@@ -349,6 +349,7 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
         if ((n = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
diff --git a/src/log.c b/src/log.c
index 8c20b9c..d6f4e34 100644
--- a/src/log.c
+++ b/src/log.c
@@ -73,7 +73,7 @@ static int log_open_console(void) {
                         return console_fd;
                 }
 
-                log_info("Succesfully opened /dev/console for logging.");
+                log_debug("Succesfully opened /dev/console for logging.");
         } else
                 console_fd = STDERR_FILENO;
 
@@ -99,7 +99,7 @@ static int log_open_kmsg(void) {
                 return -errno;
         }
 
-        log_info("Succesfully opened /dev/kmsg for logging.");
+        log_debug("Succesfully opened /dev/kmsg for logging.");
 
         return 0;
 }
@@ -146,7 +146,7 @@ static int log_open_syslog(void) {
                 goto fail;
         }
 
-        log_info("Succesfully opened syslog for logging.");
+        log_debug("Succesfully opened syslog for logging.");
 
         return 0;
 
diff --git a/src/logger.c b/src/logger.c
index 26bf888..64ac214 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -547,6 +547,7 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
         if ((n = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
diff --git a/src/notify.c b/src/notify.c
index b914a74..1c18c6b 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -134,6 +134,7 @@ int main(int argc, char* argv[]) {
         int r, retval = 1;
 
         log_parse_environment();
+        log_open();
 
         if ((r = parse_argv(argc, argv)) <= 0) {
                 retval = r < 0;
diff --git a/src/random-seed.c b/src/random-seed.c
index 91aa6c6..b9cafb7 100644
--- a/src/random-seed.c
+++ b/src/random-seed.c
@@ -39,7 +39,9 @@ int main(int argc, char *argv[]) {
                 return 1;
         }
 
+        log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
         /* When we load the seed we read it and write it to the device
          * and then immediately update the saved seed with new data,
diff --git a/src/shutdownd.c b/src/shutdownd.c
index d889824..80ff2e9 100644
--- a/src/shutdownd.c
+++ b/src/shutdownd.c
@@ -192,6 +192,7 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
         if ((n_fds = sd_listen_fds(true)) < 0) {
                 log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
diff --git a/src/systemctl.c b/src/systemctl.c
index a3186db..50473a1 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -4903,6 +4903,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;
diff --git a/src/update-utmp.c b/src/update-utmp.c
index b5d733c..5a48bd9 100644
--- a/src/update-utmp.c
+++ b/src/update-utmp.c
@@ -368,6 +368,7 @@ int main(int argc, char *argv[]) {
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();
+        log_open();
 
 #ifdef HAVE_AUDIT
         if ((c.audit_fd = audit_open()) < 0)


More information about the systemd-commits mailing list