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>
44 #include <systemd/sd-daemon.h>
52 #include "ratelimit.h"
54 #include "mount-setup.h"
55 #include "unit-name.h"
56 #include "dbus-unit.h"
59 #include "path-lookup.h"
61 #include "bus-errors.h"
62 #include "exit-status.h"
65 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
66 #define GC_QUEUE_ENTRIES_MAX 16
68 /* As soon as 5s passed since a unit was added to our GC queue, make sure to run a gc sweep */
69 #define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC)
71 /* Where clients shall send notification messages to */
72 #define NOTIFY_SOCKET_SYSTEM "/run/systemd/notify"
73 #define NOTIFY_SOCKET_USER "@/org/freedesktop/systemd1/notify"
75 static int manager_setup_notify(Manager *m) {
78 struct sockaddr_un un;
80 struct epoll_event ev;
86 m->notify_watch.type = WATCH_NOTIFY;
87 if ((m->notify_watch.fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
88 log_error("Failed to allocate notification socket: %m");
93 sa.sa.sa_family = AF_UNIX;
96 snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET_USER "/%llu", random_ull());
98 unlink(NOTIFY_SOCKET_SYSTEM);
99 strncpy(sa.un.sun_path, NOTIFY_SOCKET_SYSTEM, sizeof(sa.un.sun_path));
102 if (sa.un.sun_path[0] == '@')
103 sa.un.sun_path[0] = 0;
106 r = bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1));
110 log_error("bind() failed: %m");
114 if (setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
115 log_error("SO_PASSCRED failed: %m");
121 ev.data.ptr = &m->notify_watch;
123 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0)
126 if (sa.un.sun_path[0] == 0)
127 sa.un.sun_path[0] = '@';
129 if (!(m->notify_socket = strdup(sa.un.sun_path)))
132 log_debug("Using notification socket %s", m->notify_socket);
137 static int enable_special_signals(Manager *m) {
142 /* Enable that we get SIGINT on control-alt-del */
143 if (reboot(RB_DISABLE_CAD) < 0)
144 log_warning("Failed to enable ctrl-alt-del handling: %m");
146 if ((fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
147 log_warning("Failed to open /dev/tty0: %m");
149 /* Enable that we get SIGWINCH on kbrequest */
150 if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
151 log_warning("Failed to enable kbrequest handling: %s", strerror(errno));
153 close_nointr_nofail(fd);
159 static int manager_setup_signals(Manager *m) {
161 struct epoll_event ev;
166 /* We are not interested in SIGSTOP and friends. */
168 sa.sa_handler = SIG_DFL;
169 sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
170 assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
172 assert_se(sigemptyset(&mask) == 0);
174 sigset_add_many(&mask,
175 SIGCHLD, /* Child died */
176 SIGTERM, /* Reexecute daemon */
177 SIGHUP, /* Reload configuration */
178 SIGUSR1, /* systemd/upstart: reconnect to D-Bus */
179 SIGUSR2, /* systemd: dump status */
180 SIGINT, /* Kernel sends us this on control-alt-del */
181 SIGWINCH, /* Kernel sends us this on kbrequest (alt-arrowup) */
182 SIGPWR, /* Some kernel drivers and upsd send us this on power failure */
183 SIGRTMIN+0, /* systemd: start default.target */
184 SIGRTMIN+1, /* systemd: isolate rescue.target */
185 SIGRTMIN+2, /* systemd: isolate emergency.target */
186 SIGRTMIN+3, /* systemd: start halt.target */
187 SIGRTMIN+4, /* systemd: start poweroff.target */
188 SIGRTMIN+5, /* systemd: start reboot.target */
189 SIGRTMIN+6, /* systemd: start kexec.target */
190 SIGRTMIN+13, /* systemd: Immediate halt */
191 SIGRTMIN+14, /* systemd: Immediate poweroff */
192 SIGRTMIN+15, /* systemd: Immediate reboot */
193 SIGRTMIN+16, /* systemd: Immediate kexec */
194 SIGRTMIN+20, /* systemd: enable status messages */
195 SIGRTMIN+21, /* systemd: disable status messages */
196 SIGRTMIN+22, /* systemd: set log level to LOG_DEBUG */
197 SIGRTMIN+23, /* systemd: set log level to LOG_INFO */
198 SIGRTMIN+26, /* systemd: set log target to journal-or-kmsg */
199 SIGRTMIN+27, /* systemd: set log target to console */
200 SIGRTMIN+28, /* systemd: set log target to kmsg */
201 SIGRTMIN+29, /* systemd: set log target to syslog-or-kmsg */
203 assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
205 m->signal_watch.type = WATCH_SIGNAL;
206 if ((m->signal_watch.fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC)) < 0)
211 ev.data.ptr = &m->signal_watch;
213 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
216 if (m->running_as == MANAGER_SYSTEM)
217 return enable_special_signals(m);
222 int manager_new(ManagerRunningAs running_as, Manager **_m) {
227 assert(running_as >= 0);
228 assert(running_as < _MANAGER_RUNNING_AS_MAX);
230 if (!(m = new0(Manager, 1)))
233 dual_timestamp_get(&m->startup_timestamp);
235 m->running_as = running_as;
236 m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
237 m->exit_code = _MANAGER_EXIT_CODE_INVALID;
238 m->pin_cgroupfs_fd = -1;
244 m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = m->dev_autofs_fd = m->swap_watch.fd = -1;
245 m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
247 if (!(m->environment = strv_copy(environ)))
250 if (running_as == MANAGER_SYSTEM) {
251 m->default_controllers = strv_new("cpu", NULL);
252 if (!m->default_controllers)
256 if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
259 if (!(m->jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
262 if (!(m->transaction_jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
265 if (!(m->watch_pids = hashmap_new(trivial_hash_func, trivial_compare_func)))
268 if (!(m->cgroup_bondings = hashmap_new(string_hash_func, string_compare_func)))
271 if (!(m->watch_bus = hashmap_new(string_hash_func, string_compare_func)))
274 if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
277 if ((r = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0)
280 if ((r = manager_setup_signals(m)) < 0)
283 if ((r = manager_setup_cgroup(m)) < 0)
286 if ((r = manager_setup_notify(m)) < 0)
289 /* Try to connect to the busses, if possible. */
290 if ((r = bus_init(m, running_as != MANAGER_SYSTEM)) < 0)
294 if ((m->audit_fd = audit_open()) < 0 &&
295 /* If the kernel lacks netlink or audit support,
296 * don't worry about it. */
297 errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
298 log_error("Failed to connect to audit log: %m");
301 m->taint_usr = dir_is_empty("/usr") > 0;
311 static unsigned manager_dispatch_cleanup_queue(Manager *m) {
317 while ((u = m->cleanup_queue)) {
318 assert(u->in_cleanup_queue);
328 GC_OFFSET_IN_PATH, /* This one is on the path we were traveling */
329 GC_OFFSET_UNSURE, /* No clue */
330 GC_OFFSET_GOOD, /* We still need this unit */
331 GC_OFFSET_BAD, /* We don't need this unit anymore */
335 static void unit_gc_sweep(Unit *u, unsigned gc_marker) {
342 if (u->gc_marker == gc_marker + GC_OFFSET_GOOD ||
343 u->gc_marker == gc_marker + GC_OFFSET_BAD ||
344 u->gc_marker == gc_marker + GC_OFFSET_IN_PATH)
347 if (u->in_cleanup_queue)
350 if (unit_check_gc(u))
353 u->gc_marker = gc_marker + GC_OFFSET_IN_PATH;
357 SET_FOREACH(other, u->dependencies[UNIT_REFERENCED_BY], i) {
358 unit_gc_sweep(other, gc_marker);
360 if (other->gc_marker == gc_marker + GC_OFFSET_GOOD)
363 if (other->gc_marker != gc_marker + GC_OFFSET_BAD)
370 /* We were unable to find anything out about this entry, so
371 * let's investigate it later */
372 u->gc_marker = gc_marker + GC_OFFSET_UNSURE;
373 unit_add_to_gc_queue(u);
377 /* We definitely know that this one is not useful anymore, so
378 * let's mark it for deletion */
379 u->gc_marker = gc_marker + GC_OFFSET_BAD;
380 unit_add_to_cleanup_queue(u);
384 u->gc_marker = gc_marker + GC_OFFSET_GOOD;
387 static unsigned manager_dispatch_gc_queue(Manager *m) {
394 if ((m->n_in_gc_queue < GC_QUEUE_ENTRIES_MAX) &&
395 (m->gc_queue_timestamp <= 0 ||
396 (m->gc_queue_timestamp + GC_QUEUE_USEC_MAX) > now(CLOCK_MONOTONIC)))
399 log_debug("Running GC...");
401 m->gc_marker += _GC_OFFSET_MAX;
402 if (m->gc_marker + _GC_OFFSET_MAX <= _GC_OFFSET_MAX)
405 gc_marker = m->gc_marker;
407 while ((u = m->gc_queue)) {
408 assert(u->in_gc_queue);
410 unit_gc_sweep(u, gc_marker);
412 LIST_REMOVE(Unit, gc_queue, m->gc_queue, u);
413 u->in_gc_queue = false;
417 if (u->gc_marker == gc_marker + GC_OFFSET_BAD ||
418 u->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
419 log_debug("Collecting %s", u->id);
420 u->gc_marker = gc_marker + GC_OFFSET_BAD;
421 unit_add_to_cleanup_queue(u);
425 m->n_in_gc_queue = 0;
426 m->gc_queue_timestamp = 0;
431 static void manager_clear_jobs_and_units(Manager *m) {
437 while ((j = hashmap_first(m->transaction_jobs)))
440 while ((u = hashmap_first(m->units)))
443 manager_dispatch_cleanup_queue(m);
445 assert(!m->load_queue);
446 assert(!m->run_queue);
447 assert(!m->dbus_unit_queue);
448 assert(!m->dbus_job_queue);
449 assert(!m->cleanup_queue);
450 assert(!m->gc_queue);
452 assert(hashmap_isempty(m->transaction_jobs));
453 assert(hashmap_isempty(m->jobs));
454 assert(hashmap_isempty(m->units));
457 void manager_free(Manager *m) {
462 manager_clear_jobs_and_units(m);
464 for (c = 0; c < _UNIT_TYPE_MAX; c++)
465 if (unit_vtable[c]->shutdown)
466 unit_vtable[c]->shutdown(m);
468 /* If we reexecute ourselves, we keep the root cgroup
470 manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE);
472 manager_undo_generators(m);
476 hashmap_free(m->units);
477 hashmap_free(m->jobs);
478 hashmap_free(m->transaction_jobs);
479 hashmap_free(m->watch_pids);
480 hashmap_free(m->watch_bus);
482 if (m->epoll_fd >= 0)
483 close_nointr_nofail(m->epoll_fd);
484 if (m->signal_watch.fd >= 0)
485 close_nointr_nofail(m->signal_watch.fd);
486 if (m->notify_watch.fd >= 0)
487 close_nointr_nofail(m->notify_watch.fd);
490 if (m->audit_fd >= 0)
491 audit_close(m->audit_fd);
494 free(m->notify_socket);
496 lookup_paths_free(&m->lookup_paths);
497 strv_free(m->environment);
499 strv_free(m->default_controllers);
501 hashmap_free(m->cgroup_bondings);
502 set_free_free(m->unit_path_cache);
507 int manager_enumerate(Manager *m) {
513 /* Let's ask every type to load all units from disk/kernel
514 * that it might know */
515 for (c = 0; c < _UNIT_TYPE_MAX; c++)
516 if (unit_vtable[c]->enumerate)
517 if ((q = unit_vtable[c]->enumerate(m)) < 0)
520 manager_dispatch_load_queue(m);
524 int manager_coldplug(Manager *m) {
532 /* Then, let's set up their initial state. */
533 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
539 if ((q = unit_coldplug(u)) < 0)
546 static void manager_build_unit_path_cache(Manager *m) {
553 set_free_free(m->unit_path_cache);
555 if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
556 log_error("Failed to allocate unit path cache.");
560 /* This simply builds a list of files we know exist, so that
561 * we don't always have to go to disk */
563 STRV_FOREACH(i, m->lookup_paths.unit_path) {
566 if (!(d = opendir(*i))) {
567 log_error("Failed to open directory: %m");
571 while ((de = readdir(d))) {
574 if (ignore_file(de->d_name))
577 p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL);
583 if ((r = set_put(m->unit_path_cache, p)) < 0) {
596 log_error("Failed to build unit path cache: %s", strerror(-r));
598 set_free_free(m->unit_path_cache);
599 m->unit_path_cache = NULL;
605 int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
610 manager_run_generators(m);
612 manager_build_unit_path_cache(m);
614 /* If we will deserialize make sure that during enumeration
615 * this is already known, so we increase the counter here
620 /* First, enumerate what we can from all config files */
621 r = manager_enumerate(m);
623 /* Second, deserialize if there is something to deserialize */
625 if ((q = manager_deserialize(m, serialization, fds)) < 0)
628 /* Third, fire things up! */
629 if ((q = manager_coldplug(m)) < 0)
633 assert(m->n_reloading > 0);
640 static void transaction_delete_job(Manager *m, Job *j, bool delete_dependencies) {
644 /* Deletes one job from the transaction */
646 manager_transaction_unlink_job(m, j, delete_dependencies);
652 static void transaction_delete_unit(Manager *m, Unit *u) {
655 /* Deletes all jobs associated with a certain unit from the
658 while ((j = hashmap_get(m->transaction_jobs, u)))
659 transaction_delete_job(m, j, true);
662 static void transaction_clean_dependencies(Manager *m) {
668 /* Drops all dependencies of all installed jobs */
670 HASHMAP_FOREACH(j, m->jobs, i) {
671 while (j->subject_list)
672 job_dependency_free(j->subject_list);
673 while (j->object_list)
674 job_dependency_free(j->object_list);
677 assert(!m->transaction_anchor);
680 static void transaction_abort(Manager *m) {
685 while ((j = hashmap_first(m->transaction_jobs)))
687 transaction_delete_job(m, j, true);
691 assert(hashmap_isempty(m->transaction_jobs));
693 transaction_clean_dependencies(m);
696 static void transaction_find_jobs_that_matter_to_anchor(Manager *m, Job *j, unsigned generation) {
701 /* A recursive sweep through the graph that marks all units
702 * that matter to the anchor job, i.e. are directly or
703 * indirectly a dependency of the anchor job via paths that
704 * are fully marked as mattering. */
709 l = m->transaction_anchor;
711 LIST_FOREACH(subject, l, l) {
713 /* This link does not matter */
717 /* This unit has already been marked */
718 if (l->object->generation == generation)
721 l->object->matters_to_anchor = true;
722 l->object->generation = generation;
724 transaction_find_jobs_that_matter_to_anchor(m, l->object, generation);
728 static void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, JobType t) {
729 JobDependency *l, *last;
733 assert(j->unit == other->unit);
734 assert(!j->installed);
736 /* Merges 'other' into 'j' and then deletes j. */
739 j->state = JOB_WAITING;
740 j->override = j->override || other->override;
742 j->matters_to_anchor = j->matters_to_anchor || other->matters_to_anchor;
744 /* Patch us in as new owner of the JobDependency objects */
746 LIST_FOREACH(subject, l, other->subject_list) {
747 assert(l->subject == other);
752 /* Merge both lists */
754 last->subject_next = j->subject_list;
756 j->subject_list->subject_prev = last;
757 j->subject_list = other->subject_list;
760 /* Patch us in as new owner of the JobDependency objects */
762 LIST_FOREACH(object, l, other->object_list) {
763 assert(l->object == other);
768 /* Merge both lists */
770 last->object_next = j->object_list;
772 j->object_list->object_prev = last;
773 j->object_list = other->object_list;
776 /* Kill the other job */
777 other->subject_list = NULL;
778 other->object_list = NULL;
779 transaction_delete_job(m, other, true);
781 static bool job_is_conflicted_by(Job *j) {
786 /* Returns true if this job is pulled in by a least one
787 * ConflictedBy dependency. */
789 LIST_FOREACH(object, l, j->object_list)
796 static int delete_one_unmergeable_job(Manager *m, Job *j) {
801 /* Tries to delete one item in the linked list
802 * j->transaction_next->transaction_next->... that conflicts
803 * with another one, in an attempt to make an inconsistent
804 * transaction work. */
806 /* We rely here on the fact that if a merged with b does not
807 * merge with c, either a or b merge with c neither */
808 LIST_FOREACH(transaction, j, j)
809 LIST_FOREACH(transaction, k, j->transaction_next) {
812 /* Is this one mergeable? Then skip it */
813 if (job_type_is_mergeable(j->type, k->type))
816 /* Ok, we found two that conflict, let's see if we can
817 * drop one of them */
818 if (!j->matters_to_anchor && !k->matters_to_anchor) {
820 /* Both jobs don't matter, so let's
821 * find the one that is smarter to
822 * remove. Let's think positive and
823 * rather remove stops then starts --
824 * except if something is being
825 * stopped because it is conflicted by
826 * another unit in which case we
827 * rather remove the start. */
829 log_debug("Looking at job %s/%s conflicted_by=%s", j->unit->id, job_type_to_string(j->type), yes_no(j->type == JOB_STOP && job_is_conflicted_by(j)));
830 log_debug("Looking at job %s/%s conflicted_by=%s", k->unit->id, job_type_to_string(k->type), yes_no(k->type == JOB_STOP && job_is_conflicted_by(k)));
832 if (j->type == JOB_STOP) {
834 if (job_is_conflicted_by(j))
839 } else if (k->type == JOB_STOP) {
841 if (job_is_conflicted_by(k))
848 } else if (!j->matters_to_anchor)
850 else if (!k->matters_to_anchor)
855 /* Ok, we can drop one, so let's do so. */
856 log_debug("Fixing conflicting jobs by deleting job %s/%s", d->unit->id, job_type_to_string(d->type));
857 transaction_delete_job(m, d, true);
864 static int transaction_merge_jobs(Manager *m, DBusError *e) {
871 /* First step, check whether any of the jobs for one specific
872 * task conflict. If so, try to drop one of them. */
873 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
878 LIST_FOREACH(transaction, k, j->transaction_next) {
879 if (job_type_merge(&t, k->type) >= 0)
882 /* OK, we could not merge all jobs for this
883 * action. Let's see if we can get rid of one
886 if ((r = delete_one_unmergeable_job(m, j)) >= 0)
887 /* Ok, we managed to drop one, now
888 * let's ask our callers to call us
889 * again after garbage collecting */
892 /* We couldn't merge anything. Failure */
893 dbus_set_error(e, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
894 job_type_to_string(t), job_type_to_string(k->type), k->unit->id);
899 /* Second step, merge the jobs. */
900 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
904 /* Merge all transactions */
905 LIST_FOREACH(transaction, k, j->transaction_next)
906 assert_se(job_type_merge(&t, k->type) == 0);
908 /* If an active job is mergeable, merge it too */
910 job_type_merge(&t, j->unit->job->type); /* Might fail. Which is OK */
912 while ((k = j->transaction_next)) {
914 transaction_merge_and_delete_job(m, k, j, t);
917 transaction_merge_and_delete_job(m, j, k, t);
920 if (j->unit->job && !j->installed)
921 transaction_merge_and_delete_job(m, j, j->unit->job, t);
923 assert(!j->transaction_next);
924 assert(!j->transaction_prev);
930 static void transaction_drop_redundant(Manager *m) {
935 /* Goes through the transaction and removes all jobs that are
944 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
945 bool changes_something = false;
948 LIST_FOREACH(transaction, k, j) {
950 if (!job_is_anchor(k) &&
951 (k->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))) &&
952 (!k->unit->job || !job_type_is_conflicting(k->type, k->unit->job->type)))
955 changes_something = true;
959 if (changes_something)
962 /* log_debug("Found redundant job %s/%s, dropping.", j->unit->id, job_type_to_string(j->type)); */
963 transaction_delete_job(m, j, false);
971 static bool unit_matters_to_anchor(Unit *u, Job *j) {
973 assert(!j->transaction_prev);
975 /* Checks whether at least one of the jobs for this unit
976 * matters to the anchor. */
978 LIST_FOREACH(transaction, j, j)
979 if (j->matters_to_anchor)
985 static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation, DBusError *e) {
992 assert(!j->transaction_prev);
994 /* Does a recursive sweep through the ordering graph, looking
995 * for a cycle. If we find cycle we try to break it. */
997 /* Have we seen this before? */
998 if (j->generation == generation) {
1001 /* If the marker is NULL we have been here already and
1002 * decided the job was loop-free from here. Hence
1003 * shortcut things and return right-away. */
1007 /* So, the marker is not NULL and we already have been
1008 * here. We have a cycle. Let's try to break it. We go
1009 * backwards in our path and try to find a suitable
1010 * job to remove. We use the marker to find our way
1011 * back, since smart how we are we stored our way back
1013 log_warning("Found ordering cycle on %s/%s", j->unit->id, job_type_to_string(j->type));
1016 for (k = from; k; k = ((k->generation == generation && k->marker != k) ? k->marker : NULL)) {
1018 log_info("Walked on cycle path to %s/%s", k->unit->id, job_type_to_string(k->type));
1022 !unit_matters_to_anchor(k->unit, k)) {
1023 /* Ok, we can drop this one, so let's
1028 /* Check if this in fact was the beginning of
1036 log_warning("Breaking ordering cycle by deleting job %s/%s", delete->unit->id, job_type_to_string(delete->type));
1037 transaction_delete_unit(m, delete->unit);
1041 log_error("Unable to break cycle");
1043 dbus_set_error(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See system logs for details.");
1047 /* Make the marker point to where we come from, so that we can
1048 * find our way backwards if we want to break a cycle. We use
1049 * a special marker for the beginning: we point to
1051 j->marker = from ? from : j;
1052 j->generation = generation;
1054 /* We assume that the the dependencies are bidirectional, and
1055 * hence can ignore UNIT_AFTER */
1056 SET_FOREACH(u, j->unit->dependencies[UNIT_BEFORE], i) {
1059 /* Is there a job for this unit? */
1060 if (!(o = hashmap_get(m->transaction_jobs, u)))
1062 /* Ok, there is no job for this in the
1063 * transaction, but maybe there is already one
1068 if ((r = transaction_verify_order_one(m, o, j, generation, e)) < 0)
1072 /* Ok, let's backtrack, and remember that this entry is not on
1073 * our path anymore. */
1079 static int transaction_verify_order(Manager *m, unsigned *generation, DBusError *e) {
1088 /* Check if the ordering graph is cyclic. If it is, try to fix
1089 * that up by dropping one of the jobs. */
1091 g = (*generation)++;
1093 HASHMAP_FOREACH(j, m->transaction_jobs, i)
1094 if ((r = transaction_verify_order_one(m, j, NULL, g, e)) < 0)
1100 static void transaction_collect_garbage(Manager *m) {
1105 /* Drop jobs that are not required by any other job */
1113 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1114 if (j->object_list) {
1115 /* log_debug("Keeping job %s/%s because of %s/%s", */
1116 /* j->unit->id, job_type_to_string(j->type), */
1117 /* j->object_list->subject ? j->object_list->subject->unit->id : "root", */
1118 /* j->object_list->subject ? job_type_to_string(j->object_list->subject->type) : "root"); */
1122 /* log_debug("Garbage collecting job %s/%s", j->unit->id, job_type_to_string(j->type)); */
1123 transaction_delete_job(m, j, true);
1131 static int transaction_is_destructive(Manager *m, DBusError *e) {
1137 /* Checks whether applying this transaction means that
1138 * existing jobs would be replaced */
1140 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1143 assert(!j->transaction_prev);
1144 assert(!j->transaction_next);
1147 j->unit->job != j &&
1148 !job_type_is_superset(j->type, j->unit->job->type)) {
1150 dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
1158 static void transaction_minimize_impact(Manager *m) {
1162 /* Drops all unnecessary jobs that reverse already active jobs
1163 * or that stop a running service. */
1171 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1172 LIST_FOREACH(transaction, j, j) {
1173 bool stops_running_service, changes_existing_job;
1175 /* If it matters, we shouldn't drop it */
1176 if (j->matters_to_anchor)
1179 /* Would this stop a running service?
1180 * Would this change an existing job?
1181 * If so, let's drop this entry */
1183 stops_running_service =
1184 j->type == JOB_STOP && UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(j->unit));
1186 changes_existing_job =
1188 job_type_is_conflicting(j->type, j->unit->job->type);
1190 if (!stops_running_service && !changes_existing_job)
1193 if (stops_running_service)
1194 log_debug("%s/%s would stop a running service.", j->unit->id, job_type_to_string(j->type));
1196 if (changes_existing_job)
1197 log_debug("%s/%s would change existing job.", j->unit->id, job_type_to_string(j->type));
1199 /* Ok, let's get rid of this */
1200 log_debug("Deleting %s/%s to minimize impact.", j->unit->id, job_type_to_string(j->type));
1202 transaction_delete_job(m, j, true);
1214 static int transaction_apply(Manager *m, JobMode mode) {
1219 /* Moves the transaction jobs to the set of active jobs */
1221 if (mode == JOB_ISOLATE) {
1223 /* When isolating first kill all installed jobs which
1224 * aren't part of the new transaction */
1226 HASHMAP_FOREACH(j, m->jobs, i) {
1227 assert(j->installed);
1229 if (hashmap_get(m->transaction_jobs, j->unit))
1232 /* 'j' itself is safe to remove, but if other jobs
1233 are invalidated recursively, our iterator may become
1234 invalid and we need to start over. */
1235 if (job_finish_and_invalidate(j, JOB_CANCELED) > 0)
1240 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1242 assert(!j->transaction_prev);
1243 assert(!j->transaction_next);
1248 if ((r = hashmap_put(m->jobs, UINT32_TO_PTR(j->id), j)) < 0)
1252 while ((j = hashmap_steal_first(m->transaction_jobs))) {
1254 /* log_debug("Skipping already installed job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); */
1259 job_free(j->unit->job);
1262 j->installed = true;
1263 m->n_installed_jobs ++;
1265 /* We're fully installed. Now let's free data we don't
1268 assert(!j->transaction_next);
1269 assert(!j->transaction_prev);
1271 job_add_to_run_queue(j);
1272 job_add_to_dbus_queue(j);
1275 log_debug("Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id);
1278 /* As last step, kill all remaining job dependencies. */
1279 transaction_clean_dependencies(m);
1285 HASHMAP_FOREACH(j, m->transaction_jobs, i) {
1289 hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
1295 static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
1297 unsigned generation = 1;
1301 /* This applies the changes recorded in transaction_jobs to
1302 * the actual list of jobs, if possible. */
1304 /* First step: figure out which jobs matter */
1305 transaction_find_jobs_that_matter_to_anchor(m, NULL, generation++);
1307 /* Second step: Try not to stop any running services if
1308 * we don't have to. Don't try to reverse running
1309 * jobs if we don't have to. */
1310 if (mode == JOB_FAIL)
1311 transaction_minimize_impact(m);
1313 /* Third step: Drop redundant jobs */
1314 transaction_drop_redundant(m);
1317 /* Fourth step: Let's remove unneeded jobs that might
1319 if (mode != JOB_ISOLATE)
1320 transaction_collect_garbage(m);
1322 /* Fifth step: verify order makes sense and correct
1323 * cycles if necessary and possible */
1324 if ((r = transaction_verify_order(m, &generation, e)) >= 0)
1328 log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e, r));
1332 /* Let's see if the resulting transaction ordering
1333 * graph is still cyclic... */
1337 /* Sixth step: let's drop unmergeable entries if
1338 * necessary and possible, merge entries we can
1340 if ((r = transaction_merge_jobs(m, e)) >= 0)
1344 log_warning("Requested transaction contains unmergeable jobs: %s", bus_error(e, r));
1348 /* Seventh step: an entry got dropped, let's garbage
1349 * collect its dependencies. */
1350 if (mode != JOB_ISOLATE)
1351 transaction_collect_garbage(m);
1353 /* Let's see if the resulting transaction still has
1354 * unmergeable entries ... */
1357 /* Eights step: Drop redundant jobs again, if the merging now allows us to drop more. */
1358 transaction_drop_redundant(m);
1360 /* Ninth step: check whether we can actually apply this */
1361 if (mode == JOB_FAIL)
1362 if ((r = transaction_is_destructive(m, e)) < 0) {
1363 log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
1367 /* Tenth step: apply changes */
1368 if ((r = transaction_apply(m, mode)) < 0) {
1369 log_warning("Failed to apply transaction: %s", strerror(-r));
1373 assert(hashmap_isempty(m->transaction_jobs));
1374 assert(!m->transaction_anchor);
1379 transaction_abort(m);
1383 static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool override, bool *is_new) {
1389 /* Looks for an existing prospective job and returns that. If
1390 * it doesn't exist it is created and added to the prospective
1393 f = hashmap_get(m->transaction_jobs, unit);
1395 LIST_FOREACH(transaction, j, f) {
1396 assert(j->unit == unit);
1398 if (j->type == type) {
1405 if (unit->job && unit->job->type == type)
1407 else if (!(j = job_new(m, type, unit)))
1412 j->matters_to_anchor = false;
1413 j->override = override;
1415 LIST_PREPEND(Job, transaction, f, j);
1417 if (hashmap_replace(m->transaction_jobs, unit, f) < 0) {
1425 /* log_debug("Added job %s/%s to transaction.", unit->id, job_type_to_string(type)); */
1430 void manager_transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
1434 if (j->transaction_prev)
1435 j->transaction_prev->transaction_next = j->transaction_next;
1436 else if (j->transaction_next)
1437 hashmap_replace(m->transaction_jobs, j->unit, j->transaction_next);
1439 hashmap_remove_value(m->transaction_jobs, j->unit, j);
1441 if (j->transaction_next)
1442 j->transaction_next->transaction_prev = j->transaction_prev;
1444 j->transaction_prev = j->transaction_next = NULL;
1446 while (j->subject_list)
1447 job_dependency_free(j->subject_list);
1449 while (j->object_list) {
1450 Job *other = j->object_list->matters ? j->object_list->subject : NULL;
1452 job_dependency_free(j->object_list);
1454 if (other && delete_dependencies) {
1455 log_debug("Deleting job %s/%s as dependency of job %s/%s",
1456 other->unit->id, job_type_to_string(other->type),
1457 j->unit->id, job_type_to_string(j->type));
1458 transaction_delete_job(m, other, delete_dependencies);
1463 static int transaction_add_job_and_dependencies(
1471 bool ignore_requirements,
1482 assert(type < _JOB_TYPE_MAX);
1485 /* log_debug("Pulling in %s/%s from %s/%s", */
1486 /* unit->id, job_type_to_string(type), */
1487 /* by ? by->unit->id : "NA", */
1488 /* by ? job_type_to_string(by->type) : "NA"); */
1490 if (unit->load_state != UNIT_LOADED &&
1491 unit->load_state != UNIT_ERROR &&
1492 unit->load_state != UNIT_MASKED) {
1493 dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->id);
1497 if (type != JOB_STOP && unit->load_state == UNIT_ERROR) {
1498 dbus_set_error(e, BUS_ERROR_LOAD_FAILED,
1499 "Unit %s failed to load: %s. "
1500 "See system logs and 'systemctl status %s' for details.",
1502 strerror(-unit->load_error),
1507 if (type != JOB_STOP && unit->load_state == UNIT_MASKED) {
1508 dbus_set_error(e, BUS_ERROR_MASKED, "Unit %s is masked.", unit->id);
1512 if (!unit_job_is_applicable(unit, type)) {
1513 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->id);
1517 /* First add the job. */
1518 if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
1521 ret->ignore_order = ret->ignore_order || ignore_order;
1523 /* Then, add a link to the job. */
1524 if (!job_dependency_new(by, ret, matters, conflicts))
1527 if (is_new && !ignore_requirements) {
1530 /* If we are following some other unit, make sure we
1531 * add all dependencies of everybody following. */
1532 if (unit_following_set(ret->unit, &following) > 0) {
1533 SET_FOREACH(dep, following, i)
1534 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, false, override, false, false, ignore_order, e, NULL)) < 0) {
1535 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1541 set_free(following);
1544 /* Finally, recursively add in all dependencies. */
1545 if (type == JOB_START || type == JOB_RELOAD_OR_START) {
1546 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i)
1547 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1555 SET_FOREACH(dep, ret->unit->dependencies[UNIT_BIND_TO], i)
1556 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1565 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
1566 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, false, false, ignore_order, e, NULL)) < 0) {
1567 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1573 SET_FOREACH(dep, ret->unit->dependencies[UNIT_WANTS], i)
1574 if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, false, false, ignore_order, e, NULL)) < 0) {
1575 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1581 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE], i)
1582 if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1591 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
1592 if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, false, false, ignore_order, e, NULL)) < 0) {
1593 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1599 SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTS], i)
1600 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, true, false, ignore_order, e, NULL)) < 0) {
1609 SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i)
1610 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, false, override, false, false, ignore_order, e, NULL)) < 0) {
1611 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1619 if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
1621 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRED_BY], i)
1622 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1631 SET_FOREACH(dep, ret->unit->dependencies[UNIT_BOUND_BY], i)
1632 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
1642 if (type == JOB_RELOAD || type == JOB_RELOAD_OR_START) {
1644 SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATE_RELOAD_TO], i) {
1645 r = transaction_add_job_and_dependencies(m, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e, NULL);
1648 log_warning("Cannot add dependency reload job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
1656 /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
1668 static int transaction_add_isolate_jobs(Manager *m) {
1676 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1678 /* ignore aliases */
1682 if (u->ignore_on_isolate)
1685 /* No need to stop inactive jobs */
1686 if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
1689 /* Is there already something listed for this? */
1690 if (hashmap_get(m->transaction_jobs, u))
1693 if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, false, false, false, NULL, NULL)) < 0)
1694 log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->id, strerror(-r));
1700 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
1705 assert(type < _JOB_TYPE_MAX);
1707 assert(mode < _JOB_MODE_MAX);
1709 if (mode == JOB_ISOLATE && type != JOB_START) {
1710 dbus_set_error(e, BUS_ERROR_INVALID_JOB_MODE, "Isolate is only valid for start.");
1714 if (mode == JOB_ISOLATE && !unit->allow_isolate) {
1715 dbus_set_error(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
1719 log_debug("Trying to enqueue job %s/%s/%s", unit->id, job_type_to_string(type), job_mode_to_string(mode));
1721 if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, false,
1722 mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS,
1723 mode == JOB_IGNORE_DEPENDENCIES, e, &ret)) < 0) {
1724 transaction_abort(m);
1728 if (mode == JOB_ISOLATE)
1729 if ((r = transaction_add_isolate_jobs(m)) < 0) {
1730 transaction_abort(m);
1734 if ((r = transaction_activate(m, mode, e)) < 0)
1737 log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) ret->id);
1745 int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, DBusError *e, Job **_ret) {
1750 assert(type < _JOB_TYPE_MAX);
1752 assert(mode < _JOB_MODE_MAX);
1754 if ((r = manager_load_unit(m, name, NULL, NULL, &unit)) < 0)
1757 return manager_add_job(m, type, unit, mode, override, e, _ret);
1760 Job *manager_get_job(Manager *m, uint32_t id) {
1763 return hashmap_get(m->jobs, UINT32_TO_PTR(id));
1766 Unit *manager_get_unit(Manager *m, const char *name) {
1770 return hashmap_get(m->units, name);
1773 unsigned manager_dispatch_load_queue(Manager *m) {
1779 /* Make sure we are not run recursively */
1780 if (m->dispatching_load_queue)
1783 m->dispatching_load_queue = true;
1785 /* Dispatches the load queue. Takes a unit from the queue and
1786 * tries to load its data until the queue is empty */
1788 while ((u = m->load_queue)) {
1789 assert(u->in_load_queue);
1795 m->dispatching_load_queue = false;
1799 int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
1805 assert(name || path);
1807 /* This will prepare the unit for loading, but not actually
1808 * load anything from disk. */
1810 if (path && !is_path(path)) {
1811 dbus_set_error(e, BUS_ERROR_INVALID_PATH, "Path %s is not absolute.", path);
1816 name = file_name_from_path(path);
1818 t = unit_name_to_type(name);
1820 if (t == _UNIT_TYPE_INVALID || !unit_name_is_valid_no_type(name, false)) {
1821 dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
1825 ret = manager_get_unit(m, name);
1831 ret = unit_new(m, unit_vtable[t]->object_size);
1836 ret->fragment_path = strdup(path);
1837 if (!ret->fragment_path) {
1843 if ((r = unit_add_name(ret, name)) < 0) {
1848 unit_add_to_load_queue(ret);
1849 unit_add_to_dbus_queue(ret);
1850 unit_add_to_gc_queue(ret);
1858 int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
1863 /* This will load the service information files, but not actually
1864 * start any services or anything. */
1866 if ((r = manager_load_unit_prepare(m, name, path, e, _ret)) != 0)
1869 manager_dispatch_load_queue(m);
1872 *_ret = unit_follow_merge(*_ret);
1877 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
1884 HASHMAP_FOREACH(j, s->jobs, i)
1885 job_dump(j, f, prefix);
1888 void manager_dump_units(Manager *s, FILE *f, const char *prefix) {
1896 HASHMAP_FOREACH_KEY(u, t, s->units, i)
1898 unit_dump(u, f, prefix);
1901 void manager_clear_jobs(Manager *m) {
1906 transaction_abort(m);
1908 while ((j = hashmap_first(m->jobs)))
1909 job_finish_and_invalidate(j, JOB_CANCELED);
1912 unsigned manager_dispatch_run_queue(Manager *m) {
1916 if (m->dispatching_run_queue)
1919 m->dispatching_run_queue = true;
1921 while ((j = m->run_queue)) {
1922 assert(j->installed);
1923 assert(j->in_run_queue);
1925 job_run_and_invalidate(j);
1929 m->dispatching_run_queue = false;
1933 unsigned manager_dispatch_dbus_queue(Manager *m) {
1940 if (m->dispatching_dbus_queue)
1943 m->dispatching_dbus_queue = true;
1945 while ((u = m->dbus_unit_queue)) {
1946 assert(u->in_dbus_queue);
1948 bus_unit_send_change_signal(u);
1952 while ((j = m->dbus_job_queue)) {
1953 assert(j->in_dbus_queue);
1955 bus_job_send_change_signal(j);
1959 m->dispatching_dbus_queue = false;
1963 static int manager_process_notify_fd(Manager *m) {
1970 struct msghdr msghdr;
1972 struct ucred *ucred;
1974 struct cmsghdr cmsghdr;
1975 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
1981 iovec.iov_base = buf;
1982 iovec.iov_len = sizeof(buf)-1;
1986 msghdr.msg_iov = &iovec;
1987 msghdr.msg_iovlen = 1;
1988 msghdr.msg_control = &control;
1989 msghdr.msg_controllen = sizeof(control);
1991 if ((n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT)) <= 0) {
1995 if (errno == EAGAIN || errno == EINTR)
2001 if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) ||
2002 control.cmsghdr.cmsg_level != SOL_SOCKET ||
2003 control.cmsghdr.cmsg_type != SCM_CREDENTIALS ||
2004 control.cmsghdr.cmsg_len != CMSG_LEN(sizeof(struct ucred))) {
2005 log_warning("Received notify message without credentials. Ignoring.");
2009 ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
2011 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid))))
2012 if (!(u = cgroup_unit_by_pid(m, ucred->pid))) {
2013 log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
2017 assert((size_t) n < sizeof(buf));
2019 if (!(tags = strv_split(buf, "\n\r")))
2022 log_debug("Got notification message for unit %s", u->id);
2024 if (UNIT_VTABLE(u)->notify_message)
2025 UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags);
2033 static int manager_dispatch_sigchld(Manager *m) {
2043 /* First we call waitd() for a PID and do not reap the
2044 * zombie. That way we can still access /proc/$PID for
2045 * it while it is a zombie. */
2046 if (waitid(P_ALL, 0, &si, WEXITED|WNOHANG|WNOWAIT) < 0) {
2048 if (errno == ECHILD)
2060 if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
2063 get_process_comm(si.si_pid, &name);
2064 log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name));
2068 /* Let's flush any message the dying child might still
2069 * have queued for us. This ensures that the process
2070 * still exists in /proc so that we can figure out
2071 * which cgroup and hence unit it belongs to. */
2072 if ((r = manager_process_notify_fd(m)) < 0)
2075 /* And now figure out the unit this belongs to */
2076 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid))))
2077 u = cgroup_unit_by_pid(m, si.si_pid);
2079 /* And now, we actually reap the zombie. */
2080 if (waitid(P_PID, si.si_pid, &si, WEXITED) < 0) {
2087 if (si.si_code != CLD_EXITED && si.si_code != CLD_KILLED && si.si_code != CLD_DUMPED)
2090 log_debug("Child %lu died (code=%s, status=%i/%s)",
2091 (long unsigned) si.si_pid,
2092 sigchld_code_to_string(si.si_code),
2094 strna(si.si_code == CLD_EXITED
2095 ? exit_status_to_string(si.si_status, EXIT_STATUS_FULL)
2096 : signal_to_string(si.si_status)));
2101 log_debug("Child %lu belongs to %s", (long unsigned) si.si_pid, u->id);
2103 hashmap_remove(m->watch_pids, LONG_TO_PTR(si.si_pid));
2104 UNIT_VTABLE(u)->sigchld_event(u, si.si_pid, si.si_code, si.si_status);
2110 static int manager_start_target(Manager *m, const char *name, JobMode mode) {
2114 dbus_error_init(&error);
2116 log_debug("Activating special unit %s", name);
2118 if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
2119 log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
2121 dbus_error_free(&error);
2126 static int manager_process_signal_fd(Manager *m) {
2128 struct signalfd_siginfo sfsi;
2129 bool sigchld = false;
2134 if ((n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
2139 if (errno == EINTR || errno == EAGAIN)
2145 if (sfsi.ssi_pid > 0) {
2148 get_process_comm(sfsi.ssi_pid, &p);
2150 log_debug("Received SIG%s from PID %lu (%s).",
2151 signal_to_string(sfsi.ssi_signo),
2152 (unsigned long) sfsi.ssi_pid, strna(p));
2155 log_debug("Received SIG%s.", signal_to_string(sfsi.ssi_signo));
2157 switch (sfsi.ssi_signo) {
2164 if (m->running_as == MANAGER_SYSTEM) {
2165 /* This is for compatibility with the
2166 * original sysvinit */
2167 m->exit_code = MANAGER_REEXECUTE;
2174 if (m->running_as == MANAGER_SYSTEM) {
2175 manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE);
2179 /* Run the exit target if there is one, if not, just exit. */
2180 if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) {
2181 m->exit_code = MANAGER_EXIT;
2188 if (m->running_as == MANAGER_SYSTEM)
2189 manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
2191 /* This is a nop on non-init */
2195 if (m->running_as == MANAGER_SYSTEM)
2196 manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
2198 /* This is a nop on non-init */
2204 u = manager_get_unit(m, SPECIAL_DBUS_SERVICE);
2206 if (!u || UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u))) {
2207 log_info("Trying to reconnect to bus...");
2211 if (!u || !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) {
2212 log_info("Loading D-Bus service...");
2213 manager_start_target(m, SPECIAL_DBUS_SERVICE, JOB_REPLACE);
2224 if (!(f = open_memstream(&dump, &size))) {
2225 log_warning("Failed to allocate memory stream.");
2229 manager_dump_units(m, f, "\t");
2230 manager_dump_jobs(m, f, "\t");
2235 log_warning("Failed to write status stream");
2240 log_dump(LOG_INFO, dump);
2247 m->exit_code = MANAGER_RELOAD;
2252 /* Starting SIGRTMIN+0 */
2253 static const char * const target_table[] = {
2254 [0] = SPECIAL_DEFAULT_TARGET,
2255 [1] = SPECIAL_RESCUE_TARGET,
2256 [2] = SPECIAL_EMERGENCY_TARGET,
2257 [3] = SPECIAL_HALT_TARGET,
2258 [4] = SPECIAL_POWEROFF_TARGET,
2259 [5] = SPECIAL_REBOOT_TARGET,
2260 [6] = SPECIAL_KEXEC_TARGET
2263 /* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */
2264 static const ManagerExitCode code_table[] = {
2266 [1] = MANAGER_POWEROFF,
2267 [2] = MANAGER_REBOOT,
2271 if ((int) sfsi.ssi_signo >= SIGRTMIN+0 &&
2272 (int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(target_table)) {
2273 int idx = (int) sfsi.ssi_signo - SIGRTMIN;
2274 manager_start_target(m, target_table[idx],
2275 (idx == 1 || idx == 2) ? JOB_ISOLATE : JOB_REPLACE);
2279 if ((int) sfsi.ssi_signo >= SIGRTMIN+13 &&
2280 (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(code_table)) {
2281 m->exit_code = code_table[sfsi.ssi_signo - SIGRTMIN - 13];
2285 switch (sfsi.ssi_signo - SIGRTMIN) {
2288 log_debug("Enabling showing of status.");
2289 manager_set_show_status(m, true);
2293 log_debug("Disabling showing of status.");
2294 manager_set_show_status(m, false);
2298 log_set_max_level(LOG_DEBUG);
2299 log_notice("Setting log level to debug.");
2303 log_set_max_level(LOG_INFO);
2304 log_notice("Setting log level to info.");
2308 log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
2309 log_notice("Setting log target to journal-or-kmsg.");
2313 log_set_target(LOG_TARGET_CONSOLE);
2314 log_notice("Setting log target to console.");
2318 log_set_target(LOG_TARGET_KMSG);
2319 log_notice("Setting log target to kmsg.");
2323 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
2324 log_notice("Setting log target to syslog-or-kmsg.");
2328 log_warning("Got unhandled signal <%s>.", signal_to_string(sfsi.ssi_signo));
2335 return manager_dispatch_sigchld(m);
2340 static int process_event(Manager *m, struct epoll_event *ev) {
2347 assert_se(w = ev->data.ptr);
2349 if (w->type == WATCH_INVALID)
2356 /* An incoming signal? */
2357 if (ev->events != EPOLLIN)
2360 if ((r = manager_process_signal_fd(m)) < 0)
2367 /* An incoming daemon notification event? */
2368 if (ev->events != EPOLLIN)
2371 if ((r = manager_process_notify_fd(m)) < 0)
2378 /* Some fd event, to be dispatched to the units */
2379 UNIT_VTABLE(w->data.unit)->fd_event(w->data.unit, w->fd, ev->events, w);
2382 case WATCH_UNIT_TIMER:
2383 case WATCH_JOB_TIMER: {
2387 /* Some timer event, to be dispatched to the units */
2388 if ((k = read(w->fd, &v, sizeof(v))) != sizeof(v)) {
2390 if (k < 0 && (errno == EINTR || errno == EAGAIN))
2393 return k < 0 ? -errno : -EIO;
2396 if (w->type == WATCH_UNIT_TIMER)
2397 UNIT_VTABLE(w->data.unit)->timer_event(w->data.unit, v, w);
2399 job_timer_event(w->data.job, v, w);
2404 /* Some mount table change, intended for the mount subsystem */
2405 mount_fd_event(m, ev->events);
2409 /* Some swap table change, intended for the swap subsystem */
2410 swap_fd_event(m, ev->events);
2414 /* Some notification from udev, intended for the device subsystem */
2415 device_fd_event(m, ev->events);
2418 case WATCH_DBUS_WATCH:
2419 bus_watch_event(m, w, ev->events);
2422 case WATCH_DBUS_TIMEOUT:
2423 bus_timeout_event(m, w, ev->events);
2427 log_error("event type=%i", w->type);
2428 assert_not_reached("Unknown epoll event type.");
2434 int manager_loop(Manager *m) {
2437 RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
2440 m->exit_code = MANAGER_RUNNING;
2442 /* Release the path cache */
2443 set_free_free(m->unit_path_cache);
2444 m->unit_path_cache = NULL;
2446 manager_check_finished(m);
2448 /* There might still be some zombies hanging around from
2449 * before we were exec()'ed. Leat's reap them */
2450 if ((r = manager_dispatch_sigchld(m)) < 0)
2453 while (m->exit_code == MANAGER_RUNNING) {
2454 struct epoll_event event;
2457 if (!ratelimit_test(&rl)) {
2458 /* Yay, something is going seriously wrong, pause a little */
2459 log_warning("Looping too fast. Throttling execution a little.");
2463 if (manager_dispatch_load_queue(m) > 0)
2466 if (manager_dispatch_run_queue(m) > 0)
2469 if (bus_dispatch(m) > 0)
2472 if (manager_dispatch_cleanup_queue(m) > 0)
2475 if (manager_dispatch_gc_queue(m) > 0)
2478 if (manager_dispatch_dbus_queue(m) > 0)
2481 if (swap_dispatch_reload(m) > 0)
2484 if ((n = epoll_wait(m->epoll_fd, &event, 1, -1)) < 0) {
2494 if ((r = process_event(m, &event)) < 0)
2498 return m->exit_code;
2501 int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u) {
2509 if (!startswith(s, "/org/freedesktop/systemd1/unit/"))
2512 if (!(n = bus_path_unescape(s+31)))
2515 u = manager_get_unit(m, n);
2526 int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j) {
2535 if (!startswith(s, "/org/freedesktop/systemd1/job/"))
2538 if ((r = safe_atou(s + 30, &id)) < 0)
2541 if (!(j = manager_get_job(m, id)))
2549 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
2554 if (m->audit_fd < 0)
2557 /* Don't generate audit events if the service was already
2558 * started and we're just deserializing */
2559 if (m->n_reloading > 0)
2562 if (m->running_as != MANAGER_SYSTEM)
2565 if (u->type != UNIT_SERVICE)
2568 if (!(p = unit_name_to_prefix_and_instance(u->id))) {
2569 log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
2573 if (audit_log_user_comm_message(m->audit_fd, type, "", p, NULL, NULL, NULL, success) < 0) {
2574 log_warning("Failed to send audit message: %m");
2576 if (errno == EPERM) {
2577 /* We aren't allowed to send audit messages?
2578 * Then let's not retry again, to avoid
2579 * spamming the user with the same and same
2580 * messages over and over. */
2582 audit_close(m->audit_fd);
2592 void manager_send_unit_plymouth(Manager *m, Unit *u) {
2594 union sockaddr_union sa;
2596 char *message = NULL;
2598 /* Don't generate plymouth events if the service was already
2599 * started and we're just deserializing */
2600 if (m->n_reloading > 0)
2603 if (m->running_as != MANAGER_SYSTEM)
2606 if (u->type != UNIT_SERVICE &&
2607 u->type != UNIT_MOUNT &&
2608 u->type != UNIT_SWAP)
2611 /* We set SOCK_NONBLOCK here so that we rather drop the
2612 * message then wait for plymouth */
2613 if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
2614 log_error("socket() failed: %m");
2619 sa.sa.sa_family = AF_UNIX;
2620 strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1);
2621 if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
2623 if (errno != EPIPE &&
2626 errno != ECONNREFUSED &&
2627 errno != ECONNRESET &&
2628 errno != ECONNABORTED)
2629 log_error("connect() failed: %m");
2634 if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) {
2635 log_error("Out of memory");
2640 if (write(fd, message, n + 1) != n + 1) {
2642 if (errno != EPIPE &&
2645 errno != ECONNREFUSED &&
2646 errno != ECONNRESET &&
2647 errno != ECONNABORTED)
2648 log_error("Failed to write Plymouth message: %m");
2655 close_nointr_nofail(fd);
2660 void manager_dispatch_bus_name_owner_changed(
2663 const char* old_owner,
2664 const char *new_owner) {
2671 if (!(u = hashmap_get(m->watch_bus, name)))
2674 UNIT_VTABLE(u)->bus_name_owner_change(u, name, old_owner, new_owner);
2677 void manager_dispatch_bus_query_pid_done(
2688 if (!(u = hashmap_get(m->watch_bus, name)))
2691 UNIT_VTABLE(u)->bus_query_pid_done(u, name, pid);
2694 int manager_open_serialization(Manager *m, FILE **_f) {
2702 if (m->running_as == MANAGER_SYSTEM)
2703 asprintf(&path, "/run/systemd/dump-%lu-XXXXXX", (unsigned long) getpid());
2705 asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
2710 saved_umask = umask(0077);
2711 fd = mkostemp(path, O_RDWR|O_CLOEXEC);
2721 log_debug("Serializing state to %s", path);
2724 if (!(f = fdopen(fd, "w+")))
2732 int manager_serialize(Manager *m, FILE *f, FDSet *fds) {
2744 fprintf(f, "current-job-id=%i\n", m->current_job_id);
2745 fprintf(f, "taint-usr=%s\n", yes_no(m->taint_usr));
2747 dual_timestamp_serialize(f, "initrd-timestamp", &m->initrd_timestamp);
2748 dual_timestamp_serialize(f, "startup-timestamp", &m->startup_timestamp);
2749 dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp);
2753 HASHMAP_FOREACH_KEY(u, t, m->units, i) {
2757 if (!unit_can_serialize(u))
2764 if ((r = unit_serialize(u, f, fds)) < 0) {
2770 assert(m->n_reloading > 0);
2776 r = bus_fdset_add_all(m, fds);
2783 int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
2789 log_debug("Deserializing state...");
2794 char line[LINE_MAX], *l;
2796 if (!fgets(line, sizeof(line), f)) {
2811 if (startswith(l, "current-job-id=")) {
2814 if (safe_atou32(l+15, &id) < 0)
2815 log_debug("Failed to parse current job id value %s", l+15);
2817 m->current_job_id = MAX(m->current_job_id, id);
2818 } else if (startswith(l, "taint-usr=")) {
2821 if ((b = parse_boolean(l+10)) < 0)
2822 log_debug("Failed to parse taint /usr flag %s", l+10);
2824 m->taint_usr = m->taint_usr || b;
2825 } else if (startswith(l, "initrd-timestamp="))
2826 dual_timestamp_deserialize(l+17, &m->initrd_timestamp);
2827 else if (startswith(l, "startup-timestamp="))
2828 dual_timestamp_deserialize(l+18, &m->startup_timestamp);
2829 else if (startswith(l, "finish-timestamp="))
2830 dual_timestamp_deserialize(l+17, &m->finish_timestamp);
2832 log_debug("Unknown serialization item '%s'", l);
2837 char name[UNIT_NAME_MAX+2];
2840 if (!fgets(name, sizeof(name), f)) {
2851 if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
2854 if ((r = unit_deserialize(u, f, fds)) < 0)
2864 assert(m->n_reloading > 0);
2870 int manager_reload(Manager *m) {
2877 if ((r = manager_open_serialization(m, &f)) < 0)
2882 if (!(fds = fdset_new())) {
2888 if ((r = manager_serialize(m, f, fds)) < 0) {
2893 if (fseeko(f, 0, SEEK_SET) < 0) {
2899 /* From here on there is no way back. */
2900 manager_clear_jobs_and_units(m);
2901 manager_undo_generators(m);
2903 /* Find new unit paths */
2904 lookup_paths_free(&m->lookup_paths);
2905 if ((q = lookup_paths_init(&m->lookup_paths, m->running_as, true)) < 0)
2908 manager_run_generators(m);
2910 manager_build_unit_path_cache(m);
2912 /* First, enumerate what we can from all config files */
2913 if ((q = manager_enumerate(m)) < 0)
2916 /* Second, deserialize our stored data */
2917 if ((q = manager_deserialize(m, f, fds)) < 0)
2923 /* Third, fire things up! */
2924 if ((q = manager_coldplug(m)) < 0)
2927 assert(m->n_reloading > 0);
2940 bool manager_is_booting_or_shutting_down(Manager *m) {
2945 /* Is the initial job still around? */
2946 if (manager_get_job(m, m->default_unit_job_id))
2949 /* Is there a job for the shutdown target? */
2950 u = manager_get_unit(m, SPECIAL_SHUTDOWN_TARGET);
2957 void manager_reset_failed(Manager *m) {
2963 HASHMAP_FOREACH(u, m->units, i)
2964 unit_reset_failed(u);
2967 bool manager_unit_pending_inactive(Manager *m, const char *name) {
2973 /* Returns true if the unit is inactive or going down */
2974 if (!(u = manager_get_unit(m, name)))
2977 return unit_pending_inactive(u);
2980 void manager_check_finished(Manager *m) {
2981 char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
2982 usec_t kernel_usec = 0, initrd_usec = 0, userspace_usec = 0, total_usec = 0;
2986 if (dual_timestamp_is_set(&m->finish_timestamp))
2989 if (hashmap_size(m->jobs) > 0)
2992 dual_timestamp_get(&m->finish_timestamp);
2994 if (m->running_as == MANAGER_SYSTEM && detect_container(NULL) <= 0) {
2996 userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
2997 total_usec = m->finish_timestamp.monotonic;
2999 if (dual_timestamp_is_set(&m->initrd_timestamp)) {
3001 kernel_usec = m->initrd_timestamp.monotonic;
3002 initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
3004 log_info("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
3005 format_timespan(kernel, sizeof(kernel), kernel_usec),
3006 format_timespan(initrd, sizeof(initrd), initrd_usec),
3007 format_timespan(userspace, sizeof(userspace), userspace_usec),
3008 format_timespan(sum, sizeof(sum), total_usec));
3010 kernel_usec = m->startup_timestamp.monotonic;
3013 log_info("Startup finished in %s (kernel) + %s (userspace) = %s.",
3014 format_timespan(kernel, sizeof(kernel), kernel_usec),
3015 format_timespan(userspace, sizeof(userspace), userspace_usec),
3016 format_timespan(sum, sizeof(sum), total_usec));
3019 userspace_usec = initrd_usec = kernel_usec = 0;
3020 total_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
3022 log_debug("Startup finished in %s.",
3023 format_timespan(sum, sizeof(sum), total_usec));
3026 bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
3029 "READY=1\nSTATUS=Startup finished in %s.",
3030 format_timespan(sum, sizeof(sum), total_usec));
3033 void manager_run_generators(Manager *m) {
3035 const char *generator_path;
3036 const char *argv[3];
3041 generator_path = m->running_as == MANAGER_SYSTEM ? SYSTEM_GENERATOR_PATH : USER_GENERATOR_PATH;
3042 if (!(d = opendir(generator_path))) {
3044 if (errno == ENOENT)
3047 log_error("Failed to enumerate generator directory: %m");
3051 if (!m->generator_unit_path) {
3053 char user_path[] = "/tmp/systemd-generator-XXXXXX";
3055 if (m->running_as == MANAGER_SYSTEM && getpid() == 1) {
3056 p = "/run/systemd/generator";
3058 if (mkdir_p(p, 0755) < 0) {
3059 log_error("Failed to create generator directory: %m");
3064 if (!(p = mkdtemp(user_path))) {
3065 log_error("Failed to create generator directory: %m");
3070 if (!(m->generator_unit_path = strdup(p))) {
3071 log_error("Failed to allocate generator unit path.");
3076 argv[0] = NULL; /* Leave this empty, execute_directory() will fill something in */
3077 argv[1] = m->generator_unit_path;
3081 execute_directory(generator_path, d, (char**) argv);
3084 if (rmdir(m->generator_unit_path) >= 0) {
3085 /* Uh? we were able to remove this dir? I guess that
3086 * means the directory was empty, hence let's shortcut
3089 free(m->generator_unit_path);
3090 m->generator_unit_path = NULL;
3094 if (!strv_find(m->lookup_paths.unit_path, m->generator_unit_path)) {
3097 if (!(l = strv_append(m->lookup_paths.unit_path, m->generator_unit_path))) {
3098 log_error("Failed to add generator directory to unit search path: %m");
3102 strv_free(m->lookup_paths.unit_path);
3103 m->lookup_paths.unit_path = l;
3105 log_debug("Added generator unit path %s to search path.", m->generator_unit_path);
3113 void manager_undo_generators(Manager *m) {
3116 if (!m->generator_unit_path)
3119 strv_remove(m->lookup_paths.unit_path, m->generator_unit_path);
3120 rm_rf(m->generator_unit_path, false, true, false);
3122 free(m->generator_unit_path);
3123 m->generator_unit_path = NULL;
3126 int manager_set_default_controllers(Manager *m, char **controllers) {
3131 if (!(l = strv_copy(controllers)))
3134 strv_free(m->default_controllers);
3135 m->default_controllers = l;
3140 void manager_recheck_journal(Manager *m) {
3145 if (m->running_as != MANAGER_SYSTEM)
3148 u = manager_get_unit(m, SPECIAL_JOURNALD_SOCKET);
3149 if (u && SOCKET(u)->state != SOCKET_RUNNING) {
3150 log_close_journal();
3154 u = manager_get_unit(m, SPECIAL_JOURNALD_SERVICE);
3155 if (u && SERVICE(u)->state != SERVICE_RUNNING) {
3156 log_close_journal();
3160 /* Hmm, OK, so the socket is fully up and the service is up
3161 * too, then let's make use of the thing. */
3165 void manager_set_show_status(Manager *m, bool b) {
3168 if (m->running_as != MANAGER_SYSTEM)
3174 touch("/run/systemd/show-status");
3176 unlink("/run/systemd/show-status");
3179 bool manager_get_show_status(Manager *m) {
3182 if (m->running_as != MANAGER_SYSTEM)
3188 /* If Plymouth is running make sure we show the status, so
3189 * that there's something nice to see when people press Esc */
3191 return plymouth_running();
3194 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
3195 [MANAGER_SYSTEM] = "system",
3196 [MANAGER_USER] = "user"
3199 DEFINE_STRING_TABLE_LOOKUP(manager_running_as, ManagerRunningAs);