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:
parent
c8b03c96b7
commit
75b5fdff29
17
ChangeLog
17
ChangeLog
@ -3,16 +3,17 @@
|
||||
|
||||
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
|
||||
a starting list as a first argument. Instead, use rc_strlist_join
|
||||
to append or prepend the new list to an existing list.
|
||||
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
|
||||
added or not instead of iterating through the list looking for it.
|
||||
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 added or not instead
|
||||
of iterating through the list looking for it. rc_strlist_join now frees
|
||||
list2 for ease of use.
|
||||
|
||||
list = rc_strlist_add (list, item);
|
||||
becomes
|
||||
|
@ -493,25 +493,22 @@ char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
|
||||
strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
|
||||
{
|
||||
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));
|
||||
list = rc_strlist_join (list,
|
||||
rc_strlist_join (&list,
|
||||
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
|
||||
reverse = true;
|
||||
} else {
|
||||
list = rc_services_in_runlevel (runlevel);
|
||||
|
||||
/* Add coldplugged services */
|
||||
list = rc_strlist_join (list,
|
||||
rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
|
||||
|
||||
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) {
|
||||
char *path = rc_strcatpaths (RC_RUNLEVELDIR, bootlevel,
|
||||
(char *) NULL);
|
||||
list = rc_strlist_join (list,
|
||||
rc_ls_dir (path, RC_LS_INITD));
|
||||
rc_strlist_join (&list, rc_ls_dir (path, RC_LS_INITD));
|
||||
free (path);
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ char **rc_filter_env (void)
|
||||
if (! whitelist)
|
||||
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)
|
||||
return (NULL);
|
||||
|
@ -135,26 +135,29 @@ int rc_strlist_delete (char ***list, const char *item)
|
||||
}
|
||||
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;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
if (! list1 && list2)
|
||||
return (list2);
|
||||
if (! list2 && list1)
|
||||
return (list1);
|
||||
if (! list1 && ! list2)
|
||||
return (NULL);
|
||||
if (! lst1 && list2) {
|
||||
*list1 = list2;
|
||||
return (0);
|
||||
}
|
||||
if (! list2 && lst1)
|
||||
return (0);
|
||||
if (! lst1 && ! list2)
|
||||
return (0);
|
||||
|
||||
while (list1[i])
|
||||
while (lst1[i])
|
||||
i++;
|
||||
|
||||
while (list2[j])
|
||||
j++;
|
||||
|
||||
newlist = rc_xrealloc (list1, sizeof (char *) * (i + j + 1));
|
||||
newlist = rc_xrealloc (lst1, sizeof (char *) * (i + j + 1));
|
||||
|
||||
j = 0;
|
||||
while (list2[j]) {
|
||||
@ -164,7 +167,11 @@ char **rc_strlist_join (char **list1, char **list2)
|
||||
}
|
||||
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)
|
||||
|
||||
|
23
src/rc.c
23
src/rc.c
@ -815,7 +815,7 @@ int main (int argc, char **argv)
|
||||
/* Ensure our environment is pure
|
||||
Also, add our configuration to it */
|
||||
env = rc_filter_env ();
|
||||
env = rc_strlist_join (env, rc_make_env ());
|
||||
rc_strlist_join (&env, rc_make_env ());
|
||||
|
||||
if (env) {
|
||||
char *p;
|
||||
@ -1089,9 +1089,9 @@ 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 (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));
|
||||
stop_services = rc_strlist_join (stop_services,
|
||||
rc_strlist_join (&stop_services,
|
||||
rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
|
||||
|
||||
types = NULL;
|
||||
@ -1123,25 +1123,22 @@ int main (int argc, char **argv)
|
||||
}
|
||||
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
|
||||
(char *) NULL);
|
||||
start_services = rc_strlist_join (start_services,
|
||||
rc_ls_dir (tmp, RC_LS_INITD));
|
||||
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_strlist_join (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)
|
||||
{
|
||||
/* We need to include the boot runlevel services if we're not in it */
|
||||
char **services = rc_services_in_runlevel (bootlevel);
|
||||
|
||||
start_services = rc_strlist_join (start_services, services);
|
||||
services = rc_services_in_runlevel (newlevel ? newlevel : runlevel);
|
||||
start_services = rc_strlist_join (start_services, services);
|
||||
services = NULL;
|
||||
|
||||
rc_strlist_join (&start_services,
|
||||
rc_services_in_runlevel (bootlevel));
|
||||
rc_strlist_join (&start_services,
|
||||
rc_services_in_runlevel (newlevel ?
|
||||
newlevel : runlevel));
|
||||
STRLIST_FOREACH (coldplugged_services, service, i)
|
||||
rc_strlist_add (&start_services, service);
|
||||
|
||||
|
2
src/rc.h
2
src/rc.h
@ -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_addsortu (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_free (char **list);
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ int runscript (int argc, char **argv)
|
||||
/* Ensure our environment is pure
|
||||
Also, add our configuration to it */
|
||||
env = rc_filter_env ();
|
||||
env = rc_strlist_join (env, rc_make_env ());
|
||||
rc_strlist_join (&env, rc_make_env ());
|
||||
|
||||
if (env) {
|
||||
char *p;
|
||||
|
Loading…
Reference in New Issue
Block a user