+ if (pass_fds)
+ if ((r = service_collect_fds(s, &fds, &n_fds)) < 0)
+ goto fail;
+
+ if (timeout) {
+ if ((r = unit_watch_timer(UNIT(s), s->timeout_usec, &s->timer_watch)) < 0)
+ goto fail;
+ } else
+ unit_unwatch_timer(UNIT(s), &s->timer_watch);
+
+ if ((r = exec_spawn(c,
+ &s->exec_context,
+ fds, n_fds,
+ apply_permissions,
+ apply_chroot,
+ UNIT(s)->meta.cgroup_bondings,
+ &pid)) < 0)
+ goto fail;
+
+ if ((r = unit_watch_pid(UNIT(s), pid)) < 0)
+ /* FIXME: we need to do something here */
+ goto fail;
+
+ free(fds);
+ *_pid = pid;
+
+ return 0;
+
+fail:
+ free(fds);
+
+ if (timeout)
+ unit_unwatch_timer(UNIT(s), &s->timer_watch);
+
+ return r;
+}
+
+static void service_enter_dead(Service *s, bool success, bool allow_restart) {
+ int r;
+ assert(s);
+
+ if (!success)
+ s->failure = true;
+
+ if (allow_restart &&
+ (s->restart == SERVICE_RESTART_ALWAYS ||
+ (s->restart == SERVICE_RESTART_ON_SUCCESS && !s->failure))) {
+
+ if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
+ goto fail;
+
+ service_set_state(s, SERVICE_AUTO_RESTART);
+ } else
+ service_set_state(s, s->failure ? SERVICE_MAINTAINANCE : SERVICE_DEAD);
+
+ return;
+
+fail:
+ log_warning("%s failed to run install restart timer: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_dead(s, false, false);
+}
+
+static void service_enter_signal(Service *s, ServiceState state, bool success);
+
+static void service_enter_stop_post(Service *s, bool success) {
+ int r;
+ assert(s);
+
+ if (!success)
+ s->failure = true;
+
+ if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP_POST]))
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+
+ service_set_state(s, SERVICE_STOP_POST);
+
+ if (!s->control_command)
+ service_enter_dead(s, true, true);
+
+ return;
+
+fail:
+ log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+}
+
+static void service_enter_signal(Service *s, ServiceState state, bool success) {
+ int r;
+ bool sent = false;
+
+ assert(s);
+
+ if (!success)
+ s->failure = true;
+
+ if (s->main_pid > 0 || s->control_pid > 0) {
+ int sig;
+
+ sig = (state == SERVICE_STOP_SIGTERM || state == SERVICE_FINAL_SIGTERM) ? SIGTERM : SIGKILL;
+
+ r = 0;
+ if (s->main_pid > 0) {
+ if (kill(s->main_pid, sig) < 0 && errno != ESRCH)
+ r = -errno;
+ else
+ sent = true;
+ }
+
+ if (s->control_pid > 0) {
+ if (kill(s->control_pid, sig) < 0 && errno != ESRCH)
+ r = -errno;
+ else
+ sent = true;
+ }
+
+ if (r < 0)
+ goto fail;
+ }
+
+ service_set_state(s, state);
+
+ if (s->main_pid <= 0 && s->control_pid <= 0)
+ service_enter_dead(s, true, true);
+
+ return;
+
+fail:
+ log_warning("%s failed to kill processes: %s", unit_id(UNIT(s)), strerror(-r));
+
+ if (sent) {
+ s->failure = true;
+ service_set_state(s, state);
+ } else if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
+ service_enter_stop_post(s, false);
+ else
+ service_enter_dead(s, false, true);
+}
+
+static void service_enter_stop(Service *s, bool success) {
+ int r;
+ assert(s);
+
+ if (!success)
+ s->failure = true;
+
+ if ((s->control_command = s->exec_command[SERVICE_EXEC_STOP]))
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+ service_set_state(s, SERVICE_STOP);
+
+ if (!s->control_command)
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, true);
+
+ return;
+
+fail:
+ log_warning("%s failed to run stop executable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+}
+
+static void service_enter_start_post(Service *s) {
+ int r;
+ assert(s);
+
+ if ((s->control_command = s->exec_command[SERVICE_EXEC_START_POST]))
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+
+ service_set_state(s, SERVICE_START_POST);
+
+ if (!s->control_command)
+ service_set_state(s, SERVICE_RUNNING);
+
+ return;
+
+fail:
+ log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_stop(s, false);
+}
+
+static void service_enter_start(Service *s) {
+ pid_t pid;
+ int r;
+
+ assert(s);
+
+ assert(s->exec_command[SERVICE_EXEC_START]);
+ assert(!s->exec_command[SERVICE_EXEC_START]->command_next);
+
+ if ((r = service_spawn(s,
+ s->exec_command[SERVICE_EXEC_START],
+ s->type == SERVICE_FORKING,
+ true,
+ true,
+ true,
+ &pid)) < 0)
+ goto fail;
+
+ service_set_state(s, SERVICE_START);
+
+ if (s->type == SERVICE_SIMPLE) {
+ /* For simple services we immediately start
+ * the START_POST binaries. */
+
+ s->main_pid = pid;
+ s->main_pid_known = true;
+ service_enter_start_post(s);
+
+ } else if (s->type == SERVICE_FORKING) {
+
+ /* For forking services we wait until the start
+ * process exited. */
+
+ s->control_pid = pid;
+ s->control_command = s->exec_command[SERVICE_EXEC_START];
+ } else if (s->type == SERVICE_FINISH) {
+
+ /* For finishing services we wait until the start
+ * process exited, too, but it is our main process. */
+
+ s->main_pid = pid;
+ s->control_command = s->exec_command[SERVICE_EXEC_START];
+ } else
+ assert_not_reached("Unknown service type");
+
+ return;
+
+fail:
+ log_warning("%s failed to run start exectuable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_stop(s, false);
+}
+
+static void service_enter_start_pre(Service *s) {
+ int r;
+
+ assert(s);
+
+ if ((s->control_command = s->exec_command[SERVICE_EXEC_START_PRE]))
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+ service_set_state(s, SERVICE_START_PRE);
+
+ if (!s->control_command)
+ service_enter_start(s);
+
+ return;
+
+fail:
+ log_warning("%s failed to run start-pre executable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_dead(s, false, true);
+}
+
+static void service_enter_restart(Service *s) {
+ int r;
+ assert(s);
+
+ if ((r = manager_add_job(UNIT(s)->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
+ goto fail;
+
+ log_debug("%s scheduled restart job.", unit_id(UNIT(s)));
+ service_enter_dead(s, true, false);
+ return;
+
+fail:
+
+ log_warning("%s failed to schedule restart job: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_dead(s, false, false);
+}
+
+static void service_enter_reload(Service *s) {
+ int r;
+
+ assert(s);
+
+ if ((s->control_command = s->exec_command[SERVICE_EXEC_RELOAD]))
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+ service_set_state(s, SERVICE_RELOAD);
+
+ if (!s->control_command)
+ service_set_state(s, SERVICE_RUNNING);
+
+ return;
+
+fail:
+ log_warning("%s failed to run reload executable: %s", unit_id(UNIT(s)), strerror(-r));
+ service_enter_stop(s, false);
+}
+
+static void service_run_next(Service *s, bool success) {
+ int r;
+
+ assert(s);
+ assert(s->control_command);
+ assert(s->control_command->command_next);
+
+ if (!success)
+ s->failure = true;
+
+ s->control_command = s->control_command->command_next;
+
+ if ((r = service_spawn(s,
+ s->control_command,
+ true,
+ false,
+ !s->permissions_start_only,
+ !s->root_directory_start_only,
+ &s->control_pid)) < 0)
+ goto fail;
+
+ return;
+
+fail:
+ log_warning("%s failed to run spawn next executable: %s", unit_id(UNIT(s)), strerror(-r));
+
+ if (s->state == SERVICE_STOP)
+ service_enter_stop_post(s, false);
+ else if (s->state == SERVICE_STOP_POST)
+ service_enter_dead(s, false, true);
+ else
+ service_enter_stop(s, false);
+}
+
+static int service_start(Unit *u) {
+ Service *s = SERVICE(u);
+
+ assert(s);
+
+ /* We cannot fulfill this request right now, try again later
+ * please! */
+ if (s->state == SERVICE_STOP ||
+ s->state == SERVICE_STOP_SIGTERM ||
+ s->state == SERVICE_STOP_SIGKILL ||
+ s->state == SERVICE_STOP_POST ||
+ s->state == SERVICE_FINAL_SIGTERM ||
+ s->state == SERVICE_FINAL_SIGKILL)
+ return -EAGAIN;
+
+ /* Already on it! */
+ if (s->state == SERVICE_START_PRE ||
+ s->state == SERVICE_START ||
+ s->state == SERVICE_START_POST)
+ return 0;
+
+ assert(s->state == SERVICE_DEAD || s->state == SERVICE_MAINTAINANCE || s->state == SERVICE_AUTO_RESTART);
+
+ /* Make sure we don't enter a busy loop of some kind. */
+ if (!ratelimit_test(&s->ratelimit)) {
+ log_warning("%s start request repeated too quickly, refusing to start.", unit_id(u));
+ return -EAGAIN;
+ }
+
+ s->failure = false;
+ s->main_pid_known = false;
+
+ service_enter_start_pre(s);
+ return 0;
+}
+
+static int service_stop(Unit *u) {
+ Service *s = SERVICE(u);
+
+ assert(s);
+
+ if (s->state == SERVICE_START_PRE ||
+ s->state == SERVICE_START ||
+ s->state == SERVICE_START_POST ||
+ s->state == SERVICE_RELOAD)
+ return -EAGAIN;
+
+ if (s->state == SERVICE_AUTO_RESTART) {
+ service_set_state(s, SERVICE_DEAD);
+ return 0;
+ }
+
+ assert(s->state == SERVICE_RUNNING);
+
+ service_enter_stop(s, true);
+ return 0;
+}
+
+static int service_reload(Unit *u) {
+ Service *s = SERVICE(u);
+
+ assert(s);
+
+ assert(s->state == SERVICE_RUNNING);
+
+ service_enter_reload(s);
+ return 0;
+}
+
+static bool service_can_reload(Unit *u) {
+ Service *s = SERVICE(u);
+
+ assert(s);
+
+ return !!s->exec_command[SERVICE_EXEC_RELOAD];
+}
+
+static UnitActiveState service_active_state(Unit *u) {
+ assert(u);
+
+ return state_translation_table[SERVICE(u)->state];
+}
+
+static int main_pid_good(Service *s) {
+ assert(s);
+
+ /* Returns 0 if the pid is dead, 1 if it is good, -1 if we
+ * don't know */
+
+ /* If we know the pid file, then lets just check if it is
+ * still valid */
+ if (s->main_pid_known)
+ return s->main_pid > 0;
+
+ /* We don't know the pid */
+ return -EAGAIN;
+}
+
+static bool control_pid_good(Service *s) {
+ assert(s);
+
+ return s->control_pid > 0;
+}
+
+static int cgroup_good(Service *s) {
+ assert(s);
+
+ if (s->valid_no_process)
+ return -EAGAIN;
+
+ return cgroup_bonding_is_empty_list(UNIT(s)->meta.cgroup_bondings);
+}
+
+static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
+ Service *s = SERVICE(u);
+ bool success;
+
+ assert(s);
+ assert(pid >= 0);
+
+ success = code == CLD_EXITED && status == 0;
+ s->failure = s->failure || !success;
+
+ if (s->main_pid == pid) {
+
+ exec_status_fill(&s->main_exec_status, pid, code, status);
+ s->main_pid = 0;
+
+ if (s->type == SERVICE_SIMPLE || s->type == SERVICE_FINISH) {
+ assert(s->exec_command[SERVICE_EXEC_START]);
+ s->exec_command[SERVICE_EXEC_START]->exec_status = s->main_exec_status;
+ }
+
+ log_debug("%s: main process exited, code=%s status=%i", unit_id(u), sigchld_code_to_string(code), status);
+
+ /* The service exited, so the service is officially
+ * gone. */
+
+ switch (s->state) {
+
+ case SERVICE_START_POST:
+ case SERVICE_RELOAD:
+ case SERVICE_STOP:
+ /* Need to wait until the operation is
+ * done */
+ break;
+
+ case SERVICE_START:
+ assert(s->type == SERVICE_FINISH);
+
+ /* This was our main goal, so let's go on */
+ if (success)
+ service_enter_start_post(s);
+ else
+ service_enter_stop(s, false);
+ break;
+
+ case SERVICE_RUNNING:
+ service_enter_stop(s, success);
+ break;
+
+ case SERVICE_STOP_SIGTERM:
+ case SERVICE_STOP_SIGKILL:
+
+ if (!control_pid_good(s))
+ service_enter_stop_post(s, success);
+
+ /* If there is still a control process, wait for that first */
+ break;
+
+ default:
+ assert_not_reached("Uh, main process died at wrong time.");
+ }
+
+ } else if (s->control_pid == pid) {
+ assert(s->control_command);
+
+ exec_status_fill(&s->control_command->exec_status, pid, code, status);
+ s->control_pid = 0;
+
+ log_debug("%s: control process exited, code=%s status=%i", unit_id(u), sigchld_code_to_string(code), status);
+
+ /* If we are shutting things down anyway we
+ * don't care about failing commands. */
+
+ if (s->control_command->command_next &&
+ (success || (s->state == SERVICE_STOP || s->state == SERVICE_STOP_POST)))
+
+ /* There is another command to *
+ * execute, so let's do that. */
+
+ service_run_next(s, success);
+
+ else {
+ /* No further commands for this step, so let's
+ * figure out what to do next */
+
+ log_debug("%s got final SIGCHLD for state %s", unit_id(u), service_state_to_string(s->state));
+
+ switch (s->state) {
+
+ case SERVICE_START_PRE:
+ if (success)
+ service_enter_start(s);
+ else
+ service_enter_stop(s, false);
+ break;
+
+ case SERVICE_START:
+ assert(s->type == SERVICE_FORKING);
+
+ /* Let's try to load the pid
+ * file here if we can. We
+ * ignore the return value,
+ * since the PID file might
+ * actually be created by a
+ * START_POST script */
+
+ if (success) {
+ if (s->pid_file)
+ service_load_pid_file(s);
+
+ service_enter_start_post(s);
+ } else
+ service_enter_stop(s, false);
+
+ break;
+
+ case SERVICE_START_POST:
+ if (success && s->pid_file && !s->main_pid_known) {
+ int r;
+
+ /* Hmm, let's see if we can
+ * load the pid now after the
+ * start-post scripts got
+ * executed. */
+
+ if ((r = service_load_pid_file(s)) < 0)
+ log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s)), s->pid_file, strerror(-r));
+ }
+
+ /* Fall through */
+
+ case SERVICE_RELOAD:
+ if (success) {
+ if (main_pid_good(s) != 0 && cgroup_good(s) != 0)
+ service_set_state(s, SERVICE_RUNNING);
+ else
+ service_enter_stop(s, true);
+ } else
+ service_enter_stop(s, false);
+
+ break;
+
+ case SERVICE_STOP:
+ if (main_pid_good(s) > 0)
+ /* Still not dead and we know the PID? Let's go hunting. */
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
+ else
+ service_enter_stop_post(s, success);
+ break;
+
+ case SERVICE_STOP_SIGTERM:
+ case SERVICE_STOP_SIGKILL:
+ if (main_pid_good(s) <= 0)
+ service_enter_stop_post(s, success);
+
+ /* If there is still a service
+ * process around, wait until
+ * that one quit, too */
+ break;
+
+ case SERVICE_STOP_POST:
+ case SERVICE_FINAL_SIGTERM:
+ case SERVICE_FINAL_SIGKILL:
+ service_enter_dead(s, success, true);
+ break;
+
+ default:
+ assert_not_reached("Uh, control process died at wrong time.");
+ }
+ }
+ } else
+ assert_not_reached("Got SIGCHLD for unkown PID");
+}
+
+static void service_timer_event(Unit *u, uint64_t elapsed, Watch* w) {
+ Service *s = SERVICE(u);
+
+ assert(s);
+ assert(elapsed == 1);
+
+ assert(w == &s->timer_watch);
+
+ switch (s->state) {
+
+ case SERVICE_START_PRE:
+ case SERVICE_START:
+ case SERVICE_START_POST:
+ case SERVICE_RELOAD:
+ log_warning("%s operation timed out. Stopping.", unit_id(u));
+ service_enter_stop(s, false);
+ break;
+
+ case SERVICE_STOP:
+ log_warning("%s stopping timed out. Terminating.", unit_id(u));
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
+ break;
+
+ case SERVICE_STOP_SIGTERM:
+ log_warning("%s stopping timed out. Killing.", unit_id(u));
+ service_enter_signal(s, SERVICE_STOP_SIGKILL, false);
+ break;
+
+ case SERVICE_STOP_SIGKILL:
+ /* Uh, wie sent a SIGKILL and it is still not gone?
+ * Must be something we cannot kill, so let's just be
+ * weirded out and continue */
+
+ log_warning("%s still around after SIGKILL. Ignoring.", unit_id(u));
+ service_enter_stop_post(s, false);
+ break;
+
+ case SERVICE_STOP_POST:
+ log_warning("%s stopping timed out (2). Terminating.", unit_id(u));
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ break;
+
+ case SERVICE_FINAL_SIGTERM:
+ log_warning("%s stopping timed out (2). Killing.", unit_id(u));
+ service_enter_signal(s, SERVICE_FINAL_SIGKILL, false);
+ break;
+
+ case SERVICE_FINAL_SIGKILL:
+ log_warning("%s still around after SIGKILL (2). Entering maintainance mode.", unit_id(u));
+ service_enter_dead(s, false, true);
+ break;
+
+ case SERVICE_AUTO_RESTART:
+ log_debug("%s holdoff time over, scheduling restart.", unit_id(u));
+ service_enter_restart(s);
+ break;
+
+ default:
+ assert_not_reached("Timeout at wrong time.");
+ }
+}
+
+static void service_cgroup_notify_event(Unit *u) {
+ Service *s = SERVICE(u);
+
+ assert(u);
+
+ log_debug("%s: cgroup is empty", unit_id(u));
+
+ switch (s->state) {
+
+ /* Waiting for SIGCHLD is usually more interesting,
+ * because it includes return codes/signals. Which is
+ * why we ignore the cgroup events for most cases,
+ * except when we don't know pid which to expect the
+ * SIGCHLD for. */
+
+ case SERVICE_RUNNING:
+
+ if (!s->valid_no_process && main_pid_good(s) <= 0)
+ service_enter_stop(s, true);
+
+ break;
+
+ default:
+ ;
+ }
+}
+
+static int service_enumerate(Manager *m) {
+
+ static const char * const rcnd[] = {
+ "../rc0.d", SPECIAL_RUNLEVEL0_TARGET,
+ "../rc1.d", SPECIAL_RUNLEVEL1_TARGET,
+ "../rc2.d", SPECIAL_RUNLEVEL2_TARGET,
+ "../rc3.d", SPECIAL_RUNLEVEL3_TARGET,
+ "../rc4.d", SPECIAL_RUNLEVEL4_TARGET,
+ "../rc5.d", SPECIAL_RUNLEVEL5_TARGET,
+ "../rc6.d", SPECIAL_RUNLEVEL6_TARGET
+ };
+
+ char **p;
+ unsigned i;
+ DIR *d = NULL;
+ char *path = NULL, *fpath = NULL, *name = NULL;
+ int r;
+
+ assert(m);
+
+ STRV_FOREACH(p, m->sysvinit_path)
+ for (i = 0; i < ELEMENTSOF(rcnd); i += 2) {
+ struct dirent *de;
+
+ free(path);
+ path = NULL;
+ if (asprintf(&path, "%s/%s", *p, rcnd[i]) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (d)
+ closedir(d);
+
+ if (!(d = opendir(path))) {
+ if (errno != ENOENT)
+ log_warning("opendir() failed on %s: %s", path, strerror(errno));
+
+ continue;
+ }
+
+ while ((de = readdir(d))) {
+ Unit *runlevel, *service;
+
+ if (ignore_file(de->d_name))
+ continue;
+
+ if (de->d_name[0] != 'S' && de->d_name[0] != 'K')
+ continue;
+
+ if (strlen(de->d_name) < 4)
+ continue;
+
+ free(fpath);
+ fpath = NULL;
+ if (asprintf(&fpath, "%s/%s/%s", *p, rcnd[i], de->d_name) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (access(fpath, X_OK) < 0) {
+
+ if (errno != ENOENT)
+ log_warning("access() failed on %s: %s", fpath, strerror(errno));
+
+ continue;
+ }
+
+ free(name);
+ name = NULL;
+ if (asprintf(&name, "%s.service", de->d_name+3) < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if ((r = manager_load_unit(m, name, &service)) < 0)
+ goto finish;
+
+ if ((r = manager_load_unit(m, rcnd[i+1], &runlevel)) < 0)
+ goto finish;
+
+ if (de->d_name[0] == 'S') {
+ if ((r = unit_add_dependency(runlevel, UNIT_WANTS, service)) < 0)
+ goto finish;
+
+ if ((r = unit_add_dependency(runlevel, UNIT_AFTER, service)) < 0)
+ goto finish;
+ } else {
+ if ((r = unit_add_dependency(runlevel, UNIT_CONFLICTS, service)) < 0)
+ goto finish;
+
+ if ((r = unit_add_dependency(runlevel, UNIT_BEFORE, service)) < 0)
+ goto finish;
+ }
+ }
+ }
+
+ r = 0;
+
+finish:
+ free(path);
+ free(fpath);
+ free(name);
+ closedir(d);
+
+ return r;
+}
+
+static const char* const service_state_table[_SERVICE_STATE_MAX] = {
+ [SERVICE_DEAD] = "dead",
+ [SERVICE_START_PRE] = "start-pre",
+ [SERVICE_START] = "start",
+ [SERVICE_START_POST] = "start-post",
+ [SERVICE_RUNNING] = "running",
+ [SERVICE_RELOAD] = "reload",
+ [SERVICE_STOP] = "stop",
+ [SERVICE_STOP_SIGTERM] = "stop-sigterm",
+ [SERVICE_STOP_SIGKILL] = "stop-sigkill",
+ [SERVICE_STOP_POST] = "stop-post",
+ [SERVICE_FINAL_SIGTERM] = "final-sigterm",
+ [SERVICE_FINAL_SIGKILL] = "final-sigkill",
+ [SERVICE_MAINTAINANCE] = "maintainance",
+ [SERVICE_AUTO_RESTART] = "auto-restart",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(service_state, ServiceState);
+
+static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
+ [SERVICE_ONCE] = "once",
+ [SERVICE_RESTART_ON_SUCCESS] = "restart-on-success",
+ [SERVICE_RESTART_ALWAYS] = "restart-on-failure",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(service_restart, ServiceRestart);
+
+static const char* const service_type_table[_SERVICE_TYPE_MAX] = {
+ [SERVICE_FORKING] = "forking",
+ [SERVICE_SIMPLE] = "simple",
+ [SERVICE_FINISH] = "finish"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(service_type, ServiceType);
+
+static const char* const service_exec_command_table[_SERVICE_EXEC_MAX] = {
+ [SERVICE_EXEC_START_PRE] = "ExecStartPre",
+ [SERVICE_EXEC_START] = "ExecStart",
+ [SERVICE_EXEC_START_POST] = "ExecStartPost",
+ [SERVICE_EXEC_RELOAD] = "ExecReload",
+ [SERVICE_EXEC_STOP] = "ExecStop",
+ [SERVICE_EXEC_STOP_POST] = "ExecStopPost",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
+
+const UnitVTable service_vtable = {
+ .suffix = ".service",
+
+ .init = service_init,
+ .done = service_done,
+
+ .dump = service_dump,
+
+ .start = service_start,
+ .stop = service_stop,
+ .reload = service_reload,
+
+ .can_reload = service_can_reload,
+
+ .active_state = service_active_state,
+
+ .sigchld_event = service_sigchld_event,
+ .timer_event = service_timer_event,
+
+ .cgroup_notify_empty = service_cgroup_notify_event,