Do not ignore updated services when cleaning up removed ones

When cleaning up removed services, the assumption was made that if a
service was not 'removed', it was 'clean'. In reality, it could also
be 'updated', which was then overwritten, causing services not being
restarted. Don't do that.

As a future precaution, make the dirty field const, only allowing
updates from accessor methods.
This commit is contained in:
Tobias Waldekranz committed 2016-01-13 15:14:27 +01:00
1 parent 171d611b14
commit c641a1374e
4 files changed
+19 -8

No files matched your search

+1 -1
View File
@@ -130,7 +130,7 @@ static int service_unblock(svc_t *svc)
static int service_restart(svc_t *svc) static int service_restart(svc_t *svc)
{ {
svc->dirty = 1; svc_mark_dirty(svc);
service_step(svc); service_step(svc);
return 0; return 0;
} }
+2 -2
View File
@@ -844,7 +844,7 @@ restart:
break; break;
} }
svc->dirty = 0; svc_mark_clean(svc);
switch (svc->type) { switch (svc->type) {
case SVC_TYPE_SERVICE: case SVC_TYPE_SERVICE:
@@ -898,7 +898,7 @@ restart:
service_stop(svc); service_stop(svc);
*state = SVC_STOPPING_STATE; *state = SVC_STOPPING_STATE;
} }
svc->dirty = 0; svc_mark_clean(svc);
} }
break; break;
+13 -4
View File
@@ -352,17 +352,27 @@ void svc_mark_dynamic(void)
svc_t *svc = svc_dynamic_iterator(1); svc_t *svc = svc_dynamic_iterator(1);
while (svc) { while (svc) {
svc->dirty = -1; *((int *)&svc->dirty) = -1;
svc = svc_dynamic_iterator(0); svc = svc_dynamic_iterator(0);
} }
} }
void svc_mark_dirty(svc_t *svc)
{
*((int *)&svc->dirty) = 1;
}
void svc_mark_clean(svc_t *svc)
{
*((int *)&svc->dirty) = 0;
}
void svc_check_dirty(svc_t *svc, time_t mtime) void svc_check_dirty(svc_t *svc, time_t mtime)
{ {
if (svc->mtime != mtime) if (svc->mtime != mtime)
svc->dirty = 1; svc_mark_dirty(svc);
else else
svc->dirty = 0; svc_mark_clean(svc);
svc->mtime = mtime; svc->mtime = mtime;
} }
@@ -381,7 +391,6 @@ void svc_clean_dynamic(void (*cb)(svc_t *))
if (svc->dirty == -1 && cb) if (svc->dirty == -1 && cb)
cb(svc); cb(svc);
svc->dirty = 0;
svc = svc_dynamic_iterator(0); svc = svc_dynamic_iterator(0);
} }
} }
+3 -1
View File
@@ -84,7 +84,7 @@ typedef struct svc {
const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */ const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */
svc_type_t type; svc_type_t type;
time_t mtime; /* Modification time for .conf from /etc/finit.d/ */ time_t mtime; /* Modification time for .conf from /etc/finit.d/ */
int dirty; /* Set if old mtime != new mtime => reloaded, const int dirty; /* Set if old mtime != new mtime => reloaded,
* or -1 when marked for removal */ * or -1 when marked for removal */
int runlevels; int runlevels;
int sighup; /* This service supports SIGHUP :) */ int sighup; /* This service supports SIGHUP :) */
@@ -153,6 +153,8 @@ void svc_foreach_dynamic (void (*cb)(svc_t *));
void svc_mark_dynamic (void); void svc_mark_dynamic (void);
void svc_check_dirty (svc_t *svc, time_t mtime); void svc_check_dirty (svc_t *svc, time_t mtime);
void svc_mark_dirty (svc_t *svc);
void svc_mark_clean (svc_t *svc);
void svc_clean_dynamic (void (*cb)(svc_t *)); void svc_clean_dynamic (void (*cb)(svc_t *));
int svc_clean_bootstrap (svc_t *svc); int svc_clean_bootstrap (svc_t *svc);