1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/epoll.h>
27 #include <sys/signalfd.h>
31 #include <sys/reboot.h>
32 #include <sys/ioctl.h>
36 #include <sys/types.h>
50 #include "ratelimit.h"
52 #include "mount-setup.h"
53 #include "unit-name.h"
54 #include "dbus-unit.h"
57 #include "path-lookup.h"
59 #include "bus-errors.h"
60 #include "exit-status.h"
61 #include "sd-daemon.h"
63 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
64 #define GC_QUEUE_ENTRIES_MAX 16
66 /* As soon as 5s passed since a unit was added to our GC queue, make sure to run a gc sweep */
67 #define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC)
69 /* Where clients shall send notification messages to */
70 #define NOTIFY_SOCKET_SYSTEM "/run/systemd/notify"
71 #define NOTIFY_SOCKET_USER "@/org/freedesktop/systemd1/notify"
73 static int manager_setup_notify(Manager *m) {
76 struct sockaddr_un un;
78 struct epoll_event ev;
84 m->notify_watch.type = WATCH_NOTIFY;
85 if ((m->notify_watch.fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
86 log_error("Failed to allocate notification socket: %m");
91 sa.sa.sa_family = AF_UNIX;
94 snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET_USER "/%llu", random_ull());
96 unlink(NOTIFY_SOCKET_SYSTEM);
97 strncpy(sa.un.sun_path, NOTIFY_SOCKET_SYSTEM, sizeof(sa.un.sun_path));
100 if (sa.un.sun_path[0] == '@')
101 sa.un.sun_path[0] = 0;
104 r = bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1));
108 log_error("bind() failed: %m");
112 if (setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
113 log_error("SO_PASSCRED failed: %m");
119 ev.data.ptr = &m->notify_watch;
121 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0)
124 if (sa.un.sun_path[0] == 0)
125 sa.un.sun_path[0] = '@';
127 if (!(m->notify_socket = strdup(sa.un.sun_path)))
130 log_debug("Using notification socket %s", m->notify_socket);
135 static int enable_special_signals(Manager *m) {
140 /* Enable that we get SIGINT on control-alt-del */
141 if (reboot(RB_DISABLE_CAD) < 0)
142 log_warning("Failed to enable ctrl-alt-del handling: %m");
144 if ((fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
145 log_warning("Failed to open /dev/tty0: %m");
147 /* Enable that we get SIGWINCH on kbrequest */
148 if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
149 log_warning("Failed to enable kbrequest handling: %s", strerror(errno));
151 close_nointr_nofail(fd);
157 static int manager_setup_signals(Manager *m) {
159 struct epoll_event ev;
164 /* We are not interested in SIGSTOP and friends. */
166 sa.sa_handler = SIG_DFL;
167 sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
168 assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
170 assert_se(sigemptyset(&mask) == 0);
172 sigset_add_many(&mask,
173 SIGCHLD, /* Child died */
174 SIGTERM, /* Reexecute daemon */
175 SIGHUP, /* Reload configuration */
176 SIGUSR1, /* systemd/upstart: reconnect to D-Bus */
177 SIGUSR2, /* systemd: dump status */
178 SIGINT, /* Kernel sends us this on control-alt-del */
179 SIGWINCH, /* Kernel sends us this on kbrequest (alt-arrowup) */
180 SIGPWR, /* Some kernel drivers and upsd send us this on power failure */
181 SIGRTMIN+0, /* systemd: start default.target */
182 SIGRTMIN+1, /* systemd: isolate rescue.target */
183 SIGRTMIN+2, /* systemd: isolate emergency.target */
184 SIGRTMIN+3, /* systemd: start halt.target */
185 SIGRTMIN+4, /* systemd: start poweroff.target */
186 SIGRTMIN+5, /* systemd: start reboot.target */
187 SIGRTMIN+6, /* systemd: start kexec.target */
188 SIGRTMIN+13, /* systemd: Immediate halt */
189 SIGRTMIN+14, /* systemd: Immediate poweroff */
190 SIGRTMIN+15, /* systemd: Immediate reboot */
191 SIGRTMIN+16, /* systemd: Immediate kexec */
192 SIGRTMIN+20, /* systemd: enable status messages */
193 SIGRTMIN+21, /* systemd: disable status messages */
194 SIGRTMIN+22, /* systemd: set log level to LOG_DEBUG */
195 SIGRTMIN+23, /* systemd: set log level to LOG_INFO */
196 SIGRTMIN+27, /* systemd: set log target to console */
197 SIGRTMIN+28, /* systemd: set log target to kmsg */
198 SIGRTMIN+29, /* systemd: set log target to syslog-or-kmsg */
200 assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
202 m->signal_watch.type = WATCH_SIGNAL;
203 if ((m->signal_watch.fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC)) < 0)
208 ev.data.ptr = &m->signal_watch;
210 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
213 if (m->running_as == MANAGER_SYSTEM)
214 return enable_special_signals(m);
219 int manager_new(ManagerRunningAs running_as, Manager **_m) {
224 assert(running_as >= 0);
225 assert(running_as < _MANAGER_RUNNING_AS_MAX);
227 if (!(m = new0(Manager, 1)))
230 dual_timestamp_get(&m->startup_timestamp);
232 m->running_as = running_as;
233 m->name_data_slot = m->subscribed_data_slot = -1;
234 m->exit_code = _MANAGER_EXIT_CODE_INVALID;
235 m->pin_cgroupfs_fd = -1;
241 m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = m->dev_autofs_fd = m->swap_watch.fd = -1;
242 m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
244 if (!(m->environment = strv_copy(environ)))
247 if (!(m->default_controllers = strv_new("cpu", NULL)))
250 if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
253 if (!(m->jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
256 if (!(m->transaction_jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
259 if (!(m->watch_pids = hashmap_new(trivial_hash_func, trivial_compare_func)))
262 if (!(m->cgroup_bondings = hashmap_new(string_hash_func, string_compare_func)))
265 if (!(m->watch_bus = hashmap_new(string_hash_func, string_compare_func)))
268 if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
271 if ((r = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0)
274 if ((r = manager_setup_signals(m)) < 0)
277 if ((r = manager_setup_cgroup(m)) < 0)
280 if ((r = manager_setup_notify(m)) < 0)
283 /* Try to connect to the busses, if possible. */
284 if ((r = bus_init(m, running_as != MANAGER_SYSTEM)) < 0)
288 if ((m->audit_fd = audit_open()) < 0)
289 log_error("Failed to connect to audit log: %m");
292 m->taint_usr = dir_is_empty("/usr") > 0;
302 static unsigned manager_dispatch_cleanup_queue(Manager *m) {
308 while ((meta = m->cleanup_queue)) {
309 assert(meta->in_cleanup_queue);
311 unit_free((Unit*) meta);
319 GC_OFFSET_IN_PATH, /* This one is on the path we were traveling */
320 GC_OFFSET_UNSURE, /* No clue */
321 GC_OFFSET_GOOD, /* We still need this unit */
322 GC_OFFSET_BAD, /* We don't need this unit anymore */
326 static void unit_gc_sweep(Unit *u, unsigned gc_marker) {
333 if (u->meta.gc_marker == gc_marker + GC_OFFSET_GOOD ||
334 u->meta.gc_marker == gc_marker + GC_OFFSET_BAD ||
335 u->meta.gc_marker == gc_marker + GC_OFFSET_IN_PATH)
338 if (u->meta.in_cleanup_queue)
341 if (unit_check_gc(u))
344 u->meta.gc_marker = gc_marker + GC_OFFSET_IN_PATH;
348 SET_FOREACH(other, u->meta.dependencies[UNIT_REFERENCED_BY], i) {
349 unit_gc_sweep(other, gc_marker);
351 if (other->meta.gc_marker == gc_marker + GC_OFFSET_GOOD)
354 if (other->meta.gc_marker != gc_marker + GC_OFFSET_BAD)
361 /* We were unable to find anything out about this entry, so
362 * let's investigate it later */
363 u->meta.gc_marker = gc_marker + GC_OFFSET_UNSURE;
364 unit_add_to_gc_queue(u);
368 /* We definitely know that this one is not useful anymore, so
369 * let's mark it for deletion */
370 u->meta.gc_marker = gc_marker + GC_OFFSET_BAD;
371 unit_add_to_cleanup_queue(u);
375 u->meta.gc_marker = gc_marker + GC_OFFSET_GOOD;
378 static unsigned manager_dispatch_gc_queue(Manager *m) {
385 if ((m->n_in_gc_queue < GC_QUEUE_ENTRIES_MAX) &&
386 (m->gc_queue_timestamp <= 0 ||
387 (m->gc_queue_timestamp + GC_QUEUE_USEC_MAX) > now(CLOCK_MONOTONIC)))
390 log_debug("Running GC...");
392 m->gc_marker += _GC_OFFSET_MAX;
393 if (m->gc_marker + _GC_OFFSET_MAX <= _GC_OFFSET_MAX)
396 gc_marker = m->gc_marker;
398 while ((meta = m->gc_queue)) {
399 assert(meta->in_gc_queue);
401 unit_gc_sweep((Unit*) meta, gc_marker);
403 LIST_REMOVE(Meta, gc_queue, m->gc_queue, meta);
404 meta->in_gc_queue = false;
408 if (meta->gc_marker == gc_marker + GC_OFFSET_BAD ||
409 meta->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
410 log_debug("Collecting %s", meta->id);
411 meta->gc_marker = gc_marker + GC_OFFSET_BAD;
412 unit_add_to_cleanup_queue((Unit*) meta);
416 m->n_in_gc_queue = 0;
417 m->gc_queue_timestamp = 0;
422 static void manager_clear_jobs_and_units(Manager *m) {
428 while ((j = hashmap_first(m->transaction_jobs)))
431 while ((u = hashmap_first(m->units)))
434 manager_dispatch_cleanup_queue(m);
436 assert(!m->load_queue);
437 assert(!m->run_queue);
438 assert(!m->dbus_unit_queue);
439 assert(!m->dbus_job_queue);
440 assert(!m->cleanup_queue);
441 assert(!m->gc_queue);
443 assert(hashmap_isempty(m->transaction_jobs));
444 assert(hashmap_isempty(m->jobs));
445 assert(hashmap_isempty(m->units));
448 void manager_free(Manager *m) {
453 manager_clear_jobs_and_units(m);
455 for (c = 0; c < _UNIT_TYPE_MAX; c++)
456 if (unit_vtable[c]->shutdown)
457 unit_vtable[c]->shutdown(m);
459 /* If we reexecute ourselves, we keep the root cgroup
461 manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE);
463 manager_undo_generators(m);
467 hashmap_free(m->units);
468 hashmap_free(m->jobs);
469 hashmap_free(m->transaction_jobs);
470 hashmap_free(m->watch_pids);
471 hashmap_free(m->watch_bus);
473 if (m->epoll_fd >= 0)
474 close_nointr_nofail(m->epoll_fd);
475 if (m->signal_watch.fd >= 0)
476 close_nointr_nofail(m->signal_watch.fd);
477 if (m->notify_watch.fd >= 0)
478 close_nointr_nofail(m->notify_watch.fd);
481 if (m->audit_fd >= 0)
482 audit_close(m->audit_fd);
485 free(m->notify_socket);
487 lookup_paths_free(&m->lookup_paths);
488 strv_free(m->environment);
490 strv_free(m->default_controllers);
492 hashmap_free(m->cgroup_bondings);
493 set_free_free(m->unit_path_cache);
498 int manager_enumerate(Manager *m) {
504 /* Let's ask every type to load all units from disk/kernel
505 * that it might know */
506 for (c = 0; c < _UNIT_TYPE_MAX; c++)
507 if (unit_vtable[c]->enumerate)
508 if ((q = unit_vtable[c]->enumerate(m)) < 0)
511 manager_dispatch_load_queue(m);
515 int manager_coldplug(Manager *m) {
523 /* Then, let's set up their initial state. */
524 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
530 if ((q = unit_coldplug(u)) < 0)
537 static void manager_build_unit_path_cache(Manager *m) {
544 set_free_free(m->unit_path_cache);
546 if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
547 log_error("Failed to allocate unit path cache.");
551 /* This simply builds a list of files we know exist, so that
552 * we don't always have to go to disk */
554 STRV_FOREACH(i, m->lookup_paths.unit_path) {
557 if (!(d = opendir(*i))) {
558 log_error("Failed to open directory: %m");
562 while ((de = readdir(d))) {
565 if (ignore_file(de->d_name))
568 p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL);
574 if ((r = set_put(m->unit_path_cache, p)) < 0) {
587 log_error("Failed to build unit path cache: %s", strerror(-r));
589 set_free_free(m->unit_path_cache);
590 m->unit_path_cache = NULL;
596 int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
601 manager_run_generators(m);
603 manager_build_unit_path_cache(m);
605 /* If we will deserialize make sure that during enumeration
606 * this is already known, so we increase the counter here
611 /* First, enumerate what we can from all config files */
612 r = manager_enumerate(m);
614 /* Second, deserialize if there is something to deserialize */
616 if ((q = manager_deserialize(m, serialization, fds)) < 0)
619 /* Third, fire things up! */
620 if ((q = manager_coldplug(m)) < 0)
624 assert(m->n_reloading > 0);
631 static void transaction_delete_job(Manager *m, Job *j, bool delete_dependencies) {
635 /* Deletes one job from the transaction */
637 manager_transaction_unlink_job(m, j, delete_dependencies);
643 static void transaction_delete_unit(Manager *m, Unit *u) {
646 /* Deletes all jobs associated with a certain unit from the
649 while ((j = hashmap_get(m->transaction_jobs, u)))
650 transaction_delete_job(m, j, true);
653 static void transaction_clean_dependencies(Manager *m) {
659 /* Drops all dependencies of all installed jobs */
661 HASHMAP_FOREACH(j, m->jobs, i) {
662 while (j->subject_list)
663 job_dependency_free(j->subject_list);
664 while (j->object_list)
665 job_dependency_free(j->object_list);
668 assert(!m->transaction_anchor);
671 static void transaction_abort(Manager *m) {
676 while ((j = hashmap_first(m->transaction_jobs)))
678 transaction_delete_job(m, j, true);
682 assert(hashmap_isempty(m->transaction_jobs));
684 transaction_clean_dependencies(m);
687 static void transaction_find_jobs_that_matter_to_anchor(Manager *m, Job *j, unsigned generation) {
692 /* A recursive sweep through the graph that marks all units
693 * that matter to the anchor job, i.e. are directly or
694 * indirectly a dependency of the anchor job via paths that
695 * are fully marked as mattering. */
700 l = m->transaction_anchor;
702 LIST_FOREACH(subject, l, l) {
704 /* This link does not matter */
708 /* This unit has already been marked */
709 if (l->object->generation == generation)
712 l->object->matters_to_anchor = true;
713 l->object->generation = generation;
715 transaction_find_jobs_that_matter_to_anchor(m, l->object, generation);
719 static void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, JobType t) {
720 JobDependency *l, *last;
724 assert(j->unit == other->unit);
725 assert(!j->installed);
727 /* Merges 'other' into 'j' and then deletes j. */
730 j->state = JOB_WAITING;
731 j->override = j->override || other->override;
733 j->matters_to_anchor = j->matters_to_anchor || other->matters_to_anchor;
735 /* Patch us in as new owner of the JobDependency objects */
737 LIST_FOREACH(subject, l, other->subject_list) {
738 assert(l->subject == other);
743 /* Merge both lists */
745 last->subject_next = j->subject_list;
747 j->subject_list->subject_prev = last;
748 j->subject_list = other->subject_list;
751 /* Patch us in as new owner of the JobDependency objects */
753 LIST_FOREACH(object, l, other->object_list) {
754 assert(l->object == other);
759 /* Merge both lists */
761 last->object_next = j->object_list;
763 j->object_list->object_prev = last;
764 j->object_list = other->object_list;
767 /* Kill the other job */
768 other->subject_list = NULL;
769 other->object_list = NULL;
770 transaction_delete_job(m, other, true);
772 static bool job_is_conflicted_by(Job *j) {
777 /* Returns true if this job is pulled in by a least one
778 * ConflictedBy dependency. */
780 LIST_FOREACH(object, l, j->object_list)
787 static int delete_one_unmergeable_job(Manager *m, Job *j) {
792 /* Tries to delete one item in the linked list
793 * j->transaction_next->transaction_next->... that conflicts
794 * with another one, in an attempt to make an inconsistent
795 * transaction work. */
797 /* We rely here on the fact that if a merged with b does not
798 * merge with c, either a or b merge with c neither */
799 LIST_FOREACH(transaction, j, j)
800 LIST_FOREACH(transaction, k, j->transaction_next) {
803 /* Is this one mergeable? Then skip it */
804 if (job_type_is_mergeable(j->type, k->type))
807 /* Ok, we found two that conflict, let's see if we can
808 * drop one of them */
809 if (!j->matters_to_anchor && !k->matters_to_anchor) {
811 /* Both jobs don't matter, so let's
812 * find the one that is smarter to
813 * remove. Let's think positive and
814 * rather remove stops then starts --
815 * except if something is being
816 * stopped because it is conflicted by
817 * another unit in which case we
818 * rather remove the start. */
820 log_debug("Looking at job %s/%s conflicted_by=%s", j->unit->meta.id, job_type_to_string(j->type), yes_no(j->type == JOB_STOP && job_is_conflicted_by(j)));
821 log_debug("Looking at job %s/%s conflicted_by=%s", k->unit->meta.id, job_type_to_string(k->type), yes_no(k->type == JOB_STOP && job_is_conflicted_by(k)));
823 if (j->type == JOB_STOP) {
825 if (job_is_conflicted_by(j))
830 } else if (k->type == JOB_STOP) {
832 if (job_is_conflicted_by(k))
839 } else if (!j->matters_to_anchor)
841 else if (!k->matters_to_anchor)
846 /* Ok, we can drop one, so let's do so. */
847 log_debug("Fixing conflicting jobs by deleting job %s/%s", d->unit->meta.id, job_type_to_string(d->type));
848 transaction_delete_job(m, d, true);
855 static int transaction_merge_jobs(Manager *m, DBusError *e) {
862 /* First step, check whether any of the jobs for one specific
863 * task conflict. If so, try to drop one of them. */
864 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
869 LIST_FOREACH(transaction, k, j->transaction_next) {
870 if (job_type_merge(&t, k->type) >= 0)
873 /* OK, we could not merge all jobs for this
874 * action. Let's see if we can get rid of one
877 if ((r = delete_one_unmergeable_job(m, j)) >= 0)
878 /* Ok, we managed to drop one, now
879 * let's ask our callers to call us
880 * again after garbage collecting */
883 /* We couldn't merge anything. Failure */
884 dbus_set_error(e, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
885 job_type_to_string(t), job_type_to_string(k->type), k->unit->meta.id);
890 /* Second step, merge the jobs. */
891 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
895 /* Merge all transactions */
896 LIST_FOREACH(transaction, k, j->transaction_next)
897 assert_se(job_type_merge(&t, k->type) == 0);
899 /* If an active job is mergeable, merge it too */
900 if (j->unit->meta.job)
901 job_type_merge(&t, j->unit->meta.job->type); /* Might fail. Which is OK */
903 while ((k = j->transaction_next)) {
905 transaction_merge_and_delete_job(m, k, j, t);
908 transaction_merge_and_delete_job(m, j, k, t);
911 if (j->unit->meta.job && !j->installed)
912 transaction_merge_and_delete_job(m, j, j->unit->meta.job, t);
914 assert(!j->transaction_next);
915 assert(!j->transaction_prev);
921 static void transaction_drop_redundant(Manager *m) {
926 /* Goes through the transaction and removes all jobs that are
935 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
936 bool changes_something = false;
939 LIST_FOREACH(transaction, k, j) {
941 if (!job_is_anchor(k) &&
942 (k->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))) &&
943 (!k->unit->meta.job || !job_type_is_conflicting(k->type, k->unit->meta.job->type)))
946 changes_something = true;
950 if (changes_something)
953 /* log_debug("Found redundant job %s/%s, dropping.", j->unit->meta.id, job_type_to_string(j->type)); */
954 transaction_delete_job(m, j, false);
962 static bool unit_matters_to_anchor(Unit *u, Job *j) {
964 assert(!j->transaction_prev);
966 /* Checks whether at least one of the jobs for this unit
967 * matters to the anchor. */
969 LIST_FOREACH(transaction, j, j)
970 if (j->matters_to_anchor)
976 static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation, DBusError *e) {
983 assert(!j->transaction_prev);
985 /* Does a recursive sweep through the ordering graph, looking
986 * for a cycle. If we find cycle we try to break it. */
988 /* Have we seen this before? */
989 if (j->generation == generation) {
992 /* If the marker is NULL we have been here already and
993 * decided the job was loop-free from here. Hence
994 * shortcut things and return right-away. */
998 /* So, the marker is not NULL and we already have been
999 * here. We have a cycle. Let's try to break it. We go
1000 * backwards in our path and try to find a suitable
1001 * job to remove. We use the marker to find our way
1002 * back, since smart how we are we stored our way back
1004 log_warning("Found ordering cycle on %s/%s", j->unit->meta.id, job_type_to_string(j->type));
1007 for (k = from; k; k = ((k->generation == generation && k->marker != k) ? k->marker : NULL)) {
1009 log_info("Walked on cycle path to %s/%s", k->unit->meta.id, job_type_to_string(k->type));
1013 !unit_matters_to_anchor(k->unit, k)) {
1014 /* Ok, we can drop this one, so let's
1019 /* Check if this in fact was the beginning of
1027 log_warning("Breaking ordering cycle by deleting job %s/%s", delete->unit->meta.id, job_type_to_string(delete->type));
1028 transaction_delete_unit(m, delete->unit);
1032 log_error("Unable to break cycle");
1034 dbus_set_error(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See system logs for details.");
1038 /* Make the marker point to where we come from, so that we can
1039 * find our way backwards if we want to break a cycle. We use
1040 * a special marker for the beginning: we point to
1042 j->marker = from ? from : j;
1043 j->generation = generation;
1045 /* We assume that the the dependencies are bidirectional, and
1046 * hence can ignore UNIT_AFTER */
1047 SET_FOREACH(u, j->unit->meta.dependencies[UNIT_BEFORE], i) {
1050 /* Is there a job for this unit? */
1051 if (!(o = hashmap_get(m->transaction_jobs, u)))
1053 /* Ok, there is no job for this in the
1054 * transaction, but maybe there is already one
1056 if (!(o = u->meta.job))
1059 if ((r = transaction_verify_order_one(m, o, j, generation, e)) < 0)
1063 /* Ok, let's backtrack, and remember that this entry is not on
1064 * our path anymore. */
1070 static int transaction_verify_order(Manager *m, unsigned *generation, DBusError *e) {
1079 /* Check if the ordering graph is cyclic. If it is, try to fix
1080 * that up by dropping one of the jobs. */
1082 g = (*generation)++;
1084 HASHMAP_FOREACH(j, m->transaction_jobs, i)
1085 if ((r = transaction_verify_order_one(m, j, NULL, g, e)) < 0)
1091 static void transaction_collect_garbage(Manager *m) {
1096 /* Drop jobs that are not required by any other job */
1104 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1105 if (j->object_list) {
1106 /* log_debug("Keeping job %s/%s because of %s/%s", */
1107 /* j->unit->meta.id, job_type_to_string(j->type), */
1108 /* j->object_list->subject ? j->object_list->subject->unit->meta.id : "root", */
1109 /* j->object_list->subject ? job_type_to_string(j->object_list->subject->type) : "root"); */
1113 /* log_debug("Garbage collecting job %s/%s", j->unit->meta.id, job_type_to_string(j->type)); */
1114 transaction_delete_job(m, j, true);
1122 static int transaction_is_destructive(Manager *m, DBusError *e) {
1128 /* Checks whether applying this transaction means that
1129 * existing jobs would be replaced */
1131 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1134 assert(!j->transaction_prev);
1135 assert(!j->transaction_next);
1137 if (j->unit->meta.job &&
1138 j->unit->meta.job != j &&
1139 !job_type_is_superset(j->type, j->unit->meta.job->type)) {
1141 dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
1149 static void transaction_minimize_impact(Manager *m) {
1153 /* Drops all unnecessary jobs that reverse already active jobs
1154 * or that stop a running service. */
1162 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1163 LIST_FOREACH(transaction, j, j) {
1164 bool stops_running_service, changes_existing_job;
1166 /* If it matters, we shouldn't drop it */
1167 if (j->matters_to_anchor)
1170 /* Would this stop a running service?
1171 * Would this change an existing job?
1172 * If so, let's drop this entry */
1174 stops_running_service =
1175 j->type == JOB_STOP && UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(j->unit));
1177 changes_existing_job =
1178 j->unit->meta.job &&
1179 job_type_is_conflicting(j->type, j->unit->meta.job->type);
1181 if (!stops_running_service && !changes_existing_job)
1184 if (stops_running_service)
1185 log_debug("%s/%s would stop a running service.", j->unit->meta.id, job_type_to_string(j->type));
1187 if (changes_existing_job)
1188 log_debug("%s/%s would change existing job.", j->unit->meta.id, job_type_to_string(j->type));
1190 /* Ok, let's get rid of this */
1191 log_debug("Deleting %s/%s to minimize impact.", j->unit->meta.id, job_type_to_string(j->type));
1193 transaction_delete_job(m, j, true);
1205 static int transaction_apply(Manager *m, JobMode mode) {
1210 /* Moves the transaction jobs to the set of active jobs */
1212 if (mode == JOB_ISOLATE) {
1214 /* When isolating first kill all installed jobs which
1215 * aren't part of the new transaction */
1216 HASHMAP_FOREACH(j, m->jobs, i) {
1217 assert(j->installed);
1219 if (hashmap_get(m->transaction_jobs, j->unit))
1222 job_finish_and_invalidate(j, JOB_CANCELED);
1226 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1228 assert(!j->transaction_prev);
1229 assert(!j->transaction_next);
1234 if ((r = hashmap_put(m->jobs, UINT32_TO_PTR(j->id), j)) < 0)
1238 while ((j = hashmap_steal_first(m->transaction_jobs))) {
1240 /* log_debug("Skipping already installed job %s/%s as %u", j->unit->meta.id, job_type_to_string(j->type), (unsigned) j->id); */
1244 if (j->unit->meta.job)
1245 job_free(j->unit->meta.job);
1247 j->unit->meta.job = j;
1248 j->installed = true;
1249 m->n_installed_jobs ++;
1251 /* We're fully installed. Now let's free data we don't
1254 assert(!j->transaction_next);
1255 assert(!j->transaction_prev);
1257 job_add_to_run_queue(j);
1258 job_add_to_dbus_queue(j);
1261 log_debug("Installed new job %s/%s as %u", j->unit->meta.id, job_type_to_string(j->type), (unsigned) j->id);
1264 /* As last step, kill all remaining job dependencies. */
1265 transaction_clean_dependencies(m);
1271 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1275 hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
1281 static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
1283 unsigned generation = 1;
1287 /* This applies the changes recorded in transaction_jobs to
1288 * the actual list of jobs, if possible. */
1290 /* First step: figure out which jobs matter */
1291 transaction_find_jobs_that_matter_to_anchor(m, NULL, generation++);
1293 /* Second step: Try not to stop any running services if
1294 * we don't have to. Don't try to reverse running
1295 * jobs if we don't have to. */
1296 if (mode == JOB_FAIL)
1297 transaction_minimize_impact(m);
1299 /* Third step: Drop redundant jobs */
1300 transaction_drop_redundant(m);
1303 /* Fourth step: Let's remove unneeded jobs that might
1305 if (mode != JOB_ISOLATE)
1306 transaction_collect_garbage(m);
1308 /* Fifth step: verify order makes sense and correct
1309 * cycles if necessary and possible */
1310 if ((r = transaction_verify_order(m, &generation, e)) >= 0)
1314 log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e, r));
1318 /* Let's see if the resulting transaction ordering
1319 * graph is still cyclic... */
1323 /* Sixth step: let's drop unmergeable entries if
1324 * necessary and possible, merge entries we can
1326 if ((r = transaction_merge_jobs(m, e)) >= 0)
1330 log_warning("Requested transaction contains unmergeable jobs: %s", bus_error(e, r));
1334 /* Seventh step: an entry got dropped, let's garbage
1335 * collect its dependencies. */
1336 if (mode != JOB_ISOLATE)
1337 transaction_collect_garbage(m);
1339 /* Let's see if the resulting transaction still has
1340 * unmergeable entries ... */
1343 /* Eights step: Drop redundant jobs again, if the merging now allows us to drop more. */
1344 transaction_drop_redundant(m);
1346 /* Ninth step: check whether we can actually apply this */
1347 if (mode == JOB_FAIL)
1348 if ((r = transaction_is_destructive(m, e)) < 0) {
1349 log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
1353 /* Tenth step: apply changes */
1354 if ((r = transaction_apply(m, mode)) < 0) {
1355 log_warning("Failed to apply transaction: %s", strerror(-r));
1359 assert(hashmap_isempty(m->transaction_jobs));
1360 assert(!m->transaction_anchor);
1365 transaction_abort(m);
1369 static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool override, bool *is_new) {
1375 /* Looks for an existing prospective job and returns that. If
1376 * it doesn't exist it is created and added to the prospective
1379 f = hashmap_get(m->transaction_jobs, unit);
1381 LIST_FOREACH(transaction, j, f) {
1382 assert(j->unit == unit);
1384 if (j->type == type) {
1391 if (unit->meta.job && unit->meta.job->type == type)
1393 else if (!(j = job_new(m, type, unit)))
1398 j->matters_to_anchor = false;
1399 j->override = override;
1401 LIST_PREPEND(Job, transaction, f, j);
1403 if (hashmap_replace(m->transaction_jobs, unit, f) < 0) {
1411 /* log_debug("Added job %s/%s to transaction.", unit->meta.id, job_type_to_string(type)); */
1416 void manager_transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
1420 if (j->transaction_prev)
1421 j->transaction_prev->transaction_next = j->transaction_next;
1422 else if (j->transaction_next)
1423 hashmap_replace(m->transaction_jobs, j->unit, j->transaction_next);
1425 hashmap_remove_value(m->transaction_jobs, j->unit, j);
1427 if (j->transaction_next)
1428 j->transaction_next->transaction_prev = j->transaction_prev;
1430 j->transaction_prev = j->transaction_next = NULL;
1432 while (j->subject_list)
1433 job_dependency_free(j->subject_list);
1435 while (j->object_list) {
1436 Job *other = j->object_list->matters ? j->object_list->subject : NULL;
1438 job_dependency_free(j->object_list);
1440 if (other && delete_dependencies) {
1441 log_debug("Deleting job %s/%s as dependency of job %s/%s",
1442 other->unit->meta.id, job_type_to_string(other->type),
1443 j->unit->meta.id, job_type_to_string(j->type));
1444 transaction_delete_job(m, other, delete_dependencies);
1449 static int transaction_add_job_and_dependencies(
1457 bool ignore_requirements,
1468 assert(type < _JOB_TYPE_MAX);
1471 /* log_debug("Pulling in %s/%s from %s/%s", */
1472 /* unit->meta.id, job_type_to_string(type), */
1473 /* by ? by->unit->meta.id : "NA", */
1474 /* by ? job_type_to_string(by->type) : "NA"); */
1476 if (unit->meta.load_state != UNIT_LOADED &&
1477 unit->meta.load_state != UNIT_ERROR &&
1478 unit->meta.load_state != UNIT_MASKED) {
1479 dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->meta.id);
1483 if (type != JOB_STOP && unit->meta.load_state == UNIT_ERROR) {
1484 dbus_set_error(e, BUS_ERROR_LOAD_FAILED,
1485 "Unit %s failed to load: %s. "
1486 "See system logs and 'systemctl status %s' for details.",
1488 strerror(-unit->meta.load_error),
1493 if (type != JOB_STOP && unit->meta.load_state == UNIT_MASKED) {
1494 dbus_set_error(e, BUS_ERROR_MASKED, "Unit %s is masked.", unit->meta.id);
1498 if (!unit_job_is_applicable(unit, type)) {
1499 dbus_set_error(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE, "Job type %s is not applicable for unit %s.", job_type_to_string(type), unit->meta.id);
1503 /* First add the job. */
1504 if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
1507 ret->ignore_order = ret->ignore_order || ignore_order;
1509 /* Then, add a link to the job. */
1510 if (!job_dependency_new(by, ret, matters, conflicts))
1513 if (is_new && !ignore_requirements) {
1516 /* If we are following some other unit, make sure we
1517 * add all dependencies of everybody following. */
1518 if (unit_following_set(ret->unit, &following) > 0) {
1519 SET_FOREACH(dep, following, i)
1520 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, false, override, false, false, ignore_order, e, NULL)) < 0) {
1521 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
1527 set_free(following);
1530 /* Finally, recursively add in all dependencies. */
1531 if (type == JOB_START || type == JOB_RELOAD_OR_START) {
1532 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES], i)
1533 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1541 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_BIND_TO], i)
1542 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1551 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
1552 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, false, false, ignore_order, e, NULL)) < 0) {
1553 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
1559 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_WANTS], i)
1560 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, false, false, ignore_order, e, NULL)) < 0) {
1561 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
1567 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE], i)
1568 if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1577 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
1578 if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, false, false, ignore_order, e, NULL)) < 0) {
1579 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
1585 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTS], i)
1586 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, true, false, ignore_order, e, NULL)) < 0) {
1595 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTED_BY], i)
1596 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, false, override, false, false, ignore_order, e, NULL)) < 0) {
1597 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
1603 } else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
1605 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRED_BY], i)
1606 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1615 SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_BOUND_BY], i)
1616 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1626 /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
1638 static int transaction_add_isolate_jobs(Manager *m) {
1646 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1648 /* ignore aliases */
1649 if (u->meta.id != k)
1652 if (u->meta.ignore_on_isolate)
1655 /* No need to stop inactive jobs */
1656 if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->meta.job)
1659 /* Is there already something listed for this? */
1660 if (hashmap_get(m->transaction_jobs, u))
1663 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, false, false, false, NULL, NULL)) < 0)
1664 log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->meta.id, strerror(-r));
1670 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
1675 assert(type < _JOB_TYPE_MAX);
1677 assert(mode < _JOB_MODE_MAX);
1679 if (mode == JOB_ISOLATE && type != JOB_START) {
1680 dbus_set_error(e, BUS_ERROR_INVALID_JOB_MODE, "Isolate is only valid for start.");
1684 if (mode == JOB_ISOLATE && !unit->meta.allow_isolate) {
1685 dbus_set_error(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
1689 log_debug("Trying to enqueue job %s/%s/%s", unit->meta.id, job_type_to_string(type), job_mode_to_string(mode));
1691 if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, false,
1692 mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS,
1693 mode == JOB_IGNORE_DEPENDENCIES, e, &ret)) < 0) {
1694 transaction_abort(m);
1698 if (mode == JOB_ISOLATE)
1699 if ((r = transaction_add_isolate_jobs(m)) < 0) {
1700 transaction_abort(m);
1704 if ((r = transaction_activate(m, mode, e)) < 0)
1707 log_debug("Enqueued job %s/%s as %u", unit->meta.id, job_type_to_string(type), (unsigned) ret->id);
1715 int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, DBusError *e, Job **_ret) {
1720 assert(type < _JOB_TYPE_MAX);
1722 assert(mode < _JOB_MODE_MAX);
1724 if ((r = manager_load_unit(m, name, NULL, NULL, &unit)) < 0)
1727 return manager_add_job(m, type, unit, mode, override, e, _ret);
1730 Job *manager_get_job(Manager *m, uint32_t id) {
1733 return hashmap_get(m->jobs, UINT32_TO_PTR(id));
1736 Unit *manager_get_unit(Manager *m, const char *name) {
1740 return hashmap_get(m->units, name);
1743 unsigned manager_dispatch_load_queue(Manager *m) {
1749 /* Make sure we are not run recursively */
1750 if (m->dispatching_load_queue)
1753 m->dispatching_load_queue = true;
1755 /* Dispatches the load queue. Takes a unit from the queue and
1756 * tries to load its data until the queue is empty */
1758 while ((meta = m->load_queue)) {
1759 assert(meta->in_load_queue);
1761 unit_load((Unit*) meta);
1765 m->dispatching_load_queue = false;
1769 int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
1774 assert(name || path);
1776 /* This will prepare the unit for loading, but not actually
1777 * load anything from disk. */
1779 if (path && !is_path(path)) {
1780 dbus_set_error(e, BUS_ERROR_INVALID_PATH, "Path %s is not absolute.", path);
1785 name = file_name_from_path(path);
1787 if (!unit_name_is_valid(name, false)) {
1788 dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
1792 if ((ret = manager_get_unit(m, name))) {
1797 if (!(ret = unit_new(m)))
1801 if (!(ret->meta.fragment_path = strdup(path))) {
1806 if ((r = unit_add_name(ret, name)) < 0) {
1811 unit_add_to_load_queue(ret);
1812 unit_add_to_dbus_queue(ret);
1813 unit_add_to_gc_queue(ret);
1821 int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
1826 /* This will load the service information files, but not actually
1827 * start any services or anything. */
1829 if ((r = manager_load_unit_prepare(m, name, path, e, _ret)) != 0)
1832 manager_dispatch_load_queue(m);
1835 *_ret = unit_follow_merge(*_ret);
1840 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
1847 HASHMAP_FOREACH(j, s->jobs, i)
1848 job_dump(j, f, prefix);
1851 void manager_dump_units(Manager *s, FILE *f, const char *prefix) {
1859 HASHMAP_FOREACH_KEY(u, t, s->units, i)
1860 if (u->meta.id == t)
1861 unit_dump(u, f, prefix);
1864 void manager_clear_jobs(Manager *m) {
1869 transaction_abort(m);
1871 while ((j = hashmap_first(m->jobs)))
1872 job_finish_and_invalidate(j, JOB_CANCELED);
1875 unsigned manager_dispatch_run_queue(Manager *m) {
1879 if (m->dispatching_run_queue)
1882 m->dispatching_run_queue = true;
1884 while ((j = m->run_queue)) {
1885 assert(j->installed);
1886 assert(j->in_run_queue);
1888 job_run_and_invalidate(j);
1892 m->dispatching_run_queue = false;
1896 unsigned manager_dispatch_dbus_queue(Manager *m) {
1903 if (m->dispatching_dbus_queue)
1906 m->dispatching_dbus_queue = true;
1908 while ((meta = m->dbus_unit_queue)) {
1909 assert(meta->in_dbus_queue);
1911 bus_unit_send_change_signal((Unit*) meta);
1915 while ((j = m->dbus_job_queue)) {
1916 assert(j->in_dbus_queue);
1918 bus_job_send_change_signal(j);
1922 m->dispatching_dbus_queue = false;
1926 static int manager_process_notify_fd(Manager *m) {
1933 struct msghdr msghdr;
1935 struct ucred *ucred;
1937 struct cmsghdr cmsghdr;
1938 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
1944 iovec.iov_base = buf;
1945 iovec.iov_len = sizeof(buf)-1;
1949 msghdr.msg_iov = &iovec;
1950 msghdr.msg_iovlen = 1;
1951 msghdr.msg_control = &control;
1952 msghdr.msg_controllen = sizeof(control);
1954 if ((n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT)) <= 0) {
1958 if (errno == EAGAIN || errno == EINTR)
1964 if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) ||
1965 control.cmsghdr.cmsg_level != SOL_SOCKET ||
1966 control.cmsghdr.cmsg_type != SCM_CREDENTIALS ||
1967 control.cmsghdr.cmsg_len != CMSG_LEN(sizeof(struct ucred))) {
1968 log_warning("Received notify message without credentials. Ignoring.");
1972 ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
1974 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid))))
1975 if (!(u = cgroup_unit_by_pid(m, ucred->pid))) {
1976 log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
1980 assert((size_t) n < sizeof(buf));
1982 if (!(tags = strv_split(buf, "\n\r")))
1985 log_debug("Got notification message for unit %s", u->meta.id);
1987 if (UNIT_VTABLE(u)->notify_message)
1988 UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags);
1996 static int manager_dispatch_sigchld(Manager *m) {
2006 /* First we call waitd() for a PID and do not reap the
2007 * zombie. That way we can still access /proc/$PID for
2008 * it while it is a zombie. */
2009 if (waitid(P_ALL, 0, &si, WEXITED|WNOHANG|WNOWAIT) < 0) {
2011 if (errno == ECHILD)
2023 if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
2026 get_process_name(si.si_pid, &name);
2027 log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name));
2031 /* Let's flush any message the dying child might still
2032 * have queued for us. This ensures that the process
2033 * still exists in /proc so that we can figure out
2034 * which cgroup and hence unit it belongs to. */
2035 if ((r = manager_process_notify_fd(m)) < 0)
2038 /* And now figure out the unit this belongs to */
2039 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid))))
2040 u = cgroup_unit_by_pid(m, si.si_pid);
2042 /* And now, we actually reap the zombie. */
2043 if (waitid(P_PID, si.si_pid, &si, WEXITED) < 0) {
2050 if (si.si_code != CLD_EXITED && si.si_code != CLD_KILLED && si.si_code != CLD_DUMPED)
2053 log_debug("Child %lu died (code=%s, status=%i/%s)",
2054 (long unsigned) si.si_pid,
2055 sigchld_code_to_string(si.si_code),
2057 strna(si.si_code == CLD_EXITED
2058 ? exit_status_to_string(si.si_status, EXIT_STATUS_FULL)
2059 : signal_to_string(si.si_status)));
2064 log_debug("Child %lu belongs to %s", (long unsigned) si.si_pid, u->meta.id);
2066 hashmap_remove(m->watch_pids, LONG_TO_PTR(si.si_pid));
2067 UNIT_VTABLE(u)->sigchld_event(u, si.si_pid, si.si_code, si.si_status);
2073 static int manager_start_target(Manager *m, const char *name, JobMode mode) {
2077 dbus_error_init(&error);
2079 log_debug("Activating special unit %s", name);
2081 if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
2082 log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
2084 dbus_error_free(&error);
2089 static int manager_process_signal_fd(Manager *m) {
2091 struct signalfd_siginfo sfsi;
2092 bool sigchld = false;
2097 if ((n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
2102 if (errno == EINTR || errno == EAGAIN)
2108 if (sfsi.ssi_pid > 0) {
2111 get_process_name(sfsi.ssi_pid, &p);
2113 log_debug("Received SIG%s from PID %lu (%s).",
2114 strna(signal_to_string(sfsi.ssi_signo)),
2115 (unsigned long) sfsi.ssi_pid, strna(p));
2118 log_debug("Received SIG%s.", strna(signal_to_string(sfsi.ssi_signo)));
2120 switch (sfsi.ssi_signo) {
2127 if (m->running_as == MANAGER_SYSTEM) {
2128 /* This is for compatibility with the
2129 * original sysvinit */
2130 m->exit_code = MANAGER_REEXECUTE;
2137 if (m->running_as == MANAGER_SYSTEM) {
2138 manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE);
2142 /* Run the exit target if there is one, if not, just exit. */
2143 if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) {
2144 m->exit_code = MANAGER_EXIT;
2151 if (m->running_as == MANAGER_SYSTEM)
2152 manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
2154 /* This is a nop on non-init */
2158 if (m->running_as == MANAGER_SYSTEM)
2159 manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
2161 /* This is a nop on non-init */
2167 u = manager_get_unit(m, SPECIAL_DBUS_SERVICE);
2169 if (!u || UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u))) {
2170 log_info("Trying to reconnect to bus...");
2174 if (!u || !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) {
2175 log_info("Loading D-Bus service...");
2176 manager_start_target(m, SPECIAL_DBUS_SERVICE, JOB_REPLACE);
2187 if (!(f = open_memstream(&dump, &size))) {
2188 log_warning("Failed to allocate memory stream.");
2192 manager_dump_units(m, f, "\t");
2193 manager_dump_jobs(m, f, "\t");
2198 log_warning("Failed to write status stream");
2203 log_dump(LOG_INFO, dump);
2210 m->exit_code = MANAGER_RELOAD;
2215 /* Starting SIGRTMIN+0 */
2216 static const char * const target_table[] = {
2217 [0] = SPECIAL_DEFAULT_TARGET,
2218 [1] = SPECIAL_RESCUE_TARGET,
2219 [2] = SPECIAL_EMERGENCY_TARGET,
2220 [3] = SPECIAL_HALT_TARGET,
2221 [4] = SPECIAL_POWEROFF_TARGET,
2222 [5] = SPECIAL_REBOOT_TARGET,
2223 [6] = SPECIAL_KEXEC_TARGET
2226 /* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */
2227 static const ManagerExitCode code_table[] = {
2229 [1] = MANAGER_POWEROFF,
2230 [2] = MANAGER_REBOOT,
2234 if ((int) sfsi.ssi_signo >= SIGRTMIN+0 &&
2235 (int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(target_table)) {
2236 manager_start_target(m, target_table[sfsi.ssi_signo - SIGRTMIN],
2237 (sfsi.ssi_signo == 1 || sfsi.ssi_signo == 2) ? JOB_ISOLATE : JOB_REPLACE);
2241 if ((int) sfsi.ssi_signo >= SIGRTMIN+13 &&
2242 (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(code_table)) {
2243 m->exit_code = code_table[sfsi.ssi_signo - SIGRTMIN - 13];
2247 switch (sfsi.ssi_signo - SIGRTMIN) {
2250 log_debug("Enabling showing of status.");
2251 m->show_status = true;
2255 log_debug("Disabling showing of status.");
2256 m->show_status = false;
2260 log_set_max_level(LOG_DEBUG);
2261 log_notice("Setting log level to debug.");
2265 log_set_max_level(LOG_INFO);
2266 log_notice("Setting log level to info.");
2270 log_set_target(LOG_TARGET_CONSOLE);
2271 log_notice("Setting log target to console.");
2275 log_set_target(LOG_TARGET_KMSG);
2276 log_notice("Setting log target to kmsg.");
2280 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
2281 log_notice("Setting log target to syslog-or-kmsg.");
2285 log_warning("Got unhandled signal <%s>.", strna(signal_to_string(sfsi.ssi_signo)));
2292 return manager_dispatch_sigchld(m);
2297 static int process_event(Manager *m, struct epoll_event *ev) {
2304 assert_se(w = ev->data.ptr);
2306 if (w->type == WATCH_INVALID)
2313 /* An incoming signal? */
2314 if (ev->events != EPOLLIN)
2317 if ((r = manager_process_signal_fd(m)) < 0)
2324 /* An incoming daemon notification event? */
2325 if (ev->events != EPOLLIN)
2328 if ((r = manager_process_notify_fd(m)) < 0)
2335 /* Some fd event, to be dispatched to the units */
2336 UNIT_VTABLE(w->data.unit)->fd_event(w->data.unit, w->fd, ev->events, w);
2339 case WATCH_UNIT_TIMER:
2340 case WATCH_JOB_TIMER: {
2344 /* Some timer event, to be dispatched to the units */
2345 if ((k = read(w->fd, &v, sizeof(v))) != sizeof(v)) {
2347 if (k < 0 && (errno == EINTR || errno == EAGAIN))
2350 return k < 0 ? -errno : -EIO;
2353 if (w->type == WATCH_UNIT_TIMER)
2354 UNIT_VTABLE(w->data.unit)->timer_event(w->data.unit, v, w);
2356 job_timer_event(w->data.job, v, w);
2361 /* Some mount table change, intended for the mount subsystem */
2362 mount_fd_event(m, ev->events);
2366 /* Some swap table change, intended for the swap subsystem */
2367 swap_fd_event(m, ev->events);
2371 /* Some notification from udev, intended for the device subsystem */
2372 device_fd_event(m, ev->events);
2375 case WATCH_DBUS_WATCH:
2376 bus_watch_event(m, w, ev->events);
2379 case WATCH_DBUS_TIMEOUT:
2380 bus_timeout_event(m, w, ev->events);
2384 log_error("event type=%i", w->type);
2385 assert_not_reached("Unknown epoll event type.");
2391 int manager_loop(Manager *m) {
2394 RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
2397 m->exit_code = MANAGER_RUNNING;
2399 /* Release the path cache */
2400 set_free_free(m->unit_path_cache);
2401 m->unit_path_cache = NULL;
2403 manager_check_finished(m);
2405 /* There might still be some zombies hanging around from
2406 * before we were exec()'ed. Leat's reap them */
2407 if ((r = manager_dispatch_sigchld(m)) < 0)
2410 while (m->exit_code == MANAGER_RUNNING) {
2411 struct epoll_event event;
2414 if (!ratelimit_test(&rl)) {
2415 /* Yay, something is going seriously wrong, pause a little */
2416 log_warning("Looping too fast. Throttling execution a little.");
2420 if (manager_dispatch_load_queue(m) > 0)
2423 if (manager_dispatch_run_queue(m) > 0)
2426 if (bus_dispatch(m) > 0)
2429 if (manager_dispatch_cleanup_queue(m) > 0)
2432 if (manager_dispatch_gc_queue(m) > 0)
2435 if (manager_dispatch_dbus_queue(m) > 0)
2438 if (swap_dispatch_reload(m) > 0)
2441 if ((n = epoll_wait(m->epoll_fd, &event, 1, -1)) < 0) {
2451 if ((r = process_event(m, &event)) < 0)
2455 return m->exit_code;
2458 int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u) {
2466 if (!startswith(s, "/org/freedesktop/systemd1/unit/"))
2469 if (!(n = bus_path_unescape(s+31)))
2472 u = manager_get_unit(m, n);
2483 int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j) {
2492 if (!startswith(s, "/org/freedesktop/systemd1/job/"))
2495 if ((r = safe_atou(s + 30, &id)) < 0)
2498 if (!(j = manager_get_job(m, id)))
2506 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
2511 if (m->audit_fd < 0)
2514 /* Don't generate audit events if the service was already
2515 * started and we're just deserializing */
2516 if (m->n_reloading > 0)
2519 if (m->running_as != MANAGER_SYSTEM)
2522 if (u->meta.type != UNIT_SERVICE)
2525 if (!(p = unit_name_to_prefix_and_instance(u->meta.id))) {
2526 log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
2530 if (audit_log_user_comm_message(m->audit_fd, type, "", p, NULL, NULL, NULL, success) < 0) {
2531 log_warning("Failed to send audit message: %m");
2533 if (errno == EPERM) {
2534 /* We aren't allowed to send audit messages?
2535 * Then let's not retry again, to avoid
2536 * spamming the user with the same and same
2537 * messages over and over. */
2539 audit_close(m->audit_fd);
2549 void manager_send_unit_plymouth(Manager *m, Unit *u) {
2551 union sockaddr_union sa;
2553 char *message = NULL;
2555 /* Don't generate plymouth events if the service was already
2556 * started and we're just deserializing */
2557 if (m->n_reloading > 0)
2560 if (m->running_as != MANAGER_SYSTEM)
2563 if (u->meta.type != UNIT_SERVICE &&
2564 u->meta.type != UNIT_MOUNT &&
2565 u->meta.type != UNIT_SWAP)
2568 /* We set SOCK_NONBLOCK here so that we rather drop the
2569 * message then wait for plymouth */
2570 if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
2571 log_error("socket() failed: %m");
2576 sa.sa.sa_family = AF_UNIX;
2577 strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1);
2578 if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
2580 if (errno != EPIPE &&
2583 errno != ECONNREFUSED &&
2584 errno != ECONNRESET &&
2585 errno != ECONNABORTED)
2586 log_error("connect() failed: %m");
2591 if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->meta.id) + 1), u->meta.id, &n) < 0) {
2592 log_error("Out of memory");
2597 if (write(fd, message, n + 1) != n + 1) {
2599 if (errno != EPIPE &&
2602 errno != ECONNREFUSED &&
2603 errno != ECONNRESET &&
2604 errno != ECONNABORTED)
2605 log_error("Failed to write Plymouth message: %m");
2612 close_nointr_nofail(fd);
2617 void manager_dispatch_bus_name_owner_changed(
2620 const char* old_owner,
2621 const char *new_owner) {
2628 if (!(u = hashmap_get(m->watch_bus, name)))
2631 UNIT_VTABLE(u)->bus_name_owner_change(u, name, old_owner, new_owner);
2634 void manager_dispatch_bus_query_pid_done(
2645 if (!(u = hashmap_get(m->watch_bus, name)))
2648 UNIT_VTABLE(u)->bus_query_pid_done(u, name, pid);
2651 int manager_open_serialization(Manager *m, FILE **_f) {
2659 if (m->running_as == MANAGER_SYSTEM)
2660 asprintf(&path, "/run/systemd/dump-%lu-XXXXXX", (unsigned long) getpid());
2662 asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
2667 saved_umask = umask(0077);
2668 fd = mkostemp(path, O_RDWR|O_CLOEXEC);
2678 log_debug("Serializing state to %s", path);
2681 if (!(f = fdopen(fd, "w+")))
2689 int manager_serialize(Manager *m, FILE *f, FDSet *fds) {
2701 fprintf(f, "current-job-id=%i\n", m->current_job_id);
2702 fprintf(f, "taint-usr=%s\n", yes_no(m->taint_usr));
2704 dual_timestamp_serialize(f, "initrd-timestamp", &m->initrd_timestamp);
2705 dual_timestamp_serialize(f, "startup-timestamp", &m->startup_timestamp);
2706 dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp);
2710 HASHMAP_FOREACH_KEY(u, t, m->units, i) {
2711 if (u->meta.id != t)
2714 if (!unit_can_serialize(u))
2718 fputs(u->meta.id, f);
2721 if ((r = unit_serialize(u, f, fds)) < 0) {
2727 assert(m->n_reloading > 0);
2733 r = bus_fdset_add_all(m, fds);
2740 int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
2746 log_debug("Deserializing state...");
2751 char line[LINE_MAX], *l;
2753 if (!fgets(line, sizeof(line), f)) {
2768 if (startswith(l, "current-job-id=")) {
2771 if (safe_atou32(l+15, &id) < 0)
2772 log_debug("Failed to parse current job id value %s", l+15);
2774 m->current_job_id = MAX(m->current_job_id, id);
2775 } else if (startswith(l, "taint-usr=")) {
2778 if ((b = parse_boolean(l+10)) < 0)
2779 log_debug("Failed to parse taint /usr flag %s", l+10);
2781 m->taint_usr = m->taint_usr || b;
2782 } else if (startswith(l, "initrd-timestamp="))
2783 dual_timestamp_deserialize(l+17, &m->initrd_timestamp);
2784 else if (startswith(l, "startup-timestamp="))
2785 dual_timestamp_deserialize(l+18, &m->startup_timestamp);
2786 else if (startswith(l, "finish-timestamp="))
2787 dual_timestamp_deserialize(l+17, &m->finish_timestamp);
2789 log_debug("Unknown serialization item '%s'", l);
2794 char name[UNIT_NAME_MAX+2];
2797 if (!fgets(name, sizeof(name), f)) {
2808 if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
2811 if ((r = unit_deserialize(u, f, fds)) < 0)
2821 assert(m->n_reloading > 0);
2827 int manager_reload(Manager *m) {
2834 if ((r = manager_open_serialization(m, &f)) < 0)
2839 if (!(fds = fdset_new())) {
2845 if ((r = manager_serialize(m, f, fds)) < 0) {
2850 if (fseeko(f, 0, SEEK_SET) < 0) {
2856 /* From here on there is no way back. */
2857 manager_clear_jobs_and_units(m);
2858 manager_undo_generators(m);
2860 /* Find new unit paths */
2861 lookup_paths_free(&m->lookup_paths);
2862 if ((q = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0)
2865 manager_run_generators(m);
2867 manager_build_unit_path_cache(m);
2869 /* First, enumerate what we can from all config files */
2870 if ((q = manager_enumerate(m)) < 0)
2873 /* Second, deserialize our stored data */
2874 if ((q = manager_deserialize(m, f, fds)) < 0)
2880 /* Third, fire things up! */
2881 if ((q = manager_coldplug(m)) < 0)
2884 assert(m->n_reloading > 0);
2897 bool manager_is_booting_or_shutting_down(Manager *m) {
2902 /* Is the initial job still around? */
2903 if (manager_get_job(m, 1))
2906 /* Is there a job for the shutdown target? */
2907 if (((u = manager_get_unit(m, SPECIAL_SHUTDOWN_TARGET))))
2908 return !!u->meta.job;
2913 void manager_reset_failed(Manager *m) {
2919 HASHMAP_FOREACH(u, m->units, i)
2920 unit_reset_failed(u);
2923 bool manager_unit_pending_inactive(Manager *m, const char *name) {
2929 /* Returns true if the unit is inactive or going down */
2930 if (!(u = manager_get_unit(m, name)))
2933 return unit_pending_inactive(u);
2936 void manager_check_finished(Manager *m) {
2937 char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
2938 usec_t kernel_usec = 0, initrd_usec = 0, userspace_usec = 0, total_usec = 0;
2942 if (dual_timestamp_is_set(&m->finish_timestamp))
2945 if (hashmap_size(m->jobs) > 0)
2948 dual_timestamp_get(&m->finish_timestamp);
2950 if (m->running_as == MANAGER_SYSTEM && detect_container(NULL) <= 0) {
2952 userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
2953 total_usec = m->finish_timestamp.monotonic;
2955 if (dual_timestamp_is_set(&m->initrd_timestamp)) {
2957 kernel_usec = m->initrd_timestamp.monotonic;
2958 initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
2960 log_info("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
2961 format_timespan(kernel, sizeof(kernel), kernel_usec),
2962 format_timespan(initrd, sizeof(initrd), initrd_usec),
2963 format_timespan(userspace, sizeof(userspace), userspace_usec),
2964 format_timespan(sum, sizeof(sum), total_usec));
2966 kernel_usec = m->startup_timestamp.monotonic;
2969 log_info("Startup finished in %s (kernel) + %s (userspace) = %s.",
2970 format_timespan(kernel, sizeof(kernel), kernel_usec),
2971 format_timespan(userspace, sizeof(userspace), userspace_usec),
2972 format_timespan(sum, sizeof(sum), total_usec));
2975 userspace_usec = initrd_usec = kernel_usec = 0;
2976 total_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
2978 log_debug("Startup finished in %s.",
2979 format_timespan(sum, sizeof(sum), total_usec));
2982 bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
2985 "READY=1\nSTATUS=Startup finished in %s.",
2986 format_timespan(sum, sizeof(sum), total_usec));
2989 void manager_run_generators(Manager *m) {
2991 const char *generator_path;
2992 const char *argv[3];
2997 generator_path = m->running_as == MANAGER_SYSTEM ? SYSTEM_GENERATOR_PATH : USER_GENERATOR_PATH;
2998 if (!(d = opendir(generator_path))) {
3000 if (errno == ENOENT)
3003 log_error("Failed to enumerate generator directory: %m");
3007 if (!m->generator_unit_path) {
3009 char user_path[] = "/tmp/systemd-generator-XXXXXX";
3011 if (m->running_as == MANAGER_SYSTEM && getpid() == 1) {
3012 p = "/run/systemd/generator";
3014 if (mkdir_p(p, 0755) < 0) {
3015 log_error("Failed to create generator directory: %m");
3020 if (!(p = mkdtemp(user_path))) {
3021 log_error("Failed to create generator directory: %m");
3026 if (!(m->generator_unit_path = strdup(p))) {
3027 log_error("Failed to allocate generator unit path.");
3032 argv[0] = NULL; /* Leave this empty, execute_directory() will fill something in */
3033 argv[1] = m->generator_unit_path;
3037 execute_directory(generator_path, d, (char**) argv);
3040 if (rmdir(m->generator_unit_path) >= 0) {
3041 /* Uh? we were able to remove this dir? I guess that
3042 * means the directory was empty, hence let's shortcut
3045 free(m->generator_unit_path);
3046 m->generator_unit_path = NULL;
3050 if (!strv_find(m->lookup_paths.unit_path, m->generator_unit_path)) {
3053 if (!(l = strv_append(m->lookup_paths.unit_path, m->generator_unit_path))) {
3054 log_error("Failed to add generator directory to unit search path: %m");
3058 strv_free(m->lookup_paths.unit_path);
3059 m->lookup_paths.unit_path = l;
3061 log_debug("Added generator unit path %s to search path.", m->generator_unit_path);
3069 void manager_undo_generators(Manager *m) {
3072 if (!m->generator_unit_path)
3075 strv_remove(m->lookup_paths.unit_path, m->generator_unit_path);
3076 rm_rf(m->generator_unit_path, false, true);
3078 free(m->generator_unit_path);
3079 m->generator_unit_path = NULL;
3082 int manager_set_default_controllers(Manager *m, char **controllers) {
3087 if (!(l = strv_copy(controllers)))
3090 strv_free(m->default_controllers);
3091 m->default_controllers = l;
3096 void manager_recheck_syslog(Manager *m) {
3101 if (m->running_as != MANAGER_SYSTEM)
3104 if ((u = manager_get_unit(m, SPECIAL_SYSLOG_SOCKET))) {
3107 state = SOCKET(u)->state;
3109 if (state != SOCKET_DEAD &&
3110 state != SOCKET_FAILED &&
3111 state != SOCKET_RUNNING) {
3113 /* Hmm, the socket is not set up, or is still
3114 * listening, let's better not try to use
3115 * it. Note that we have no problem if the
3116 * socket is completely down, since there
3117 * might be a foreign /dev/log socket around
3118 * and we want to make use of that.
3126 if ((u = manager_get_unit(m, SPECIAL_SYSLOG_TARGET)))
3127 if (TARGET(u)->state != TARGET_ACTIVE) {
3132 /* Hmm, OK, so the socket is either fully up, or fully down,
3133 * and the target is up, then let's make use of the socket */
3137 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
3138 [MANAGER_SYSTEM] = "system",
3139 [MANAGER_USER] = "user"
3142 DEFINE_STRING_TABLE_LOOKUP(manager_running_as, ManagerRunningAs);