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/>.
29 #include "load-fragment.h"
30 #include "load-dropin.h"
33 #include "unit-name.h"
34 #include "dbus-service.h"
36 #include "bus-errors.h"
38 #define COMMENTS "#;\n"
39 #define NEWLINES "\n\r"
41 typedef enum RunlevelType {
50 const RunlevelType type;
52 /* Standard SysV runlevels for start-up */
53 { "rc1.d", SPECIAL_RESCUE_TARGET, RUNLEVEL_UP },
54 { "rc2.d", SPECIAL_RUNLEVEL2_TARGET, RUNLEVEL_UP },
55 { "rc3.d", SPECIAL_RUNLEVEL3_TARGET, RUNLEVEL_UP },
56 { "rc4.d", SPECIAL_RUNLEVEL4_TARGET, RUNLEVEL_UP },
57 { "rc5.d", SPECIAL_RUNLEVEL5_TARGET, RUNLEVEL_UP },
60 /* SUSE style boot.d */
61 { "boot.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT },
65 /* Debian style rcS.d */
66 { "rcS.d", SPECIAL_SYSINIT_TARGET, RUNLEVEL_SYSINIT },
69 /* Standard SysV runlevels for shutdown */
70 { "rc0.d", SPECIAL_POWEROFF_TARGET, RUNLEVEL_DOWN },
71 { "rc6.d", SPECIAL_REBOOT_TARGET, RUNLEVEL_DOWN }
73 /* Note that the order here matters, as we read the
74 directories in this order, and we want to make sure that
75 sysv_start_priority is known when we first load the
76 unit. And that value we only know from S links. Hence
77 UP/SYSINIT must be read before DOWN */
80 #define RUNLEVELS_UP "12345"
81 /* #define RUNLEVELS_DOWN "06" */
82 /* #define RUNLEVELS_BOOT "bBsS" */
84 static const UnitActiveState state_translation_table[_SERVICE_STATE_MAX] = {
85 [SERVICE_DEAD] = UNIT_INACTIVE,
86 [SERVICE_START_PRE] = UNIT_ACTIVATING,
87 [SERVICE_START] = UNIT_ACTIVATING,
88 [SERVICE_START_POST] = UNIT_ACTIVATING,
89 [SERVICE_RUNNING] = UNIT_ACTIVE,
90 [SERVICE_EXITED] = UNIT_ACTIVE,
91 [SERVICE_RELOAD] = UNIT_RELOADING,
92 [SERVICE_STOP] = UNIT_DEACTIVATING,
93 [SERVICE_STOP_SIGTERM] = UNIT_DEACTIVATING,
94 [SERVICE_STOP_SIGKILL] = UNIT_DEACTIVATING,
95 [SERVICE_STOP_POST] = UNIT_DEACTIVATING,
96 [SERVICE_FINAL_SIGTERM] = UNIT_DEACTIVATING,
97 [SERVICE_FINAL_SIGKILL] = UNIT_DEACTIVATING,
98 [SERVICE_FAILED] = UNIT_FAILED,
99 [SERVICE_AUTO_RESTART] = UNIT_ACTIVATING
102 static void service_init(Unit *u) {
103 Service *s = SERVICE(u);
106 assert(u->meta.load_state == UNIT_STUB);
108 s->timeout_usec = DEFAULT_TIMEOUT_USEC;
109 s->restart_usec = DEFAULT_RESTART_USEC;
110 s->timer_watch.type = WATCH_INVALID;
111 s->sysv_start_priority = -1;
114 exec_context_init(&s->exec_context);
116 RATELIMIT_INIT(s->ratelimit, 10*USEC_PER_SEC, 5);
118 s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
121 static void service_unwatch_control_pid(Service *s) {
124 if (s->control_pid <= 0)
127 unit_unwatch_pid(UNIT(s), s->control_pid);
131 static void service_unwatch_main_pid(Service *s) {
134 if (s->main_pid <= 0)
137 unit_unwatch_pid(UNIT(s), s->main_pid);
141 static int service_set_main_pid(Service *s, pid_t pid) {
152 if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid())
153 log_warning("%s: Supervising process %lu which is not our child. We'll most likely not notice when it exits.",
154 s->meta.id, (unsigned long) pid);
157 s->main_pid_known = true;
159 exec_status_start(&s->main_exec_status, pid);
164 static void service_close_socket_fd(Service *s) {
167 if (s->socket_fd < 0)
170 close_nointr_nofail(s->socket_fd);
174 static void service_connection_unref(Service *s) {
180 socket_connection_unref(s->socket);
184 static void service_done(Unit *u) {
185 Service *s = SERVICE(u);
195 free(s->sysv_runlevels);
196 s->sysv_runlevels = NULL;
198 free(s->status_text);
199 s->status_text = NULL;
201 exec_context_done(&s->exec_context);
202 exec_command_free_array(s->exec_command, _SERVICE_EXEC_COMMAND_MAX);
203 s->control_command = NULL;
205 /* This will leak a process, but at least no memory or any of
207 service_unwatch_main_pid(s);
208 service_unwatch_control_pid(s);
211 unit_unwatch_bus_name(UNIT(u), s->bus_name);
216 service_close_socket_fd(s);
217 service_connection_unref(s);
219 unit_unwatch_timer(u, &s->timer_watch);
222 static char *sysv_translate_name(const char *name) {
225 if (!(r = new(char, strlen(name) + sizeof(".service"))))
228 if (startswith(name, "boot."))
229 /* Drop SuSE-style boot. prefix */
230 strcpy(stpcpy(r, name + 5), ".service");
231 else if (endswith(name, ".sh"))
232 /* Drop Debian-style .sh suffix */
233 strcpy(stpcpy(r, name) - 3, ".service");
235 /* Normal init scripts */
236 strcpy(stpcpy(r, name), ".service");
241 static int sysv_translate_facility(const char *name, char **_r) {
243 static const char * const table[] = {
244 /* LSB defined facilities */
245 "$local_fs", SPECIAL_LOCAL_FS_TARGET,
246 "$network", SPECIAL_NETWORK_TARGET,
247 "$named", SPECIAL_NSS_LOOKUP_TARGET,
248 "$portmap", SPECIAL_RPCBIND_TARGET,
249 "$remote_fs", SPECIAL_REMOTE_FS_TARGET,
250 "$syslog", SPECIAL_SYSLOG_TARGET,
251 "$time", SPECIAL_RTC_SET_TARGET,
253 /* Debian extensions */
255 "$mail-transport-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
257 "$mail-transfer-agent", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
258 "$x-display-manager", SPECIAL_DISPLAY_MANAGER_SERVICE,
261 /* Fedora extensions, lacking the $ prefix */
262 "MTA", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
263 "smtpdaemon", SPECIAL_MAIL_TRANSFER_AGENT_TARGET,
264 "httpd", SPECIAL_HTTP_DAEMON_TARGET,
271 for (i = 0; i < ELEMENTSOF(table); i += 2)
272 if (streq(table[i], name)) {
273 if (!(r = strdup(table[i+1])))
282 if (!(r = sysv_translate_name(name)))
293 static int sysv_fix_order(Service *s) {
299 if (s->sysv_start_priority < 0)
302 /* For each pair of services where at least one lacks a LSB
303 * header, we use the start priority value to order things. */
305 LIST_FOREACH(units_per_type, other, s->meta.manager->units_per_type[UNIT_SERVICE]) {
308 bool special_s, special_t;
310 t = (Service*) other;
315 if (t->sysv_start_priority < 0)
318 /* If both units have modern headers we don't care
319 * about the priorities */
320 if ((!s->sysv_path || s->sysv_has_lsb) &&
321 (!t->sysv_path || t->sysv_has_lsb))
324 special_s = s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels);
325 special_t = t->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, t->sysv_runlevels);
327 if (special_t && !special_s)
329 else if (special_s && !special_t)
331 else if (t->sysv_start_priority < s->sysv_start_priority)
333 else if (t->sysv_start_priority > s->sysv_start_priority)
338 /* FIXME: Maybe we should compare the name here lexicographically? */
340 if (!(r = unit_add_dependency(UNIT(s), d, UNIT(t), true)) < 0)
347 static ExecCommand *exec_command_new(const char *path, const char *arg1) {
350 if (!(c = new0(ExecCommand, 1)))
353 if (!(c->path = strdup(path))) {
358 if (!(c->argv = strv_new(path, arg1, NULL))) {
367 static int sysv_exec_commands(Service *s) {
371 assert(s->sysv_path);
373 if (!(c = exec_command_new(s->sysv_path, "start")))
375 exec_command_append_list(s->exec_command+SERVICE_EXEC_START, c);
377 if (!(c = exec_command_new(s->sysv_path, "stop")))
379 exec_command_append_list(s->exec_command+SERVICE_EXEC_STOP, c);
381 if (!(c = exec_command_new(s->sysv_path, "reload")))
383 exec_command_append_list(s->exec_command+SERVICE_EXEC_RELOAD, c);
388 static int service_load_sysv_path(Service *s, const char *path) {
405 if (!(f = fopen(path, "re"))) {
406 r = errno == ENOENT ? 0 : -errno;
411 if (!(s->sysv_path = strdup(path))) {
417 char l[LINE_MAX], *t;
419 if (!fgets(l, sizeof(l), f)) {
424 log_error("Failed to read configuration file '%s': %s", path, strerror(-r));
434 if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
436 s->sysv_has_lsb = true;
440 if ((state == LSB_DESCRIPTION || state == LSB) && streq(t, "### END INIT INFO")) {
446 t += strspn(t, WHITESPACE);
448 if (state == NORMAL) {
450 /* Try to parse Red Hat style chkconfig headers */
452 if (startswith_no_case(t, "chkconfig:")) {
454 char runlevels[16], *k;
458 if (sscanf(t+10, "%15s %i %*i",
460 &start_priority) != 2) {
462 log_warning("[%s:%u] Failed to parse chkconfig line. Ignoring.", path, line);
466 /* A start priority gathered from the
467 * symlink farms is preferred over the
468 * data from the LSB header. */
469 if (start_priority < 0 || start_priority > 99)
470 log_warning("[%s:%u] Start priority out of range. Ignoring.", path, line);
471 else if (s->sysv_start_priority < 0)
472 s->sysv_start_priority = start_priority;
474 char_array_0(runlevels);
475 k = delete_chars(runlevels, WHITESPACE "-");
480 if (!(d = strdup(k))) {
485 free(s->sysv_runlevels);
486 s->sysv_runlevels = d;
489 } else if (startswith_no_case(t, "description:") &&
490 !u->meta.description) {
492 size_t k = strlen(t);
495 if (t[k-1] == '\\') {
500 if (!(d = strappend("LSB: ", strstrip(t+12)))) {
505 free(u->meta.description);
506 u->meta.description = d;
508 } else if (startswith_no_case(t, "pidfile:")) {
515 if (!path_is_absolute(fn)) {
516 log_warning("[%s:%u] PID file not absolute. Ignoring.", path, line);
520 if (!(fn = strdup(fn))) {
529 } else if (state == DESCRIPTION) {
531 /* Try to parse Red Hat style description
534 size_t k = strlen(t);
542 assert(u->meta.description);
543 if (asprintf(&d, "%s %s", u->meta.description, strstrip(t)) < 0) {
548 free(u->meta.description);
549 u->meta.description = d;
551 } else if (state == LSB || state == LSB_DESCRIPTION) {
553 if (startswith_no_case(t, "Provides:")) {
559 FOREACH_WORD_QUOTED(w, z, t+9, i) {
562 if (!(n = strndup(w, z))) {
567 r = sysv_translate_facility(n, &m);
576 if (unit_name_to_type(m) == UNIT_SERVICE)
577 r = unit_add_name(u, m);
579 r = unit_add_dependency_by_name(u, UNIT_BEFORE, m, NULL, true);
581 if (s->sysv_enabled) {
584 if ((k = unit_add_dependency_by_name_inverse(u, UNIT_WANTS, m, NULL, true)) < 0)
590 log_error("[%s:%u] Failed to add LSB Provides name %s, ignoring: %s", path, line, m, strerror(-r));
595 } else if (startswith_no_case(t, "Required-Start:") ||
596 startswith_no_case(t, "Should-Start:") ||
597 startswith_no_case(t, "X-Start-Before:") ||
598 startswith_no_case(t, "X-Start-After:")) {
604 FOREACH_WORD_QUOTED(w, z, strchr(t, ':')+1, i) {
607 if (!(n = strndup(w, z))) {
612 r = sysv_translate_facility(n, &m);
621 r = unit_add_dependency_by_name(u, startswith_no_case(t, "X-Start-Before:") ? UNIT_BEFORE : UNIT_AFTER, m, NULL, true);
624 log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", path, line, m, strerror(-r));
628 } else if (startswith_no_case(t, "Default-Start:")) {
633 k = delete_chars(t+14, WHITESPACE "-");
636 if (!(d = strdup(k))) {
641 free(s->sysv_runlevels);
642 s->sysv_runlevels = d;
645 } else if (startswith_no_case(t, "Description:") &&
646 !u->meta.description) {
649 /* We use the long description only if
650 * no short description is set. */
652 state = LSB_DESCRIPTION;
654 if (!(d = strappend("LSB: ", strstrip(t+12)))) {
659 free(u->meta.description);
660 u->meta.description = d;
662 } else if (startswith_no_case(t, "Short-Description:")) {
667 if (!(d = strappend("LSB: ", strstrip(t+18)))) {
672 free(u->meta.description);
673 u->meta.description = d;
675 } else if (startswith_no_case(t, "X-Interactive:")) {
678 if ((b = parse_boolean(strstrip(t+14))) < 0) {
679 log_warning("[%s:%u] Couldn't parse interactive flag. Ignoring.", path, line);
684 s->exec_context.std_input = EXEC_INPUT_TTY;
686 s->exec_context.std_input = EXEC_INPUT_NULL;
688 } else if (state == LSB_DESCRIPTION) {
690 if (startswith(l, "#\t") || startswith(l, "# ")) {
693 assert(u->meta.description);
694 if (asprintf(&d, "%s %s", u->meta.description, t) < 0) {
699 free(u->meta.description);
700 u->meta.description = d;
707 if ((r = sysv_exec_commands(s)) < 0)
710 if (s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels)) {
711 /* If there a runlevels configured for this service
712 * but none of the standard ones, then we assume this
713 * is some special kind of service (which might be
714 * needed for early boot) and don't create any links
717 s->meta.default_dependencies = false;
719 /* Don't timeout special services during boot (like fsck) */
723 /* Special setting for all SysV services */
724 s->type = SERVICE_FORKING;
725 s->remain_after_exit = true;
726 s->restart = SERVICE_ONCE;
727 s->exec_context.std_output =
728 (s->meta.manager->sysv_console || s->exec_context.std_input == EXEC_INPUT_TTY)
729 ? EXEC_OUTPUT_TTY : EXEC_OUTPUT_NULL;
730 s->exec_context.kill_mode = KILL_PROCESS_GROUP;
732 u->meta.load_state = UNIT_LOADED;
743 static int service_load_sysv_name(Service *s, const char *name) {
749 /* For SysV services we strip the boot. or .sh
750 * prefixes/suffixes. */
751 if (startswith(name, "boot.") ||
752 endswith(name, ".sh.service"))
755 STRV_FOREACH(p, s->meta.manager->lookup_paths.sysvinit_path) {
759 if (asprintf(&path, "%s/%s", *p, name) < 0)
762 assert(endswith(path, ".service"));
763 path[strlen(path)-8] = 0;
765 r = service_load_sysv_path(s, path);
767 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
768 /* Try Debian style xxx.sh source'able init scripts */
770 r = service_load_sysv_path(s, path);
775 if (r >= 0 && s->meta.load_state == UNIT_STUB) {
776 /* Try SUSE style boot.xxx init scripts */
778 if (asprintf(&path, "%s/boot.%s", *p, name) < 0)
781 path[strlen(path)-8] = 0;
782 r = service_load_sysv_path(s, path);
789 if ((s->meta.load_state != UNIT_STUB))
796 static int service_load_sysv(Service *s) {
803 /* Load service data from SysV init scripts, preferably with
806 if (strv_isempty(s->meta.manager->lookup_paths.sysvinit_path))
809 if ((t = s->meta.id))
810 if ((r = service_load_sysv_name(s, t)) < 0)
813 if (s->meta.load_state == UNIT_STUB)
814 SET_FOREACH(t, s->meta.names, i) {
818 if ((r = service_load_sysv_name(s, t)) < 0)
821 if (s->meta.load_state != UNIT_STUB)
828 static int service_verify(Service *s) {
831 if (s->meta.load_state != UNIT_LOADED)
834 if (!s->exec_command[SERVICE_EXEC_START]) {
835 log_error("%s lacks ExecStart setting. Refusing.", s->meta.id);
839 if (s->type != SERVICE_ONESHOT &&
840 s->exec_command[SERVICE_EXEC_START]->command_next) {
841 log_error("%s has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.", s->meta.id);
845 if (s->type == SERVICE_DBUS && !s->bus_name) {
846 log_error("%s is of type D-Bus but no D-Bus service name has been specified. Refusing.", s->meta.id);
850 if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) {
851 log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", s->meta.id);
858 static int service_add_default_dependencies(Service *s) {
863 /* Add a number of automatic dependencies useful for the
864 * majority of services. */
866 /* First, pull in base system */
867 if (s->meta.manager->running_as == MANAGER_SYSTEM) {
869 if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_BASIC_TARGET, NULL, true)) < 0)
872 } else if (s->meta.manager->running_as == MANAGER_SESSION) {
874 if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SOCKETS_TARGET, NULL, true)) < 0)
878 /* Second, activate normal shutdown */
879 return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTED_BY, SPECIAL_SHUTDOWN_TARGET, NULL, true);
882 static int service_load(Unit *u) {
884 Service *s = SERVICE(u);
888 /* Load a .service file */
889 if ((r = unit_load_fragment(u)) < 0)
892 /* Load a classic init script as a fallback, if we couldn't find anything */
893 if (u->meta.load_state == UNIT_STUB)
894 if ((r = service_load_sysv(s)) < 0)
897 /* Still nothing found? Then let's give up */
898 if (u->meta.load_state == UNIT_STUB)
901 /* We were able to load something, then let's add in the
902 * dropin directories. */
903 if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
906 /* This is a new unit? Then let's add in some extras */
907 if (u->meta.load_state == UNIT_LOADED) {
908 if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
911 if ((r = unit_add_default_cgroup(u)) < 0)
914 if ((r = sysv_fix_order(s)) < 0)
918 if ((r = unit_watch_bus_name(u, s->bus_name)) < 0)
921 if (s->type == SERVICE_NOTIFY && s->notify_access == NOTIFY_NONE)
922 s->notify_access = NOTIFY_MAIN;
924 if (s->type == SERVICE_DBUS || s->bus_name)
925 if ((r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, SPECIAL_DBUS_TARGET, NULL, true)) < 0)
928 if (s->meta.default_dependencies)
929 if ((r = service_add_default_dependencies(s)) < 0)
933 return service_verify(s);
936 static void service_dump(Unit *u, FILE *f, const char *prefix) {
938 ServiceExecCommand c;
939 Service *s = SERVICE(u);
945 p2 = strappend(prefix, "\t");
946 prefix2 = p2 ? p2 : prefix;
949 "%sService State: %s\n"
950 "%sPermissionsStartOnly: %s\n"
951 "%sRootDirectoryStartOnly: %s\n"
952 "%sRemainAfterExit: %s\n"
955 "%sNotifyAccess: %s\n",
956 prefix, service_state_to_string(s->state),
957 prefix, yes_no(s->permissions_start_only),
958 prefix, yes_no(s->root_directory_start_only),
959 prefix, yes_no(s->remain_after_exit),
960 prefix, service_type_to_string(s->type),
961 prefix, service_restart_to_string(s->restart),
962 prefix, notify_access_to_string(s->notify_access));
964 if (s->control_pid > 0)
966 "%sControl PID: %lu\n",
967 prefix, (unsigned long) s->control_pid);
972 prefix, (unsigned long) s->main_pid);
977 prefix, s->pid_file);
982 "%sBus Name Good: %s\n",
984 prefix, yes_no(s->bus_name_good));
986 exec_context_dump(&s->exec_context, f, prefix);
988 for (c = 0; c < _SERVICE_EXEC_COMMAND_MAX; c++) {
990 if (!s->exec_command[c])
993 fprintf(f, "%s-> %s:\n",
994 prefix, service_exec_command_to_string(c));
996 exec_command_dump_list(s->exec_command[c], f, prefix2);
1001 "%sSysV Init Script Path: %s\n"
1002 "%sSysV Init Script has LSB Header: %s\n",
1003 prefix, s->sysv_path,
1004 prefix, yes_no(s->sysv_has_lsb));
1006 if (s->sysv_start_priority >= 0)
1008 "%sSysVStartPriority: %i\n"
1009 "%sSysVEnabled: %s\n",
1010 prefix, s->sysv_start_priority,
1011 prefix, yes_no(s->sysv_enabled));
1013 if (s->sysv_runlevels)
1014 fprintf(f, "%sSysVRunLevels: %s\n",
1015 prefix, s->sysv_runlevels);
1018 fprintf(f, "%sStatus Text: %s\n",
1019 prefix, s->status_text);
1024 static int service_load_pid_file(Service *s) {
1031 if (s->main_pid_known)
1034 assert(s->main_pid <= 0);
1039 if ((r = read_one_line_file(s->pid_file, &k)) < 0)
1042 r = parse_pid(k, &pid);
1048 if (kill(pid, 0) < 0 && errno != EPERM) {
1049 log_warning("PID %lu read from file %s does not exist. Your service or init script might be broken.",
1050 (unsigned long) pid, s->pid_file);
1054 if ((r = service_set_main_pid(s, pid)) < 0)
1057 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1058 /* FIXME: we need to do something here */
1064 static int service_get_sockets(Service *s, Set **_set) {
1073 if (s->socket_fd >= 0)
1076 /* Collects all Socket objects that belong to this
1077 * service. Note that a service might have multiple sockets
1078 * via multiple names. */
1080 if (!(set = set_new(NULL, NULL)))
1083 SET_FOREACH(t, s->meta.names, i) {
1087 /* Look for all socket objects that go by any of our
1088 * units and collect their fds */
1090 if (!(k = unit_name_change_suffix(t, ".socket"))) {
1095 p = manager_get_unit(s->meta.manager, k);
1101 if ((r = set_put(set, p)) < 0)
1113 static int service_notify_sockets_dead(Service *s) {
1121 if (s->socket_fd >= 0)
1124 /* Notifies all our sockets when we die */
1125 if ((r = service_get_sockets(s, &set)) < 0)
1128 SET_FOREACH(sock, set, i)
1129 socket_notify_service_dead(sock);
1136 static void service_set_state(Service *s, ServiceState state) {
1137 ServiceState old_state;
1140 old_state = s->state;
1143 if (state != SERVICE_START_PRE &&
1144 state != SERVICE_START &&
1145 state != SERVICE_START_POST &&
1146 state != SERVICE_RELOAD &&
1147 state != SERVICE_STOP &&
1148 state != SERVICE_STOP_SIGTERM &&
1149 state != SERVICE_STOP_SIGKILL &&
1150 state != SERVICE_STOP_POST &&
1151 state != SERVICE_FINAL_SIGTERM &&
1152 state != SERVICE_FINAL_SIGKILL &&
1153 state != SERVICE_AUTO_RESTART)
1154 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1156 if (state != SERVICE_START &&
1157 state != SERVICE_START_POST &&
1158 state != SERVICE_RUNNING &&
1159 state != SERVICE_RELOAD &&
1160 state != SERVICE_STOP &&
1161 state != SERVICE_STOP_SIGTERM &&
1162 state != SERVICE_STOP_SIGKILL)
1163 service_unwatch_main_pid(s);
1165 if (state != SERVICE_START_PRE &&
1166 state != SERVICE_START &&
1167 state != SERVICE_START_POST &&
1168 state != SERVICE_RELOAD &&
1169 state != SERVICE_STOP &&
1170 state != SERVICE_STOP_SIGTERM &&
1171 state != SERVICE_STOP_SIGKILL &&
1172 state != SERVICE_STOP_POST &&
1173 state != SERVICE_FINAL_SIGTERM &&
1174 state != SERVICE_FINAL_SIGKILL) {
1175 service_unwatch_control_pid(s);
1176 s->control_command = NULL;
1177 s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
1180 if (state == SERVICE_DEAD ||
1181 state == SERVICE_STOP ||
1182 state == SERVICE_STOP_SIGTERM ||
1183 state == SERVICE_STOP_SIGKILL ||
1184 state == SERVICE_STOP_POST ||
1185 state == SERVICE_FINAL_SIGTERM ||
1186 state == SERVICE_FINAL_SIGKILL ||
1187 state == SERVICE_FAILED ||
1188 state == SERVICE_AUTO_RESTART)
1189 service_notify_sockets_dead(s);
1191 if (state != SERVICE_START_PRE &&
1192 state != SERVICE_START &&
1193 state != SERVICE_START_POST &&
1194 state != SERVICE_RUNNING &&
1195 state != SERVICE_RELOAD &&
1196 state != SERVICE_STOP &&
1197 state != SERVICE_STOP_SIGTERM &&
1198 state != SERVICE_STOP_SIGKILL &&
1199 state != SERVICE_STOP_POST &&
1200 state != SERVICE_FINAL_SIGTERM &&
1201 state != SERVICE_FINAL_SIGKILL &&
1202 !(state == SERVICE_DEAD && s->meta.job)) {
1203 service_close_socket_fd(s);
1204 service_connection_unref(s);
1207 /* For the inactive states unit_notify() will trim the cgroup,
1208 * but for exit we have to do that ourselves... */
1209 if (state == SERVICE_EXITED)
1210 cgroup_bonding_trim_list(s->meta.cgroup_bondings, true);
1212 if (old_state != state)
1213 log_debug("%s changed %s -> %s", s->meta.id, service_state_to_string(old_state), service_state_to_string(state));
1215 unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
1218 static int service_coldplug(Unit *u) {
1219 Service *s = SERVICE(u);
1223 assert(s->state == SERVICE_DEAD);
1225 if (s->deserialized_state != s->state) {
1227 if (s->deserialized_state == SERVICE_START_PRE ||
1228 s->deserialized_state == SERVICE_START ||
1229 s->deserialized_state == SERVICE_START_POST ||
1230 s->deserialized_state == SERVICE_RELOAD ||
1231 s->deserialized_state == SERVICE_STOP ||
1232 s->deserialized_state == SERVICE_STOP_SIGTERM ||
1233 s->deserialized_state == SERVICE_STOP_SIGKILL ||
1234 s->deserialized_state == SERVICE_STOP_POST ||
1235 s->deserialized_state == SERVICE_FINAL_SIGTERM ||
1236 s->deserialized_state == SERVICE_FINAL_SIGKILL ||
1237 s->deserialized_state == SERVICE_AUTO_RESTART) {
1239 if (s->deserialized_state == SERVICE_AUTO_RESTART || s->timeout_usec > 0) {
1242 k = s->deserialized_state == SERVICE_AUTO_RESTART ? s->restart_usec : s->timeout_usec;
1244 if ((r = unit_watch_timer(UNIT(s), k, &s->timer_watch)) < 0)
1249 if ((s->deserialized_state == SERVICE_START &&
1250 (s->type == SERVICE_FORKING ||
1251 s->type == SERVICE_DBUS ||
1252 s->type == SERVICE_ONESHOT ||
1253 s->type == SERVICE_NOTIFY)) ||
1254 s->deserialized_state == SERVICE_START_POST ||
1255 s->deserialized_state == SERVICE_RUNNING ||
1256 s->deserialized_state == SERVICE_RELOAD ||
1257 s->deserialized_state == SERVICE_STOP ||
1258 s->deserialized_state == SERVICE_STOP_SIGTERM ||
1259 s->deserialized_state == SERVICE_STOP_SIGKILL)
1260 if (s->main_pid > 0)
1261 if ((r = unit_watch_pid(UNIT(s), s->main_pid)) < 0)
1264 if (s->deserialized_state == SERVICE_START_PRE ||
1265 s->deserialized_state == SERVICE_START ||
1266 s->deserialized_state == SERVICE_START_POST ||
1267 s->deserialized_state == SERVICE_RELOAD ||
1268 s->deserialized_state == SERVICE_STOP ||
1269 s->deserialized_state == SERVICE_STOP_SIGTERM ||
1270 s->deserialized_state == SERVICE_STOP_SIGKILL ||
1271 s->deserialized_state == SERVICE_STOP_POST ||
1272 s->deserialized_state == SERVICE_FINAL_SIGTERM ||
1273 s->deserialized_state == SERVICE_FINAL_SIGKILL)
1274 if (s->control_pid > 0)
1275 if ((r = unit_watch_pid(UNIT(s), s->control_pid)) < 0)
1278 service_set_state(s, s->deserialized_state);
1284 static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) {
1288 unsigned rn_fds = 0;
1296 if (s->socket_fd >= 0)
1299 if ((r = service_get_sockets(s, &set)) < 0)
1302 SET_FOREACH(sock, set, i) {
1306 if ((r = socket_collect_fds(sock, &cfds, &cn_fds)) < 0)
1318 if (!(t = new(int, rn_fds+cn_fds))) {
1324 memcpy(t, rfds, rn_fds);
1325 memcpy(t+rn_fds, cfds, cn_fds);
1330 rn_fds = rn_fds+cn_fds;
1348 static int service_spawn(
1353 bool apply_permissions,
1355 bool apply_tty_stdin,
1356 bool set_notify_socket,
1361 int *fds = NULL, *fdsbuf = NULL;
1362 unsigned n_fds = 0, n_env = 0;
1363 char **argv = NULL, **final_env = NULL, **our_env = NULL;
1370 s->exec_context.std_input == EXEC_INPUT_SOCKET ||
1371 s->exec_context.std_output == EXEC_OUTPUT_SOCKET ||
1372 s->exec_context.std_error == EXEC_OUTPUT_SOCKET) {
1374 if (s->socket_fd >= 0) {
1375 fds = &s->socket_fd;
1378 if ((r = service_collect_fds(s, &fdsbuf, &n_fds)) < 0)
1385 if (timeout && s->timeout_usec) {
1386 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1389 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1391 if (!(argv = unit_full_printf_strv(UNIT(s), c->argv))) {
1396 if (!(our_env = new0(char*, 3))) {
1401 if (set_notify_socket)
1402 if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=@%s", s->meta.manager->notify_socket) < 0) {
1407 if (s->main_pid > 0)
1408 if (asprintf(our_env + n_env++, "MAINPID=%lu", (unsigned long) s->main_pid) < 0) {
1413 if (!(final_env = strv_env_merge(2,
1414 s->meta.manager->environment,
1429 s->meta.manager->confirm_spawn,
1430 s->meta.cgroup_bondings,
1437 if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
1438 /* FIXME: we need to do something here */
1444 strv_free(final_env);
1454 strv_free(final_env);
1457 unit_unwatch_timer(UNIT(s), &s->timer_watch);
1462 static int main_pid_good(Service *s) {
1465 /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
1468 /* If we know the pid file, then lets just check if it is
1470 if (s->main_pid_known)
1471 return s->main_pid > 0;
1473 /* We don't know the pid */
1477 static int control_pid_good(Service *s) {
1480 return s->control_pid > 0;
1483 static int cgroup_good(Service *s) {
1488 if ((r = cgroup_bonding_is_empty_list(s->meta.cgroup_bondings)) < 0)
1494 static void service_enter_dead(Service *s, bool success, bool allow_restart) {
1501 if (allow_restart &&
1502 !s->forbid_restart &&
1503 (s->restart == SERVICE_RESTART_ALWAYS ||
1504 (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
1506 if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
1509 service_set_state(s, SERVICE_AUTO_RESTART);
1511 service_set_state(s, s->failure ? SERVICE_FAILED : SERVICE_DEAD);
1513 s->forbid_restart = false;
1518 log_warning("%s failed to run install restart timer: %s", s->meta.id, strerror(-r));
1519 service_enter_dead(s, false, false);
1522 static void service_enter_signal(Service *s, ServiceState state, bool success);
1524 static void service_enter_stop_post(Service *s, bool success) {
1531 service_unwatch_control_pid(s);
1533 s->control_command_id = SERVICE_EXEC_STOP_POST;
1534 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST])) {
1535 if ((r = service_spawn(s,
1539 !s->permissions_start_only,
1540 !s->root_directory_start_only,
1543 &s->control_pid)) < 0)
1547 service_set_state(s, SERVICE_STOP_POST);
1549 service_enter_signal(s, SERVICE_FINAL_SIGTERM, true);
1554 log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
1555 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1558 static void service_enter_signal(Service *s, ServiceState state, bool success) {
1560 Set *pid_set = NULL;
1561 bool wait_for_exit = false;
1568 if (s->exec_context.kill_mode != KILL_NONE) {
1569 int sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? s->exec_context.kill_signal : SIGKILL;
1571 if (s->main_pid > 0) {
1572 if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
1574 s->main_pid, sig) < 0 && errno != ESRCH)
1576 log_warning("Failed to kill main process %li: %m", (long) s->main_pid);
1578 wait_for_exit = true;
1581 if (s->control_pid > 0) {
1582 if (kill(s->exec_context.kill_mode == KILL_PROCESS_GROUP ?
1584 s->control_pid, sig) < 0 && errno != ESRCH)
1586 log_warning("Failed to kill control process %li: %m", (long) s->control_pid);
1588 wait_for_exit = true;
1591 if (s->exec_context.kill_mode == KILL_CONTROL_GROUP) {
1593 if (!(pid_set = set_new(trivial_hash_func, trivial_compare_func))) {
1598 /* Exclude the main/control pids from being killed via the cgroup */
1599 if (s->main_pid > 0)
1600 if ((r = set_put(pid_set, LONG_TO_PTR(s->main_pid))) < 0)
1603 if (s->control_pid > 0)
1604 if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
1607 if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, pid_set)) < 0) {
1608 if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
1609 log_warning("Failed to kill control group: %s", strerror(-r));
1611 wait_for_exit = true;
1617 if (wait_for_exit) {
1618 if (s->timeout_usec > 0)
1619 if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
1622 service_set_state(s, state);
1623 } else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
1624 service_enter_stop_post(s, true);
1626 service_enter_dead(s, true, true);
1631 log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r));
1633 if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
1634 service_enter_stop_post(s, false);
1636 service_enter_dead(s, false, true);
1642 static void service_enter_stop(Service *s, bool success) {
1650 service_unwatch_control_pid(s);
1652 s->control_command_id = SERVICE_EXEC_STOP;
1653 if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP])) {
1654 if ((r = service_spawn(s,
1658 !s->permissions_start_only,
1659 !s->root_directory_start_only,
1662 &s->control_pid)) < 0)
1665 service_set_state(s, SERVICE_STOP);
1667 service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
1672 log_warning("%s failed to run 'stop' task: %s", s->meta.id, strerror(-r));
1673 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1676 static void service_enter_running(Service *s, bool success) {
1677 int main_pid_ok, cgroup_ok;
1683 main_pid_ok = main_pid_good(s);
1684 cgroup_ok = cgroup_good(s);
1686 if ((main_pid_ok > 0 || (main_pid_ok < 0 && cgroup_ok != 0)) &&
1687 (s->bus_name_good || s->type != SERVICE_DBUS))
1688 service_set_state(s, SERVICE_RUNNING);
1689 else if (s->remain_after_exit)
1690 service_set_state(s, SERVICE_EXITED);
1692 service_enter_stop(s, true);
1695 static void service_enter_start_post(Service *s) {
1699 service_unwatch_control_pid(s);
1701 s->control_command_id = SERVICE_EXEC_START_POST;
1702 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST])) {
1703 if ((r = service_spawn(s,
1707 !s->permissions_start_only,
1708 !s->root_directory_start_only,
1711 &s->control_pid)) < 0)
1714 service_set_state(s, SERVICE_START_POST);
1716 service_enter_running(s, true);
1721 log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
1722 service_enter_stop(s, false);
1725 static void service_enter_start(Service *s) {
1731 assert(s->exec_command[SERVICE_EXEC_START]);
1732 assert(!s->exec_command[SERVICE_EXEC_START]->command_next || s->type == SERVICE_ONESHOT);
1734 if (s->type == SERVICE_FORKING)
1735 service_unwatch_control_pid(s);
1737 service_unwatch_main_pid(s);
1739 s->control_command_id = SERVICE_EXEC_START;
1740 s->control_command = s->exec_command[SERVICE_EXEC_START];
1742 if ((r = service_spawn(s,
1744 s->type == SERVICE_FORKING || s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY,
1749 s->notify_access != NOTIFY_NONE,
1753 if (s->type == SERVICE_SIMPLE) {
1754 /* For simple services we immediately start
1755 * the START_POST binaries. */
1757 service_set_main_pid(s, pid);
1758 service_enter_start_post(s);
1760 } else if (s->type == SERVICE_FORKING) {
1762 /* For forking services we wait until the start
1763 * process exited. */
1765 s->control_pid = pid;
1766 service_set_state(s, SERVICE_START);
1768 } else if (s->type == SERVICE_ONESHOT ||
1769 s->type == SERVICE_DBUS ||
1770 s->type == SERVICE_NOTIFY) {
1772 /* For oneshot services we wait until the start
1773 * process exited, too, but it is our main process. */
1775 /* For D-Bus services we know the main pid right away,
1776 * but wait for the bus name to appear on the
1777 * bus. Notify services are similar. */
1779 service_set_main_pid(s, pid);
1780 service_set_state(s, SERVICE_START);
1782 assert_not_reached("Unknown service type");
1787 log_warning("%s failed to run 'start' task: %s", s->meta.id, strerror(-r));
1788 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1791 static void service_enter_start_pre(Service *s) {
1796 service_unwatch_control_pid(s);
1798 s->control_command_id = SERVICE_EXEC_START_PRE;
1799 if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE])) {
1800 if ((r = service_spawn(s,
1804 !s->permissions_start_only,
1805 !s->root_directory_start_only,
1808 &s->control_pid)) < 0)
1811 service_set_state(s, SERVICE_START_PRE);
1813 service_enter_start(s);
1818 log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
1819 service_enter_dead(s, false, true);
1822 static void service_enter_restart(Service *s) {
1827 dbus_error_init(&error);
1829 service_enter_dead(s, true, false);
1831 if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, &error, NULL)) < 0)
1834 log_debug("%s scheduled restart job.", s->meta.id);
1838 log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
1839 service_enter_dead(s, false, false);
1841 dbus_error_free(&error);
1844 static void service_enter_reload(Service *s) {
1849 service_unwatch_control_pid(s);
1851 s->control_command_id = SERVICE_EXEC_RELOAD;
1852 if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD])) {
1853 if ((r = service_spawn(s,
1857 !s->permissions_start_only,
1858 !s->root_directory_start_only,
1861 &s->control_pid)) < 0)
1864 service_set_state(s, SERVICE_RELOAD);
1866 service_enter_running(s, true);
1871 log_warning("%s failed to run 'reload' task: %s", s->meta.id, strerror(-r));
1872 service_enter_stop(s, false);
1875 static void service_run_next_control(Service *s, bool success) {
1879 assert(s->control_command);
1880 assert(s->control_command->command_next);
1885 assert(s->control_command_id != SERVICE_EXEC_START);
1887 s->control_command = s->control_command->command_next;
1888 service_unwatch_control_pid(s);
1890 if ((r = service_spawn(s,
1894 !s->permissions_start_only,
1895 !s->root_directory_start_only,
1896 s->control_command_id == SERVICE_EXEC_START_PRE ||
1897 s->control_command_id == SERVICE_EXEC_STOP_POST,
1899 &s->control_pid)) < 0)
1905 log_warning("%s failed to run next control task: %s", s->meta.id, strerror(-r));
1907 if (s->state == SERVICE_START_PRE)
1908 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
1909 else if (s->state == SERVICE_STOP)
1910 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
1911 else if (s->state == SERVICE_STOP_POST)
1912 service_enter_dead(s, false, true);
1914 service_enter_stop(s, false);
1917 static void service_run_next_main(Service *s, bool success) {
1922 assert(s->control_command);
1923 assert(s->control_command->command_next);
1928 assert(s->control_command_id == SERVICE_EXEC_START);
1929 assert(s->type == SERVICE_ONESHOT);
1931 s->control_command = s->control_command->command_next;
1932 service_unwatch_main_pid(s);
1934 if ((r = service_spawn(s,
1941 s->notify_access != NOTIFY_NONE,
1945 service_set_main_pid(s, pid);
1950 log_warning("%s failed to run next main task: %s", s->meta.id, strerror(-r));
1951 service_enter_stop(s, false);
1954 static int service_start(Unit *u) {
1955 Service *s = SERVICE(u);
1959 /* We cannot fulfill this request right now, try again later
1961 if (s->state == SERVICE_STOP ||
1962 s->state == SERVICE_STOP_SIGTERM ||
1963 s->state == SERVICE_STOP_SIGKILL ||
1964 s->state == SERVICE_STOP_POST ||
1965 s->state == SERVICE_FINAL_SIGTERM ||
1966 s->state == SERVICE_FINAL_SIGKILL)
1969 /* Already on it! */
1970 if (s->state == SERVICE_START_PRE ||
1971 s->state == SERVICE_START ||
1972 s->state == SERVICE_START_POST)
1975 assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED || s->state == SERVICE_AUTO_RESTART);
1977 /* Make sure we don't enter a busy loop of some kind. */
1978 if (!ratelimit_test(&s->ratelimit)) {
1979 log_warning("%s start request repeated too quickly, refusing to start.", u->meta.id);
1983 if ((s->exec_context.std_input == EXEC_INPUT_SOCKET ||
1984 s->exec_context.std_output == EXEC_OUTPUT_SOCKET ||
1985 s->exec_context.std_error == EXEC_OUTPUT_SOCKET) &&
1987 log_warning("%s can only be started with a per-connection socket.", u->meta.id);
1992 s->main_pid_known = false;
1993 s->forbid_restart = false;
1995 service_enter_start_pre(s);
1999 static int service_stop(Unit *u) {
2000 Service *s = SERVICE(u);
2004 /* This is a user request, so don't do restarts on this
2006 s->forbid_restart = true;
2009 if (s->state == SERVICE_STOP ||
2010 s->state == SERVICE_STOP_SIGTERM ||
2011 s->state == SERVICE_STOP_SIGKILL ||
2012 s->state == SERVICE_STOP_POST ||
2013 s->state == SERVICE_FINAL_SIGTERM ||
2014 s->state == SERVICE_FINAL_SIGKILL)
2017 /* Don't allow a restart */
2018 if (s->state == SERVICE_AUTO_RESTART) {
2019 service_set_state(s, SERVICE_DEAD);
2023 /* If there's already something running we go directly into
2025 if (s->state == SERVICE_START_PRE ||
2026 s->state == SERVICE_START ||
2027 s->state == SERVICE_START_POST ||
2028 s->state == SERVICE_RELOAD) {
2029 service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
2033 assert(s->state == SERVICE_RUNNING ||
2034 s->state == SERVICE_EXITED);
2036 service_enter_stop(s, true);
2040 static int service_reload(Unit *u) {
2041 Service *s = SERVICE(u);
2045 assert(s->state == SERVICE_RUNNING || s->state == SERVICE_EXITED);
2047 service_enter_reload(s);
2051 static bool service_can_reload(Unit *u) {
2052 Service *s = SERVICE(u);
2056 return !!s->exec_command[SERVICE_EXEC_RELOAD];
2059 static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
2060 Service *s = SERVICE(u);
2066 unit_serialize_item(u, f, "state", service_state_to_string(s->state));
2067 unit_serialize_item(u, f, "failure", yes_no(s->failure));
2069 if (s->control_pid > 0)
2070 unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
2072 if (s->main_pid_known && s->main_pid > 0)
2073 unit_serialize_item_format(u, f, "main-pid", "%lu", (unsigned long) s->main_pid);
2075 unit_serialize_item(u, f, "main-pid-known", yes_no(s->main_pid_known));
2078 unit_serialize_item(u, f, "status-text", s->status_text);
2080 /* There's a minor uncleanliness here: if there are multiple
2081 * commands attached here, we will start from the first one
2083 if (s->control_command_id >= 0)
2084 unit_serialize_item(u, f, "control-command", service_exec_command_to_string(s->control_command_id));
2086 if (s->socket_fd >= 0) {
2089 if ((copy = fdset_put_dup(fds, s->socket_fd)) < 0)
2092 unit_serialize_item_format(u, f, "socket-fd", "%i", copy);
2095 if (s->main_exec_status.pid > 0) {
2096 unit_serialize_item_format(u, f, "main-exec-status-pid", "%lu", (unsigned long) s->main_exec_status.pid);
2098 if (s->main_exec_status.start_timestamp.realtime > 0) {
2099 unit_serialize_item_format(u, f, "main-exec-status-start-realtime",
2100 "%llu", (unsigned long long) s->main_exec_status.start_timestamp.realtime);
2102 unit_serialize_item_format(u, f, "main-exec-status-start-monotonic",
2103 "%llu", (unsigned long long) s->main_exec_status.start_timestamp.monotonic);
2106 if (s->main_exec_status.exit_timestamp.realtime > 0) {
2107 unit_serialize_item_format(u, f, "main-exec-status-exit-realtime",
2108 "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.realtime);
2109 unit_serialize_item_format(u, f, "main-exec-status-exit-monotonic",
2110 "%llu", (unsigned long long) s->main_exec_status.exit_timestamp.monotonic);
2112 unit_serialize_item_format(u, f, "main-exec-status-code", "%i", s->main_exec_status.code);
2113 unit_serialize_item_format(u, f, "main-exec-status-status", "%i", s->main_exec_status.status);
2120 static int service_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
2121 Service *s = SERVICE(u);
2128 if (streq(key, "state")) {
2131 if ((state = service_state_from_string(value)) < 0)
2132 log_debug("Failed to parse state value %s", value);
2134 s->deserialized_state = state;
2135 } else if (streq(key, "failure")) {
2138 if ((b = parse_boolean(value)) < 0)
2139 log_debug("Failed to parse failure value %s", value);
2141 s->failure = b || s->failure;
2142 } else if (streq(key, "control-pid")) {
2145 if (parse_pid(value, &pid) < 0)
2146 log_debug("Failed to parse control-pid value %s", value);
2148 s->control_pid = pid;
2149 } else if (streq(key, "main-pid")) {
2152 if (parse_pid(value, &pid) < 0)
2153 log_debug("Failed to parse main-pid value %s", value);
2155 service_set_main_pid(s, (pid_t) pid);
2156 } else if (streq(key, "main-pid-known")) {
2159 if ((b = parse_boolean(value)) < 0)
2160 log_debug("Failed to parse main-pid-known value %s", value);
2162 s->main_pid_known = b;
2163 } else if (streq(key, "status-text")) {
2166 if ((t = strdup(value))) {
2167 free(s->status_text);
2171 } else if (streq(key, "control-command")) {
2172 ServiceExecCommand id;
2174 if ((id = service_exec_command_from_string(value)) < 0)
2175 log_debug("Failed to parse exec-command value %s", value);
2177 s->control_command_id = id;
2178 s->control_command = s->exec_command[id];
2180 } else if (streq(key, "socket-fd")) {
2183 if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
2184 log_debug("Failed to parse socket-fd value %s", value);
2187 if (s->socket_fd >= 0)
2188 close_nointr_nofail(s->socket_fd);
2189 s->socket_fd = fdset_remove(fds, fd);
2191 } else if (streq(key, "main-exec-status-pid")) {
2194 if (parse_pid(value, &pid) < 0)
2195 log_debug("Failed to parse main-exec-status-pid value %s", value);
2197 s->main_exec_status.pid = pid;
2198 } else if (streq(key, "main-exec-status-code")) {
2201 if (safe_atoi(value, &i) < 0)
2202 log_debug("Failed to parse main-exec-status-code value %s", value);
2204 s->main_exec_status.code = i;
2205 } else if (streq(key, "main-exec-status-status")) {
2208 if (safe_atoi(value, &i) < 0)
2209 log_debug("Failed to parse main-exec-status-status value %s", value);
2211 s->main_exec_status.status = i;
2212 } else if (streq(key, "main-exec-status-start-realtime")) {
2215 if (safe_atou64(value, &k) < 0)
2216 log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
2218 s->main_exec_status.start_timestamp.realtime = (usec_t) k;
2219 } else if (streq(key, "main-exec-status-start-monotonic")) {
2222 if (safe_atou64(value, &k) < 0)
2223 log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
2225 s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
2226 } else if (streq(key, "main-exec-status-exit-realtime")) {
2229 if (safe_atou64(value, &k) < 0)
2230 log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
2232 s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
2233 } else if (streq(key, "main-exec-status-exit-monotonic")) {
2236 if (safe_atou64(value, &k) < 0)
2237 log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
2239 s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
2241 log_debug("Unknown serialization key '%s'", key);
2246 static UnitActiveState service_active_state(Unit *u) {
2249 return state_translation_table[SERVICE(u)->state];
2252 static const char *service_sub_state_to_string(Unit *u) {
2255 return service_state_to_string(SERVICE(u)->state);
2258 static bool service_check_gc(Unit *u) {
2259 Service *s = SERVICE(u);
2263 return !!s->sysv_path;
2266 static bool service_check_snapshot(Unit *u) {
2267 Service *s = SERVICE(u);
2271 return !s->got_socket_fd;
2274 static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
2275 Service *s = SERVICE(u);
2282 success = is_clean_exit_lsb(code, status);
2284 success = is_clean_exit(code, status);
2286 if (s->main_pid == pid) {
2289 exec_status_exit(&s->main_exec_status, pid, code, status);
2291 if (s->type != SERVICE_FORKING && s->control_command) {
2292 s->control_command->exec_status = s->main_exec_status;
2294 if (s->control_command->ignore)
2298 log_full(success ? LOG_DEBUG : LOG_NOTICE,
2299 "%s: main process exited, code=%s, status=%i", u->meta.id, sigchld_code_to_string(code), status);
2300 s->failure = s->failure || !success;
2302 if (s->control_command &&
2303 s->control_command->command_next &&
2306 /* There is another command to *
2307 * execute, so let's do that. */
2309 log_debug("%s running next main command for state %s", u->meta.id, service_state_to_string(s->state));
2310 service_run_next_main(s, success);
2314 /* The service exited, so the service is officially
2317 s->control_command = NULL;
2318 s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
2322 case SERVICE_START_POST:
2323 case SERVICE_RELOAD:
2325 /* Need to wait until the operation is
2330 if (s->type == SERVICE_ONESHOT) {
2331 /* This was our main goal, so let's go on */
2333 service_enter_start_post(s);
2335 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
2338 assert(s->type == SERVICE_DBUS || s->type == SERVICE_NOTIFY);
2343 case SERVICE_RUNNING:
2344 service_enter_running(s, success);
2347 case SERVICE_STOP_SIGTERM:
2348 case SERVICE_STOP_SIGKILL:
2350 if (!control_pid_good(s))
2351 service_enter_stop_post(s, success);
2353 /* If there is still a control process, wait for that first */
2357 assert_not_reached("Uh, main process died at wrong time.");
2361 } else if (s->control_pid == pid) {
2365 if (s->control_command) {
2366 exec_status_exit(&s->control_command->exec_status, pid, code, status);
2368 if (s->control_command->ignore)
2372 log_full(success ? LOG_DEBUG : LOG_NOTICE,
2373 "%s: control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
2374 s->failure = s->failure || !success;
2376 if (s->control_command &&
2377 s->control_command->command_next &&
2380 /* There is another command to *
2381 * execute, so let's do that. */
2383 log_debug("%s running next control command for state %s", u->meta.id, service_state_to_string(s->state));
2384 service_run_next_control(s, success);
2387 /* No further commands for this step, so let's
2388 * figure out what to do next */
2390 s->control_command = NULL;
2391 s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
2393 log_debug("%s got final SIGCHLD for state %s", u->meta.id, service_state_to_string(s->state));
2397 case SERVICE_START_PRE:
2399 service_enter_start(s);
2401 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
2405 assert(s->type == SERVICE_FORKING);
2407 /* Let's try to load the pid
2408 * file here if we can. We
2409 * ignore the return value,
2410 * since the PID file might
2411 * actually be created by a
2412 * START_POST script */
2416 service_load_pid_file(s);
2418 service_enter_start_post(s);
2420 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
2424 case SERVICE_START_POST:
2425 if (success && s->pid_file && !s->main_pid_known) {
2428 /* Hmm, let's see if we can
2429 * load the pid now after the
2430 * start-post scripts got
2433 if ((r = service_load_pid_file(s)) < 0)
2434 log_warning("%s: failed to load PID file %s: %s", s->meta.id, s->pid_file, strerror(-r));
2439 case SERVICE_RELOAD:
2441 service_enter_running(s, true);
2443 service_enter_stop(s, false);
2448 service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
2451 case SERVICE_STOP_SIGTERM:
2452 case SERVICE_STOP_SIGKILL:
2453 if (main_pid_good(s) <= 0)
2454 service_enter_stop_post(s, success);
2456 /* If there is still a service
2457 * process around, wait until
2458 * that one quit, too */
2461 case SERVICE_STOP_POST:
2462 case SERVICE_FINAL_SIGTERM:
2463 case SERVICE_FINAL_SIGKILL:
2464 service_enter_dead(s, success, true);
2468 assert_not_reached("Uh, control process died at wrong time.");
2473 /* Notify clients about changed exit status */
2474 unit_add_to_dbus_queue(u);
2477 static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
2478 Service *s = SERVICE(u);
2481 assert(elapsed == 1);
2483 assert(w == &s->timer_watch);
2487 case SERVICE_START_PRE:
2489 log_warning("%s operation timed out. Terminating.", u->meta.id);
2490 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
2493 case SERVICE_START_POST:
2494 case SERVICE_RELOAD:
2495 log_warning("%s operation timed out. Stopping.", u->meta.id);
2496 service_enter_stop(s, false);
2500 log_warning("%s stopping timed out. Terminating.", u->meta.id);
2501 service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
2504 case SERVICE_STOP_SIGTERM:
2505 log_warning("%s stopping timed out. Killing.", u->meta.id);
2506 service_enter_signal(s, SERVICE_STOP_SIGKILL, false);
2509 case SERVICE_STOP_SIGKILL:
2510 /* Uh, wie sent a SIGKILL and it is still not gone?
2511 * Must be something we cannot kill, so let's just be
2512 * weirded out and continue */
2514 log_warning("%s still around after SIGKILL. Ignoring.", u->meta.id);
2515 service_enter_stop_post(s, false);
2518 case SERVICE_STOP_POST:
2519 log_warning("%s stopping timed out (2). Terminating.", u->meta.id);
2520 service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
2523 case SERVICE_FINAL_SIGTERM:
2524 log_warning("%s stopping timed out (2). Killing.", u->meta.id);
2525 service_enter_signal(s, SERVICE_FINAL_SIGKILL, false);
2528 case SERVICE_FINAL_SIGKILL:
2529 log_warning("%s still around after SIGKILL (2). Entering failed mode.", u->meta.id);
2530 service_enter_dead(s, false, true);
2533 case SERVICE_AUTO_RESTART:
2534 log_info("%s holdoff time over, scheduling restart.", u->meta.id);
2535 service_enter_restart(s);
2539 assert_not_reached("Timeout at wrong time.");
2543 static void service_cgroup_notify_event(Unit *u) {
2544 Service *s = SERVICE(u);
2548 log_debug("%s: cgroup is empty", u->meta.id);
2552 /* Waiting for SIGCHLD is usually more interesting,
2553 * because it includes return codes/signals. Which is
2554 * why we ignore the cgroup events for most cases,
2555 * except when we don't know pid which to expect the
2558 case SERVICE_RUNNING:
2559 service_enter_running(s, true);
2562 case SERVICE_STOP_SIGTERM:
2563 case SERVICE_STOP_SIGKILL:
2564 if (main_pid_good(s) <= 0 && !control_pid_good(s))
2565 service_enter_stop_post(s, true);
2569 case SERVICE_FINAL_SIGTERM:
2570 case SERVICE_FINAL_SIGKILL:
2571 if (main_pid_good(s) <= 0 && !control_pid_good(s))
2572 service_enter_dead(s, true, true);
2581 static void service_notify_message(Unit *u, pid_t pid, char **tags) {
2582 Service *s = SERVICE(u);
2587 if (s->notify_access == NOTIFY_NONE) {
2588 log_warning("%s: Got notification message from PID %lu, but reception is disabled.",
2589 u->meta.id, (unsigned long) pid);
2593 if (s->notify_access == NOTIFY_MAIN && pid != s->main_pid) {
2594 log_warning("%s: Got notification message from PID %lu, but reception only permitted for PID %lu",
2595 u->meta.id, (unsigned long) pid, (unsigned long) s->main_pid);
2599 log_debug("%s: Got message", u->meta.id);
2601 /* Interpret MAINPID= */
2602 if ((e = strv_find_prefix(tags, "MAINPID=")) &&
2603 (s->state == SERVICE_START ||
2604 s->state == SERVICE_START_POST ||
2605 s->state == SERVICE_RUNNING ||
2606 s->state == SERVICE_RELOAD)) {
2608 if (parse_pid(e + 8, &pid) < 0)
2609 log_warning("Failed to parse notification message %s", e);
2611 log_debug("%s: got %s", u->meta.id, e);
2612 service_set_main_pid(s, pid);
2616 /* Interpret READY= */
2617 if (s->type == SERVICE_NOTIFY &&
2618 s->state == SERVICE_START &&
2619 strv_find(tags, "READY=1")) {
2620 log_debug("%s: got READY=1", u->meta.id);
2622 service_enter_start_post(s);
2625 /* Interpret STATUS= */
2626 if ((e = strv_find_prefix(tags, "STATUS="))) {
2630 if (!(t = strdup(e+7))) {
2631 log_error("Failed to allocate string.");
2635 log_debug("%s: got %s", u->meta.id, e);
2637 free(s->status_text);
2640 free(s->status_text);
2641 s->status_text = NULL;
2646 /* Notify clients about changed status or main pid */
2647 unit_add_to_dbus_queue(u);
2650 static int service_enumerate(Manager *m) {
2654 char *path = NULL, *fpath = NULL, *name = NULL;
2655 Set *runlevel_services[ELEMENTSOF(rcnd_table)], *shutdown_services = NULL;
2662 zero(runlevel_services);
2664 STRV_FOREACH(p, m->lookup_paths.sysvrcnd_path)
2665 for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
2670 if (asprintf(&path, "%s/%s", *p, rcnd_table[i].path) < 0) {
2678 if (!(d = opendir(path))) {
2679 if (errno != ENOENT)
2680 log_warning("opendir() failed on %s: %s", path, strerror(errno));
2685 while ((de = readdir(d))) {
2688 if (ignore_file(de->d_name))
2691 if (de->d_name[0] != 'S' && de->d_name[0] != 'K')
2694 if (strlen(de->d_name) < 4)
2697 a = undecchar(de->d_name[1]);
2698 b = undecchar(de->d_name[2]);
2705 if (asprintf(&fpath, "%s/%s/%s", *p, rcnd_table[i].path, de->d_name) < 0) {
2710 if (access(fpath, X_OK) < 0) {
2712 if (errno != ENOENT)
2713 log_warning("access() failed on %s: %s", fpath, strerror(errno));
2719 if (!(name = sysv_translate_name(de->d_name + 3))) {
2724 if ((r = manager_load_unit_prepare(m, name, NULL, NULL, &service)) < 0) {
2725 log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
2729 if (de->d_name[0] == 'S') {
2731 if (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_SYSINIT) {
2732 SERVICE(service)->sysv_start_priority =
2733 MAX(a*10 + b, SERVICE(service)->sysv_start_priority);
2735 SERVICE(service)->sysv_enabled = true;
2738 if ((r = set_ensure_allocated(&runlevel_services[i], trivial_hash_func, trivial_compare_func)) < 0)
2741 if ((r = set_put(runlevel_services[i], service)) < 0)
2744 } else if (de->d_name[0] == 'K' &&
2745 (rcnd_table[i].type == RUNLEVEL_DOWN ||
2746 rcnd_table[i].type == RUNLEVEL_SYSINIT)) {
2748 if ((r = set_ensure_allocated(&shutdown_services, trivial_hash_func, trivial_compare_func)) < 0)
2751 if ((r = set_put(shutdown_services, service)) < 0)
2757 /* Now we loaded all stubs and are aware of the lowest
2758 start-up priority for all services, not let's actually load
2759 the services, this will also tell us which services are
2760 actually native now */
2761 manager_dispatch_load_queue(m);
2763 /* If this is a native service, rely on native ways to pull in
2764 * a service, don't pull it in via sysv rcN.d links. */
2765 for (i = 0; i < ELEMENTSOF(rcnd_table); i ++)
2766 SET_FOREACH(service, runlevel_services[i], j) {
2767 service = unit_follow_merge(service);
2769 if (service->meta.fragment_path)
2772 if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_WANTS, rcnd_table[i].target, NULL, true)) < 0)
2776 /* We honour K links only for halt/reboot. For the normal
2777 * runlevels we assume the stop jobs will be implicitly added
2778 * by the core logic. Also, we don't really distuingish here
2779 * between the runlevels 0 and 6 and just add them to the
2780 * special shutdown target. On SUSE the boot.d/ runlevel is
2781 * also used for shutdown, so we add links for that too to the
2782 * shutdown target.*/
2783 SET_FOREACH(service, shutdown_services, j) {
2784 service = unit_follow_merge(service);
2786 if (service->meta.fragment_path)
2789 if ((r = unit_add_two_dependencies_by_name_inverse(service, UNIT_AFTER, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0)
2800 for (i = 0; i < ELEMENTSOF(rcnd_table); i++)
2801 set_free(runlevel_services[i]);
2802 set_free(shutdown_services);
2810 static void service_bus_name_owner_change(
2813 const char *old_owner,
2814 const char *new_owner) {
2816 Service *s = SERVICE(u);
2821 assert(streq(s->bus_name, name));
2822 assert(old_owner || new_owner);
2824 if (old_owner && new_owner)
2825 log_debug("%s's D-Bus name %s changed owner from %s to %s", u->meta.id, name, old_owner, new_owner);
2827 log_debug("%s's D-Bus name %s no longer registered by %s", u->meta.id, name, old_owner);
2829 log_debug("%s's D-Bus name %s now registered by %s", u->meta.id, name, new_owner);
2831 s->bus_name_good = !!new_owner;
2833 if (s->type == SERVICE_DBUS) {
2835 /* service_enter_running() will figure out what to
2837 if (s->state == SERVICE_RUNNING)
2838 service_enter_running(s, true);
2839 else if (s->state == SERVICE_START && new_owner)
2840 service_enter_start_post(s);
2842 } else if (new_owner &&
2844 (s->state == SERVICE_START ||
2845 s->state == SERVICE_START_POST ||
2846 s->state == SERVICE_RUNNING ||
2847 s->state == SERVICE_RELOAD)) {
2849 /* Try to acquire PID from bus service */
2850 log_debug("Trying to acquire PID from D-Bus name...");
2852 bus_query_pid(u->meta.manager, name);
2856 static void service_bus_query_pid_done(
2861 Service *s = SERVICE(u);
2866 log_debug("%s's D-Bus name %s is now owned by process %u", u->meta.id, name, (unsigned) pid);
2868 if (s->main_pid <= 0 &&
2869 (s->state == SERVICE_START ||
2870 s->state == SERVICE_START_POST ||
2871 s->state == SERVICE_RUNNING ||
2872 s->state == SERVICE_RELOAD))
2873 service_set_main_pid(s, pid);
2876 int service_set_socket_fd(Service *s, int fd, Socket *sock) {
2880 /* This is called by the socket code when instantiating a new
2881 * service for a stream socket and the socket needs to be
2884 if (s->meta.load_state != UNIT_LOADED)
2887 if (s->socket_fd >= 0)
2890 if (s->state != SERVICE_DEAD)
2894 s->got_socket_fd = true;
2900 static void service_reset_failed(Unit *u) {
2901 Service *s = SERVICE(u);
2905 if (s->state == SERVICE_FAILED)
2906 service_set_state(s, SERVICE_DEAD);
2911 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
2912 [SERVICE_DEAD] = "dead",
2913 [SERVICE_START_PRE] = "start-pre",
2914 [SERVICE_START] = "start",
2915 [SERVICE_START_POST] = "start-post",
2916 [SERVICE_RUNNING] = "running",
2917 [SERVICE_EXITED] = "exited",
2918 [SERVICE_RELOAD] = "reload",
2919 [SERVICE_STOP] = "stop",
2920 [SERVICE_STOP_SIGTERM] = "stop-sigterm",
2921 [SERVICE_STOP_SIGKILL] = "stop-sigkill",
2922 [SERVICE_STOP_POST] = "stop-post",
2923 [SERVICE_FINAL_SIGTERM] = "final-sigterm",
2924 [SERVICE_FINAL_SIGKILL] = "final-sigkill",
2925 [SERVICE_FAILED] = "failed",
2926 [SERVICE_AUTO_RESTART] = "auto-restart",
2929 DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
2931 static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
2932 [SERVICE_ONCE] = "once",
2933 [SERVICE_RESTART_ON_SUCCESS] = "restart-on-success",
2934 [SERVICE_RESTART_ALWAYS] = "restart-always",
2937 DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
2939 static const char* const service_type_table[_SERVICE_TYPE_MAX] = {
2940 [SERVICE_SIMPLE] = "simple",
2941 [SERVICE_FORKING] = "forking",
2942 [SERVICE_ONESHOT] = "oneshot",
2943 [SERVICE_DBUS] = "dbus",
2944 [SERVICE_NOTIFY] = "notify"
2947 DEFINE_STRING_TABLE_LOOKUP(service_type, ServiceType);
2949 static const char* const service_exec_command_table[_SERVICE_EXEC_COMMAND_MAX] = {
2950 [SERVICE_EXEC_START_PRE] = "ExecStartPre",
2951 [SERVICE_EXEC_START] = "ExecStart",
2952 [SERVICE_EXEC_START_POST] = "ExecStartPost",
2953 [SERVICE_EXEC_RELOAD] = "ExecReload",
2954 [SERVICE_EXEC_STOP] = "ExecStop",
2955 [SERVICE_EXEC_STOP_POST] = "ExecStopPost",
2958 DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
2960 static const char* const notify_access_table[_NOTIFY_ACCESS_MAX] = {
2961 [NOTIFY_NONE] = "none",
2962 [NOTIFY_MAIN] = "main",
2963 [NOTIFY_ALL] = "all"
2966 DEFINE_STRING_TABLE_LOOKUP(notify_access, NotifyAccess);
2968 const UnitVTable service_vtable = {
2969 .suffix = ".service",
2970 .show_status = true,
2972 .init = service_init,
2973 .done = service_done,
2974 .load = service_load,
2976 .coldplug = service_coldplug,
2978 .dump = service_dump,
2980 .start = service_start,
2981 .stop = service_stop,
2982 .reload = service_reload,
2984 .can_reload = service_can_reload,
2986 .serialize = service_serialize,
2987 .deserialize_item = service_deserialize_item,
2989 .active_state = service_active_state,
2990 .sub_state_to_string = service_sub_state_to_string,
2992 .check_gc = service_check_gc,
2993 .check_snapshot = service_check_snapshot,
2995 .sigchld_event = service_sigchld_event,
2996 .timer_event = service_timer_event,
2998 .reset_failed = service_reset_failed,
3000 .cgroup_notify_empty = service_cgroup_notify_event,
3001 .notify_message = service_notify_message,
3003 .bus_name_owner_change = service_bus_name_owner_change,
3004 .bus_query_pid_done = service_bus_query_pid_done,
3006 .bus_interface = "org.freedesktop.systemd1.Service",
3007 .bus_message_handler = bus_service_message_handler,
3008 .bus_invalidating_properties = bus_service_invalidating_properties,
3010 .enumerate = service_enumerate