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 Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser 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>
47 #include "transaction.h"
54 #include "ratelimit.h"
56 #include "mount-setup.h"
57 #include "unit-name.h"
58 #include "dbus-unit.h"
61 #include "path-lookup.h"
63 #include "bus-errors.h"
64 #include "exit-status.h"
67 #include "cgroup-util.h"
68 #include "path-util.h"
70 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
71 #define GC_QUEUE_ENTRIES_MAX 16
73 /* As soon as 5s passed since a unit was added to our GC queue, make sure to run a gc sweep */
74 #define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC)
76 /* Where clients shall send notification messages to */
77 #define NOTIFY_SOCKET_SYSTEM "/run/systemd/notify"
78 #define NOTIFY_SOCKET_USER "@/org/freedesktop/systemd1/notify"
80 static int manager_setup_notify(Manager *m) {
83 struct sockaddr_un un;
85 struct epoll_event ev;
91 m->notify_watch.type = WATCH_NOTIFY;
92 if ((m->notify_watch.fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
93 log_error("Failed to allocate notification socket: %m");
98 sa.sa.sa_family = AF_UNIX;
101 snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET_USER "/%llu", random_ull());
103 unlink(NOTIFY_SOCKET_SYSTEM);
104 strncpy(sa.un.sun_path, NOTIFY_SOCKET_SYSTEM, sizeof(sa.un.sun_path));
107 if (sa.un.sun_path[0] == '@')
108 sa.un.sun_path[0] = 0;
111 r = bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1));
115 log_error("bind() failed: %m");
119 if (setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
120 log_error("SO_PASSCRED failed: %m");
126 ev.data.ptr = &m->notify_watch;
128 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0)
131 if (sa.un.sun_path[0] == 0)
132 sa.un.sun_path[0] = '@';
134 if (!(m->notify_socket = strdup(sa.un.sun_path)))
137 log_debug("Using notification socket %s", m->notify_socket);
142 static int enable_special_signals(Manager *m) {
147 /* Enable that we get SIGINT on control-alt-del. In containers
148 * this will fail with EPERM, so ignore that. */
149 if (reboot(RB_DISABLE_CAD) < 0 && errno != EPERM)
150 log_warning("Failed to enable ctrl-alt-del handling: %m");
152 fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
154 /* Support systems without virtual console */
156 log_warning("Failed to open /dev/tty0: %m");
158 /* Enable that we get SIGWINCH on kbrequest */
159 if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
160 log_warning("Failed to enable kbrequest handling: %s", strerror(errno));
162 close_nointr_nofail(fd);
168 static int manager_setup_signals(Manager *m) {
170 struct epoll_event ev;
175 /* We are not interested in SIGSTOP and friends. */
177 sa.sa_handler = SIG_DFL;
178 sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
179 assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
181 assert_se(sigemptyset(&mask) == 0);
183 sigset_add_many(&mask,
184 SIGCHLD, /* Child died */
185 SIGTERM, /* Reexecute daemon */
186 SIGHUP, /* Reload configuration */
187 SIGUSR1, /* systemd/upstart: reconnect to D-Bus */
188 SIGUSR2, /* systemd: dump status */
189 SIGINT, /* Kernel sends us this on control-alt-del */
190 SIGWINCH, /* Kernel sends us this on kbrequest (alt-arrowup) */
191 SIGPWR, /* Some kernel drivers and upsd send us this on power failure */
192 SIGRTMIN+0, /* systemd: start default.target */
193 SIGRTMIN+1, /* systemd: isolate rescue.target */
194 SIGRTMIN+2, /* systemd: isolate emergency.target */
195 SIGRTMIN+3, /* systemd: start halt.target */
196 SIGRTMIN+4, /* systemd: start poweroff.target */
197 SIGRTMIN+5, /* systemd: start reboot.target */
198 SIGRTMIN+6, /* systemd: start kexec.target */
199 SIGRTMIN+13, /* systemd: Immediate halt */
200 SIGRTMIN+14, /* systemd: Immediate poweroff */
201 SIGRTMIN+15, /* systemd: Immediate reboot */
202 SIGRTMIN+16, /* systemd: Immediate kexec */
203 SIGRTMIN+20, /* systemd: enable status messages */
204 SIGRTMIN+21, /* systemd: disable status messages */
205 SIGRTMIN+22, /* systemd: set log level to LOG_DEBUG */
206 SIGRTMIN+23, /* systemd: set log level to LOG_INFO */
207 SIGRTMIN+26, /* systemd: set log target to journal-or-kmsg */
208 SIGRTMIN+27, /* systemd: set log target to console */
209 SIGRTMIN+28, /* systemd: set log target to kmsg */
210 SIGRTMIN+29, /* systemd: set log target to syslog-or-kmsg */
212 assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
214 m->signal_watch.type = WATCH_SIGNAL;
215 if ((m->signal_watch.fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC)) < 0)
220 ev.data.ptr = &m->signal_watch;
222 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
225 if (m->running_as == MANAGER_SYSTEM)
226 return enable_special_signals(m);
231 static void manager_strip_environment(Manager *m) {
234 /* Remove variables from the inherited set that are part of
235 * the container interface:
236 * http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface */
237 strv_remove_prefix(m->environment, "container=");
238 strv_remove_prefix(m->environment, "container_");
240 /* Remove variables from the inherited set that are part of
241 * the initrd interface:
242 * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */
243 strv_remove_prefix(m->environment, "RD_");
246 int manager_new(ManagerRunningAs running_as, Manager **_m) {
251 assert(running_as >= 0);
252 assert(running_as < _MANAGER_RUNNING_AS_MAX);
254 if (!(m = new0(Manager, 1)))
257 dual_timestamp_get(&m->startup_timestamp);
259 m->running_as = running_as;
260 m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
261 m->exit_code = _MANAGER_EXIT_CODE_INVALID;
262 m->pin_cgroupfs_fd = -1;
263 m->idle_pipe[0] = m->idle_pipe[1] = -1;
269 m->signal_watch.fd = m->mount_watch.fd = m->udev_watch.fd = m->epoll_fd = m->dev_autofs_fd = m->swap_watch.fd = -1;
270 m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
272 m->environment = strv_copy(environ);
276 manager_strip_environment(m);
278 if (running_as == MANAGER_SYSTEM) {
279 m->default_controllers = strv_new("cpu", NULL);
280 if (!m->default_controllers)
284 if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
287 if (!(m->jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
290 if (!(m->watch_pids = hashmap_new(trivial_hash_func, trivial_compare_func)))
293 if (!(m->cgroup_bondings = hashmap_new(string_hash_func, string_compare_func)))
296 if (!(m->watch_bus = hashmap_new(string_hash_func, string_compare_func)))
299 if ((m->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
302 if ((r = manager_setup_signals(m)) < 0)
305 if ((r = manager_setup_cgroup(m)) < 0)
308 if ((r = manager_setup_notify(m)) < 0)
311 /* Try to connect to the busses, if possible. */
312 if ((r = bus_init(m, running_as != MANAGER_SYSTEM)) < 0)
316 if ((m->audit_fd = audit_open()) < 0 &&
317 /* If the kernel lacks netlink or audit support,
318 * don't worry about it. */
319 errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
320 log_error("Failed to connect to audit log: %m");
323 m->taint_usr = dir_is_empty("/usr") > 0;
333 static unsigned manager_dispatch_cleanup_queue(Manager *m) {
339 while ((u = m->cleanup_queue)) {
340 assert(u->in_cleanup_queue);
350 GC_OFFSET_IN_PATH, /* This one is on the path we were traveling */
351 GC_OFFSET_UNSURE, /* No clue */
352 GC_OFFSET_GOOD, /* We still need this unit */
353 GC_OFFSET_BAD, /* We don't need this unit anymore */
357 static void unit_gc_sweep(Unit *u, unsigned gc_marker) {
364 if (u->gc_marker == gc_marker + GC_OFFSET_GOOD ||
365 u->gc_marker == gc_marker + GC_OFFSET_BAD ||
366 u->gc_marker == gc_marker + GC_OFFSET_IN_PATH)
369 if (u->in_cleanup_queue)
372 if (unit_check_gc(u))
375 u->gc_marker = gc_marker + GC_OFFSET_IN_PATH;
379 SET_FOREACH(other, u->dependencies[UNIT_REFERENCED_BY], i) {
380 unit_gc_sweep(other, gc_marker);
382 if (other->gc_marker == gc_marker + GC_OFFSET_GOOD)
385 if (other->gc_marker != gc_marker + GC_OFFSET_BAD)
392 /* We were unable to find anything out about this entry, so
393 * let's investigate it later */
394 u->gc_marker = gc_marker + GC_OFFSET_UNSURE;
395 unit_add_to_gc_queue(u);
399 /* We definitely know that this one is not useful anymore, so
400 * let's mark it for deletion */
401 u->gc_marker = gc_marker + GC_OFFSET_BAD;
402 unit_add_to_cleanup_queue(u);
406 u->gc_marker = gc_marker + GC_OFFSET_GOOD;
409 static unsigned manager_dispatch_gc_queue(Manager *m) {
416 if ((m->n_in_gc_queue < GC_QUEUE_ENTRIES_MAX) &&
417 (m->gc_queue_timestamp <= 0 ||
418 (m->gc_queue_timestamp + GC_QUEUE_USEC_MAX) > now(CLOCK_MONOTONIC)))
421 log_debug("Running GC...");
423 m->gc_marker += _GC_OFFSET_MAX;
424 if (m->gc_marker + _GC_OFFSET_MAX <= _GC_OFFSET_MAX)
427 gc_marker = m->gc_marker;
429 while ((u = m->gc_queue)) {
430 assert(u->in_gc_queue);
432 unit_gc_sweep(u, gc_marker);
434 LIST_REMOVE(Unit, gc_queue, m->gc_queue, u);
435 u->in_gc_queue = false;
439 if (u->gc_marker == gc_marker + GC_OFFSET_BAD ||
440 u->gc_marker == gc_marker + GC_OFFSET_UNSURE) {
441 log_debug("Collecting %s", u->id);
442 u->gc_marker = gc_marker + GC_OFFSET_BAD;
443 unit_add_to_cleanup_queue(u);
447 m->n_in_gc_queue = 0;
448 m->gc_queue_timestamp = 0;
453 static void manager_clear_jobs_and_units(Manager *m) {
458 while ((u = hashmap_first(m->units)))
461 manager_dispatch_cleanup_queue(m);
463 assert(!m->load_queue);
464 assert(!m->run_queue);
465 assert(!m->dbus_unit_queue);
466 assert(!m->dbus_job_queue);
467 assert(!m->cleanup_queue);
468 assert(!m->gc_queue);
470 assert(hashmap_isempty(m->jobs));
471 assert(hashmap_isempty(m->units));
474 void manager_free(Manager *m) {
480 manager_clear_jobs_and_units(m);
482 for (c = 0; c < _UNIT_TYPE_MAX; c++)
483 if (unit_vtable[c]->shutdown)
484 unit_vtable[c]->shutdown(m);
486 /* If we reexecute ourselves, we keep the root cgroup
488 manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE);
490 manager_undo_generators(m);
494 hashmap_free(m->units);
495 hashmap_free(m->jobs);
496 hashmap_free(m->watch_pids);
497 hashmap_free(m->watch_bus);
499 if (m->epoll_fd >= 0)
500 close_nointr_nofail(m->epoll_fd);
501 if (m->signal_watch.fd >= 0)
502 close_nointr_nofail(m->signal_watch.fd);
503 if (m->notify_watch.fd >= 0)
504 close_nointr_nofail(m->notify_watch.fd);
507 if (m->audit_fd >= 0)
508 audit_close(m->audit_fd);
511 free(m->notify_socket);
513 lookup_paths_free(&m->lookup_paths);
514 strv_free(m->environment);
516 strv_free(m->default_controllers);
518 hashmap_free(m->cgroup_bondings);
519 set_free_free(m->unit_path_cache);
521 close_pipe(m->idle_pipe);
523 free(m->switch_root);
524 free(m->switch_root_init);
526 for (i = 0; i < RLIMIT_NLIMITS; i++)
532 int manager_enumerate(Manager *m) {
538 /* Let's ask every type to load all units from disk/kernel
539 * that it might know */
540 for (c = 0; c < _UNIT_TYPE_MAX; c++)
541 if (unit_vtable[c]->enumerate)
542 if ((q = unit_vtable[c]->enumerate(m)) < 0)
545 manager_dispatch_load_queue(m);
549 int manager_coldplug(Manager *m) {
557 /* Then, let's set up their initial state. */
558 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
564 if ((q = unit_coldplug(u)) < 0)
571 static void manager_build_unit_path_cache(Manager *m) {
578 set_free_free(m->unit_path_cache);
580 if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
581 log_error("Failed to allocate unit path cache.");
585 /* This simply builds a list of files we know exist, so that
586 * we don't always have to go to disk */
588 STRV_FOREACH(i, m->lookup_paths.unit_path) {
591 if (!(d = opendir(*i))) {
592 log_error("Failed to open directory: %m");
596 while ((de = readdir(d))) {
599 if (ignore_file(de->d_name))
602 p = join(streq(*i, "/") ? "" : *i, "/", de->d_name, NULL);
608 if ((r = set_put(m->unit_path_cache, p)) < 0) {
621 log_error("Failed to build unit path cache: %s", strerror(-r));
623 set_free_free(m->unit_path_cache);
624 m->unit_path_cache = NULL;
630 int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
635 manager_run_generators(m);
637 r = lookup_paths_init(
638 &m->lookup_paths, m->running_as, true,
639 m->generator_unit_path,
640 m->generator_unit_path_early,
641 m->generator_unit_path_late);
645 manager_build_unit_path_cache(m);
647 /* If we will deserialize make sure that during enumeration
648 * this is already known, so we increase the counter here
653 /* First, enumerate what we can from all config files */
654 r = manager_enumerate(m);
656 /* Second, deserialize if there is something to deserialize */
658 q = manager_deserialize(m, serialization, fds);
663 /* Third, fire things up! */
664 q = manager_coldplug(m);
669 assert(m->n_reloading > 0);
676 int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
681 assert(type < _JOB_TYPE_MAX);
683 assert(mode < _JOB_MODE_MAX);
685 if (mode == JOB_ISOLATE && type != JOB_START) {
686 dbus_set_error(e, BUS_ERROR_INVALID_JOB_MODE, "Isolate is only valid for start.");
690 if (mode == JOB_ISOLATE && !unit->allow_isolate) {
691 dbus_set_error(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
695 log_debug("Trying to enqueue job %s/%s/%s", unit->id, job_type_to_string(type), job_mode_to_string(mode));
697 job_type_collapse(&type, unit);
699 tr = transaction_new();
703 r = transaction_add_job_and_dependencies(tr, type, unit, NULL, true, override, false,
704 mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS,
705 mode == JOB_IGNORE_DEPENDENCIES, e);
709 if (mode == JOB_ISOLATE) {
710 r = transaction_add_isolate_jobs(tr, m);
715 r = transaction_activate(tr, m, mode, e);
719 log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) tr->anchor_job->id);
722 *_ret = tr->anchor_job;
724 transaction_free(tr);
728 transaction_abort(tr);
729 transaction_free(tr);
733 int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, DBusError *e, Job **_ret) {
738 assert(type < _JOB_TYPE_MAX);
740 assert(mode < _JOB_MODE_MAX);
742 if ((r = manager_load_unit(m, name, NULL, NULL, &unit)) < 0)
745 return manager_add_job(m, type, unit, mode, override, e, _ret);
748 Job *manager_get_job(Manager *m, uint32_t id) {
751 return hashmap_get(m->jobs, UINT32_TO_PTR(id));
754 Unit *manager_get_unit(Manager *m, const char *name) {
758 return hashmap_get(m->units, name);
761 unsigned manager_dispatch_load_queue(Manager *m) {
767 /* Make sure we are not run recursively */
768 if (m->dispatching_load_queue)
771 m->dispatching_load_queue = true;
773 /* Dispatches the load queue. Takes a unit from the queue and
774 * tries to load its data until the queue is empty */
776 while ((u = m->load_queue)) {
777 assert(u->in_load_queue);
783 m->dispatching_load_queue = false;
787 int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
793 assert(name || path);
795 /* This will prepare the unit for loading, but not actually
796 * load anything from disk. */
798 if (path && !is_path(path)) {
799 dbus_set_error(e, BUS_ERROR_INVALID_PATH, "Path %s is not absolute.", path);
804 name = path_get_file_name(path);
806 t = unit_name_to_type(name);
808 if (t == _UNIT_TYPE_INVALID || !unit_name_is_valid_no_type(name, false)) {
809 dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
813 ret = manager_get_unit(m, name);
819 ret = unit_new(m, unit_vtable[t]->object_size);
824 ret->fragment_path = strdup(path);
825 if (!ret->fragment_path) {
831 if ((r = unit_add_name(ret, name)) < 0) {
836 unit_add_to_load_queue(ret);
837 unit_add_to_dbus_queue(ret);
838 unit_add_to_gc_queue(ret);
846 int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
851 /* This will load the service information files, but not actually
852 * start any services or anything. */
854 if ((r = manager_load_unit_prepare(m, name, path, e, _ret)) != 0)
857 manager_dispatch_load_queue(m);
860 *_ret = unit_follow_merge(*_ret);
865 void manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
872 HASHMAP_FOREACH(j, s->jobs, i)
873 job_dump(j, f, prefix);
876 void manager_dump_units(Manager *s, FILE *f, const char *prefix) {
884 HASHMAP_FOREACH_KEY(u, t, s->units, i)
886 unit_dump(u, f, prefix);
889 void manager_clear_jobs(Manager *m) {
894 while ((j = hashmap_first(m->jobs)))
895 /* No need to recurse. We're cancelling all jobs. */
896 job_finish_and_invalidate(j, JOB_CANCELED, false);
899 unsigned manager_dispatch_run_queue(Manager *m) {
903 if (m->dispatching_run_queue)
906 m->dispatching_run_queue = true;
908 while ((j = m->run_queue)) {
909 assert(j->installed);
910 assert(j->in_run_queue);
912 job_run_and_invalidate(j);
916 m->dispatching_run_queue = false;
920 unsigned manager_dispatch_dbus_queue(Manager *m) {
927 if (m->dispatching_dbus_queue)
930 m->dispatching_dbus_queue = true;
932 while ((u = m->dbus_unit_queue)) {
933 assert(u->in_dbus_queue);
935 bus_unit_send_change_signal(u);
939 while ((j = m->dbus_job_queue)) {
940 assert(j->in_dbus_queue);
942 bus_job_send_change_signal(j);
946 m->dispatching_dbus_queue = false;
950 static int manager_process_notify_fd(Manager *m) {
957 struct msghdr msghdr;
961 struct cmsghdr cmsghdr;
962 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
968 iovec.iov_base = buf;
969 iovec.iov_len = sizeof(buf)-1;
973 msghdr.msg_iov = &iovec;
974 msghdr.msg_iovlen = 1;
975 msghdr.msg_control = &control;
976 msghdr.msg_controllen = sizeof(control);
978 if ((n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT)) <= 0) {
982 if (errno == EAGAIN || errno == EINTR)
988 if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) ||
989 control.cmsghdr.cmsg_level != SOL_SOCKET ||
990 control.cmsghdr.cmsg_type != SCM_CREDENTIALS ||
991 control.cmsghdr.cmsg_len != CMSG_LEN(sizeof(struct ucred))) {
992 log_warning("Received notify message without credentials. Ignoring.");
996 ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
998 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(ucred->pid))))
999 if (!(u = cgroup_unit_by_pid(m, ucred->pid))) {
1000 log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
1004 assert((size_t) n < sizeof(buf));
1006 if (!(tags = strv_split(buf, "\n\r")))
1009 log_debug("Got notification message for unit %s", u->id);
1011 if (UNIT_VTABLE(u)->notify_message)
1012 UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags);
1020 static int manager_dispatch_sigchld(Manager *m) {
1030 /* First we call waitd() for a PID and do not reap the
1031 * zombie. That way we can still access /proc/$PID for
1032 * it while it is a zombie. */
1033 if (waitid(P_ALL, 0, &si, WEXITED|WNOHANG|WNOWAIT) < 0) {
1035 if (errno == ECHILD)
1047 if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
1050 get_process_comm(si.si_pid, &name);
1051 log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name));
1055 /* Let's flush any message the dying child might still
1056 * have queued for us. This ensures that the process
1057 * still exists in /proc so that we can figure out
1058 * which cgroup and hence unit it belongs to. */
1059 if ((r = manager_process_notify_fd(m)) < 0)
1062 /* And now figure out the unit this belongs to */
1063 if (!(u = hashmap_get(m->watch_pids, LONG_TO_PTR(si.si_pid))))
1064 u = cgroup_unit_by_pid(m, si.si_pid);
1066 /* And now, we actually reap the zombie. */
1067 if (waitid(P_PID, si.si_pid, &si, WEXITED) < 0) {
1074 if (si.si_code != CLD_EXITED && si.si_code != CLD_KILLED && si.si_code != CLD_DUMPED)
1077 log_debug("Child %lu died (code=%s, status=%i/%s)",
1078 (long unsigned) si.si_pid,
1079 sigchld_code_to_string(si.si_code),
1081 strna(si.si_code == CLD_EXITED
1082 ? exit_status_to_string(si.si_status, EXIT_STATUS_FULL)
1083 : signal_to_string(si.si_status)));
1088 log_debug("Child %lu belongs to %s", (long unsigned) si.si_pid, u->id);
1090 hashmap_remove(m->watch_pids, LONG_TO_PTR(si.si_pid));
1091 UNIT_VTABLE(u)->sigchld_event(u, si.si_pid, si.si_code, si.si_status);
1097 static int manager_start_target(Manager *m, const char *name, JobMode mode) {
1101 dbus_error_init(&error);
1103 log_debug("Activating special unit %s", name);
1105 if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
1106 log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
1108 dbus_error_free(&error);
1113 static int manager_process_signal_fd(Manager *m) {
1115 struct signalfd_siginfo sfsi;
1116 bool sigchld = false;
1121 if ((n = read(m->signal_watch.fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
1126 if (errno == EINTR || errno == EAGAIN)
1132 if (sfsi.ssi_pid > 0) {
1135 get_process_comm(sfsi.ssi_pid, &p);
1137 log_debug("Received SIG%s from PID %lu (%s).",
1138 signal_to_string(sfsi.ssi_signo),
1139 (unsigned long) sfsi.ssi_pid, strna(p));
1142 log_debug("Received SIG%s.", signal_to_string(sfsi.ssi_signo));
1144 switch (sfsi.ssi_signo) {
1151 if (m->running_as == MANAGER_SYSTEM) {
1152 /* This is for compatibility with the
1153 * original sysvinit */
1154 m->exit_code = MANAGER_REEXECUTE;
1161 if (m->running_as == MANAGER_SYSTEM) {
1162 manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE);
1166 /* Run the exit target if there is one, if not, just exit. */
1167 if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) {
1168 m->exit_code = MANAGER_EXIT;
1175 if (m->running_as == MANAGER_SYSTEM)
1176 manager_start_target(m, SPECIAL_KBREQUEST_TARGET, JOB_REPLACE);
1178 /* This is a nop on non-init */
1182 if (m->running_as == MANAGER_SYSTEM)
1183 manager_start_target(m, SPECIAL_SIGPWR_TARGET, JOB_REPLACE);
1185 /* This is a nop on non-init */
1191 u = manager_get_unit(m, SPECIAL_DBUS_SERVICE);
1193 if (!u || UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u))) {
1194 log_info("Trying to reconnect to bus...");
1198 if (!u || !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) {
1199 log_info("Loading D-Bus service...");
1200 manager_start_target(m, SPECIAL_DBUS_SERVICE, JOB_REPLACE);
1211 if (!(f = open_memstream(&dump, &size))) {
1212 log_warning("Failed to allocate memory stream.");
1216 manager_dump_units(m, f, "\t");
1217 manager_dump_jobs(m, f, "\t");
1222 log_warning("Failed to write status stream");
1227 log_dump(LOG_INFO, dump);
1234 m->exit_code = MANAGER_RELOAD;
1239 /* Starting SIGRTMIN+0 */
1240 static const char * const target_table[] = {
1241 [0] = SPECIAL_DEFAULT_TARGET,
1242 [1] = SPECIAL_RESCUE_TARGET,
1243 [2] = SPECIAL_EMERGENCY_TARGET,
1244 [3] = SPECIAL_HALT_TARGET,
1245 [4] = SPECIAL_POWEROFF_TARGET,
1246 [5] = SPECIAL_REBOOT_TARGET,
1247 [6] = SPECIAL_KEXEC_TARGET
1250 /* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */
1251 static const ManagerExitCode code_table[] = {
1253 [1] = MANAGER_POWEROFF,
1254 [2] = MANAGER_REBOOT,
1258 if ((int) sfsi.ssi_signo >= SIGRTMIN+0 &&
1259 (int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(target_table)) {
1260 int idx = (int) sfsi.ssi_signo - SIGRTMIN;
1261 manager_start_target(m, target_table[idx],
1262 (idx == 1 || idx == 2) ? JOB_ISOLATE : JOB_REPLACE);
1266 if ((int) sfsi.ssi_signo >= SIGRTMIN+13 &&
1267 (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(code_table)) {
1268 m->exit_code = code_table[sfsi.ssi_signo - SIGRTMIN - 13];
1272 switch (sfsi.ssi_signo - SIGRTMIN) {
1275 log_debug("Enabling showing of status.");
1276 manager_set_show_status(m, true);
1280 log_debug("Disabling showing of status.");
1281 manager_set_show_status(m, false);
1285 log_set_max_level(LOG_DEBUG);
1286 log_notice("Setting log level to debug.");
1290 log_set_max_level(LOG_INFO);
1291 log_notice("Setting log level to info.");
1295 log_set_target(LOG_TARGET_JOURNAL_OR_KMSG);
1296 log_notice("Setting log target to journal-or-kmsg.");
1300 log_set_target(LOG_TARGET_CONSOLE);
1301 log_notice("Setting log target to console.");
1305 log_set_target(LOG_TARGET_KMSG);
1306 log_notice("Setting log target to kmsg.");
1310 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
1311 log_notice("Setting log target to syslog-or-kmsg.");
1315 log_warning("Got unhandled signal <%s>.", signal_to_string(sfsi.ssi_signo));
1322 return manager_dispatch_sigchld(m);
1327 static int process_event(Manager *m, struct epoll_event *ev) {
1334 assert_se(w = ev->data.ptr);
1336 if (w->type == WATCH_INVALID)
1343 /* An incoming signal? */
1344 if (ev->events != EPOLLIN)
1347 if ((r = manager_process_signal_fd(m)) < 0)
1354 /* An incoming daemon notification event? */
1355 if (ev->events != EPOLLIN)
1358 if ((r = manager_process_notify_fd(m)) < 0)
1365 /* Some fd event, to be dispatched to the units */
1366 UNIT_VTABLE(w->data.unit)->fd_event(w->data.unit, w->fd, ev->events, w);
1369 case WATCH_UNIT_TIMER:
1370 case WATCH_JOB_TIMER: {
1374 /* Some timer event, to be dispatched to the units */
1375 if ((k = read(w->fd, &v, sizeof(v))) != sizeof(v)) {
1377 if (k < 0 && (errno == EINTR || errno == EAGAIN))
1380 return k < 0 ? -errno : -EIO;
1383 if (w->type == WATCH_UNIT_TIMER)
1384 UNIT_VTABLE(w->data.unit)->timer_event(w->data.unit, v, w);
1386 job_timer_event(w->data.job, v, w);
1391 /* Some mount table change, intended for the mount subsystem */
1392 mount_fd_event(m, ev->events);
1396 /* Some swap table change, intended for the swap subsystem */
1397 swap_fd_event(m, ev->events);
1401 /* Some notification from udev, intended for the device subsystem */
1402 device_fd_event(m, ev->events);
1405 case WATCH_DBUS_WATCH:
1406 bus_watch_event(m, w, ev->events);
1409 case WATCH_DBUS_TIMEOUT:
1410 bus_timeout_event(m, w, ev->events);
1414 log_error("event type=%i", w->type);
1415 assert_not_reached("Unknown epoll event type.");
1421 int manager_loop(Manager *m) {
1424 RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
1427 m->exit_code = MANAGER_RUNNING;
1429 /* Release the path cache */
1430 set_free_free(m->unit_path_cache);
1431 m->unit_path_cache = NULL;
1433 manager_check_finished(m);
1435 /* There might still be some zombies hanging around from
1436 * before we were exec()'ed. Leat's reap them */
1437 r = manager_dispatch_sigchld(m);
1441 while (m->exit_code == MANAGER_RUNNING) {
1442 struct epoll_event event;
1446 if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)
1449 if (!ratelimit_test(&rl)) {
1450 /* Yay, something is going seriously wrong, pause a little */
1451 log_warning("Looping too fast. Throttling execution a little.");
1456 if (manager_dispatch_load_queue(m) > 0)
1459 if (manager_dispatch_run_queue(m) > 0)
1462 if (bus_dispatch(m) > 0)
1465 if (manager_dispatch_cleanup_queue(m) > 0)
1468 if (manager_dispatch_gc_queue(m) > 0)
1471 if (manager_dispatch_dbus_queue(m) > 0)
1474 if (swap_dispatch_reload(m) > 0)
1477 /* Sleep for half the watchdog time */
1478 if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM) {
1479 wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
1485 n = epoll_wait(m->epoll_fd, &event, 1, wait_msec);
1497 r = process_event(m, &event);
1502 return m->exit_code;
1505 int manager_load_unit_from_dbus_path(Manager *m, const char *s, DBusError *e, Unit **_u) {
1514 if (!startswith(s, "/org/freedesktop/systemd1/unit/"))
1517 n = bus_path_unescape(s+31);
1521 r = manager_load_unit(m, n, NULL, e, &u);
1532 int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j) {
1541 if (!startswith(s, "/org/freedesktop/systemd1/job/"))
1544 if ((r = safe_atou(s + 30, &id)) < 0)
1547 if (!(j = manager_get_job(m, id)))
1555 void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
1560 if (m->audit_fd < 0)
1563 /* Don't generate audit events if the service was already
1564 * started and we're just deserializing */
1565 if (m->n_reloading > 0)
1568 if (m->running_as != MANAGER_SYSTEM)
1571 if (u->type != UNIT_SERVICE)
1574 if (!(p = unit_name_to_prefix_and_instance(u->id))) {
1575 log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
1579 if (audit_log_user_comm_message(m->audit_fd, type, "", p, NULL, NULL, NULL, success) < 0) {
1580 if (errno == EPERM) {
1581 /* We aren't allowed to send audit messages?
1582 * Then let's not retry again. */
1583 audit_close(m->audit_fd);
1586 log_warning("Failed to send audit message: %m");
1594 void manager_send_unit_plymouth(Manager *m, Unit *u) {
1596 union sockaddr_union sa;
1598 char *message = NULL;
1600 /* Don't generate plymouth events if the service was already
1601 * started and we're just deserializing */
1602 if (m->n_reloading > 0)
1605 if (m->running_as != MANAGER_SYSTEM)
1608 if (u->type != UNIT_SERVICE &&
1609 u->type != UNIT_MOUNT &&
1610 u->type != UNIT_SWAP)
1613 /* We set SOCK_NONBLOCK here so that we rather drop the
1614 * message then wait for plymouth */
1615 if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) {
1616 log_error("socket() failed: %m");
1621 sa.sa.sa_family = AF_UNIX;
1622 strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1);
1623 if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
1625 if (errno != EPIPE &&
1628 errno != ECONNREFUSED &&
1629 errno != ECONNRESET &&
1630 errno != ECONNABORTED)
1631 log_error("connect() failed: %m");
1636 if (asprintf(&message, "U\002%c%s%n", (int) (strlen(u->id) + 1), u->id, &n) < 0) {
1637 log_error("Out of memory");
1642 if (write(fd, message, n + 1) != n + 1) {
1644 if (errno != EPIPE &&
1647 errno != ECONNREFUSED &&
1648 errno != ECONNRESET &&
1649 errno != ECONNABORTED)
1650 log_error("Failed to write Plymouth message: %m");
1657 close_nointr_nofail(fd);
1662 void manager_dispatch_bus_name_owner_changed(
1665 const char* old_owner,
1666 const char *new_owner) {
1673 if (!(u = hashmap_get(m->watch_bus, name)))
1676 UNIT_VTABLE(u)->bus_name_owner_change(u, name, old_owner, new_owner);
1679 void manager_dispatch_bus_query_pid_done(
1690 if (!(u = hashmap_get(m->watch_bus, name)))
1693 UNIT_VTABLE(u)->bus_query_pid_done(u, name, pid);
1696 int manager_open_serialization(Manager *m, FILE **_f) {
1704 if (m->running_as == MANAGER_SYSTEM)
1705 asprintf(&path, "/run/systemd/dump-%lu-XXXXXX", (unsigned long) getpid());
1707 asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
1712 saved_umask = umask(0077);
1713 fd = mkostemp(path, O_RDWR|O_CLOEXEC);
1723 log_debug("Serializing state to %s", path);
1726 if (!(f = fdopen(fd, "w+")))
1734 int manager_serialize(Manager *m, FILE *f, FDSet *fds) {
1746 fprintf(f, "current-job-id=%i\n", m->current_job_id);
1747 fprintf(f, "taint-usr=%s\n", yes_no(m->taint_usr));
1749 dual_timestamp_serialize(f, "initrd-timestamp", &m->initrd_timestamp);
1751 if (! in_initrd()) {
1752 dual_timestamp_serialize(f, "startup-timestamp", &m->startup_timestamp);
1753 dual_timestamp_serialize(f, "finish-timestamp", &m->finish_timestamp);
1758 HASHMAP_FOREACH_KEY(u, t, m->units, i) {
1762 if (!unit_can_serialize(u))
1769 if ((r = unit_serialize(u, f, fds)) < 0) {
1775 assert(m->n_reloading > 0);
1781 r = bus_fdset_add_all(m, fds);
1788 int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
1794 log_debug("Deserializing state...");
1799 char line[LINE_MAX], *l;
1801 if (!fgets(line, sizeof(line), f)) {
1816 if (startswith(l, "current-job-id=")) {
1819 if (safe_atou32(l+15, &id) < 0)
1820 log_debug("Failed to parse current job id value %s", l+15);
1822 m->current_job_id = MAX(m->current_job_id, id);
1823 } else if (startswith(l, "taint-usr=")) {
1826 if ((b = parse_boolean(l+10)) < 0)
1827 log_debug("Failed to parse taint /usr flag %s", l+10);
1829 m->taint_usr = m->taint_usr || b;
1830 } else if (startswith(l, "initrd-timestamp="))
1831 dual_timestamp_deserialize(l+17, &m->initrd_timestamp);
1832 else if (startswith(l, "startup-timestamp="))
1833 dual_timestamp_deserialize(l+18, &m->startup_timestamp);
1834 else if (startswith(l, "finish-timestamp="))
1835 dual_timestamp_deserialize(l+17, &m->finish_timestamp);
1837 log_debug("Unknown serialization item '%s'", l);
1842 char name[UNIT_NAME_MAX+2];
1845 if (!fgets(name, sizeof(name), f)) {
1856 if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
1859 if ((r = unit_deserialize(u, f, fds)) < 0)
1869 assert(m->n_reloading > 0);
1875 int manager_reload(Manager *m) {
1882 r = manager_open_serialization(m, &f);
1895 r = manager_serialize(m, f, fds);
1901 if (fseeko(f, 0, SEEK_SET) < 0) {
1907 /* From here on there is no way back. */
1908 manager_clear_jobs_and_units(m);
1909 manager_undo_generators(m);
1910 lookup_paths_free(&m->lookup_paths);
1912 /* Find new unit paths */
1913 manager_run_generators(m);
1915 q = lookup_paths_init(
1916 &m->lookup_paths, m->running_as, true,
1917 m->generator_unit_path,
1918 m->generator_unit_path_early,
1919 m->generator_unit_path_late);
1923 manager_build_unit_path_cache(m);
1925 /* First, enumerate what we can from all config files */
1926 q = manager_enumerate(m);
1930 /* Second, deserialize our stored data */
1931 q = manager_deserialize(m, f, fds);
1938 /* Third, fire things up! */
1939 q = manager_coldplug(m);
1943 assert(m->n_reloading > 0);
1956 bool manager_is_booting_or_shutting_down(Manager *m) {
1961 /* Is the initial job still around? */
1962 if (manager_get_job(m, m->default_unit_job_id))
1965 /* Is there a job for the shutdown target? */
1966 u = manager_get_unit(m, SPECIAL_SHUTDOWN_TARGET);
1973 void manager_reset_failed(Manager *m) {
1979 HASHMAP_FOREACH(u, m->units, i)
1980 unit_reset_failed(u);
1983 bool manager_unit_pending_inactive(Manager *m, const char *name) {
1989 /* Returns true if the unit is inactive or going down */
1990 if (!(u = manager_get_unit(m, name)))
1993 return unit_pending_inactive(u);
1996 void manager_check_finished(Manager *m) {
1997 char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX];
1998 usec_t kernel_usec, initrd_usec, userspace_usec, total_usec;
2002 if (hashmap_size(m->jobs) > 0)
2005 /* Notify Type=idle units that we are done now */
2006 close_pipe(m->idle_pipe);
2008 if (dual_timestamp_is_set(&m->finish_timestamp))
2011 dual_timestamp_get(&m->finish_timestamp);
2013 if (m->running_as == MANAGER_SYSTEM && detect_container(NULL) <= 0) {
2015 userspace_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
2016 total_usec = m->finish_timestamp.monotonic;
2018 if (dual_timestamp_is_set(&m->initrd_timestamp)) {
2020 kernel_usec = m->initrd_timestamp.monotonic;
2021 initrd_usec = m->startup_timestamp.monotonic - m->initrd_timestamp.monotonic;
2023 log_info("Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
2024 format_timespan(kernel, sizeof(kernel), kernel_usec),
2025 format_timespan(initrd, sizeof(initrd), initrd_usec),
2026 format_timespan(userspace, sizeof(userspace), userspace_usec),
2027 format_timespan(sum, sizeof(sum), total_usec));
2029 kernel_usec = m->startup_timestamp.monotonic;
2032 log_info("Startup finished in %s (kernel) + %s (userspace) = %s.",
2033 format_timespan(kernel, sizeof(kernel), kernel_usec),
2034 format_timespan(userspace, sizeof(userspace), userspace_usec),
2035 format_timespan(sum, sizeof(sum), total_usec));
2038 userspace_usec = initrd_usec = kernel_usec = 0;
2039 total_usec = m->finish_timestamp.monotonic - m->startup_timestamp.monotonic;
2041 log_debug("Startup finished in %s.",
2042 format_timespan(sum, sizeof(sum), total_usec));
2045 bus_broadcast_finished(m, kernel_usec, initrd_usec, userspace_usec, total_usec);
2048 "READY=1\nSTATUS=Startup finished in %s.",
2049 format_timespan(sum, sizeof(sum), total_usec));
2052 static int create_generator_dir(Manager *m, char **generator, const char *name) {
2063 if (m->running_as == MANAGER_SYSTEM && getpid() == 1) {
2065 p = strappend("/run/systemd/", name);
2067 log_error("Out of memory");
2071 r = mkdir_p_label(p, 0755);
2073 log_error("Failed to create generator directory: %s", strerror(-r));
2078 p = join("/tmp/systemd-", name, ".XXXXXX", NULL);
2080 log_error("Out of memory");
2086 log_error("Failed to create generator directory: %m");
2095 static void trim_generator_dir(Manager *m, char **generator) {
2102 if (rmdir(*generator) >= 0) {
2110 void manager_run_generators(Manager *m) {
2112 const char *generator_path;
2113 const char *argv[5];
2119 generator_path = m->running_as == MANAGER_SYSTEM ? SYSTEM_GENERATOR_PATH : USER_GENERATOR_PATH;
2120 d = opendir(generator_path);
2122 if (errno == ENOENT)
2125 log_error("Failed to enumerate generator directory: %m");
2129 r = create_generator_dir(m, &m->generator_unit_path, "generator");
2133 r = create_generator_dir(m, &m->generator_unit_path_early, "generator.early");
2137 r = create_generator_dir(m, &m->generator_unit_path_late, "generator.late");
2141 argv[0] = NULL; /* Leave this empty, execute_directory() will fill something in */
2142 argv[1] = m->generator_unit_path;
2143 argv[2] = m->generator_unit_path_early;
2144 argv[3] = m->generator_unit_path_late;
2148 execute_directory(generator_path, d, (char**) argv);
2151 trim_generator_dir(m, &m->generator_unit_path);
2152 trim_generator_dir(m, &m->generator_unit_path_early);
2153 trim_generator_dir(m, &m->generator_unit_path_late);
2160 static void remove_generator_dir(Manager *m, char **generator) {
2167 strv_remove(m->lookup_paths.unit_path, *generator);
2168 rm_rf(*generator, false, true, false);
2174 void manager_undo_generators(Manager *m) {
2177 remove_generator_dir(m, &m->generator_unit_path);
2178 remove_generator_dir(m, &m->generator_unit_path_early);
2179 remove_generator_dir(m, &m->generator_unit_path_late);
2182 int manager_set_default_controllers(Manager *m, char **controllers) {
2187 l = strv_copy(controllers);
2191 strv_free(m->default_controllers);
2192 m->default_controllers = l;
2194 cg_shorten_controllers(m->default_controllers);
2199 int manager_set_default_rlimits(Manager *m, struct rlimit **default_rlimit) {
2204 for (i = 0; i < RLIMIT_NLIMITS; i++) {
2205 if (!default_rlimit[i])
2208 m->rlimit[i] = newdup(struct rlimit, default_rlimit[i], 1);
2216 void manager_recheck_journal(Manager *m) {
2221 if (m->running_as != MANAGER_SYSTEM)
2224 u = manager_get_unit(m, SPECIAL_JOURNALD_SOCKET);
2225 if (u && SOCKET(u)->state != SOCKET_RUNNING) {
2226 log_close_journal();
2230 u = manager_get_unit(m, SPECIAL_JOURNALD_SERVICE);
2231 if (u && SERVICE(u)->state != SERVICE_RUNNING) {
2232 log_close_journal();
2236 /* Hmm, OK, so the socket is fully up and the service is up
2237 * too, then let's make use of the thing. */
2241 void manager_set_show_status(Manager *m, bool b) {
2244 if (m->running_as != MANAGER_SYSTEM)
2250 touch("/run/systemd/show-status");
2252 unlink("/run/systemd/show-status");
2255 bool manager_get_show_status(Manager *m) {
2258 if (m->running_as != MANAGER_SYSTEM)
2264 /* If Plymouth is running make sure we show the status, so
2265 * that there's something nice to see when people press Esc */
2267 return plymouth_running();
2270 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
2271 [MANAGER_SYSTEM] = "system",
2272 [MANAGER_USER] = "user"
2275 DEFINE_STRING_TABLE_LOOKUP(manager_running_as, ManagerRunningAs);