if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) {
log_warning("%s: Supervising process %lu which is not our child. We'll most likely not notice when it exits.",
- s->meta.id, (unsigned long) pid);
+ UNIT(s)->id, (unsigned long) pid);
s->main_pid_alien = true;
} else
/* For each pair of services where at least one lacks a LSB
* header, we use the start priority value to order things. */
- LIST_FOREACH(units_by_type, other, s->meta.manager->units_by_type[UNIT_SERVICE]) {
+ LIST_FOREACH(units_by_type, other, UNIT(s)->manager->units_by_type[UNIT_SERVICE]) {
Service *t;
UnitDependency d;
bool special_s, special_t;
if (s == t)
continue;
- if (t->meta.load_state != UNIT_LOADED)
+ if (UNIT(t)->load_state != UNIT_LOADED)
continue;
if (t->sysv_start_priority < 0)
/* If both units have modern headers we don't care
* about the priorities */
- if ((s->meta.fragment_path || s->sysv_has_lsb) &&
- (t->meta.fragment_path || t->sysv_has_lsb))
+ if ((UNIT(s)->fragment_path || s->sysv_has_lsb) &&
+ (UNIT(t)->fragment_path || t->sysv_has_lsb))
continue;
special_s = s->sysv_runlevels && !chars_intersect(RUNLEVELS_UP, s->sysv_runlevels);
* needed for early boot) and don't create any links
* to it. */
- s->meta.default_dependencies = false;
+ UNIT(s)->default_dependencies = false;
/* Don't timeout special services during boot (like fsck) */
s->timeout_usec = 0;
s->guess_main_pid = false;
s->restart = SERVICE_RESTART_NO;
- if (s->meta.manager->sysv_console)
+ if (UNIT(s)->manager->sysv_console)
s->exec_context.std_output = EXEC_OUTPUT_JOURNAL_AND_CONSOLE;
s->exec_context.kill_mode = KILL_PROCESS;
return -ENOENT;
#endif
- STRV_FOREACH(p, s->meta.manager->lookup_paths.sysvinit_path) {
+ STRV_FOREACH(p, UNIT(s)->manager->lookup_paths.sysvinit_path) {
char *path;
int r;
r = service_load_sysv_path(s, path);
#if defined(TARGET_DEBIAN) || defined(TARGET_UBUNTU) || defined(TARGET_ANGSTROM)
- if (r >= 0 && s->meta.load_state == UNIT_STUB) {
+ if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
/* Try Debian style *.sh source'able init scripts */
strcat(path, ".sh");
r = service_load_sysv_path(s, path);
free(path);
#ifdef TARGET_SUSE
- if (r >= 0 && s->meta.load_state == UNIT_STUB) {
+ if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
/* Try SUSE style boot.* init scripts */
path = join(*p, "/boot.", name, NULL);
#endif
#ifdef TARGET_FRUGALWARE
- if (r >= 0 && s->meta.load_state == UNIT_STUB) {
+ if (r >= 0 && UNIT(s)->load_state == UNIT_STUB) {
/* Try Frugalware style rc.* init scripts */
path = join(*p, "/rc.", name, NULL);
if (r < 0)
return r;
- if ((s->meta.load_state != UNIT_STUB))
+ if ((UNIT(s)->load_state != UNIT_STUB))
break;
}
/* Load service data from SysV init scripts, preferably with
* LSB headers ... */
- if (strv_isempty(s->meta.manager->lookup_paths.sysvinit_path))
+ if (strv_isempty(UNIT(s)->manager->lookup_paths.sysvinit_path))
return 0;
- if ((t = s->meta.id))
+ if ((t = UNIT(s)->id))
if ((r = service_load_sysv_name(s, t)) < 0)
return r;
- if (s->meta.load_state == UNIT_STUB)
- SET_FOREACH(t, s->meta.names, i) {
- if (t == s->meta.id)
+ if (UNIT(s)->load_state == UNIT_STUB)
+ SET_FOREACH(t, UNIT(s)->names, i) {
+ if (t == UNIT(s)->id)
continue;
if ((r = service_load_sysv_name(s, t)) < 0)
return r;
- if (s->meta.load_state != UNIT_STUB)
+ if (UNIT(s)->load_state != UNIT_STUB)
break;
}
/* For each pair of services where both have an fsck priority
* we order things based on it. */
- LIST_FOREACH(units_by_type, other, s->meta.manager->units_by_type[UNIT_SERVICE]) {
+ LIST_FOREACH(units_by_type, other, UNIT(s)->manager->units_by_type[UNIT_SERVICE]) {
Service *t;
UnitDependency d;
if (s == t)
continue;
- if (t->meta.load_state != UNIT_LOADED)
+ if (UNIT(t)->load_state != UNIT_LOADED)
continue;
if (t->fsck_passno <= 0)
static int service_verify(Service *s) {
assert(s);
- if (s->meta.load_state != UNIT_LOADED)
+ if (UNIT(s)->load_state != UNIT_LOADED)
return 0;
if (!s->exec_command[SERVICE_EXEC_START]) {
- log_error("%s lacks ExecStart setting. Refusing.", s->meta.id);
+ log_error("%s lacks ExecStart setting. Refusing.", UNIT(s)->id);
return -EINVAL;
}
if (s->type != SERVICE_ONESHOT &&
s->exec_command[SERVICE_EXEC_START]->command_next) {
- log_error("%s has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.", s->meta.id);
+ log_error("%s has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.", UNIT(s)->id);
return -EINVAL;
}
if (s->type == SERVICE_ONESHOT &&
s->exec_command[SERVICE_EXEC_RELOAD]) {
- log_error("%s has an ExecReload setting, which is not allowed for Type=oneshot services. Refusing.", s->meta.id);
+ log_error("%s has an ExecReload setting, which is not allowed for Type=oneshot services. Refusing.", UNIT(s)->id);
return -EINVAL;
}
if (s->type == SERVICE_DBUS && !s->bus_name) {
- log_error("%s is of type D-Bus but no D-Bus service name has been specified. Refusing.", s->meta.id);
+ log_error("%s is of type D-Bus but no D-Bus service name has been specified. Refusing.", UNIT(s)->id);
return -EINVAL;
}
if (s->exec_context.pam_name && s->exec_context.kill_mode != KILL_CONTROL_GROUP) {
- log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", s->meta.id);
+ log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", UNIT(s)->id);
return -EINVAL;
}
* majority of services. */
/* First, pull in base system */
- if (s->meta.manager->running_as == MANAGER_SYSTEM) {
+ if (UNIT(s)->manager->running_as == MANAGER_SYSTEM) {
if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_BASIC_TARGET, NULL, true)) < 0)
return r;
- } else if (s->meta.manager->running_as == MANAGER_USER) {
+ } else if (UNIT(s)->manager->running_as == MANAGER_USER) {
if ((r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SOCKETS_TARGET, NULL, true)) < 0)
return r;
if (s->exec_context.std_error == EXEC_OUTPUT_INHERIT &&
s->exec_context.std_output == EXEC_OUTPUT_INHERIT &&
s->exec_context.std_input == EXEC_INPUT_NULL)
- s->exec_context.std_error = s->meta.manager->default_std_error;
+ s->exec_context.std_error = UNIT(s)->manager->default_std_error;
if (s->exec_context.std_output == EXEC_OUTPUT_INHERIT &&
s->exec_context.std_input == EXEC_INPUT_NULL)
- s->exec_context.std_output = s->meta.manager->default_std_output;
+ s->exec_context.std_output = UNIT(s)->manager->default_std_output;
}
static int service_load(Unit *u) {
if ((r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_REQUIRES, SPECIAL_DBUS_SOCKET, NULL, true)) < 0)
return r;
- if (s->meta.default_dependencies)
+ if (UNIT(s)->default_dependencies)
if ((r = service_add_default_dependencies(s)) < 0)
return r;
}
assert(s->main_pid <= 0);
- if ((pid = cgroup_bonding_search_main_pid_list(s->meta.cgroup_bondings)) <= 0)
+ if ((pid = cgroup_bonding_search_main_pid_list(UNIT(s)->cgroup_bondings)) <= 0)
return -ENOENT;
log_debug("Main PID guessed: %lu", (unsigned long) pid);
if (s->socket_fd >= 0)
return;
- SET_FOREACH(u, s->meta.dependencies[UNIT_TRIGGERED_BY], i)
+ SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERED_BY], i)
if (u->type == UNIT_SOCKET)
socket_notify_service_dead(SOCKET(u));
if (!s->pid_file_pathspec)
return;
- log_debug("Stopping watch for %s's PID file %s", s->meta.id, s->pid_file_pathspec->path);
+ log_debug("Stopping watch for %s's PID file %s", UNIT(s)->id, s->pid_file_pathspec->path);
path_spec_unwatch(s->pid_file_pathspec, UNIT(s));
path_spec_done(s->pid_file_pathspec);
free(s->pid_file_pathspec);
state != SERVICE_STOP_POST &&
state != SERVICE_FINAL_SIGTERM &&
state != SERVICE_FINAL_SIGKILL &&
- !(state == SERVICE_DEAD && s->meta.job)) {
+ !(state == SERVICE_DEAD && UNIT(s)->job)) {
service_close_socket_fd(s);
service_connection_unref(s);
}
/* For the inactive states unit_notify() will trim the cgroup,
* but for exit we have to do that ourselves... */
- if (state == SERVICE_EXITED && s->meta.manager->n_reloading <= 0)
- cgroup_bonding_trim_list(s->meta.cgroup_bondings, true);
+ if (state == SERVICE_EXITED && UNIT(s)->manager->n_reloading <= 0)
+ cgroup_bonding_trim_list(UNIT(s)->cgroup_bondings, true);
if (old_state != state)
- log_debug("%s changed %s -> %s", s->meta.id, service_state_to_string(old_state), service_state_to_string(state));
+ log_debug("%s changed %s -> %s", UNIT(s)->id, service_state_to_string(old_state), service_state_to_string(state));
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], !s->reload_failure);
s->reload_failure = false;
if (s->socket_fd >= 0)
return 0;
- SET_FOREACH(u, s->meta.dependencies[UNIT_TRIGGERED_BY], i) {
+ SET_FOREACH(u, UNIT(s)->dependencies[UNIT_TRIGGERED_BY], i) {
int *cfds;
unsigned cn_fds;
Socket *sock;
}
if (set_notify_socket)
- if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=%s", s->meta.manager->notify_socket) < 0) {
+ if (asprintf(our_env + n_env++, "NOTIFY_SOCKET=%s", UNIT(s)->manager->notify_socket) < 0) {
r = -ENOMEM;
goto fail;
}
}
if (!(final_env = strv_env_merge(2,
- s->meta.manager->environment,
+ UNIT(s)->manager->environment,
our_env,
NULL))) {
r = -ENOMEM;
apply_permissions,
apply_chroot,
apply_tty_stdin,
- s->meta.manager->confirm_spawn,
- s->meta.cgroup_bondings,
- s->meta.cgroup_attributes,
+ UNIT(s)->manager->confirm_spawn,
+ UNIT(s)->cgroup_bondings,
+ UNIT(s)->cgroup_attributes,
&pid);
if (r < 0)
assert(s);
- if ((r = cgroup_bonding_is_empty_list(s->meta.cgroup_bondings)) < 0)
+ if ((r = cgroup_bonding_is_empty_list(UNIT(s)->cgroup_bondings)) < 0)
return r;
return !r;
return;
fail:
- log_warning("%s failed to run install restart timer: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run install restart timer: %s", UNIT(s)->id, strerror(-r));
service_enter_dead(s, false, false);
}
return;
fail:
- log_warning("%s failed to run 'stop-post' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'stop-post' task: %s", UNIT(s)->id, strerror(-r));
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
if ((r = set_put(pid_set, LONG_TO_PTR(s->control_pid))) < 0)
goto fail;
- if ((r = cgroup_bonding_kill_list(s->meta.cgroup_bondings, sig, true, pid_set)) < 0) {
+ if ((r = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, sig, true, pid_set)) < 0) {
if (r != -EAGAIN && r != -ESRCH && r != -ENOENT)
log_warning("Failed to kill control group: %s", strerror(-r));
} else if (r > 0)
return;
fail:
- log_warning("%s failed to kill processes: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to kill processes: %s", UNIT(s)->id, strerror(-r));
if (state == SERVICE_STOP_SIGTERM || state == SERVICE_STOP_SIGKILL)
service_enter_stop_post(s, false);
return;
fail:
- log_warning("%s failed to run 'stop' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'stop' task: %s", UNIT(s)->id, strerror(-r));
service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
}
return;
fail:
- log_warning("%s failed to run 'start-post' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'start-post' task: %s", UNIT(s)->id, strerror(-r));
service_enter_stop(s, false);
}
/* We want to ensure that nobody leaks processes from
* START_PRE here, so let's go on a killing spree, People
* should not spawn long running processes from START_PRE. */
- cgroup_bonding_kill_list(s->meta.cgroup_bondings, SIGKILL, true, NULL);
+ cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, SIGKILL, true, NULL);
if (s->type == SERVICE_FORKING) {
s->control_command_id = SERVICE_EXEC_START;
return;
fail:
- log_warning("%s failed to run 'start' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'start' task: %s", UNIT(s)->id, strerror(-r));
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
/* Before we start anything, let's clear up what might
* be left from previous runs. */
- cgroup_bonding_kill_list(s->meta.cgroup_bondings, SIGKILL, true, NULL);
+ cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, SIGKILL, true, NULL);
s->control_command_id = SERVICE_EXEC_START_PRE;
return;
fail:
- log_warning("%s failed to run 'start-pre' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'start-pre' task: %s", UNIT(s)->id, strerror(-r));
service_enter_dead(s, false, true);
}
assert(s);
dbus_error_init(&error);
- if (s->meta.job) {
+ if (UNIT(s)->job) {
log_info("Job pending for unit, delaying automatic restart.");
if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
service_enter_dead(s, true, false);
- if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, &error, NULL)) < 0)
+ if ((r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(s), JOB_FAIL, false, &error, NULL)) < 0)
goto fail;
- log_debug("%s scheduled restart job.", s->meta.id);
+ log_debug("%s scheduled restart job.", UNIT(s)->id);
return;
fail:
- log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
+ log_warning("%s failed to schedule restart job: %s", UNIT(s)->id, bus_error(&error, -r));
service_enter_dead(s, false, false);
dbus_error_free(&error);
return;
fail:
- log_warning("%s failed to run 'reload' task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run 'reload' task: %s", UNIT(s)->id, strerror(-r));
s->reload_failure = true;
service_enter_running(s, true);
}
return;
fail:
- log_warning("%s failed to run next control task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run next control task: %s", UNIT(s)->id, strerror(-r));
if (s->state == SERVICE_START_PRE)
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
return;
fail:
- log_warning("%s failed to run next main task: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to run next main task: %s", UNIT(s)->id, strerror(-r));
service_enter_stop(s, false);
}
static int service_watch_pid_file(Service *s) {
int r;
- log_debug("Setting watch for %s's PID file %s", s->meta.id, s->pid_file_pathspec->path);
+ log_debug("Setting watch for %s's PID file %s", UNIT(s)->id, s->pid_file_pathspec->path);
r = path_spec_watch(s->pid_file_pathspec, UNIT(s));
if (r < 0)
goto fail;
return 0;
fail:
log_error("Failed to set a watch for %s's PID file %s: %s",
- s->meta.id, s->pid_file_pathspec->path, strerror(-r));
+ UNIT(s)->id, s->pid_file_pathspec->path, strerror(-r));
service_unwatch_pid_file(s);
return r;
}
assert(s);
assert(pid >= 0);
- if (!s->meta.fragment_path)
+ if (!UNIT(s)->fragment_path)
success = is_clean_exit_lsb(code, status);
else
success = is_clean_exit(code, status);
/* If we were hoping for the daemon to write its PID file,
* we can give up now. */
if (s->pid_file_pathspec) {
- log_warning("%s never wrote its PID file. Failing.", s->meta.id);
+ log_warning("%s never wrote its PID file. Failing.", UNIT(s)->id);
service_unwatch_pid_file(s);
if (s->state == SERVICE_START)
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
* service for a stream socket and the socket needs to be
* configured. */
- if (s->meta.load_state != UNIT_LOADED)
+ if (UNIT(s)->load_state != UNIT_LOADED)
return -EINVAL;
if (s->socket_fd >= 0)
goto finish;
}
- if ((q = cgroup_bonding_kill_list(s->meta.cgroup_bondings, signo, false, pid_set)) < 0)
+ if ((q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, pid_set)) < 0)
if (q != -EAGAIN && q != -ESRCH && q != -ENOENT)
r = q;
}