chiark / gitweb /
manager: don't show kernel boot-up time for containers
[elogind.git] / src / manager.c
index 8bbde7c38e09f66733b43697dc9fdd471be5778e..df75eca8c48d6167bcc468b33d3662c7309d93d1 100644 (file)
@@ -66,7 +66,8 @@
 #define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC)
 
 /* Where clients shall send notification messages to */
-#define NOTIFY_SOCKET "/org/freedesktop/systemd1/notify"
+#define NOTIFY_SOCKET_SYSTEM "/dev/.run/systemd/notify"
+#define NOTIFY_SOCKET_USER "@/org/freedesktop/systemd1/notify"
 
 static int manager_setup_notify(Manager *m) {
         union {
@@ -88,9 +89,14 @@ static int manager_setup_notify(Manager *m) {
         sa.sa.sa_family = AF_UNIX;
 
         if (getpid() != 1)
-                snprintf(sa.un.sun_path+1, sizeof(sa.un.sun_path)-1, NOTIFY_SOCKET "/%llu", random_ull());
-        else
-                strncpy(sa.un.sun_path+1, NOTIFY_SOCKET, sizeof(sa.un.sun_path)-1);
+                snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET_USER "/%llu", random_ull());
+        else {
+                unlink(NOTIFY_SOCKET_SYSTEM);
+                strncpy(sa.un.sun_path, NOTIFY_SOCKET_SYSTEM, sizeof(sa.un.sun_path));
+        }
+
+        if (sa.un.sun_path[0] == '@')
+                sa.un.sun_path[0] = 0;
 
         if (bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
                 log_error("bind() failed: %m");
@@ -109,7 +115,10 @@ static int manager_setup_notify(Manager *m) {
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0)
                 return -errno;
 
-        if (!(m->notify_socket = strdup(sa.un.sun_path+1)))
+        if (sa.un.sun_path[0] == 0)
+                sa.un.sun_path[0] = '@';
+
+        if (!(m->notify_socket = strdup(sa.un.sun_path)))
                 return -ENOMEM;
 
         log_debug("Using notification socket %s", m->notify_socket);
@@ -2048,6 +2057,8 @@ static int manager_process_signal_fd(Manager *m) {
         assert(m);
 
         for (;;) {
+                char *p = NULL;
+
                 if ((n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
 
                         if (n >= 0)
@@ -2059,7 +2070,11 @@ static int manager_process_signal_fd(Manager *m) {
                         return -errno;
                 }
 
-                log_debug("Received SIG%s", strna(signal_to_string(sfsi.ssi_signo)));
+                get_process_name(sfsi.ssi_pid, &p);
+                log_debug("Received SIG%s from PID %lu (%s)",
+                          strna(signal_to_string(sfsi.ssi_signo)),
+                          (unsigned long) sfsi.ssi_pid, strna(p));
+                free(p);
 
                 switch (sfsi.ssi_signo) {
 
@@ -2439,8 +2454,19 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
                 return;
         }
 
-        if (audit_log_user_comm_message(m->audit_fd, type, "", p, NULL, NULL, NULL, success) < 0)
-                log_error("Failed to send audit message: %m");
+        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. */
+
+                        audit_close(m->audit_fd);
+                        m->audit_fd = -1;
+                }
+        }
 
         free(p);
 #endif
@@ -2815,7 +2841,8 @@ void manager_check_finished(Manager *m) {
 
         dual_timestamp_get(&m->finish_timestamp);
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (m->running_as == MANAGER_SYSTEM && detect_container(NULL) <= 0) {
+
                 if (dual_timestamp_is_set(&m->initrd_timestamp)) {
                         log_info("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
                                  format_timespan(kernel, sizeof(kernel),