chiark / gitweb /
watchdog: make watchdog dbus properties writable
[elogind.git] / src / core / manager.c
index 6be8e8fbe2727dcb5d0819e56fc5410882ed7664..c8ac29be5b00e24cc49cf878c240d13b6c1bb432 100644 (file)
@@ -141,13 +141,17 @@ static int enable_special_signals(Manager *m) {
 
         assert(m);
 
-        /* Enable that we get SIGINT on control-alt-del */
-        if (reboot(RB_DISABLE_CAD) < 0)
+        /* Enable that we get SIGINT on control-alt-del. In containers
+         * this will fail with EPERM, so ignore that. */
+        if (reboot(RB_DISABLE_CAD) < 0 && errno != EPERM)
                 log_warning("Failed to enable ctrl-alt-del handling: %m");
 
-        if ((fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
-                log_warning("Failed to open /dev/tty0: %m");
-        else {
+        fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
+        if (fd < 0) {
+                /* Support systems without virtual console */
+                if (fd != -ENOENT)
+                        log_warning("Failed to open /dev/tty0: %m");
+        } else {
                 /* Enable that we get SIGWINCH on kbrequest */
                 if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
                         log_warning("Failed to enable kbrequest handling: %s", strerror(errno));
@@ -2453,7 +2457,6 @@ static int process_event(Manager *m, struct epoll_event *ev) {
 
 int manager_loop(Manager *m) {
         int r;
-        int wait_msec = -1;
 
         RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
 
@@ -2472,18 +2475,12 @@ int manager_loop(Manager *m) {
         if (r < 0)
                 return r;
 
-        /* Sleep for half the watchdog time */
-        if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)  {
-                wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
-                if (wait_msec <= 0)
-                        wait_msec = 1;
-        }
-
         while (m->exit_code == MANAGER_RUNNING) {
                 struct epoll_event event;
                 int n;
+                int wait_msec = -1;
 
-                if (wait_msec >= 0)
+                if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)
                         watchdog_ping();
 
                 if (!ratelimit_test(&rl)) {
@@ -2514,6 +2511,14 @@ int manager_loop(Manager *m) {
                 if (swap_dispatch_reload(m) > 0)
                         continue;
 
+                /* Sleep for half the watchdog time */
+                if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM) {
+                        wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
+                        if (wait_msec <= 0)
+                                wait_msec = 1;
+                } else
+                        wait_msec = -1;
+
                 n = epoll_wait(m->epoll_fd, &event, 1, wait_msec);
                 if (n < 0) {
 
@@ -2607,17 +2612,13 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
         }
 
         if (audit_log_user_comm_message(m->audit_fd, type, "", p, NULL, NULL, NULL, success) < 0) {
-                log_warning("Failed to send audit message: %m");
-
                 if (errno == EPERM) {
                         /* We aren't allowed to send audit messages?
-                         * Then let's not retry again, to avoid
-                         * spamming the user with the same and same
-                         * messages over and over. */
-
+                         * Then let's not retry again. */
                         audit_close(m->audit_fd);
                         m->audit_fd = -1;
-                }
+                } else
+                        log_warning("Failed to send audit message: %m");
         }
 
         free(p);
@@ -3015,7 +3016,7 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) {
 
 void manager_check_finished(Manager *m) {
         char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
-        usec_t kernel_usec = 0, initrd_usec = 0, userspace_usec = 0, total_usec = 0;
+        usec_t kernel_usec, initrd_usec, userspace_usec, total_usec;
 
         assert(m);