Match the recent api change to rc_strlist_join also. We now free the 2nd list for ease of use.

This commit is contained in:
Roy Marples 2007-09-18 14:08:56 +00:00
parent c8b03c96b7
commit 75b5fdff29
7 changed files with 48 additions and 46 deletions

View File

@ -3,16 +3,17 @@
18 Sep 2007; Roy Marples <uberlord@gentoo.org>: 18 Sep 2007; Roy Marples <uberlord@gentoo.org>:
API change! rc_config_env is renamed to rc_make_env and takes no argument. API changes!
API change! rc_ls_dir, rc_get_config and rc_get_list no longer take rc_ls_dir, rc_get_config and rc_get_list no longer take a starting list
a starting list as a first argument. Instead, use rc_strlist_join as a first argument. Instead, use rc_strlist_join to append or prepend
to append or prepend the new list to an existing list. the new list to an existing list.
API change! rc_strlist_add and friends now take char *** instead of rc_strlist_add and friends now take char *** instead of char ** and
char ** and return a pointer to the item added instead of the new return a pointer to the item added instead of the new list head. This is
list head. This is so we can easily tell if the item was successfully so we can easily tell if the item was successfully added or not instead
added or not instead of iterating through the list looking for it. of iterating through the list looking for it. rc_strlist_join now frees
list2 for ease of use.
list = rc_strlist_add (list, item); list = rc_strlist_add (list, item);
becomes becomes

View File

