aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-10-15 14:40:53 +0000
committerRoy Marples <roy@marples.name>2007-10-15 14:40:53 +0000
commit5d215f9d63b718eefff69ad20648fb3d66b15c25 (patch)
tree7402c207a87f290d9b81966102ca751f25b5758a
parentc7f679e97e83de461c8f2de320b6b120bdecc50a (diff)
const correctness
-rw-r--r--src/librc-depend.c18
-rw-r--r--src/rc-depend.c6
-rw-r--r--src/rc-status.c5
-rw-r--r--src/rc.c30
-rw-r--r--src/rc.h5
-rw-r--r--src/runscript.c90
6 files changed, 55 insertions, 99 deletions
diff --git a/src/librc-depend.c b/src/librc-depend.c
index c00f4fa8..69c06c2e 100644
--- a/src/librc-depend.c
+++ b/src/librc-depend.c
@@ -351,13 +351,14 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
return (providers.list);
}
-static void visit_service (rc_depinfo_t *deptree, char **types,
+static void visit_service (rc_depinfo_t *deptree, const char * const *types,
struct lhead *sorted, struct lhead *visited,
rc_depinfo_t *depinfo,
const char *runlevel, int options)
{
int i, j, k;
- char *lp, *item;
+ char *lp;
+ const char *item;
char *service;
rc_depinfo_t *di;
rc_deptype_t *dt;
@@ -441,13 +442,13 @@ static void visit_service (rc_depinfo_t *deptree, char **types,
}
char **rc_deptree_depends (rc_depinfo_t *deptree,
- char **types, char **services,
+ const char * const *types, const char * const *services,
const char *runlevel, int options)
{
struct lhead sorted;
struct lhead visited;
rc_depinfo_t *di;
- char *service;
+ const char *service;
int i;
if (! deptree || ! services)
@@ -476,11 +477,11 @@ char **rc_deptree_depends (rc_depinfo_t *deptree,
}
librc_hidden_def(rc_deptree_depends)
+static const const char *order_types[] = { "ineed", "iuse", "iafter", NULL };
char **rc_deptree_order (rc_depinfo_t *deptree, const char *runlevel,
int options)
{
char **list = NULL;
- char **types = NULL;
char **services = NULL;
bool reverse = false;
char **tmp = NULL;
@@ -525,13 +526,10 @@ char **rc_deptree_order (rc_depinfo_t *deptree, const char *runlevel,
/* Now we have our lists, we need to pull in any dependencies
and order them */
- rc_strlist_add (&types, "ineed");
- rc_strlist_add (&types, "iuse");
- rc_strlist_add (&types, "iafter");
- services = rc_deptree_depends (deptree, types, list, runlevel,
+ services = rc_deptree_depends (deptree, order_types, (const char **) list,
+ runlevel,
RC_DEP_STRICT | RC_DEP_TRACE | options);
rc_strlist_free (list);
- rc_strlist_free (types);
if (reverse)
rc_strlist_reverse (services);
diff --git a/src/rc-depend.c b/src/rc-depend.c
index 8a0f1894..190d5c8c 100644
--- a/src/rc-depend.c
+++ b/src/rc-depend.c
@@ -114,7 +114,8 @@ int rc_depend (int argc, char **argv)
list = NULL;
rc_strlist_add (&list, argv[optind]);
errno = 0;
- depends = rc_deptree_depends (deptree, NULL, list, runlevel, 0);
+ depends = rc_deptree_depends (deptree, NULL, (const char **) list,
+ runlevel, 0);
if (! depends && errno == ENOENT)
eerror ("no dependency info for service `%s'", argv[optind]);
else
@@ -140,7 +141,8 @@ int rc_depend (int argc, char **argv)
rc_strlist_add (&types, "iuse");
}
- depends = rc_deptree_depends (deptree, types, services, runlevel, options);
+ depends = rc_deptree_depends (deptree, (const char **) types,
+ (const char **) services, runlevel, options);
if (depends) {
STRLIST_FOREACH (depends, service, i) {
diff --git a/src/rc-status.c b/src/rc-status.c
index cb62e7c8..324177c9 100644
--- a/src/rc-status.c
+++ b/src/rc-status.c
@@ -19,7 +19,7 @@
#define APPLET "rc-status"
-static char const *types[] = { "ineed", "iuse", "iafter", NULL };
+static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL };
static void print_level (char *level)
{
@@ -146,7 +146,8 @@ int rc_status (int argc, char **argv)
print_level (level);
services = rc_services_in_runlevel (level);
if (deptree) {
- ordered = rc_deptree_depends (deptree, (char **) types, services,
+ ordered = rc_deptree_depends (deptree, types_nua,
+ (const char **) services,
level, depopts);
rc_strlist_free (services);
services = ordered;
diff --git a/src/rc.c b/src/rc.c
index 773bb457..4906d6a1 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -72,7 +72,6 @@ static char **coldplugged_services = NULL;
static char **stop_services = NULL;
static char **start_services = NULL;
static rc_depinfo_t *deptree = NULL;
-static char **types = NULL;
static char *tmp = NULL;
struct termios *termios_orig = NULL;
@@ -84,6 +83,9 @@ typedef struct pidlist
} pidlist_t;
static pidlist_t *service_pids = NULL;
+static const char *types_n[] = { "needsme", NULL };
+static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL };
+
static void cleanup (void)
{
if (applet && strcmp (applet, "rc") == 0) {
@@ -108,7 +110,6 @@ static void cleanup (void)
rc_strlist_free (stop_services);
rc_strlist_free (start_services);
rc_deptree_free (deptree);
- rc_strlist_free (types);
/* Clean runlevel start, stop markers */
if (! rc_in_plugin) {
@@ -1153,17 +1154,11 @@ int main (int argc, char **argv)
rc_strlist_join (&stop_services, tmplist);
rc_strlist_free (tmplist);
- types = NULL;
- rc_strlist_add (&types, "ineed");
- rc_strlist_add (&types, "iuse");
- rc_strlist_add (&types, "iafter");
-
- deporder = rc_deptree_depends (deptree, types, stop_services,
+ deporder = rc_deptree_depends (deptree, types_nua,
+ (const char **) stop_services,
runlevel, depoptions | RC_DEP_STOP);
rc_strlist_free (stop_services);
- rc_strlist_free (types);
- types = NULL;
stop_services = deporder;
deporder = NULL;
rc_strlist_reverse (stop_services);
@@ -1212,8 +1207,6 @@ int main (int argc, char **argv)
if (going_down)
rc_runlevel_set (newlevel);
- types = NULL;
- rc_strlist_add (&types, "needsme");
/* Now stop the services that shouldn't be running */
STRLIST_FOREACH (stop_services, service, i) {
bool found = false;
@@ -1274,7 +1267,8 @@ int main (int argc, char **argv)
/* We got this far! Or last check is to see if any any service that
going to be started depends on us */
rc_strlist_add (&stopdeps, service);
- deporder = rc_deptree_depends (deptree, types, stopdeps,
+ deporder = rc_deptree_depends (deptree, types_n,
+ (const char **) stopdeps,
runlevel, RC_DEP_STRICT);
rc_strlist_free (stopdeps);
stopdeps = NULL;
@@ -1298,8 +1292,6 @@ int main (int argc, char **argv)
wait_pid (pid);
}
}
- rc_strlist_free (types);
- types = NULL;
/* Wait for our services to finish */
wait_for_services ();
@@ -1341,13 +1333,9 @@ int main (int argc, char **argv)
rc_service_mark (service, RC_SERVICE_COLDPLUGGED);
/* Order the services to start */
- rc_strlist_add (&types, "ineed");
- rc_strlist_add (&types, "iuse");
- rc_strlist_add (&types, "iafter");
- deporder = rc_deptree_depends (deptree, types, start_services,
+ deporder = rc_deptree_depends (deptree, types_nua,
+ (const char **) start_services,
runlevel, depoptions | RC_DEP_START);
- rc_strlist_free (types);
- types = NULL;
rc_strlist_free (start_services);
start_services = deporder;
deporder = NULL;
diff --git a/src/rc.h b/src/rc.h
index 6040345a..1a5368ad 100644
--- a/src/rc.h
+++ b/src/rc.h
@@ -264,8 +264,9 @@ rc_depinfo_t *rc_deptree_load (void);
* @param services to check
* @param options to pass
* @return NULL terminated list of services in order */
-char **rc_deptree_depends (rc_depinfo_t *deptree, char **types,
- char **services, const char *runlevel, int options);
+char **rc_deptree_depends (rc_depinfo_t *deptree, const char * const *types,
+ const char * const *services, const char *runlevel,
+ int options);
/*! List all the services that should be stoppned and then started, in order,
* for the given runlevel, including sysinit and boot services where
diff --git a/src/runscript.c b/src/runscript.c
index 852194bb..a375b70b 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -51,10 +51,8 @@ static char *exclusive = NULL;
static char *mtime_test = NULL;
static rc_depinfo_t *deptree = NULL;
static char **services = NULL;
-static char **svclist = NULL;
static char **tmplist = NULL;
static char **providelist = NULL;
-static char **types = NULL;
static char **restart_services = NULL;
static char **need_services = NULL;
static char **use_services = NULL;
@@ -73,6 +71,15 @@ static int master_tty = -1;
extern char **environ;
+static const char *types_b[] = { "broken", NULL };
+static const char *types_n[] = { "ineed", NULL };
+static const char *types_nu[] = { "ineed", "iuse", NULL };
+static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL };
+static const char *types_p[] = { "iprovide", NULL };
+
+static const char *types_m[] = { "needsme", NULL };
+static const char *types_mua[] = { "needsme", "usesme", "beforeme", NULL };
+
#ifdef __linux__
static void (*selinux_run_init_old) (void);
static void (*selinux_run_init_new) (int argc, char **argv);
@@ -299,8 +306,6 @@ static void cleanup (void)
rc_plugin_unload ();
rc_deptree_free (deptree);
rc_strlist_free (services);
- rc_strlist_free (types);
- rc_strlist_free (svclist);
rc_strlist_free (providelist);
rc_strlist_free (need_services);
rc_strlist_free (use_services);
@@ -580,6 +585,7 @@ static void svc_start (bool deps)
int i;
int j;
int depoptions = RC_DEP_TRACE;
+ const char *svcl[] = { applet, NULL };
rc_service_state_t state;
hook_out = RC_HOOK_SERVICE_START_OUT;
@@ -617,14 +623,8 @@ static void svc_start (bool deps)
if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
eerrorx ("failed to load deptree");
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, "broken");
- rc_strlist_free (svclist);
- svclist = NULL;
- rc_strlist_add (&svclist, applet);
rc_strlist_free (services);
- services = rc_deptree_depends (deptree, types, svclist, softlevel, 0);
+ services = rc_deptree_depends (deptree, types_b, svcl, softlevel, 0);
if (services) {
eerrorn ("ERROR: `%s' needs ", applet);
STRLIST_FOREACH (services, svc, i) {
@@ -637,16 +637,12 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = NULL;
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, "ineed");
rc_strlist_free (need_services);
- need_services = rc_deptree_depends (deptree, types, svclist,
+ need_services = rc_deptree_depends (deptree, types_n, svcl,
softlevel, depoptions);
- rc_strlist_add (&types, "iuse");
rc_strlist_free (use_services);
- use_services = rc_deptree_depends (deptree, types, svclist,
+ use_services = rc_deptree_depends (deptree, types_nu, svcl,
softlevel, depoptions);
if (! rc_runlevel_starting ()) {
@@ -659,9 +655,8 @@ static void svc_start (bool deps)
}
/* Now wait for them to start */
- rc_strlist_add (&types, "iafter");
- services = rc_deptree_depends (deptree, types, svclist,
- softlevel, depoptions);
+ services = rc_deptree_depends (deptree, types_nua, svcl,
+ softlevel, depoptions);
/* We use tmplist to hold our scheduled by list */
rc_strlist_free (tmplist);
@@ -712,18 +707,13 @@ static void svc_start (bool deps)
rc_service_mark (service, RC_SERVICE_STOPPED);
unlink_mtime_test ();
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, "iprovide");
STRLIST_FOREACH (tmplist, svc, i) {
+ const char *sl[] = { svc, NULL };
rc_service_schedule_start (svc, service);
- rc_strlist_free (svclist);
- svclist = NULL;
- rc_strlist_add (&svclist, svc);
rc_strlist_free (providelist);
- providelist = rc_deptree_depends (deptree, types, svclist,
- softlevel, depoptions);
+ providelist = rc_deptree_depends (deptree, types_p, sl,
+ softlevel, depoptions);
STRLIST_FOREACH (providelist, svc2, j)
rc_service_schedule_start (svc2, service);
@@ -749,10 +739,6 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = NULL;
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_free (svclist);
- svclist = NULL;
}
if (ibsave)
@@ -791,14 +777,8 @@ static void svc_start (bool deps)
services = NULL;
/* Do the same for any services we provide */
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, "iprovide");
- rc_strlist_free (svclist);
- svclist = NULL;
- rc_strlist_add (&svclist, applet);
rc_strlist_free (tmplist);
- tmplist = rc_deptree_depends (deptree, types, svclist, softlevel, depoptions);
+ tmplist = rc_deptree_depends (deptree, types_p, svcl, softlevel, depoptions);
STRLIST_FOREACH (tmplist, svc2, j) {
rc_strlist_free (services);
@@ -815,6 +795,8 @@ static void svc_start (bool deps)
static void svc_stop (bool deps)
{
bool stopped;
+ const char *svcl[] = { applet, NULL };
+
rc_service_state_t state = rc_service_state (service);
hook_out = RC_HOOK_SERVICE_STOP_OUT;
@@ -857,17 +839,11 @@ static void svc_stop (bool deps)
if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
eerrorx ("failed to load deptree");
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, "needsme");
- rc_strlist_free (svclist);
- svclist = NULL;
- rc_strlist_add (&svclist, applet);
rc_strlist_free (tmplist);
tmplist = NULL;
rc_strlist_free (services);
- services = rc_deptree_depends (deptree, types, svclist,
- softlevel, depoptions);
+ services = rc_deptree_depends (deptree, types_m, svcl,
+ softlevel, depoptions);
rc_strlist_reverse (services);
STRLIST_FOREACH (services, svc, i) {
rc_service_state_t svcs = rc_service_state (svc);
@@ -915,10 +891,8 @@ static void svc_stop (bool deps)
/* We now wait for other services that may use us and are stopping
This is important when a runlevel stops */
- rc_strlist_add (&types, "usesme");
- rc_strlist_add (&types, "ibefore");
- services = rc_deptree_depends (deptree, types, svclist,
- softlevel, depoptions);
+ services = rc_deptree_depends (deptree, types_mua, svcl,
+ softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) {
if (rc_service_state (svc) & RC_SERVICE_STOPPED)
continue;
@@ -927,8 +901,6 @@ static void svc_stop (bool deps)
rc_strlist_free (services);
services = NULL;
- rc_strlist_free (types);
- types = NULL;
}
if (ibsave)
@@ -957,7 +929,6 @@ static void svc_stop (bool deps)
unlink (exclusive);
hook_out = 0;
rc_plugin_run (RC_HOOK_SERVICE_STOP_OUT, applet);
-
}
static void svc_restart (bool deps)
@@ -1213,6 +1184,8 @@ int runscript (int argc, char **argv)
strcmp (optarg, "ibefore") == 0 ||
strcmp (optarg, "iprovide") == 0) {
int depoptions = RC_DEP_TRACE;
+ const char *t[] = { optarg, NULL };
+ const char *s[] = { applet, NULL };
if (rc_env_bool ("RC_DEPEND_STRICT"))
depoptions |= RC_DEP_STRICT;
@@ -1220,15 +1193,8 @@ int runscript (int argc, char **argv)
if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
eerrorx ("failed to load deptree");
- rc_strlist_free (types);
- types = NULL;
- rc_strlist_add (&types, optarg);
- rc_strlist_free (svclist);
- svclist = NULL;
- rc_strlist_add (&svclist, applet);
rc_strlist_free (services);
- services = rc_deptree_depends (deptree, types, svclist,
- softlevel, depoptions);
+ services = rc_deptree_depends (deptree, t, s, softlevel, depoptions);
STRLIST_FOREACH (services, svc, i)
printf ("%s%s", i == 1 ? "" : " ", svc);
if (services)