aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog17
-rw-r--r--src/librc-depend.c15
-rw-r--r--src/librc-misc.c2
-rw-r--r--src/librc-strlist.c27
-rw-r--r--src/rc.c29
-rw-r--r--src/rc.h2
-rw-r--r--src/runscript.c2
7 files changed, 48 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index 011250da..4cb714e2 100644
--- a/ChangeLog
+++ b/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
diff --git a/src/librc-depend.c b/src/librc-depend.c
index b5c11ad6..32bbf2bd 100644
--- a/src/librc-depend.c
+++ b/src/librc-depend.c
@@ -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_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
- list = rc_strlist_join (list,
- rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
+ rc_strlist_join (&list,
+ rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
+ 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);
}
}
diff --git a/src/librc-misc.c b/src/librc-misc.c
index eef38d39..9bac7902 100644
--- a/src/librc-misc.c
+++ b/src/librc-misc.c
@@ -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);
diff --git a/src/librc-strlist.c b/src/librc-strlist.c
index fbcc8f10..dc9bc20c 100644
--- a/src/librc-strlist.c
+++ b/src/librc-strlist.c
@@ -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)
diff --git a/src/rc.c b/src/rc.c
index 9ebcb5d6..561d895c 100644
--- a/src/rc.c
+++ b/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,10 +1089,10 @@ 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_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
- stop_services = rc_strlist_join (stop_services,
- rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
+ rc_strlist_join (&stop_services,
+ rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD));
+ rc_strlist_join (&stop_services,
+ rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD));
types = NULL;
rc_strlist_add (&types, "ineed");
@@ -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_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
+ 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);
diff --git a/src/rc.h b/src/rc.h
index 4dca669a..8bb8a4f3 100644
--- a/src/rc.h
+++ b/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);
diff --git a/src/runscript.c b/src/runscript.c
index 8057c99e..f7d49fb7 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -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;