diff options
author | Roy Marples <roy@marples.name> | 2007-10-05 10:36:53 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-10-05 10:36:53 +0000 |
commit | 3bfba57f5b2d89a5022fac932e46ca467a4b9f26 (patch) | |
tree | c730a290d7c3c261db1d8bdf65f1662e749ecaf8 /src | |
parent | 05b8eff319536ade894d07705bc74abaf425788e (diff) |
Punt rc_rm_dir
Diffstat (limited to 'src')
-rw-r--r-- | src/librc-misc.c | 38 | ||||
-rw-r--r-- | src/librc.c | 43 | ||||
-rw-r--r-- | src/librc.h | 1 | ||||
-rw-r--r-- | src/rc.c | 34 | ||||
-rw-r--r-- | src/rc.h | 6 | ||||
-rw-r--r-- | src/rc.map | 1 |
6 files changed, 72 insertions, 51 deletions
diff --git a/src/librc-misc.c b/src/librc-misc.c index 11cbadc6..4a97ae00 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -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; diff --git a/src/librc.c b/src/librc.c index 1ff76928..8c27b56a 100644 --- a/src/librc.c +++ b/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); diff --git a/src/librc.h b/src/librc.h index 3d0ce3ef..152e7fc6 100644 --- a/src/librc.h +++ b/src/librc.h @@ -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) @@ -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. @@ -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; |