chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
service: never supervise ourselves
[elogind.git]
/
src
/
service.c
diff --git
a/src/service.c
b/src/service.c
index 8ff7b73138016a9a4ace7991574df55a3c6a57cd..547a55567abef7ea133d4cd3030739b94038d74e 100644
(file)
--- a/
src/service.c
+++ b/
src/service.c
@@
-40,7
+40,7
@@
typedef enum RunlevelType {
RUNLEVEL_UP,
RUNLEVEL_DOWN,
typedef enum RunlevelType {
RUNLEVEL_UP,
RUNLEVEL_DOWN,
- RUNLEVEL_
BASIC
+ RUNLEVEL_
SYSINIT
} RunlevelType;
static const struct {
} RunlevelType;
static const struct {
@@
-58,10
+58,10
@@
static const struct {
{ "rc6.d", SPECIAL_RUNLEVEL6_TARGET, RUNLEVEL_DOWN },
/* SUSE style boot.d */
{ "rc6.d", SPECIAL_RUNLEVEL6_TARGET, RUNLEVEL_DOWN },
/* SUSE style boot.d */
- { "boot.d", SPECIAL_
BASIC_TARGET, RUNLEVEL_BASIC
},
+ { "boot.d", SPECIAL_
SYSINIT_TARGET, RUNLEVEL_SYSINIT
},
/* Debian style rcS.d */
/* Debian style rcS.d */
- { "rcS.d", SPECIAL_
BASIC_TARGET, RUNLEVEL_BASIC
},
+ { "rcS.d", SPECIAL_
SYSINIT_TARGET, RUNLEVEL_SYSINIT
},
};
#define RUNLEVELS_UP "12345"
};
#define RUNLEVELS_UP "12345"
@@
-340,9
+340,6
@@
static int service_load_sysv_path(Service *s, const char *path) {
goto finish;
}
goto finish;
}
- s->type = SERVICE_FORKING;
- s->restart = SERVICE_ONCE;
-
free(s->sysv_path);
if (!(s->sysv_path = strdup(path))) {
r = -ENOMEM;
free(s->sysv_path);
if (!(s->sysv_path = strdup(path))) {
r = -ENOMEM;
@@
-650,8
+647,10
@@
static int service_load_sysv_path(Service *s, const char *path) {
s->timeout_usec = 0;
/* Special setting for all SysV services */
s->timeout_usec = 0;
/* Special setting for all SysV services */
+ s->type = SERVICE_FORKING;
s->valid_no_process = true;
s->kill_mode = KILL_PROCESS_GROUP;
s->valid_no_process = true;
s->kill_mode = KILL_PROCESS_GROUP;
+ s->restart = SERVICE_ONCE;
u->meta.load_state = UNIT_LOADED;
r = 0;
u->meta.load_state = UNIT_LOADED;
r = 0;
@@
-676,7
+675,7
@@
static int service_load_sysv_name(Service *s, const char *name) {
endswith(name, ".sh.service"))
return -ENOENT;
endswith(name, ".sh.service"))
return -ENOENT;
- STRV_FOREACH(p, UNIT(s)->meta.manager->sysvinit_path) {
+ STRV_FOREACH(p, UNIT(s)->meta.manager->
lookup_paths.
sysvinit_path) {
char *path;
int r;
char *path;
int r;
@@
-727,7
+726,7
@@
static int service_load_sysv(Service *s) {
/* Load service data from SysV init scripts, preferably with
* LSB headers ... */
/* Load service data from SysV init scripts, preferably with
* LSB headers ... */
- if (strv_isempty(UNIT(s)->meta.manager->sysvinit_path))
+ if (strv_isempty(UNIT(s)->meta.manager->
lookup_paths.
sysvinit_path))
return 0;
if ((t = UNIT(s)->meta.id))
return 0;
if ((t = UNIT(s)->meta.id))
@@
-937,6
+936,9
@@
static int service_load_pid_file(Service *s) {
if ((unsigned long) (pid_t) p != p)
return -ERANGE;
if ((unsigned long) (pid_t) p != p)
return -ERANGE;
+ if (p <= 1)
+ return -ERANGE;
+
if (kill((pid_t) p, 0) < 0 && errno != EPERM) {
log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.",
(unsigned long long) p, s->pid_file);
if (kill((pid_t) p, 0) < 0 && errno != EPERM) {
log_warning("PID %llu read from file %s does not exist. Your service or init script might be broken.",
(unsigned long long) p, s->pid_file);
@@
-1378,7
+1380,7
@@
static void service_enter_stop_post(Service *s, bool success) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
stop-post executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'stop-post' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
@@
-1474,7
+1476,7
@@
static void service_enter_stop(Service *s, bool success) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
stop executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'stop' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
}
service_enter_signal(s, SERVICE_STOP_SIGTERM, false);
}
@@
-1519,7
+1521,7
@@
static void service_enter_start_post(Service *s) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
start-post executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'start-post' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_stop(s, false);
}
service_enter_stop(s, false);
}
@@
-1585,7
+1587,7
@@
static void service_enter_start(Service *s) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
start exectuable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'start' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
}
@@
-1614,7
+1616,7
@@
static void service_enter_start_pre(Service *s) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
start-pre executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'start-pre' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_dead(s, false, true);
}
service_enter_dead(s, false, true);
}
@@
-1661,7
+1663,7
@@
static void service_enter_reload(Service *s) {
return;
fail:
return;
fail:
- log_warning("%s failed to run
reload executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run
'reload' task
: %s", UNIT(s)->meta.id, strerror(-r));
service_enter_stop(s, false);
}
service_enter_stop(s, false);
}
@@
-1691,7
+1693,7
@@
static void service_run_next(Service *s, bool success) {
return;
fail:
return;
fail:
- log_warning("%s failed to run spawn next
executable
: %s", UNIT(s)->meta.id, strerror(-r));
+ log_warning("%s failed to run spawn next
task
: %s", UNIT(s)->meta.id, strerror(-r));
if (s->state == SERVICE_START_PRE)
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
if (s->state == SERVICE_START_PRE)
service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
@@
-1964,14
+1966,18
@@
static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
break;
case SERVICE_START:
break;
case SERVICE_START:
- assert(s->type == SERVICE_FINISH);
+ if (s->type == SERVICE_FINISH) {
+ /* This was our main goal, so let's go on */
+ if (success)
+ service_enter_start_post(s);
+ else
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
+ break;
+ } else {
+ assert(s->type == SERVICE_DBUS);
- /* This was our main goal, so let's go on */
- if (success)
- service_enter_start_post(s);
- else
- service_enter_signal(s, SERVICE_FINAL_SIGTERM, false);
- break;
+ /* Fall through */
+ }
case SERVICE_RUNNING:
service_enter_running(s, success);
case SERVICE_RUNNING:
service_enter_running(s, success);
@@
-2198,7
+2204,7
@@
static int service_enumerate(Manager *m) {
assert(m);
assert(m);
- STRV_FOREACH(p, m->sysvrcnd_path)
+ STRV_FOREACH(p, m->
lookup_paths.
sysvrcnd_path)
for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
struct dirent *de;
for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
struct dirent *de;
@@
-2265,7
+2271,7
@@
static int service_enumerate(Manager *m) {
}
if (de->d_name[0] == 'S' &&
}
if (de->d_name[0] == 'S' &&
- (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_
BASIC
))
+ (rcnd_table[i].type == RUNLEVEL_UP || rcnd_table[i].type == RUNLEVEL_
SYSINIT
))
SERVICE(service)->sysv_start_priority =
MAX(a*10 + b, SERVICE(service)->sysv_start_priority);
SERVICE(service)->sysv_start_priority =
MAX(a*10 + b, SERVICE(service)->sysv_start_priority);
@@
-2284,7
+2290,9
@@
static int service_enumerate(Manager *m) {
if ((r = unit_add_dependency(service, UNIT_BEFORE, runlevel_target, true)) < 0)
goto finish;
if ((r = unit_add_dependency(service, UNIT_BEFORE, runlevel_target, true)) < 0)
goto finish;
- } else if (de->d_name[0] == 'K' && rcnd_table[i].type == RUNLEVEL_DOWN) {
+ } else if (de->d_name[0] == 'K' &&
+ (rcnd_table[i].type == RUNLEVEL_DOWN ||
+ rcnd_table[i].type == RUNLEVEL_SYSINIT)) {
Unit *shutdown_target;
/* We honour K links only for
Unit *shutdown_target;
/* We honour K links only for
@@
-2296,7
+2304,12
@@
static int service_enumerate(Manager *m) {
* really distuingish here
* between the runlevels 0 and
* 6 and just add them to the
* really distuingish here
* between the runlevels 0 and
* 6 and just add them to the
- * special shutdown target. */
+ * special shutdown target. On
+ * SUSE the boot.d/ runlevel
+ * is also used for shutdown,
+ * so we add links for that
+ * too to the shutdown
+ * target.*/
if ((r = manager_load_unit(m, SPECIAL_SHUTDOWN_TARGET, NULL, &shutdown_target)) < 0)
goto finish;
if ((r = manager_load_unit(m, SPECIAL_SHUTDOWN_TARGET, NULL, &shutdown_target)) < 0)
goto finish;