service: check whether sysv scripts where changed

This commit is contained in:
Lennart Poettering
2011-06-21 19:29:45 +02:00
parent 8d0e38a2b9
commit 5f4b19f4bc
5 changed files with 60 additions and 12 deletions
+40
View File
@@ -470,6 +470,7 @@ static int service_load_sysv_path(Service *s, const char *path) {
LSB_DESCRIPTION
} state = NORMAL;
char *short_description = NULL, *long_description = NULL, *chkconfig_description = NULL, *description;
struct stat st;
assert(s);
assert(path);
@@ -481,12 +482,26 @@ static int service_load_sysv_path(Service *s, const char *path) {
goto finish;
}
zero(st);
if (fstat(fileno(f), &st) < 0) {
r = -errno;
goto finish;
}
free(s->sysv_path);
if (!(s->sysv_path = strdup(path))) {
r = -ENOMEM;
goto finish;
}
s->sysv_mtime = timespec_load(&st.st_mtim);
if (null_or_empty(&st)) {
u->meta.load_state = UNIT_MASKED;
r = 0;
goto finish;
}
while (!feof(f)) {
char l[LINE_MAX], *t;
@@ -3212,6 +3227,29 @@ static void service_reset_failed(Unit *u) {
s->failure = false;
}
static bool service_need_daemon_reload(Unit *u) {
Service *s = SERVICE(u);
assert(s);
#ifdef HAVE_SYSV_COMPAT
if (s->sysv_path) {
struct stat st;
zero(st);
if (stat(s->sysv_path, &st) < 0)
/* What, cannot access this anymore? */
return true;
if (s->sysv_mtime > 0 &&
timespec_load(&st.st_mtim) != s->sysv_mtime)
return true;
}
#endif
return false;
}
static int service_kill(Unit *u, KillWho who, KillMode mode, int signo, DBusError *error) {
Service *s = SERVICE(u);
int r = 0;
@@ -3361,6 +3399,8 @@ const UnitVTable service_vtable = {
.reset_failed = service_reset_failed,
.need_daemon_reload = service_need_daemon_reload,
.cgroup_notify_empty = service_cgroup_notify_event,
.notify_message = service_notify_message,
+1
View File
@@ -144,6 +144,7 @@ struct Service {
char *sysv_path;
char *sysv_runlevels;
usec_t sysv_mtime;
#endif
char *bus_name;
+15 -11
View File
@@ -2305,21 +2305,25 @@ void unit_status_printf(Unit *u, const char *format, ...) {
}
bool unit_need_daemon_reload(Unit *u) {
struct stat st;
assert(u);
if (!u->meta.fragment_path)
return false;
if (u->meta.fragment_path) {
struct stat st;
zero(st);
if (stat(u->meta.fragment_path, &st) < 0)
/* What, cannot access this anymore? */
return true;
zero(st);
if (stat(u->meta.fragment_path, &st) < 0)
/* What, cannot access this anymore? */
return true;
return
u->meta.fragment_mtime &&
timespec_load(&st.st_mtim) != u->meta.fragment_mtime;
if (u->meta.fragment_mtime > 0 &&
timespec_load(&st.st_mtim) != u->meta.fragment_mtime)
return true;
}
if (UNIT_VTABLE(u)->need_daemon_reload)
return UNIT_VTABLE(u)->need_daemon_reload(u);
return false;
}
void unit_reset_failed(Unit *u) {
+3
View File
@@ -317,6 +317,9 @@ struct UnitVTable {
void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
void (*timer_event)(Unit *u, uint64_t n_elapsed, Watch *w);
/* Check whether unit needs a daemon reload */
bool (*need_daemon_reload)(Unit *u);
/* Reset failed state if we are in failed state */
void (*reset_failed)(Unit *u);