chiark / gitweb /
build-sys: add autoconf macro to pick macro for x32 compatibility
[elogind.git] / src / core / manager.c
index ac11ce18064e74397ea3f80dc90d95385272cada..d4afc931f3d7270e3fa43650312e7b2e10b8f234 100644 (file)
@@ -157,8 +157,8 @@ static int manager_setup_time_change(Manager *m) {
 
         /* We only care for the cancellation event, hence we set the
          * timeout to the latest possible value. */
-        assert_cc(sizeof(time_t) == sizeof(long));
-        its.it_value.tv_sec = LONG_MAX;
+        assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
+        its.it_value.tv_sec = TIME_T_MAX;
 
         if (timerfd_settime(m->time_change_watch.fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0) {
                 log_debug("Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
@@ -301,6 +301,7 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
                 return -ENOMEM;
 
         dual_timestamp_get(&m->userspace_timestamp);
+        dual_timestamp_from_monotonic(&m->kernel_timestamp, 0);
 
         m->running_as = running_as;
         m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
@@ -487,7 +488,7 @@ static unsigned manager_dispatch_gc_queue(Manager *m) {
 
                 if (u->gc_marker == gc_marker + GC_OFFSET_BAD ||
                     u->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
-                        log_debug("Collecting %s", u->id);
+                        log_debug_unit(u->id, "Collecting %s", u->id);
                         u->gc_marker = gc_marker + GC_OFFSET_BAD;
                         unit_add_to_cleanup_queue(u);
                 }
@@ -634,7 +635,8 @@ static void manager_build_unit_path_cache(Manager *m) {
         STRV_FOREACH(i, m->lookup_paths.unit_path) {
                 struct dirent *de;
 
-                if (!(d = opendir(*i))) {
+                d = opendir(*i);
+                if (!d) {
                         log_error("Failed to open directory: %m");
                         continue;
                 }
@@ -748,7 +750,9 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
                 return -EPERM;
         }
 
-        log_debug("Trying to enqueue job %s/%s/%s", unit->id, job_type_to_string(type), job_mode_to_string(mode));
+        log_debug_unit(unit->id,
+                       "Trying to enqueue job %s/%s/%s", unit->id,
+                       job_type_to_string(type), job_mode_to_string(mode));
 
         job_type_collapse(&type, unit);
 
@@ -772,7 +776,9 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
         if (r < 0)
                 goto tr_abort;
 
-        log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) tr->anchor_job->id);
+        log_debug_unit(unit->id,
+                       "Enqueued job %s/%s as %u", unit->id,
+                       job_type_to_string(type), (unsigned) tr->anchor_job->id);
 
         if (_ret)
                 *_ret = tr->anchor_job;
@@ -1033,7 +1039,8 @@ static int manager_process_notify_fd(Manager *m) {
                 msghdr.msg_control = &control;
                 msghdr.msg_controllen = sizeof(control);
 
-                if ((n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT)) <= 0) {
+                n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT);
+                if (n <= 0) {
                         if (n >= 0)
                                 return -EIO;
 
@@ -1053,18 +1060,22 @@ static int manager_process_notify_fd(Manager *m) {
 
                 ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
 
-                if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid))))
-                        if (!(u = cgroup_unit_by_pid(m, ucred->pid))) {
+                u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid));
+                if (!u) {
+                        u = cgroup_unit_by_pid(m, ucred->pid);
+                        if (!u) {
                                 log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
                                 continue;
                         }
+                }
 
                 assert((size_t) n < sizeof(buf));
                 buf[n] = 0;
-                if (!(tags = strv_split(buf, "\n\r")))
-                        return -ENOMEM;
+                tags = strv_split(buf, "\n\r");
+                if (!tags)
+                        return log_oom();
 
-                log_debug("Got notification message for unit %s", u->id);
+                log_debug_unit(u->id, "Got notification message for unit %s", u->id);
 
                 if (UNIT_VTABLE(u)->notify_message)
                         UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags);
@@ -1103,22 +1114,23 @@ static int manager_dispatch_sigchld(Manager *m) {
                         break;
 
                 if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
-                        char *name = NULL;
+                        char _cleanup_free_ *name = NULL;
 
                         get_process_comm(si.si_pid, &name);
                         log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name));
-                        free(name);
                 }
 
                 /* Let's flush any message the dying child might still
                  * have queued for us. This ensures that the process
                  * still exists in /proc so that we can figure out
                  * which cgroup and hence unit it belongs to. */
-                if ((r = manager_process_notify_fd(m)) < 0)
+                r = manager_process_notify_fd(m);
+                if (r < 0)
                         return r;
 
                 /* And now figure out the unit this belongs to */
-                if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid))))
+                u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid));
+                if (!u)
                         u = cgroup_unit_by_pid(m, si.si_pid);
 
                 /* And now, we actually reap the zombie. */
@@ -1143,7 +1155,8 @@ static int manager_dispatch_sigchld(Manager *m) {
                 if (!u)
                         continue;
 
-                log_debug("Child %lu belongs to %s", (long unsigned) si.si_pid, u->id);
+                log_debug_unit(u->id,
+                               "Child %lu belongs to %s", (long unsigned) si.si_pid, u->id);
 
                 hashmap_remove(m->watch_pids, LONG_TO_PTR(si.si_pid));
                 UNIT_VTABLE(u)->sigchld_event(u, si.si_pid, si.si_code, si.si_status);
@@ -1158,10 +1171,12 @@ static int manager_start_target(Manager *m, const char *name, JobMode mode) {
 
         dbus_error_init(&error);
 
-        log_debug("Activating special unit %s", name);
+        log_debug_unit(name, "Activating special unit %s", name);
 
-        if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
-                log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
+        r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL);
+        if (r < 0)
+                log_error_unit(name,
+                               "Failed to enqueue %s job: %s", name, bus_error(&error, r));
 
         dbus_error_free(&error);
 
@@ -1176,7 +1191,8 @@ static int manager_process_signal_fd(Manager *m) {
         assert(m);
 
         for (;;) {
-                if ((n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
+                n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi));
+                if (n != sizeof(sfsi)) {
 
                         if (n >= 0)
                                 return -EIO;
@@ -1666,8 +1682,10 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
         if (u->type != UNIT_SERVICE)
                 return;
 
-        if (!(p = unit_name_to_prefix_and_instance(u->id))) {
-                log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
+        p = unit_name_to_prefix_and_instance(u->id);
+        if (!p) {
+                log_error_unit(u->id,
+                               "Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
                 return;
         }
 
@@ -1973,7 +1991,8 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
 
                 char_array_0(name);
 
-                if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
+                r = manager_load_unit(m, strstrip(name), NULL, NULL, &u);
+                if (r < 0)
                         goto finish;
 
                 r = unit_deserialize(u, f, fds);
@@ -2130,7 +2149,8 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) {
         assert(name);
 
         /* Returns true if the unit is inactive or going down */
-        if (!(u = manager_get_unit(m, name)))
+        u = manager_get_unit(m, name);
+        if (!u)
                 return true;
 
         return unit_pending_inactive(u);