@ -493,25 +493,22 @@ char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
strcmp (runlevel, RC_LEVEL_REBOOT) == 0) strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
{ {
list = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD); list = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD);
list = rc_strlist_join (list, rc_strlist_join (&list,
rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD)); rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
list = rc_strlist_join (list, rc_strlist_join (&list,
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD)); rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
reverse = true; reverse = true;
} else { } else {
list = rc_services_in_runlevel (runlevel); list = rc_services_in_runlevel (runlevel);
/* Add coldplugged services */ /* Add coldplugged services */
list = rc_strlist_join (list, rc_strlist_join (&list, rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
/* If we're not the boot runlevel then add that too */ /* 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 *path = rc_strcatpaths (RC_RUNLEVELDIR, bootlevel,
(char *) NULL); (char *) NULL);
list = rc_strlist_join (list, rc_strlist_join (&list, rc_ls_dir (path, RC_LS_INITD));
rc_ls_dir (path, RC_LS_INITD));
free (path); free (path);
} }
} }

View File

@ -462,7 +462,7 @@ char **rc_filter_env (void)
if (! whitelist) if (! whitelist)
ewarn ("system environment whitelist (" SYS_WHITELIST ") missing"); ewarn ("system environment whitelist (" SYS_WHITELIST ") missing");
whitelist = rc_strlist_join (whitelist, rc_get_list (USR_WHITELIST)); rc_strlist_join (&whitelist, rc_get_list (USR_WHITELIST));
if (! whitelist) if (! whitelist)
return (NULL); return (NULL);

View File

@ -135,26 +135,29 @@ int rc_strlist_delete (char ***list, const char *item)
} }
librc_hidden_def(rc_strlist_delete) librc_hidden_def(rc_strlist_delete)
char **rc_strlist_join (char **list1, char **list2) int rc_strlist_join (char ***list1, char **list2)
{ {
char **lst1 = *list1;
char **newlist; char **newlist;
int i = 0; int i = 0;
int j = 0; int j = 0;
if (! list1 && list2) if (! lst1 && list2) {
return (list2); *list1 = list2;
if (! list2 && list1) return (0);
return (list1); }
if (! list1 && ! list2) if (! list2 && lst1)
return (NULL); return (0);
if (! lst1 && ! list2)
return (0);
while (list1[i]) while (lst1[i])
i++; i++;
while (list2[j]) while (list2[j])
j++; j++;
newlist = rc_xrealloc (list1, sizeof (char *) * (i + j + 1)); newlist = rc_xrealloc (lst1, sizeof (char *) * (i + j + 1));
j = 0; j = 0;
while (list2[j]) { while (list2[j]) {
@ -164,7 +167,11 @@ char **rc_strlist_join (char **list1, char **list2)
} }
newlist[i] = NULL; newlist[i] = NULL;
return (newlist); /* We free list2 here for ease of use. */
free (list2);
*list1 = newlist;
return (0);
} }
librc_hidden_def(rc_strlist_join) librc_hidden_def(rc_strlist_join)

View File

@ -815,7 +815,7 @@ int main (int argc, char **argv)
/* Ensure our environment is pure /* Ensure our environment is pure
Also, add our configuration to it */ Also, add our configuration to it */
env = rc_filter_env (); env = rc_filter_env ();
env = rc_strlist_join (env, rc_make_env ()); rc_strlist_join (&env, rc_make_env ());
if (env) { if (env) {
char *p; char *p;
@ -1089,10 +1089,10 @@ int main (int argc, char **argv)
/* Build a list of all services to stop and then work out the /* Build a list of all services to stop and then work out the
correct order for stopping them */ correct order for stopping them */
stop_services = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD); stop_services = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD);
stop_services = rc_strlist_join (stop_services, rc_strlist_join (&stop_services,
rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD)); rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
stop_services = rc_strlist_join (stop_services, rc_strlist_join (&stop_services,
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD)); rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
types = NULL; types = NULL;
rc_strlist_add (&types, "ineed"); rc_strlist_add (&types, "ineed");
@ -1123,25 +1123,22 @@ int main (int argc, char **argv)
} }
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel, tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
(char *) NULL); (char *) NULL);
start_services = rc_strlist_join (start_services, rc_strlist_join (&start_services, rc_ls_dir (tmp, RC_LS_INITD));
rc_ls_dir (tmp, RC_LS_INITD));
CHAR_FREE (tmp); CHAR_FREE (tmp);
} else { } else {
/* Store our list of coldplugged services */ /* Store our list of coldplugged services */
coldplugged_services = rc_strlist_join (coldplugged_services, rc_strlist_join (&coldplugged_services,
rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD)); rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 && if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 && strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0) strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
{ {
/* We need to include the boot runlevel services if we're not in it */ /* We need to include the boot runlevel services if we're not in it */
char **services = rc_services_in_runlevel (bootlevel); rc_strlist_join (&start_services,
rc_services_in_runlevel (bootlevel));
start_services = rc_strlist_join (start_services, services); rc_strlist_join (&start_services,
services = rc_services_in_runlevel (newlevel ? newlevel : runlevel); rc_services_in_runlevel (newlevel ?
start_services = rc_strlist_join (start_services, services); newlevel : runlevel));
services = NULL;
STRLIST_FOREACH (coldplugged_services, service, i) STRLIST_FOREACH (coldplugged_services, service, i)
rc_strlist_add (&start_services, service); rc_strlist_add (&start_services, service);

View File

@ -203,7 +203,7 @@ char *rc_strlist_addsort (char ***list, const char *item);
char *rc_strlist_addsortc (char ***list, const char *item); char *rc_strlist_addsortc (char ***list, const char *item);
char *rc_strlist_addsortu (char ***list, const char *item); char *rc_strlist_addsortu (char ***list, const char *item);
int rc_strlist_delete (char ***list, const char *item); int rc_strlist_delete (char ***list, const char *item);
char **rc_strlist_join (char **list1, char **list2); int rc_strlist_join (char ***list1, char **list2);
void rc_strlist_reverse (char **list); void rc_strlist_reverse (char **list);
void rc_strlist_free (char **list); void rc_strlist_free (char **list);

View File

@ -1049,7 +1049,7 @@ int runscript (int argc, char **argv)
/* Ensure our environment is pure /* Ensure our environment is pure
Also, add our configuration to it */ Also, add our configuration to it */
env = rc_filter_env (); env = rc_filter_env ();
env = rc_strlist_join (env, rc_make_env ()); rc_strlist_join (&env, rc_make_env ());
if (env) { if (env) {
char *p; char *p;