aboutsummaryrefslogtreecommitdiff
path: root/src/runscript.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-09-25 17:19:02 +0000
committerRoy Marples <roy@marples.name>2007-09-25 17:19:02 +0000
commit1a6451654fe365c1981b18f35cb6e453166d1b32 (patch)
tree35f036a9e6eba2322267b23688495a9f2390ada8 /src/runscript.c
parentb24e87794849f38611f0b9644c1e30222d8369a6 (diff)
We no longer use bool in our public headers, using int instead.
Diffstat (limited to 'src/runscript.c')
-rw-r--r--src/runscript.c178
1 files changed, 90 insertions, 88 deletions
diff --git a/src/runscript.c b/src/runscript.c
index 4bbc0dab..9645116a 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -83,7 +83,7 @@ static void setup_selinux (int argc, char **argv)
{
void *lib_handle = NULL;
- if (! rc_exists (SELINUX_LIB))
+ if (rc_exists (SELINUX_LIB) != 0)
return;
lib_handle = dlopen (SELINUX_LIB, RTLD_NOW | RTLD_GLOBAL);
@@ -186,10 +186,10 @@ static bool in_control ()
if (sighup)
return (false);
- if (! mtime_test || ! rc_exists (mtime_test))
+ if (! mtime_test || rc_exists (mtime_test) != 0)
return (false);
- if (rc_service_state (applet, rc_service_stopped))
+ if (rc_service_state (applet, rc_service_stopped) == 0)
return (false);
if (! (mtime = get_mtime (mtime_test, false)))
@@ -197,7 +197,7 @@ static bool in_control ()
while (tests[i]) {
path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL);
- if (rc_exists (path)) {
+ if (rc_exists (path) == 0) {
time_t m = get_mtime (path, false);
if (mtime < m && m != 0) {
free (path);
@@ -214,13 +214,13 @@ static bool in_control ()
static void uncoldplug ()
{
char *cold = rc_strcatpaths (RC_SVCDIR, "coldplugged", applet, (char *) NULL);
- if (rc_exists (cold) && unlink (cold) != 0)
+ if (rc_exists (cold) == 0 && unlink (cold) != 0)
eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno));
free (cold);
}
static void start_services (char **list) {
- bool inactive;
+ int inactive;
char *svc;
int i;
@@ -228,16 +228,16 @@ static void start_services (char **list) {
return;
inactive = rc_service_state (service, rc_service_inactive);
- if (! inactive)
+ if (inactive != 0)
inactive = rc_service_state (service, rc_service_wasinactive);
- if (inactive ||
- rc_service_state (service, rc_service_starting) ||
- rc_service_state (service, rc_service_started))
+ if (inactive != 0 ||
+ rc_service_state (service, rc_service_starting) == 0 ||
+ rc_service_state (service, rc_service_started) == 0)
{
STRLIST_FOREACH (list, svc, i) {
- if (rc_service_state (svc, rc_service_stopped)) {
- if (inactive) {
+ if (rc_service_state (svc, rc_service_stopped) == 0) {
+ if (inactive != 0) {
rc_schedule_start_service (service, svc);
ewarn ("WARNING: %s is scheduled to started when %s has started",
svc, applet);
@@ -272,26 +272,26 @@ static void cleanup (void)
free (ibsave);
if (! rc_in_plugin && in_control ()) {
- if (rc_service_state (applet, rc_service_stopping)) {
+ if (rc_service_state (applet, rc_service_stopping) == 0) {
/* If the we're shutting down, do it cleanly */
if ((softlevel &&
- rc_runlevel_stopping () &&
+ rc_runlevel_stopping () == 0 &&
(strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (softlevel, RC_LEVEL_REBOOT) == 0)))
rc_mark_service (applet, rc_service_stopped);
- else if (rc_service_state (applet, rc_service_wasinactive))
+ else if (rc_service_state (applet, rc_service_wasinactive) == 0)
rc_mark_service (applet, rc_service_inactive);
else
rc_mark_service (applet, rc_service_started);
}
- else if (rc_service_state (applet, rc_service_starting))
+ else if (rc_service_state (applet, rc_service_starting) == 0)
{
- if (rc_service_state (applet, rc_service_wasinactive))
+ if (rc_service_state (applet, rc_service_wasinactive) == 0)
rc_mark_service (applet, rc_service_inactive);
else
rc_mark_service (applet, rc_service_stopped);
}
- if (exclusive && rc_exists (exclusive))
+ if (exclusive && rc_exists (exclusive) == 0)
unlink (exclusive);
}
@@ -393,7 +393,7 @@ static bool svc_exec (const char *arg1, const char *arg2)
close (slave_tty);
}
- if (rc_exists (RC_SVCDIR "/runscript.sh")) {
+ if (rc_exists (RC_SVCDIR "/runscript.sh") == 0) {
execl (RC_SVCDIR "/runscript.sh", service, service, arg1, arg2,
(char *) NULL);
eerror ("%s: exec `" RC_SVCDIR "/runscript.sh': %s",
@@ -461,23 +461,23 @@ static rc_service_state_t svc_status ()
rc_service_state_t retval = rc_service_stopped;
- if (rc_service_state (service, rc_service_stopping)) {
+ if (rc_service_state (service, rc_service_stopping) == 0) {
snprintf (status, sizeof (status), "stopping");
e = &ewarn;
retval = rc_service_stopping;
- } else if (rc_service_state (service, rc_service_starting)) {
+ } else if (rc_service_state (service, rc_service_starting) == 0) {
snprintf (status, sizeof (status), "starting");
e = &ewarn;
retval = rc_service_starting;
- } else if (rc_service_state (service, rc_service_inactive)) {
+ } else if (rc_service_state (service, rc_service_inactive) == 0) {
snprintf (status, sizeof (status), "inactive");
e = &ewarn;
retval = rc_service_inactive;
- } else if (rc_service_state (service, rc_service_crashed)) {
+ } else if (rc_service_state (service, rc_service_crashed) == 0) {
snprintf (status, sizeof (status), "crashed");
e = &eerror;
retval = rc_service_crashed;
- } else if (rc_service_state (service, rc_service_started)) {
+ } else if (rc_service_state (service, rc_service_started) == 0) {
snprintf (status, sizeof (status), "started");
retval = rc_service_started;
} else
@@ -507,7 +507,7 @@ static void make_exclusive ()
snprintf (mtime_test, i, "%s.%d", path, getpid ());
free (path);
- if (rc_exists (mtime_test) && unlink (mtime_test) != 0) {
+ if (rc_exists (mtime_test) == 0 && unlink (mtime_test) != 0) {
eerror ("%s: unlink `%s': %s",
applet, mtime_test, strerror (errno));
free (mtime_test);
@@ -562,32 +562,33 @@ static void svc_start (bool deps)
rc_plugin_run (rc_hook_service_start_in, applet);
hook_out = rc_hook_service_start_out;
- if (rc_is_env ("IN_HOTPLUG", "1") || in_background) {
- if (! rc_service_state (service, rc_service_inactive) &&
- ! rc_service_state (service, rc_service_stopped))
+ if (rc_is_env ("IN_HOTPLUG", "1") == 0 || in_background) {
+ if (rc_service_state (service, rc_service_inactive) != 0 &&
+ rc_service_state (service, rc_service_stopped) != 0)
exit (EXIT_FAILURE);
background = true;
}
- if (rc_service_state (service, rc_service_started)) {
+ if (rc_service_state (service, rc_service_started) == 0) {
ewarn ("WARNING: %s has already been started", applet);
return;
- } else if (rc_service_state (service, rc_service_starting))
+ } else if (rc_service_state (service, rc_service_starting) == 0)
ewarnx ("WARNING: %s is already starting", applet);
- else if (rc_service_state (service, rc_service_stopping))
+ else if (rc_service_state (service, rc_service_stopping) == 0)
ewarnx ("WARNING: %s is stopping", applet);
- else if (rc_service_state (service, rc_service_inactive) && ! background)
+ else if (rc_service_state (service, rc_service_inactive) == 0 &&
+ ! background)
ewarnx ("WARNING: %s has already started, but is inactive", applet);
- if (! rc_mark_service (service, rc_service_starting))
+ if (rc_mark_service (service, rc_service_starting) != 0)
eerrorx ("ERROR: %s has been started by something else", applet);
make_exclusive (service);
- if (rc_is_env ("RC_DEPEND_STRICT", "yes"))
+ if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0)
depoptions |= RC_DEP_STRICT;
- if (rc_runlevel_starting ())
+ if (rc_runlevel_starting () == 0)
depoptions |= RC_DEP_START;
if (deps) {
@@ -626,11 +627,11 @@ static void svc_start (bool deps)
use_services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions);
- if (! rc_runlevel_starting ()) {
+ if (! rc_runlevel_starting () == 0) {
STRLIST_FOREACH (use_services, svc, i)
- if (rc_service_state (svc, rc_service_stopped)) {
+ if (rc_service_state (svc, rc_service_stopped) == 0) {
pid_t pid = rc_start_service (svc);
- if (! rc_is_env ("RC_PARALLEL", "yes"))
+ if (rc_is_env ("RC_PARALLEL", "yes") != 0)
rc_waitpid (pid);
}
}
@@ -645,13 +646,14 @@ static void svc_start (bool deps)
tmplist = NULL;
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_started))
+ if (rc_service_state (svc, rc_service_started) == 0)
continue;
/* Don't wait for services which went inactive but are now in
* starting state which we are after */
- if (rc_service_state (svc, rc_service_starting) &&
- rc_service_state(svc, rc_service_wasinactive)) {
+ if (rc_service_state (svc, rc_service_starting) == 0 &&
+ rc_service_state (svc, rc_service_wasinactive) == 0)
+ {
bool use = false;
STRLIST_FOREACH (use_services, svc2, j)
if (strcmp (svc, svc2) == 0) {
@@ -662,15 +664,15 @@ static void svc_start (bool deps)
continue;
}
- if (! rc_wait_service (svc))
+ if (rc_wait_service (svc) != 0)
eerror ("%s: timed out waiting for %s", applet, svc);
- if (rc_service_state (svc, rc_service_started))
+ if (rc_service_state (svc, rc_service_started) == 0)
continue;
STRLIST_FOREACH (need_services, svc2, j)
if (strcmp (svc, svc2) == 0) {
- if (rc_service_state (svc, rc_service_inactive) ||
- rc_service_state (svc, rc_service_wasinactive))
+ if (rc_service_state (svc, rc_service_inactive) == 0 ||
+ rc_service_state (svc, rc_service_wasinactive) == 0)
rc_strlist_add (&tmplist, svc);
else
eerrorx ("ERROR: cannot start %s as %s would not start",
@@ -740,11 +742,11 @@ static void svc_start (bool deps)
if (in_control ()) {
if (! started) {
- if (rc_service_state (service, rc_service_wasinactive))
+ if (rc_service_state (service, rc_service_wasinactive) == 0)
rc_mark_service (service, rc_service_inactive);
else {
rc_mark_service (service, rc_service_stopped);
- if (rc_runlevel_starting ())
+ if (rc_runlevel_starting () == 0)
rc_mark_service (service, rc_service_failed);
}
rc_plugin_run (rc_hook_service_start_done, applet);
@@ -755,7 +757,7 @@ static void svc_start (bool deps)
rc_plugin_run (rc_hook_service_start_done, applet);
} else {
rc_plugin_run (rc_hook_service_start_done, applet);
- if (rc_service_state (service, rc_service_inactive))
+ if (rc_service_state (service, rc_service_inactive) == 0)
ewarnx ("WARNING: %s has started, but is inactive", applet);
else
ewarnx ("WARNING: %s not under our control, aborting", applet);
@@ -765,7 +767,7 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = rc_services_scheduled (service);
STRLIST_FOREACH (services, svc, i)
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, rc_service_stopped) == 0)
rc_start_service (svc);
rc_strlist_free (services);
services = NULL;
@@ -784,7 +786,7 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = rc_services_scheduled (svc2);
STRLIST_FOREACH (services, svc, i)
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, rc_service_stopped) == 0)
rc_start_service (svc);
}
@@ -798,39 +800,39 @@ static void svc_stop (bool deps)
hook_out = rc_hook_service_stop_out;
- if (rc_runlevel_stopping () &&
- rc_service_state (service, rc_service_failed))
+ if (rc_runlevel_stopping () == 0 &&
+ rc_service_state (service, rc_service_failed) == 0)
exit (EXIT_FAILURE);
- if (rc_is_env ("IN_HOTPLUG", "1") || in_background)
- if (! rc_service_state (service, rc_service_started) &&
- ! rc_service_state (service, rc_service_inactive))
+ if (rc_is_env ("IN_HOTPLUG", "1") == 0 || in_background)
+ if (rc_service_state (service, rc_service_started) != 0 &&
+ rc_service_state (service, rc_service_inactive) != 0)
exit (EXIT_FAILURE);
- if (rc_service_state (service, rc_service_stopped)) {
+ if (rc_service_state (service, rc_service_stopped) == 0) {
ewarn ("WARNING: %s is already stopped", applet);
return;
- } else if (rc_service_state (service, rc_service_stopping))
+ } else if (rc_service_state (service, rc_service_stopping) == 0)
ewarnx ("WARNING: %s is already stopping", applet);
- if (! rc_mark_service (service, rc_service_stopping))
+ if (rc_mark_service (service, rc_service_stopping) != 0)
eerrorx ("ERROR: %s has been stopped by something else", applet);
make_exclusive (service);
- if (! rc_runlevel_stopping () &&
- rc_service_in_runlevel (service, RC_LEVEL_BOOT))
+ if (rc_runlevel_stopping () != 0 &&
+ rc_service_in_runlevel (service, RC_LEVEL_BOOT) == 0)
ewarn ("WARNING: you are stopping a boot service");
- if (deps && ! rc_service_state (service, rc_service_wasinactive)) {
+ if (deps && rc_service_state (service, rc_service_wasinactive) != 0) {
int depoptions = RC_DEP_TRACE;
char *svc;
int i;
- if (rc_is_env ("RC_DEPEND_STRICT", "yes"))
+ if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0)
depoptions |= RC_DEP_STRICT;
- if (rc_runlevel_stopping ())
+ if (rc_runlevel_stopping () == 0)
depoptions |= RC_DEP_STOP;
if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
@@ -849,15 +851,15 @@ static void svc_stop (bool deps)
softlevel, depoptions);
rc_strlist_reverse (services);
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_started) ||
- rc_service_state (svc, rc_service_inactive))
+ if (rc_service_state (svc, rc_service_started) == 0 ||
+ rc_service_state (svc, rc_service_inactive) == 0)
{
rc_wait_service (svc);
- if (rc_service_state (svc, rc_service_started) ||
- rc_service_state (svc, rc_service_inactive))
+ if (rc_service_state (svc, rc_service_started) == 0 ||
+ rc_service_state (svc, rc_service_inactive) == 0)
{
pid_t pid = rc_stop_service (svc);
- if (! rc_is_env ("RC_PARALLEL", "yes"))
+ if (rc_is_env ("RC_PARALLEL", "yes") == 0)
rc_waitpid (pid);
rc_strlist_add (&tmplist, svc);
}
@@ -867,14 +869,14 @@ static void svc_stop (bool deps)
services = NULL;
STRLIST_FOREACH (tmplist, svc, i) {
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, rc_service_stopped) == 0)
continue;
/* We used to loop 3 times here - maybe re-do this if needed */
rc_wait_service (svc);
- if (! rc_service_state (svc, rc_service_stopped)) {
+ if (! rc_service_state (svc, rc_service_stopped) == 0) {
- if (rc_runlevel_stopping ()) {
+ if (rc_runlevel_stopping () == 0) {
/* If shutting down, we should stop even if a dependant failed */
if (softlevel &&
(strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 ||
@@ -898,7 +900,7 @@ static void svc_stop (bool deps)
services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, rc_service_stopped) == 0)
continue;
rc_wait_service (svc);
}
@@ -922,7 +924,7 @@ static void svc_stop (bool deps)
}
if (! stopped) {
- if (rc_service_state (service, rc_service_wasinactive))
+ if (rc_service_state (service, rc_service_wasinactive) == 0)
rc_mark_service (service, rc_service_inactive);
else
rc_mark_service (service, rc_service_started);
@@ -952,15 +954,15 @@ static void svc_restart (bool deps)
our status is invalid.
One workaround would be to introduce a new status, or status locking. */
if (! deps) {
- if (rc_service_state (service, rc_service_started) ||
- rc_service_state (service, rc_service_inactive))
+ if (rc_service_state (service, rc_service_started) == 0 ||
+ rc_service_state (service, rc_service_inactive) == 0)
svc_exec ("stop", "start");
else
svc_exec ("start", NULL);
return;
}
- if (! rc_service_state (service, rc_service_stopped)) {
+ if (! rc_service_state (service, rc_service_stopped) == 0) {
get_started_services ();
svc_stop (deps);
}
@@ -1028,7 +1030,7 @@ int runscript (int argc, char **argv)
#ifdef __linux__
/* coldplug events can trigger init scripts, but we don't want to run them
until after rc sysinit has completed so we punt them to the boot runlevel */
- if (rc_exists ("/dev/.rcsysinit")) {
+ if (rc_exists ("/dev/.rcsysinit") == 0) {
eerror ("%s: cannot run until sysvinit completes", applet);
if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST)
eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno));
@@ -1088,7 +1090,7 @@ int runscript (int argc, char **argv)
setenv ("RC_RUNSCRIPT_PID", pid, 1);
/* eprefix is kinda klunky, but it works for our purposes */
- if (rc_is_env ("RC_PARALLEL", "yes")) {
+ if (rc_is_env ("RC_PARALLEL", "yes") == 0) {
int l = 0;
int ll;
@@ -1130,7 +1132,7 @@ int runscript (int argc, char **argv)
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno));
case 's':
- if (! rc_service_state (service, rc_service_started))
+ if (rc_service_state (service, rc_service_started) != 0)
exit (EXIT_FAILURE);
break;
case 'C':
@@ -1152,13 +1154,13 @@ int runscript (int argc, char **argv)
/* Save the IN_BACKGROUND env flag so it's ONLY passed to the service
that is being called and not any dependents */
if (getenv ("IN_BACKGROUND")) {
- in_background = rc_is_env ("IN_BACKGROUND", "true");
+ in_background = (rc_is_env ("IN_BACKGROUND", "true") == 0);
ibsave = rc_xstrdup (getenv ("IN_BACKGROUND"));
unsetenv ("IN_BACKGROUND");
}
- if (rc_is_env ("IN_HOTPLUG", "1")) {
- if (! rc_is_env ("RC_HOTPLUG", "yes") || ! rc_allow_plug (applet))
+ if (rc_is_env ("IN_HOTPLUG", "1") == 0) {
+ if (rc_is_env ("RC_HOTPLUG", "yes") != 0 || rc_allow_plug (applet) != 0)
eerrorx ("%s: not allowed to be hotplugged", applet);
}
@@ -1210,7 +1212,7 @@ int runscript (int argc, char **argv)
strcmp (optarg, "iprovide") == 0) {
int depoptions = RC_DEP_TRACE;
- if (rc_is_env ("RC_DEPEND_STRICT", "yes"))
+ if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0)
depoptions |= RC_DEP_STRICT;
if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
@@ -1244,7 +1246,7 @@ int runscript (int argc, char **argv)
if (strcmp (optarg, "conditionalrestart") == 0 ||
strcmp (optarg, "condrestart") == 0)
{
- if (rc_service_state (service, rc_service_started))
+ if (rc_service_state (service, rc_service_started) == 0)
svc_restart (deps);
} else if (strcmp (optarg, "restart") == 0) {
svc_restart (deps);
@@ -1258,16 +1260,16 @@ int runscript (int argc, char **argv)
if (deps) {
if (! in_background &&
- ! rc_runlevel_stopping () &&
- rc_service_state (service, rc_service_stopped))
+ rc_runlevel_stopping () != 0 &&
+ rc_service_state (service, rc_service_stopped) == 0)
uncoldplug ();
if (in_background &&
- rc_service_state (service, rc_service_inactive))
+ rc_service_state (service, rc_service_inactive) == 0)
{
int j;
STRLIST_FOREACH (restart_services, svc, j)
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, rc_service_stopped) == 0)
rc_schedule_start_service (service, svc);
}
}