Punt rc_rm_dir
This commit is contained in:
parent
05b8eff319
commit
3bfba57f5b
@ -95,44 +95,6 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
|
||||
librc_hidden_def(rc_strcatpaths)
|
||||
|
||||
|
||||
bool rc_rm_dir (const char *pathname, bool top)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *d;
|
||||
|
||||
if ((dp = opendir (pathname)) == NULL)
|
||||
return (false);
|
||||
|
||||
errno = 0;
|
||||
while (((d = readdir (dp)) != NULL) && errno == 0) {
|
||||
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) {
|
||||
char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
|
||||
if (d->d_type == DT_DIR) {
|
||||
if (! rc_rm_dir (tmp, true))
|
||||
{
|
||||
free (tmp);
|
||||
closedir (dp);
|
||||
return (false);
|
||||
}
|
||||
} else {
|
||||
if (unlink (tmp)) {
|
||||
free (tmp);
|
||||
closedir (dp);
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
free (tmp);
|
||||
}
|
||||
}
|
||||
closedir (dp);
|
||||
|
||||
if (top && rmdir (pathname) != 0)
|
||||
return (false);
|
||||
|
||||
return (true);
|
||||
}
|
||||
librc_hidden_def(rc_rm_dir)
|
||||
|
||||
char **rc_config_load (const char *file)
|
||||
{
|
||||
char **list = NULL;
|
||||
|
43
src/librc.c
43
src/librc.c
@ -86,6 +86,43 @@ static char **ls_dir (const char *dir, int options)
|
||||
return (list);
|
||||
}
|
||||
|
||||
static bool rm_dir (const char *pathname, bool top)
|
||||
{
|
||||
DIR *dp;
|
||||
struct dirent *d;
|
||||
|
||||
if ((dp = opendir (pathname)) == NULL)
|
||||
return (false);
|
||||
|
||||
errno = 0;
|
||||
while (((d = readdir (dp)) != NULL) && errno == 0) {
|
||||
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) {
|
||||
char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
|
||||
if (d->d_type == DT_DIR) {
|
||||
if (! rm_dir (tmp, true))
|
||||
{
|
||||
free (tmp);
|
||||
closedir (dp);
|
||||
return (false);
|
||||
}
|
||||
} else {
|
||||
if (unlink (tmp)) {
|
||||
free (tmp);
|
||||
closedir (dp);
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
free (tmp);
|
||||
}
|
||||
}
|
||||
closedir (dp);
|
||||
|
||||
if (top && rmdir (pathname) != 0)
|
||||
return (false);
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
static const char *rc_parse_service_state (rc_service_state_t state)
|
||||
{
|
||||
int i;
|
||||
@ -407,11 +444,11 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
|
||||
/* Remove any options and daemons the service may have stored */
|
||||
if (state == RC_SERVICE_STOPPED) {
|
||||
char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL);
|
||||
rc_rm_dir (dir, true);
|
||||
rm_dir (dir, true);
|
||||
free (dir);
|
||||
|
||||
dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL);
|
||||
rc_rm_dir (dir, true);
|
||||
rm_dir (dir, true);
|
||||
free (dir);
|
||||
|
||||
rc_service_schedule_clear (service);
|
||||
@ -643,7 +680,7 @@ bool rc_service_schedule_clear (const char *service)
|
||||
bool retval;
|
||||
|
||||
free (svc);
|
||||
if (! (retval = rc_rm_dir (dir, true)) && errno == ENOENT)
|
||||
if (! (retval = rm_dir (dir, true)) && errno == ENOENT)
|
||||
retval = true;
|
||||
free (dir);
|
||||
return (retval);
|
||||
|
@ -65,7 +65,6 @@ librc_hidden_proto(rc_env_config)
|
||||
librc_hidden_proto(rc_env_filter)
|
||||
librc_hidden_proto(rc_exists)
|
||||
librc_hidden_proto(rc_find_pids)
|
||||
librc_hidden_proto(rc_rm_dir)
|
||||
librc_hidden_proto(rc_runlevel_exists)
|
||||
librc_hidden_proto(rc_runlevel_get)
|
||||
librc_hidden_proto(rc_runlevel_list)
|
||||
|
34
src/rc.c
34
src/rc.c
@ -1026,7 +1026,24 @@ int main (int argc, char **argv)
|
||||
eerrorx ("failed to load deptree");
|
||||
|
||||
/* Clean the failed services state dir now */
|
||||
rc_rm_dir (RC_SVCDIR "/failed", false);
|
||||
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;
|
||||
|
||||
asprintf (&tmp, 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);
|
||||
rmdir (RC_SVCDIR "/failed");
|
||||
}
|
||||
|
||||
mkdir (RC_STOPPING, 0755);
|
||||
|
||||
@ -1037,12 +1054,25 @@ int main (int argc, char **argv)
|
||||
here when we are ready for them */
|
||||
if ((dp = opendir (DEVBOOT))) {
|
||||
while ((d = readdir (dp))) {
|
||||
if (d->d_name[0] == '.' &&
|
||||
(d->d_name[1] == '\0' ||
|
||||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
|
||||
continue;
|
||||
|
||||
if (rc_service_exists (d->d_name) &&
|
||||
rc_service_plugable (d->d_name))
|
||||
rc_service_mark (d->d_name, RC_SERVICE_COLDPLUGGED);
|
||||
|
||||
tmp = asprintf (&tmp, 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);
|
||||
rc_rm_dir (DEVBOOT, true);
|
||||
rmdir (DEVBOOT);
|
||||
}
|
||||
#else
|
||||
/* BSD's on the other hand populate /dev automagically and use devd.
|
||||
|
6
src/rc.h
6
src/rc.h
@ -438,10 +438,4 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL;
|
||||
* @return true if it matches true, yes or 1, false if otherwise. */
|
||||
bool rc_env_bool (const char *variable);
|
||||
|
||||
/*! Remove a directory
|
||||
* @param pathname to remove
|
||||
* @param top remove the top level directory too
|
||||
* @return true if successful, otherwise false */
|
||||
bool rc_rm_dir (const char *pathname, bool top);
|
||||
|
||||
#endif
|
||||
|
@ -14,7 +14,6 @@ global:
|
||||
rc_env_filter;
|
||||
rc_environ_fd;
|
||||
rc_find_pids;
|
||||
rc_rm_dir;
|
||||
rc_runlevel_exists;
|
||||
rc_runlevel_get;
|
||||
rc_runlevel_list;
|
||||
|
Loading…
Reference in New Issue
Block a user