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;
}
r = q;
}
+ /* Any fds left? Find some unit which wants them. This is
+ * useful to allow container managers to pass some file
+ * descriptors to us pre-initialized. This enables
+ * socket-based activation of entire containers. */
+ if (fdset_size(fds) > 0) {
+ q = manager_distribute_fds(m, fds);
+ if (q < 0)
+ r = q;
+ }
+
/* Third, fire things up! */
q = manager_coldplug(m);
if (q < 0)
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;
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);
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. */
log_debug("Activating special unit %s", name);
- if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
+ r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL);
+ if (r < 0)
log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
dbus_error_free(&error);
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;
if (u->type != UNIT_SERVICE)
return;
- if (!(p = unit_name_to_prefix_and_instance(u->id))) {
+ p = unit_name_to_prefix_and_instance(u->id);
+ if (!p) {
log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
return;
}
log_debug("Serializing state to %s", path);
free(path);
- if (!(f = fdopen(fd, "w+")))
+ f = fdopen(fd, "w+");
+ if (!f)
return -errno;
*_f = f;
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;
- if ((r = unit_deserialize(u, f, fds)) < 0)
+ r = unit_deserialize(u, f, fds);
+ if (r < 0)
goto finish;
}
return r;
}
+int manager_distribute_fds(Manager *m, FDSet *fds) {
+ Unit *u;
+ Iterator i;
+ int r;
+
+ assert(m);
+
+ HASHMAP_FOREACH(u, m->units, i) {
+
+ if (fdset_size(fds) <= 0)
+ break;
+
+ if (UNIT_VTABLE(u)->distribute_fds) {
+ r = UNIT_VTABLE(u)->distribute_fds(u, fds);
+ if (r < 0)
+ return r;
+ }
+ }
+
+ return 0;
+}
+
int manager_reload(Manager *m) {
int r, q;
FILE *f;
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);