chiark / gitweb /
manager: don't show kernel boot-up time for containers
[elogind.git] / src / manager.c
index d77dc096172fa9fdf757a5fc0601ffa9c7280f23..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);
@@ -294,7 +303,7 @@ static unsigned manager_dispatch_cleanup_queue(Manager *m) {
 }
 
 enum {
-        GC_OFFSET_IN_PATH,  /* This one is on the path we were travelling */
+        GC_OFFSET_IN_PATH,  /* This one is on the path we were traveling */
         GC_OFFSET_UNSURE,   /* No clue */
         GC_OFFSET_GOOD,     /* We still need this unit */
         GC_OFFSET_BAD,      /* We don't need this unit anymore */
@@ -768,7 +777,7 @@ static int delete_one_unmergeable_job(Manager *m, Job *j) {
 
         /* Tries to delete one item in the linked list
          * j->transaction_next->transaction_next->... that conflicts
-         * whith another one, in an attempt to make an inconsistent
+         * with another one, in an attempt to make an inconsistent
          * transaction work. */
 
         /* We rely here on the fact that if a merged with b does not
@@ -1286,7 +1295,7 @@ static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
                         break;
 
                 if (r != -EAGAIN) {
-                        log_warning("Requested transaction contains unmergable jobs: %s", bus_error(e, r));
+                        log_warning("Requested transaction contains unmergeable jobs: %s", bus_error(e, r));
                         goto rollback;
                 }
 
@@ -1330,7 +1339,7 @@ static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool o
         assert(m);
         assert(unit);
 
-        /* Looks for an axisting prospective job and returns that. If
+        /* Looks for an existing prospective job and returns that. If
          * it doesn't exist it is created and added to the prospective
          * jobs list. */
 
@@ -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
@@ -2550,22 +2576,20 @@ void manager_dispatch_bus_query_pid_done(
 }
 
 int manager_open_serialization(Manager *m, FILE **_f) {
-        char *path;
+        char *path = NULL;
         mode_t saved_umask;
         int fd;
         FILE *f;
 
         assert(_f);
 
-        if (m->running_as == MANAGER_SYSTEM) {
-                mkdir_p("/dev/.systemd", 0755);
+        if (m->running_as == MANAGER_SYSTEM)
+                asprintf(&path, "/dev/.run/systemd/dump-%lu-XXXXXX", (unsigned long) getpid());
+        else
+                asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
 
-                if (asprintf(&path, "/dev/.systemd/dump-%lu-XXXXXX", (unsigned long) getpid()) < 0)
-                        return -ENOMEM;
-        } else {
-                if (asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid()) < 0)
-                        return -ENOMEM;
-        }
+        if (!path)
+                return -ENOMEM;
 
         saved_umask = umask(0077);
         fd = mkostemp(path, O_RDWR|O_CLOEXEC);
@@ -2817,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),
@@ -2862,7 +2887,7 @@ void manager_run_generators(Manager *m) {
 
         if (!m->generator_unit_path) {
                 char *p;
-                char system_path[] = "/dev/.systemd/generator-XXXXXX",
+                char system_path[] = "/dev/.run/systemd/generator-XXXXXX",
                         user_path[] = "/tmp/systemd-generator-XXXXXX";
 
                 if (!(p = mkdtemp(m->running_as == MANAGER_SYSTEM ? system_path : user_path))) {