Clean the failed dir when we start and end rc so that failed services can be re-attempted outside of rc

This commit is contained in:
Roy Marples 2007-12-29 18:59:24 +00:00
parent 0ddc38960c
commit 3bf35803da

View File

@ -112,6 +112,35 @@ static pidlist_t *service_pids = NULL;
static const char *const types_n[] = { "needsme", NULL }; static const char *const types_n[] = { "needsme", NULL };
static const char *const types_nua[] = { "ineed", "iuse", "iafter", NULL }; static const char *const types_nua[] = { "ineed", "iuse", "iafter", NULL };
static void clean_failed (void)
{
DIR *dp;
struct dirent *d;
int i;
char *path;
/* Clean the failed services state dir now */
if ((dp = opendir (RC_SVCDIR "/failed"))) {
while ((d = readdir (dp))) {
if (d->d_name[0] == '.' &&
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
i = strlen (RC_SVCDIR "/failed/") + strlen (d->d_name) + 1;
path = xmalloc (sizeof (char) * i);
snprintf (path, i, RC_SVCDIR "/failed/%s", d->d_name);
if (path) {
if (unlink (path))
eerror ("%s: unlink `%s': %s", applet, path,
strerror (errno));
free (path);
}
}
closedir (dp);
}
}
static void cleanup (void) static void cleanup (void)
{ {
if (applet && strcmp (applet, "rc") == 0) { if (applet && strcmp (applet, "rc") == 0) {
@ -141,6 +170,7 @@ static void cleanup (void)
if (! rc_in_plugin && ! rc_in_logger) { if (! rc_in_plugin && ! rc_in_logger) {
rmdir (RC_STARTING); rmdir (RC_STARTING);
rmdir (RC_STOPPING); rmdir (RC_STOPPING);
clean_failed ();
rc_logger_close (); rc_logger_close ();
} }
@ -1124,25 +1154,7 @@ int main (int argc, char **argv)
eerrorx ("failed to load deptree"); eerrorx ("failed to load deptree");
/* Clean the failed services state dir now */ /* Clean the failed services state dir now */
if ((dp = opendir (RC_SVCDIR "/failed"))) { clean_failed ();
while ((d = readdir (dp))) {
if (d->d_name[0] == '.' &&
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
i = strlen (RC_SVCDIR "/failed/") + strlen (d->d_name) + 1;
tmp = xmalloc (sizeof (char) * i);
snprintf (tmp, i, RC_SVCDIR "/failed/%s", d->d_name);
if (tmp) {
if (unlink (tmp))
eerror ("%s: unlink `%s': %s", applet, tmp,
strerror (errno));
free (tmp);
}
}
closedir (dp);
}
mkdir (RC_STOPPING, 0755); mkdir (RC_STOPPING, 0755);