sysv-generator.c revision 0ec0deaa30d0e68430f03fa6f32affa576481d18
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering This file is part of systemd.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Copyright 2014 Thomas H.P. Andersen
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Copyright 2010 Lennart Poettering
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Copyright 2011 Michal Schmidt
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering systemd is free software; you can redistribute it and/or modify it
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering (at your option) any later version.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering systemd is distributed in the hope that it will be useful, but
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering Lesser General Public License for more details.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering You should have received a copy of the GNU Lesser General Public License
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poetteringstatic const struct {
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering /* Standard SysV runlevels for start-up */
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc1.d", SPECIAL_RESCUE_TARGET, RUNLEVEL_UP },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc2.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc3.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc4.d", SPECIAL_MULTI_USER_TARGET, RUNLEVEL_UP },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc5.d", SPECIAL_GRAPHICAL_TARGET, RUNLEVEL_UP },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering /* Standard SysV runlevels for shutdown */
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc0.d", SPECIAL_POWEROFF_TARGET, RUNLEVEL_DOWN },
4819ff0358b6317c195fd4b1768e03d09c871070Lennart Poettering { "rc6.d", SPECIAL_REBOOT_TARGET, RUNLEVEL_DOWN }
typedef struct SysvStub {
char *name;
char *path;
char *description;
int sysv_start_priority;
char *pid_file;
char **before;
char **after;
char **wants;
char **wanted_by;
char **conflicts;
bool has_lsb;
bool reload;
bool loaded;
} SysvStub;
free(s);
hashmap_free(*h);
return -errno;
const char *link;
return -errno;
const char *unit;
assert(s);
if (!s->loaded)
return log_oom();
fprintf(f,
s->path);
if (s->description)
fprintf(f,
if (s->pid_file)
fprintf(f,
if (s->reload)
r = fflush_and_check(f);
char *res;
return NULL;
if (res)
*res = 0;
return NULL;
return res;
static const char * const table[] = {
char *filename_no_sh, *e, *m;
return log_oom();
*ret = m;
m = sysv_translate_name(n);
return log_oom();
*ret = m;
assert(s);
switch (unit_name_to_type(m)) {
case UNIT_SERVICE:
case UNIT_TARGET:
return log_oom();
return log_oom();
return log_oom();
case _UNIT_TYPE_INVALID:
static int handle_dependencies(SysvStub *s, unsigned line, const char *full_text, const char *text) {
assert(s);
bool is_before;
return log_oom();
return log_oom();
unsigned line = 0;
LSB,
_cleanup_free_ char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL;
char *description;
bool supports_reload = false;
char l[LINE_MAX];
assert(s);
line++;
t = strstrip(l);
if (usage_contains_reload(t)) {
supports_reload = true;
s->has_lsb = true;
size_t k;
k = strlen(t);
if (isempty(j))
j = NULL;
return log_oom();
const char *fn;
return log_oom();
size_t k;
k = strlen(t);
j = strstrip(t);
if (!isempty(j)) {
char *d = NULL;
d = strdup(j);
return log_oom();
if (isempty(j))
j = NULL;
return log_oom();
if (isempty(j))
j = NULL;
return log_oom();
j = strstrip(t);
if (!isempty(j)) {
char *d = NULL;
if (long_description)
d = strdup(j);
return log_oom();
long_description = d;
if (short_description)
else if (chkconfig_description)
else if (long_description)
if (description) {
return log_oom();
s->description = d;
s->loaded = true;
fail:
Iterator j;
assert(s);
if (!s->loaded)
if (s->sysv_start_priority < 0)
if (s == other)
return log_oom();
return log_oom();
char **path;
FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", *path)) {
if (!name)
return log_oom();
if (r < 0 && r != -ENOENT) {
if (!fpath)
return log_oom();
if (!service)
return log_oom();
return log_oom();
Iterator j;
if (!path) {
r = log_oom();
goto finish;
FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", path)) {
if (!fpath) {
r = log_oom();
goto finish;
if (!name) {
r = log_oom();
goto finish;
if (!service){
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
log_oom();
goto finish;
Iterator j;
return EXIT_FAILURE;
log_open();
goto finish;
if (!all_services) {
r = log_oom();
goto finish;
goto finish;
goto finish;