API change! rc_ls_dir, rc_get_config and rc_get_list no longer take

a starting list as a first argument. Instead, use rc_strlist_join
to append or prepend the new list to an existing list.
This commit is contained in:
Roy Marples 2007-09-18 12:04:51 +00:00
parent f1bba12892
commit 936dc94351
9 changed files with 64 additions and 54 deletions

View File

@ -3,6 +3,10 @@
18 Sep 2007; Roy Marples <uberlord@gentoo.org>:
API change! rc_ls_dir, rc_get_config and rc_get_list no longer take
a starting list as a first argument. Instead, use rc_strlist_join
to append or prepend the new list to an existing list.
API change! rc_strlist_add and friends now take char *** instead of
char ** and return a pointer to the item added instead of the new
list head. This is so we can easily tell if the item was successfully

View File

@ -85,7 +85,7 @@ static struct option longopts[] = {
int env_update (int argc, char **argv)
{
char **files = rc_ls_dir (NULL, ENVDIR, 0);
char **files = rc_ls_dir (ENVDIR, 0);
char *file;
char **envs = NULL;
char *env;
@ -138,7 +138,7 @@ int env_update (int argc, char **argv)
*(file + j - 1) != '~' &&
(j < 4 || strcmp (file + j - 4, ".bak") != 0) &&
(j < 5 || strcmp (file + j - 5, ".core") != 0))
entries = rc_get_config (NULL, path);
entries = rc_get_config (path);
free (path);
STRLIST_FOREACH (entries, entry, j) {
@ -293,7 +293,7 @@ int env_update (int argc, char **argv)
if (ldconfig) {
/* Update ld.so.conf only if different */
if (rc_exists (LDSOCONF)) {
char **lines = rc_get_list (NULL, LDSOCONF);
char **lines = rc_get_list (LDSOCONF);
char *line;
ld = false;

View File

@ -324,7 +324,7 @@ void rc_set_service_daemon (const char *service, const char *exec,
/* Regardless, erase any existing daemon info */
if (rc_is_dir (dirpath)) {
char *oldfile = NULL;
files = rc_ls_dir (NULL, dirpath, 0);
files = rc_ls_dir (dirpath, 0);
STRLIST_FOREACH (files, file, i) {
ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
nfiles++;
@ -407,7 +407,7 @@ bool rc_service_started_daemon (const char *service, const char *exec,
retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
free (file);
} else {
char **files = rc_ls_dir (NULL, dirpath, 0);
char **files = rc_ls_dir (dirpath, 0);
STRLIST_FOREACH (files, file, i) {
retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
if (retval)
@ -454,7 +454,7 @@ bool rc_service_daemons_crashed (const char *service)
}
memset (buffer, 0, sizeof (buffer));
files = rc_ls_dir (NULL, dirpath, 0);
files = rc_ls_dir (dirpath, 0);
STRLIST_FOREACH (files, file, i) {
path = rc_strcatpaths (dirpath, file, (char *) NULL);
fp = fopen (path, "r");

View File

@ -492,25 +492,26 @@ char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
{
list = rc_ls_dir (list, RC_SVCDIR_STARTING, RC_LS_INITD);
list = rc_ls_dir (list, RC_SVCDIR_INACTIVE, RC_LS_INITD);
list = rc_ls_dir (list, RC_SVCDIR_STARTED, RC_LS_INITD);
list = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD);
list = rc_strlist_join (list,
rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
list = rc_strlist_join (list,
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
reverse = true;
}
else
{
} else {
list = rc_services_in_runlevel (runlevel);
/* Add coldplugged services */
list = rc_ls_dir (list, RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
list = rc_strlist_join (list,
rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
/* If we're not the boot runlevel then add that too */
if (strcmp (runlevel, bootlevel) != 0)
{
if (strcmp (runlevel, bootlevel) != 0) {
char *path = rc_strcatpaths (RC_RUNLEVELDIR, bootlevel,
(char *) NULL);
list = rc_ls_dir (list, path, RC_LS_INITD);
list = rc_strlist_join (list,
rc_ls_dir (path, RC_LS_INITD));
free (path);
}
}
@ -551,7 +552,7 @@ static bool is_newer_than (const char *file, const char *target)
if (rc_is_dir (target))
{
char **targets = rc_ls_dir (NULL, target, 0);
char **targets = rc_ls_dir (target, 0);
char *t;
int i;
bool newer = true;
@ -651,7 +652,7 @@ int rc_update_deptree (bool force)
if (! rc_exists (RC_DEPCONFIG))
return 0;
config = rc_get_list (NULL, RC_DEPCONFIG);
config = rc_get_list (RC_DEPCONFIG);
STRLIST_FOREACH (config, service, i) {
if (! is_newer_than (RC_DEPTREE, service)) {
newer = true;

View File

@ -209,17 +209,18 @@ bool rc_is_exec (const char *pathname)
}
librc_hidden_def(rc_is_exec)
char **rc_ls_dir (char **list, const char *dir, int options)
char **rc_ls_dir (const char *dir, int options)
{
DIR *dp;
struct dirent *d;
char **list = NULL;
if (! dir)
return (list);
return (NULL);
if ((dp = opendir (dir)) == NULL) {
eerror ("failed to opendir `%s': %s", dir, strerror (errno));
return (list);
return (NULL);
}
errno = 0;
@ -303,8 +304,9 @@ bool rc_rm_dir (const char *pathname, bool top)
}
librc_hidden_def(rc_rm_dir)
char **rc_get_config (char **list, const char *file)
char **rc_get_config (const char *file)
{
char **list = NULL;
FILE *fp;
char buffer[RC_LINEBUFFER];
char *p;
@ -319,7 +321,7 @@ char **rc_get_config (char **list, const char *file)
if (! (fp = fopen (file, "r"))) {
ewarn ("load_config_file `%s': %s", file, strerror (errno));
return (list);
return (NULL);
}
while (fgets (buffer, RC_LINEBUFFER, fp)) {
@ -404,16 +406,17 @@ char *rc_get_config_entry (char **list, const char *entry)
}
librc_hidden_def(rc_get_config_entry)
char **rc_get_list (char **list, const char *file)
char **rc_get_list (const char *file)
{
FILE *fp;
char buffer[RC_LINEBUFFER];
char *p;
char *token;
char **list = NULL;
if (! (fp = fopen (file, "r"))) {
ewarn ("rc_get_list `%s': %s", file, strerror (errno));
return (list);
return (NULL);
}
while (fgets (buffer, RC_LINEBUFFER, fp)) {
@ -455,17 +458,17 @@ char **rc_filter_env (void)
char *e;
int pplen = strlen (PATH_PREFIX);
whitelist = rc_get_list (whitelist, SYS_WHITELIST);
whitelist = rc_get_list (SYS_WHITELIST);
if (! whitelist)
ewarn ("system environment whitelist (" SYS_WHITELIST ") missing");
whitelist = rc_get_list (whitelist, USR_WHITELIST);
whitelist = rc_strlist_join (whitelist, rc_get_list (USR_WHITELIST));
if (! whitelist)
return (NULL);
if (rc_is_file (PROFILE_ENV))
profile = rc_get_config (profile, PROFILE_ENV);
profile = rc_get_config (PROFILE_ENV);
STRLIST_FOREACH (whitelist, env_name, count) {
char *space = strchr (env_name, ' ');
@ -593,9 +596,9 @@ char **rc_config_env (char **env)
/* Don't trust environ for softlevel yet */
snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, rc_get_runlevel());
if (rc_exists (buffer))
config = rc_get_config (NULL, buffer);
config = rc_get_config (buffer);
else
config = rc_get_config (NULL, RC_CONFIG);
config = rc_get_config (RC_CONFIG);
STRLIST_FOREACH (config, line, i) {
p = strchr (line, '=');

View File

@ -45,7 +45,7 @@ librc_hidden_def(rc_runlevel_stopping)
char **rc_get_runlevels (void)
{
char **dirs = rc_ls_dir (NULL, RC_RUNLEVELDIR, 0);
char **dirs = rc_ls_dir (RC_RUNLEVELDIR, 0);
char **runlevels = NULL;
int i;
char *dir;
@ -384,7 +384,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
/* These are final states, so remove us from scheduled */
if (state == rc_service_started || state == rc_service_stopped) {
char *sdir = rc_strcatpaths (RC_SVCDIR, "scheduled", (char *) NULL);
char **dirs = rc_ls_dir (NULL, sdir, 0);
char **dirs = rc_ls_dir (sdir, 0);
char *dir;
int serrno;
@ -692,7 +692,7 @@ char **rc_services_in_runlevel (const char *runlevel)
char **list = NULL;
if (! runlevel)
return (rc_ls_dir (NULL, RC_INITDIR, RC_LS_INITD));
return (rc_ls_dir (RC_INITDIR, RC_LS_INITD));
/* These special levels never contain any services */
if (strcmp (runlevel, RC_LEVEL_SYSINIT) == 0 ||
@ -703,7 +703,7 @@ char **rc_services_in_runlevel (const char *runlevel)
if (! rc_is_dir (dir))
eerror ("runlevel `%s' does not exist", runlevel);
else
list = rc_ls_dir (list, dir, RC_LS_INITD);
list = rc_ls_dir (dir, RC_LS_INITD);
free (dir);
return (list);
@ -717,13 +717,13 @@ char **rc_services_in_state (rc_service_state_t state)
char **list = NULL;
if (state == rc_service_scheduled) {
char **dirs = rc_ls_dir (NULL, dir, 0);
char **dirs = rc_ls_dir (dir, 0);
char *d;
int i;
STRLIST_FOREACH (dirs, d, i) {
char *p = rc_strcatpaths (dir, d, (char *) NULL);
char **entries = rc_ls_dir (NULL, p, RC_LS_INITD);
char **entries = rc_ls_dir (p, RC_LS_INITD);
char *e;
int j;
@ -738,7 +738,7 @@ char **rc_services_in_state (rc_service_state_t state)
free (dirs);
} else {
if (rc_is_dir (dir))
list = rc_ls_dir (list, dir, RC_LS_INITD);
list = rc_ls_dir (dir, RC_LS_INITD);
}
free (dir);
@ -798,7 +798,7 @@ librc_hidden_def(rc_service_delete)
char **rc_services_scheduled_by (const char *service)
{
char **dirs = rc_ls_dir (NULL, RC_SVCDIR "/scheduled", 0);
char **dirs = rc_ls_dir (RC_SVCDIR "/scheduled", 0);
char **list = NULL;
char *dir;
int i;
@ -824,7 +824,7 @@ char **rc_services_scheduled (const char *service)
char **list = NULL;
if (rc_is_dir (dir))
list = rc_ls_dir (list, dir, RC_LS_INITD);
list = rc_ls_dir (dir, RC_LS_INITD);
free (svc);
free (dir);

View File

@ -62,7 +62,7 @@ void rc_plugin_load (void)
if (! rc_exists (RC_PLUGINDIR))
return;
files = rc_ls_dir (NULL, RC_PLUGINDIR, 0);
files = rc_ls_dir (RC_PLUGINDIR, 0);
STRLIST_FOREACH (files, file, i) {
char *p = rc_strcatpaths (RC_PLUGINDIR, file, NULL);
void *h = dlopen (p, RTLD_LAZY);

View File

@ -1027,7 +1027,7 @@ int main (int argc, char **argv)
stores a list of coldplugged services in DEVBOOT for us to pick up
here when we are ready for them */
if (rc_is_dir (DEVBOOT)) {
start_services = rc_ls_dir (NULL, DEVBOOT, RC_LS_INITD);
start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD);
rc_rm_dir (DEVBOOT, true);
STRLIST_FOREACH (start_services, service, i)
@ -1051,7 +1051,7 @@ int main (int argc, char **argv)
{
#if defined(__DragonFly__) || defined(__FreeBSD__)
/* The net interfaces are easy - they're all in net /dev/net :) */
start_services = rc_ls_dir (NULL, "/dev/net", 0);
start_services = rc_ls_dir ("/dev/net", 0);
STRLIST_FOREACH (start_services, service, i) {
j = (strlen ("net.") + strlen (service) + 1);
tmp = rc_xmalloc (sizeof (char *) * j);
@ -1065,7 +1065,7 @@ int main (int argc, char **argv)
/* The mice are a little more tricky.
If we coldplug anything else, we'll probably do it here. */
start_services = rc_ls_dir (NULL, "/dev", 0);
start_services = rc_ls_dir ("/dev", 0);
STRLIST_FOREACH (start_services, service, i) {
if (strncmp (service, "psm", 3) == 0 ||
strncmp (service, "ums", 3) == 0)
@ -1088,9 +1088,11 @@ int main (int argc, char **argv)
/* Build a list of all services to stop and then work out the
correct order for stopping them */
stop_services = rc_ls_dir (stop_services, RC_SVCDIR_STARTING, RC_LS_INITD);
stop_services = rc_ls_dir (stop_services, RC_SVCDIR_INACTIVE, RC_LS_INITD);
stop_services = rc_ls_dir (stop_services, RC_SVCDIR_STARTED, RC_LS_INITD);
stop_services = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD);
stop_services = rc_strlist_join (stop_services,
rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
stop_services = rc_strlist_join (stop_services,
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
types = NULL;
rc_strlist_add (&types, "ineed");
@ -1106,8 +1108,7 @@ int main (int argc, char **argv)
rc_strlist_reverse (stop_services);
/* Load our list of coldplugged services */
coldplugged_services = rc_ls_dir (coldplugged_services,
RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
coldplugged_services = rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
/* Load our start services now.
We have different rules dependent on runlevel. */
@ -1122,12 +1123,13 @@ int main (int argc, char **argv)
}
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
(char *) NULL);
start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
start_services = rc_strlist_join (start_services,
rc_ls_dir (tmp, RC_LS_INITD));
CHAR_FREE (tmp);
} else {
/* Store our list of coldplugged services */
coldplugged_services = rc_ls_dir (coldplugged_services, RC_SVCDIR_COLDPLUGGED,
RC_LS_INITD);
coldplugged_services = rc_strlist_join (coldplugged_services,
rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)

View File

@ -182,13 +182,13 @@ bool rc_is_dir (const char *pathname);
bool rc_is_exec (const char *pathname);
#define RC_LS_INITD 0x01
char **rc_ls_dir (char **list, const char *dir, int options);
char **rc_ls_dir (const char *dir, int options);
bool rc_rm_dir (const char *pathname, bool top);
/* Config file functions */
char **rc_get_list (char **list, const char *file);
char **rc_get_config (char **list, const char *file);
char **rc_get_list (const char *file);
char **rc_get_config (const char *file);
char *rc_get_config_entry (char **list, const char *entry);
/* Make an environment list which filters out all unwanted values