From 1a6451654fe365c1981b18f35cb6e453166d1b32 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 25 Sep 2007 17:19:02 +0000 Subject: We no longer use bool in our public headers, using int instead. --- ChangeLog | 5 ++ src/env-update.c | 4 +- src/librc-daemon.c | 68 +++++++++--------- src/librc-depend.c | 36 +++++----- src/librc-misc.c | 96 +++++++++++--------------- src/librc.c | 151 ++++++++++++++++++++-------------------- src/mountinfo.c | 2 +- src/rc-plugin.c | 2 +- src/rc-status.c | 15 ++-- src/rc-update.c | 20 +++--- src/rc.c | 65 +++++++++--------- src/rc.h | 97 +++++++++++++------------- src/runscript.c | 178 ++++++++++++++++++++++++------------------------ src/start-stop-daemon.c | 4 +- 14 files changed, 365 insertions(+), 378 deletions(-) diff --git a/ChangeLog b/ChangeLog index e72fd33f..1ef80760 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 + 25 Sep 2007; Roy Marples : + + We no longer use bool in our public headers, using int instead. + This makes us more like our base libraries. + 25 Sep 2007; Mike Frysinger : Skip consolefont setup when RC_TTY_NUMBER is set to 0. diff --git a/src/env-update.c b/src/env-update.c index c9739a78..254a0348 100644 --- a/src/env-update.c +++ b/src/env-update.c @@ -134,7 +134,7 @@ int env_update (int argc, char **argv) char **entries = NULL; j = strlen (file); - if (! rc_is_dir (path) && + if (rc_is_dir (path) != 0 && j > 2 && *file >= '0' && *file <= '9' && @@ -297,7 +297,7 @@ int env_update (int argc, char **argv) if (ldconfig) { /* Update ld.so.conf only if different */ - if (rc_exists (LDSOCONF)) { + if (rc_exists (LDSOCONF) == 0) { char **lines = rc_get_list (LDSOCONF); char *line; ld = false; diff --git a/src/librc-daemon.c b/src/librc-daemon.c index 5b1e0239..42192f45 100644 --- a/src/librc-daemon.c +++ b/src/librc-daemon.c @@ -147,7 +147,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, librc_hidden_def(rc_find_pids) #elif defined(__DragonFly__) || defined(__FreeBSD__) || \ - defined(__NetBSD__) || defined(__OpenBSD__) + defined(__NetBSD__) || defined(__OpenBSD__) # if defined(__DragonFly__) || defined(__FreeBSD__) # ifndef KERN_PROC_PROC @@ -228,9 +228,9 @@ librc_hidden_def(rc_find_pids) # error "Platform not supported!" #endif -static bool _match_daemon (const char *path, const char *file, - const char *mexec, const char *mname, - const char *mpidfile) +static int _match_daemon (const char *path, const char *file, + const char *mexec, const char *mname, + const char *mpidfile) { char buffer[RC_LINEBUFFER]; char *ffile = rc_strcatpaths (path, file, (char *) NULL); @@ -238,15 +238,15 @@ static bool _match_daemon (const char *path, const char *file, int lc = 0; int m = 0; - if (! rc_exists (ffile)) { + if (rc_exists (ffile) != 0) { free (ffile); - return (false); + return (-1); } if ((fp = fopen (ffile, "r")) == NULL) { eerror ("fopen `%s': %s", ffile, strerror (errno)); free (ffile); - return (false); + return (-1); } if (! mname) @@ -277,12 +277,12 @@ static bool _match_daemon (const char *path, const char *file, fclose (fp); free (ffile); - return (m == 111 ? true : false); + return (m == 111 ? 0 : -1); } -void rc_set_service_daemon (const char *service, const char *exec, - const char *name, const char *pidfile, - bool started) +int rc_set_service_daemon (const char *service, const char *exec, + const char *name, const char *pidfile, + bool started) { char *svc = rc_xstrdup (service); char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), @@ -295,10 +295,11 @@ void rc_set_service_daemon (const char *service, const char *exec, char *mname; char *mpidfile; int nfiles = 0; + int retval = -1; free (svc); if (! exec && ! name && ! pidfile) - return; + return (-1); if (exec) { i = strlen (exec) + 6; @@ -322,7 +323,7 @@ void rc_set_service_daemon (const char *service, const char *exec, mpidfile = rc_xstrdup ("pidfile="); /* Regardless, erase any existing daemon info */ - if (rc_is_dir (dirpath)) { + if (rc_is_dir (dirpath) == 0) { char *oldfile = NULL; files = rc_ls_dir (dirpath, 0); STRLIST_FOREACH (files, file, i) { @@ -330,7 +331,7 @@ void rc_set_service_daemon (const char *service, const char *exec, nfiles++; if (! oldfile) { - if (_match_daemon (dirpath, file, mexec, mname, mpidfile)) { + if (_match_daemon (dirpath, file, mexec, mname, mpidfile) == 0) { unlink (ffile); oldfile = ffile; nfiles--; @@ -350,7 +351,7 @@ void rc_set_service_daemon (const char *service, const char *exec, char buffer[10]; FILE *fp; - if (! rc_is_dir (dirpath)) + if (rc_is_dir (dirpath) != 0) if (mkdir (dirpath, 0755) != 0) eerror ("mkdir `%s': %s", dirpath, strerror (errno)); @@ -360,6 +361,7 @@ void rc_set_service_daemon (const char *service, const char *exec, eerror ("fopen `%s': %s", file, strerror (errno)); else { fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); + retval = 0; fclose (fp); } free (file); @@ -369,30 +371,32 @@ void rc_set_service_daemon (const char *service, const char *exec, free (mname); free (mpidfile); free (dirpath); + + return (retval); } librc_hidden_def(rc_set_service_daemon) -bool rc_service_started_daemon (const char *service, const char *exec, - int indx) +int rc_service_started_daemon (const char *service, const char *exec, + int indx) { char *dirpath; char *file; int i; char *mexec; - bool retval = false; + int retval = -1; char *svc; if (! service || ! exec) - return (false); + return (-1); svc = rc_xstrdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); - if (! rc_is_dir (dirpath)) { + if (rc_is_dir (dirpath) != 0) { free (dirpath); - return (false); + return (-1); } i = strlen (exec) + 6; @@ -409,7 +413,7 @@ bool rc_service_started_daemon (const char *service, const char *exec, char **files = rc_ls_dir (dirpath, 0); STRLIST_FOREACH (files, file, i) { retval = _match_daemon (dirpath, file, mexec, NULL, NULL); - if (retval) + if (retval == 0) break; } rc_strlist_free (files); @@ -420,7 +424,7 @@ bool rc_service_started_daemon (const char *service, const char *exec, } librc_hidden_def(rc_service_started_daemon) -bool rc_service_daemons_crashed (const char *service) +int rc_service_daemons_crashed (const char *service) { char *dirpath; char **files; @@ -436,20 +440,20 @@ bool rc_service_daemons_crashed (const char *service) pid_t *pids = NULL; char *p; char *token; - bool retval = false; + int retval = -1; char *svc; if (! service) - return (false); + return (-1); svc = rc_xstrdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); - if (! rc_is_dir (dirpath)) { + if (rc_is_dir (dirpath) != 0) { free (dirpath); - return (false); + return (-1); } memset (buffer, 0, sizeof (buffer)); @@ -493,21 +497,21 @@ bool rc_service_daemons_crashed (const char *service) pid = 0; if (pidfile) { - if (! rc_exists (pidfile)) { - retval = true; + if (rc_exists (pidfile) != 0) { + retval = 0; break; } if ((fp = fopen (pidfile, "r")) == NULL) { eerror ("fopen `%s': %s", pidfile, strerror (errno)); - retval = true; + retval = 0; break; } if (fscanf (fp, "%d", &pid) != 1) { eerror ("no pid found in `%s'", pidfile); fclose (fp); - retval = true; + retval = 0; break; } @@ -523,7 +527,7 @@ bool rc_service_daemons_crashed (const char *service) } if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) { - retval = true; + retval = 0; break; } free (pids); diff --git a/src/librc-depend.c b/src/librc-depend.c index 4df64635..cc6fcbdd 100644 --- a/src/librc-depend.c +++ b/src/librc-depend.c @@ -185,10 +185,10 @@ librc_hidden_def(rc_get_deptype) static bool valid_service (const char *runlevel, const char *service) { return ((strcmp (runlevel, bootlevel) != 0 && - rc_service_in_runlevel (service, bootlevel)) || - rc_service_in_runlevel (service, runlevel) || - rc_service_state (service, rc_service_coldplugged) || - rc_service_state (service, rc_service_started)); + rc_service_in_runlevel (service, bootlevel) == 0) || + rc_service_in_runlevel (service, runlevel) == 0 || + rc_service_state (service, rc_service_coldplugged) == 0 || + rc_service_state (service, rc_service_started) == 0); } static bool get_provided1 (const char *runlevel, struct lhead *providers, @@ -204,25 +204,25 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers, { bool ok = true; if (level) - ok = rc_service_in_runlevel (service, level); + ok = (rc_service_in_runlevel (service, level) == 0); else if (coldplugged) - ok = (rc_service_state (service, rc_service_coldplugged) && - ! rc_service_in_runlevel (service, runlevel) && - ! rc_service_in_runlevel (service, bootlevel)); + ok = (rc_service_state (service, rc_service_coldplugged) == 0 && + rc_service_in_runlevel (service, runlevel) != 0 && + rc_service_in_runlevel (service, bootlevel) != 0); if (! ok) continue; switch (state) { case rc_service_started: - ok = rc_service_state (service, state); + ok = (rc_service_state (service, state) == 0); break; case rc_service_inactive: case rc_service_starting: case rc_service_stopping: - ok = (rc_service_state (service, rc_service_starting) || - rc_service_state (service, rc_service_stopping) || - rc_service_state (service, rc_service_inactive)); + ok = (rc_service_state (service, rc_service_starting) == 0 || + rc_service_state (service, rc_service_stopping) == 0 || + rc_service_state (service, rc_service_inactive) == 0); break; default: break; @@ -257,7 +257,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo, if (! deptree || ! depinfo) return (NULL); - if (rc_service_exists (depinfo->service)) + if (rc_service_exists (depinfo->service) == -1) return (NULL); dt = rc_get_deptype (depinfo, "providedby"); @@ -281,8 +281,8 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo, if (options & RC_DEP_STRICT) { STRLIST_FOREACH (dt->services, service, i) - if (rc_service_in_runlevel (service, runlevel) || - rc_service_in_runlevel (service, bootlevel)) + if (rc_service_in_runlevel (service, runlevel) == 0 || + rc_service_in_runlevel (service, bootlevel) == 0) rc_strlist_add (&providers.list, service); if (providers.list) @@ -556,7 +556,7 @@ static bool is_newer_than (const char *file, const char *target) if (mtime < buf.st_mtime) return (false); - if (rc_is_dir (target)) + if (rc_is_dir (target) == 0) { char **targets = rc_ls_dir (target, 0); char *t; @@ -641,7 +641,7 @@ int rc_update_deptree (bool force) /* Create base directories if needed */ for (i = 0; depdirs[i]; i++) - if (! rc_is_dir (depdirs[i])) + if (rc_is_dir (depdirs[i]) != 0) if (mkdir (depdirs[i], 0755) != 0) eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno)); @@ -655,7 +655,7 @@ int rc_update_deptree (bool force) /* Some init scripts dependencies change depending on config files * outside of baselayout, like syslog-ng, so we check those too. */ - if (! rc_exists (RC_DEPCONFIG)) + if (rc_exists (RC_DEPCONFIG) != 0) return 0; config = rc_get_list (RC_DEPCONFIG); diff --git a/src/librc-misc.c b/src/librc-misc.c index bd92e584..b0d654ca 100644 --- a/src/librc-misc.c +++ b/src/librc-misc.c @@ -57,18 +57,18 @@ char *rc_xstrdup (const char *str) } librc_hidden_def(rc_xstrdup) -bool rc_is_env (const char *var, const char *val) +int rc_is_env (const char *var, const char *val) { char *v; if (! var) - return (false); + return (-1); v = getenv (var); if (! v) - return (val == NULL ? true : false); + return (val == NULL ? 0 : -1); - return (strcasecmp (v, val) == 0 ? true : false); + return (strcasecmp (v, val)); } librc_hidden_def(rc_is_env) @@ -123,78 +123,58 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) } librc_hidden_def(rc_strcatpaths) -bool rc_exists (const char *pathname) +int rc_exists (const char *pathname) { struct stat buf; if (! pathname) - return (false); - - if (stat (pathname, &buf) == 0) - return (true); + return (-1); - errno = 0; - return (false); + return (stat (pathname, &buf)); } librc_hidden_def(rc_exists) -bool rc_is_file (const char *pathname) +int rc_is_file (const char *pathname) { struct stat buf; - if (! pathname) - return (false); + if (pathname && stat (pathname, &buf) == 0) + return (S_ISREG (buf.st_mode) ? 0 : -1); - if (stat (pathname, &buf) == 0) - return (S_ISREG (buf.st_mode)); - - errno = 0; - return (false); + return (-1); } librc_hidden_def(rc_is_file) -bool rc_is_dir (const char *pathname) +int rc_is_dir (const char *pathname) { struct stat buf; - if (! pathname) - return (false); - - if (stat (pathname, &buf) == 0) - return (S_ISDIR (buf.st_mode)); + if (pathname && stat (pathname, &buf) == 0) + return (S_ISDIR (buf.st_mode) ? 0 : -1); - errno = 0; - return (false); + return (-1); } librc_hidden_def(rc_is_dir) -bool rc_is_link (const char *pathname) +int rc_is_link (const char *pathname) { struct stat buf; - if (! pathname) - return (false); - - if (lstat (pathname, &buf) == 0) - return (S_ISLNK (buf.st_mode)); + if (pathname && lstat (pathname, &buf) == 0) + return (S_ISLNK (buf.st_mode) ? 0 : -1); - errno = 0; - return (false); + return (-1); } librc_hidden_def(rc_is_link) -bool rc_is_exec (const char *pathname) +int rc_is_exec (const char *pathname) { struct stat buf; - if (! pathname) - return (false); - - if (lstat (pathname, &buf) == 0) - return (buf.st_mode & S_IXUGO); + if (pathname && lstat (pathname, &buf) == 0) + return (buf.st_mode & S_IXUGO ? 0 : -1); - errno = 0; - return (false); + return (-1); } librc_hidden_def(rc_is_exec) @@ -219,9 +199,9 @@ char **rc_ls_dir (const char *dir, int options) int l = strlen (d->d_name); char *init = rc_strcatpaths (RC_INITDIR, d->d_name, (char *) NULL); - bool ok = rc_exists (init); + int ok = rc_exists (init); free (init); - if (! ok) + if (ok != 0) continue; /* .sh files are not init scripts */ @@ -245,17 +225,17 @@ char **rc_ls_dir (const char *dir, int options) } librc_hidden_def(rc_ls_dir) -bool rc_rm_dir (const char *pathname, bool top) +int rc_rm_dir (const char *pathname, bool top) { DIR *dp; struct dirent *d; if (! pathname) - return (false); + return (-1); if ((dp = opendir (pathname)) == NULL) { eerror ("failed to opendir `%s': %s", pathname, strerror (errno)); - return (false); + return (-1); } errno = 0; @@ -263,18 +243,18 @@ bool rc_rm_dir (const char *pathname, bool top) if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) { char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL); if (d->d_type == DT_DIR) { - if (! rc_rm_dir (tmp, true)) + if (rc_rm_dir (tmp, true) != 0) { free (tmp); closedir (dp); - return (false); + return (-1); } } else { if (unlink (tmp)) { eerror ("failed to unlink `%s': %s", tmp, strerror (errno)); free (tmp); closedir (dp); - return (false); + return (-1); } } free (tmp); @@ -286,10 +266,10 @@ bool rc_rm_dir (const char *pathname, bool top) if (top && rmdir (pathname) != 0) { eerror ("failed to rmdir `%s': %s", pathname, strerror (errno)); - return false; + return (-1); } - return (true); + return (0); } librc_hidden_def(rc_rm_dir) @@ -462,7 +442,7 @@ char **rc_filter_env (void) if (! whitelist) return (NULL); - if (rc_is_file (PROFILE_ENV)) + if (rc_is_file (PROFILE_ENV) == 0) profile = rc_get_config (PROFILE_ENV); STRLIST_FOREACH (whitelist, env_name, count) { @@ -544,7 +524,7 @@ static bool file_regex (const char *file, const char *regex) bool retval = false; int result; - if (! rc_exists (file)) + if (rc_exists (file) != 0) return (false); if (! (fp = fopen (file, "r"))) { @@ -592,7 +572,7 @@ char **rc_make_env (void) /* Don't trust environ for softlevel yet */ snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); - if (rc_exists (buffer)) + if (rc_exists (buffer) == 0) config = rc_get_config (buffer); else config = rc_get_config (RC_CONFIG); @@ -639,7 +619,7 @@ char **rc_make_env (void) rc_strlist_add (&env, line); free (line); - if (rc_exists (RC_KSOFTLEVEL)) { + if (rc_exists (RC_KSOFTLEVEL) == 0) { if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno)); else { @@ -665,7 +645,7 @@ char **rc_make_env (void) We store this special system in RC_SYS so our scripts run fast */ memset (sys, 0, sizeof (sys)); - if (rc_is_dir ("/proc/xen")) { + if (rc_is_dir ("/proc/xen") == 0) { fp = fopen ("/proc/xen/capabilities", "r"); if (fp) { fclose (fp); diff --git a/src/librc.c b/src/librc.c index dd2e0b6b..632f35fc 100644 --- a/src/librc.c +++ b/src/librc.c @@ -31,13 +31,13 @@ static const char *rc_service_state_names[] = { NULL }; -bool rc_runlevel_starting (void) +int rc_runlevel_starting (void) { return (rc_is_dir (RC_STARTING)); } librc_hidden_def(rc_runlevel_starting) -bool rc_runlevel_stopping (void) +int rc_runlevel_stopping (void) { return (rc_is_dir (RC_STOPPING)); } @@ -52,7 +52,7 @@ char **rc_get_runlevels (void) STRLIST_FOREACH (dirs, dir, i) { char *path = rc_strcatpaths (RC_RUNLEVELDIR, dir, (char *) NULL); - if (rc_is_dir (path)) + if (rc_is_dir (path) == 0) rc_strlist_addsort (&runlevels, dir); free (path); } @@ -95,13 +95,13 @@ void rc_set_runlevel (const char *runlevel) } librc_hidden_def(rc_set_runlevel) -bool rc_runlevel_exists (const char *runlevel) +int rc_runlevel_exists (const char *runlevel) { char *path; - bool retval; + int retval; if (! runlevel) - return (false); + return (-1); path = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); retval = rc_is_dir (path); @@ -124,10 +124,10 @@ char *rc_resolve_service (const char *service) return (rc_xstrdup (service)); file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL); - if (! rc_is_link (file)) { + if (rc_is_link (file) != 0) { free (file); file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL); - if (! rc_is_link (file)) { + if (rc_is_link (file) != 0) { free (file); file = NULL; } @@ -146,14 +146,14 @@ char *rc_resolve_service (const char *service) } librc_hidden_def(rc_resolve_service) -bool rc_service_exists (const char *service) +int rc_service_exists (const char *service) { char *file; - bool retval = false; + int retval = -1; int len; if (! service) - return (false); + return (-1); len = strlen (service); @@ -161,11 +161,10 @@ bool rc_service_exists (const char *service) if (len > 2 && service[len - 3] == '.' && service[len - 2] == 's' && service[len - 1] == 'h') - return (false); + return (-1); file = rc_resolve_service (service); - if (rc_exists (file)) - retval = rc_is_exec (file); + retval = rc_is_exec (file); free (file); return (retval); } @@ -247,14 +246,14 @@ char *rc_service_description (const char *service, const char *option) } librc_hidden_def(rc_service_description) -bool rc_service_in_runlevel (const char *service, const char *runlevel) +int rc_service_in_runlevel (const char *service, const char *runlevel) { char *file; - bool retval; + int retval; char *svc; if (! runlevel || ! service) - return (false); + return (-1); svc = rc_xstrdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), @@ -267,7 +266,7 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel) } librc_hidden_def(rc_service_in_runlevel) -bool rc_mark_service (const char *service, const rc_service_state_t state) +int rc_mark_service (const char *service, const rc_service_state_t state) { char *file; int i = 0; @@ -278,21 +277,21 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) bool skip_wasinactive = false; if (! service) - return (false); + return (-1); svc = rc_xstrdup (service); base = basename (svc); if (state != rc_service_stopped) { - if (! rc_is_file(init)) { + if (rc_is_file(init) != 0) { free (init); free (svc); - return (false); + return (-1); } file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base, (char *) NULL); - if (rc_exists (file)) + if (rc_exists (file) == 0) unlink (file); i = symlink (init, file); if (i != 0) { @@ -300,7 +299,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) free (file); free (init); free (svc); - return (false); + return (-1); } free (file); @@ -310,7 +309,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) if (state == rc_service_coldplugged) { free (init); free (svc); - return (true); + return (0); } /* Remove any old states now */ @@ -325,7 +324,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) { file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base, (char *) NULL); - if (rc_exists (file)) { + if (rc_exists (file) == 0) { if ((state == rc_service_starting || state == rc_service_stopping) && i == rc_service_inactive) @@ -358,7 +357,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) state == rc_service_inactive) { file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL); - if (rc_exists (file)) + if (rc_exists (file) == 0) if (unlink (file) != 0) eerror ("unlink `%s': %s", file, strerror (errno)); free (file); @@ -368,12 +367,12 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) if (state == rc_service_stopped) { char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL); - if (rc_is_dir (dir)) + if (rc_is_dir (dir) == 0) rc_rm_dir (dir, true); free (dir); dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL); - if (rc_is_dir (dir)) + if (rc_is_dir (dir) == 0) rc_rm_dir (dir, true); free (dir); @@ -390,7 +389,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) STRLIST_FOREACH (dirs, dir, i) { char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL); file = rc_strcatpaths (bdir, base, (char *) NULL); - if (rc_exists (file)) + if (rc_exists (file) == 0) if (unlink (file) != 0) eerror ("unlink `%s': %s", file, strerror (errno)); free (file); @@ -407,11 +406,11 @@ bool rc_mark_service (const char *service, const rc_service_state_t state) free (svc); free (init); - return (true); + return (0); } librc_hidden_def(rc_mark_service) -bool rc_service_state (const char *service, const rc_service_state_t state) +int rc_service_state (const char *service, const rc_service_state_t state) { char *file; bool retval; @@ -419,24 +418,22 @@ bool rc_service_state (const char *service, const rc_service_state_t state) /* If the init script does not exist then we are stopped */ if (! rc_service_exists (service)) - return (state == rc_service_stopped ? true : false); + return (state == rc_service_stopped ? 0 : -1); /* We check stopped state by not being in any of the others */ if (state == rc_service_stopped) - return ( ! (rc_service_state (service, rc_service_started) || - rc_service_state (service, rc_service_starting) || - rc_service_state (service, rc_service_stopping) || - rc_service_state (service, rc_service_inactive))); + return (rc_service_state (service, rc_service_started) | + rc_service_state (service, rc_service_starting) | + rc_service_state (service, rc_service_stopping) | + rc_service_state (service, rc_service_inactive)); /* The crashed state and scheduled states are virtual */ if (state == rc_service_crashed) return (rc_service_daemons_crashed (service)); else if (state == rc_service_scheduled) { char **services = rc_services_scheduled_by (service); - retval = (services); - if (services) - free (services); - return (retval); + rc_strlist_free (services); + return (services ? 0 : -1); } /* Now we just check if a file by the service name rc_exists @@ -459,7 +456,7 @@ char *rc_get_service_option (const char *service, const char *option) (char *) NULL); char *value = NULL; - if (rc_exists (file)) { + if (rc_exists (file) == 0) { if ((fp = fopen (file, "r")) == NULL) eerror ("fopen `%s': %s", file, strerror (errno)); else { @@ -475,20 +472,20 @@ char *rc_get_service_option (const char *service, const char *option) } librc_hidden_def(rc_get_service_option) -bool rc_set_service_option (const char *service, const char *option, +int rc_set_service_option (const char *service, const char *option, const char *value) { FILE *fp; char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL); char *file = rc_strcatpaths (path, option, (char *) NULL); - bool retval = false; + int retval = -1; - if (! rc_is_dir (path)) { + if (rc_is_dir (path) != 0) { if (mkdir (path, 0755) != 0) { eerror ("mkdir `%s': %s", path, strerror (errno)); free (path); free (file); - return (false); + return (-1); } } @@ -498,7 +495,7 @@ bool rc_set_service_option (const char *service, const char *option, if (value) fprintf (fp, "%s", value); fclose (fp); - retval = true; + retval = 0; } free (path); @@ -515,7 +512,7 @@ static pid_t _exec_service (const char *service, const char *arg) char *svc; file = rc_resolve_service (service); - if (! rc_is_file (file)) { + if (rc_is_file (file) != 0) { rc_mark_service (service, rc_service_stopped); free (file); return (0); @@ -566,7 +563,7 @@ int rc_waitpid (pid_t pid) { pid_t rc_stop_service (const char *service) { - if (rc_service_state (service, rc_service_stopped)) + if (rc_service_state (service, rc_service_stopped) == 0) return (0); return (_exec_service (service, "stop")); @@ -575,7 +572,7 @@ librc_hidden_def(rc_stop_service) pid_t rc_start_service (const char *service) { - if (! rc_service_state (service, rc_service_stopped)) + if (! rc_service_state (service, rc_service_stopped) == 0) return (0); return (_exec_service (service, "start")); @@ -598,7 +595,7 @@ void rc_schedule_start_service (const char *service, dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc), (char *) NULL); free (svc); - if (! rc_is_dir (dir)) + if (rc_is_dir (dir) != 0) if (mkdir (dir, 0755) != 0) { eerror ("mkdir `%s': %s", dir, strerror (errno)); free (dir); @@ -609,7 +606,7 @@ void rc_schedule_start_service (const char *service, svc = rc_xstrdup (service_to_start); file = rc_strcatpaths (dir, basename (svc), (char *) NULL); free (svc); - if (! rc_exists (file) && symlink (init, file) != 0) + if (rc_exists (file) != 0 && symlink (init, file) != 0) eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno)); free (init); @@ -625,24 +622,24 @@ void rc_schedule_clear (const char *service) (char *) NULL); free (svc); - if (rc_is_dir (dir)) + if (rc_is_dir (dir) == 0) rc_rm_dir (dir, true); free (dir); } librc_hidden_def(rc_schedule_clear) -bool rc_wait_service (const char *service) +int rc_wait_service (const char *service) { char *svc; char *base; char *fifo; struct timespec ts; int nloops = WAIT_MAX / WAIT_INTERVAL; - bool retval = false; + int retval = -1; bool forever = false; if (! service) - return (false); + return (-1); svc = rc_xstrdup (service); base = basename (svc); @@ -657,8 +654,8 @@ bool rc_wait_service (const char *service) ts.tv_nsec = WAIT_INTERVAL; while (nloops) { - if (! rc_exists (fifo)) { - retval = true; + if (rc_exists (fifo) != 0) { + retval = 0; break; } @@ -692,7 +689,7 @@ char **rc_services_in_runlevel (const char *runlevel) return (NULL); dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); - if (! rc_is_dir (dir)) + if (rc_is_dir (dir) != 0) eerror ("runlevel `%s' does not exist", runlevel); else list = rc_ls_dir (dir, RC_LS_INITD); @@ -729,7 +726,7 @@ char **rc_services_in_state (rc_service_state_t state) if (dirs) free (dirs); } else { - if (rc_is_dir (dir)) + if (rc_is_dir (dir) == 0) list = rc_ls_dir (dir, RC_LS_INITD); } @@ -738,21 +735,21 @@ char **rc_services_in_state (rc_service_state_t state) } librc_hidden_def(rc_services_in_state) -bool rc_service_add (const char *runlevel, const char *service) +int rc_service_add (const char *runlevel, const char *service) { - bool retval; + int retval; char *init; char *file; char *svc; if (! rc_runlevel_exists (runlevel)) { errno = ENOENT; - return (false); + return (-1); } - if (rc_service_in_runlevel (service, runlevel)) { + if (rc_service_in_runlevel (service, runlevel) == 0) { errno = EEXIST; - return (false); + return (-1); } init = rc_resolve_service (service); @@ -760,29 +757,27 @@ bool rc_service_add (const char *runlevel, const char *service) file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); - retval = (symlink (init, file) == 0); + retval = symlink (init, file); free (init); free (file); return (retval); } librc_hidden_def(rc_service_add) -bool rc_service_delete (const char *runlevel, const char *service) +int rc_service_delete (const char *runlevel, const char *service) { char *file; char *svc; - bool retval = false; + int retval; if (! runlevel || ! service) - return (false); + return (-1); svc = rc_xstrdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); - if (unlink (file) == 0) - retval = true; - + retval = unlink (file); free (file); return (retval); } @@ -798,7 +793,7 @@ char **rc_services_scheduled_by (const char *service) STRLIST_FOREACH (dirs, dir, i) { char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service, (char *) NULL); - if (rc_exists (file)) + if (rc_exists (file) == 0) rc_strlist_add (&list, file); free (file); } @@ -815,7 +810,7 @@ char **rc_services_scheduled (const char *service) (char *) NULL); char **list = NULL; - if (rc_is_dir (dir)) + if (rc_is_dir (dir) == 0) list = rc_ls_dir (dir, RC_LS_INITD); free (svc); @@ -824,23 +819,23 @@ char **rc_services_scheduled (const char *service) } librc_hidden_def(rc_services_scheduled) -bool rc_allow_plug (char *service) +int rc_allow_plug (char *service) { char *list; char *p; char *star; char *token; - bool allow = true; + int allow = 0; char *match = getenv ("RC_PLUG_SERVICES"); if (! match) - return true; + return (0); list = rc_xstrdup (match); p = list; while ((token = strsep (&p, " "))) { - bool truefalse = true; + int truefalse = 0; if (token[0] == '!') { - truefalse = false; + truefalse = -1; token++; } diff --git a/src/mountinfo.c b/src/mountinfo.c index a0250e83..11a94bfc 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -364,7 +364,7 @@ int mountinfo (int argc, char **argv) continue; if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0) continue; - if (! rc_is_env ("RC_QUIET", "yes")) + if (rc_is_env ("RC_QUIET", "yes") != 0) printf ("%s\n", n); result = EXIT_SUCCESS; } diff --git a/src/rc-plugin.c b/src/rc-plugin.c index 76b8e08e..637768ca 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -61,7 +61,7 @@ void rc_plugin_load (void) /* Ensure some sanity here */ rc_plugin_unload (); - if (! rc_exists (RC_PLUGINDIR)) + if (rc_exists (RC_PLUGINDIR) != 0) return; files = rc_ls_dir (RC_PLUGINDIR, 0); diff --git a/src/rc-status.c b/src/rc-status.c index 9ebd56c8..00612177 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -33,20 +33,21 @@ static void print_service (char *service) int cols = printf (" %s\n", service); einfo_color_t color = ecolor_bad; - if (rc_service_state (service, rc_service_stopping)) + if (rc_service_state (service, rc_service_stopping) == 0) snprintf (status, sizeof (status), "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 "); color = ecolor_warn; - } else if (rc_service_state (service, rc_service_inactive)) { + } else if (rc_service_state (service, rc_service_inactive) == 0) { snprintf (status, sizeof (status), "inactive "); color = ecolor_warn; - } else if (geteuid () == 0 && rc_service_state (service, rc_service_crashed)) + } else if (geteuid () == 0 && + rc_service_state (service, rc_service_crashed) == 0) snprintf (status, sizeof (status), " 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 "); color = ecolor_good; - } else if (rc_service_state (service, rc_service_scheduled)) { + } else if (rc_service_state (service, rc_service_scheduled) == 0) { snprintf (status, sizeof (status), "scheduled"); color = ecolor_warn; } else @@ -107,7 +108,7 @@ int rc_status (int argc, char **argv) STRLIST_FOREACH (services, service, i) { bool found = false; STRLIST_FOREACH (levels, level, j) - if (rc_service_in_runlevel (service, level)) { + if (rc_service_in_runlevel (service, level) == 0) { found = true; break; } diff --git a/src/rc-update.c b/src/rc-update.c index e0dc0867..a9d48feb 100644 --- a/src/rc-update.c +++ b/src/rc-update.c @@ -33,15 +33,15 @@ static ssize_t add (const char *runlevel, const char *service) { ssize_t retval = -1; - if (! rc_service_exists (service)) + if (rc_service_exists (service) != 0) eerror ("%s: service `%s' does not exist", applet, service); - else if (! rc_runlevel_exists (runlevel)) + else if (rc_runlevel_exists (runlevel) != 0) eerror ("%s: runlevel `%s' does not exist", applet, runlevel); - else if (rc_service_in_runlevel (service, runlevel)) { + else if (rc_service_in_runlevel (service, runlevel) == 0) { ewarn ("%s: %s already installed in runlevel `%s'; skipping", applet, service, runlevel); retval = 0; - } else if (rc_service_add (runlevel, service)) { + } else if (rc_service_add (runlevel, service) == 0) { einfo ("%s added to runlevel %s", service, runlevel); retval = 1; } else @@ -55,16 +55,16 @@ static ssize_t delete (const char *runlevel, const char *service) { ssize_t retval = -1; - if (rc_service_in_runlevel (service, runlevel)) { - if (rc_service_delete (runlevel, service)) { + if (rc_service_in_runlevel (service, runlevel) == 0) { + if (rc_service_delete (runlevel, service) == 0) { einfo ("%s removed from runlevel %s", service, runlevel); retval = 1; } else eerror ("%s: failed to remove service `%s' from runlevel `%s': %s", applet, service, runlevel, strerror (errno)); - } else if (! rc_service_exists (service)) + } else if (rc_service_exists (service) == -1) eerror ("%s: service `%s' does not exist", applet, service); - else if (! rc_runlevel_exists (runlevel)) + else if (rc_runlevel_exists (runlevel) != 0) eerror ("%s: runlevel `%s' does not exist", applet, runlevel); else retval = 0; @@ -85,7 +85,7 @@ static void show (char **runlevels, bool verbose) bool inone = false; STRLIST_FOREACH (runlevels, runlevel, j) { - if (rc_service_in_runlevel (service, runlevel)) { + if (rc_service_in_runlevel (service, runlevel) == 0) { rc_strlist_add (&in, runlevel); inone = true; } else { @@ -198,7 +198,7 @@ int rc_update (int argc, char **argv) optind++; while (optind < argc) - if (rc_runlevel_exists (argv[optind])) + if (rc_runlevel_exists (argv[optind]) == 0) rc_strlist_add (&runlevels, argv[optind++]); else { rc_strlist_free (runlevels); diff --git a/src/rc.c b/src/rc.c index da805ccb..95761280 100644 --- a/src/rc.c +++ b/src/rc.c @@ -109,9 +109,9 @@ static void cleanup (void) /* Clean runlevel start, stop markers */ if (! rc_in_plugin) { - if (rc_is_dir (RC_STARTING)) + if (rc_is_dir (RC_STARTING) == 0) rc_rm_dir (RC_STARTING, true); - if (rc_is_dir (RC_STOPPING)) + if (rc_is_dir (RC_STOPPING) == 0) rc_rm_dir (RC_STOPPING, true); } } @@ -263,7 +263,7 @@ static int do_e (int argc, char **argv) static int do_service (int argc, char **argv) { - bool ok = false; + int ok = -1; if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) eerrorx ("%s: no service specified", applet); @@ -286,17 +286,16 @@ static int do_service (int argc, char **argv) int idx = 0; if (argc > 2) sscanf (argv[2], "%d", &idx); - exit (rc_service_started_daemon (argv[0], argv[1], idx) - ? 0 : 1); + ok = rc_service_started_daemon (argv[0], argv[1], idx); } else eerrorx ("%s: unknown applet", applet); - return (ok ? EXIT_SUCCESS : EXIT_FAILURE); + return (ok); } static int do_mark_service (int argc, char **argv) { - bool ok = false; + int ok = -1; char *svcname = getenv ("SVCNAME"); if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) @@ -319,7 +318,7 @@ static int do_mark_service (int argc, char **argv) /* If we're marking ourselves then we need to inform our parent runscript process so they do not mark us based on our exit code */ - if (ok && svcname && strcmp (svcname, argv[0]) == 0) { + if (ok == 0 && svcname && strcmp (svcname, argv[0]) == 0) { char *runscript_pid = getenv ("RC_RUNSCRIPT_PID"); char *mtime; pid_t pid = 0; @@ -339,17 +338,17 @@ static int do_mark_service (int argc, char **argv) mtime = rc_xmalloc (l); snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", svcname, runscript_pid); - if (rc_exists (mtime) && unlink (mtime) != 0) + if (rc_exists (mtime) == 0 && unlink (mtime) != 0) eerror ("%s: unlink: %s", applet, strerror (errno)); free (mtime); } - return (ok ? EXIT_SUCCESS : EXIT_FAILURE); + return (ok); } static int do_options (int argc, char **argv) { - bool ok = false; + int ok = -1; char *service = getenv ("SVCNAME"); if (! service) @@ -363,14 +362,14 @@ static int do_options (int argc, char **argv) if (option) { printf ("%s", option); free (option); - ok = true; + ok = 0; } } else if (strcmp (applet, "save_options") == 0) ok = rc_set_service_option (service, argv[0], argv[1]); else eerrorx ("%s: unknown applet", applet); - return (ok ? EXIT_SUCCESS : EXIT_FAILURE); + return (ok); } #ifdef __linux__ @@ -382,7 +381,7 @@ static char *proc_getent (const char *ent) char *value = NULL; int i; - if (! rc_exists ("/proc/cmdline")) + if (rc_exists ("/proc/cmdline") != 0) return (NULL); if (! (fp = fopen ("/proc/cmdline", "r"))) { @@ -545,7 +544,7 @@ static void set_ksoftlevel (const char *runlevel) strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) { - if (rc_exists (RC_KSOFTLEVEL) && + if (rc_exists (RC_KSOFTLEVEL) == 0 && unlink (RC_KSOFTLEVEL) != 0) eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); return; @@ -565,7 +564,7 @@ static int get_ksoftlevel (char *buffer, int buffer_len) FILE *fp; int i = 0; - if (! rc_exists (RC_KSOFTLEVEL)) + if (rc_exists (RC_KSOFTLEVEL) != 0) return (0); if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { @@ -784,9 +783,9 @@ int main (int argc, char **argv) exit (do_mark_service (argc, argv)); if (strcmp (applet, "is_runlevel_start") == 0) - exit (rc_runlevel_starting () ? 0 : 1); + exit (rc_runlevel_starting ()); else if (strcmp (applet, "is_runlevel_stop") == 0) - exit (rc_runlevel_stopping () ? 0 : 1); + exit (rc_runlevel_stopping ()); if (strcmp (applet, "rc-abort") == 0) { char *p = getenv ("RC_PID"); @@ -880,7 +879,7 @@ int main (int argc, char **argv) snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); setenv ("RC_PID", pidstr, 1); - interactive = rc_exists (INTERACTIVE); + interactive = (rc_exists (INTERACTIVE) == 0); rc_plugin_load (); /* Load current softlevel */ @@ -907,7 +906,7 @@ int main (int argc, char **argv) /* exec init-early.sh if it exists * This should just setup the console to use the correct * font. Maybe it should setup the keyboard too? */ - if (rc_exists (INITEARLYSH)) + if (rc_exists (INITEARLYSH) == 0) run_script (INITEARLYSH); uname (&uts); @@ -1015,7 +1014,7 @@ int main (int argc, char **argv) /* Check if runlevel is valid if we're changing */ if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) { tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL); - if (! rc_is_dir (tmp)) + if (rc_is_dir (tmp) != 0) eerrorx ("%s: is not a valid runlevel", newlevel); CHAR_FREE (tmp); } @@ -1025,7 +1024,7 @@ int main (int argc, char **argv) eerrorx ("failed to load deptree"); /* Clean the failed services state dir now */ - if (rc_is_dir (RC_SVCDIR "/failed")) + if (rc_is_dir (RC_SVCDIR "/failed") == 0) rc_rm_dir (RC_SVCDIR "/failed", false); mkdir (RC_STOPPING, 0755); @@ -1035,12 +1034,12 @@ int main (int argc, char **argv) its coldplugging thing. runscript knows when we're not ready so it stores a list of coldplugged services in DEVBOOT for us to pick up here when we are ready for them */ - if (rc_is_dir (DEVBOOT)) { + if (rc_is_dir (DEVBOOT) == 0) { start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD); rc_rm_dir (DEVBOOT, true); STRLIST_FOREACH (start_services, service, i) - if (rc_allow_plug (service)) + if (rc_allow_plug (service) == 0) rc_mark_service (service, rc_service_coldplugged); /* We need to dump this list now. This may seem redunant, but only Linux needs this and saves on @@ -1065,7 +1064,7 @@ int main (int argc, char **argv) j = (strlen ("net.") + strlen (service) + 1); tmp = rc_xmalloc (sizeof (char *) * j); snprintf (tmp, j, "net.%s", service); - if (rc_service_exists (tmp) && rc_allow_plug (tmp)) + if (rc_service_exists (tmp) == 0 && rc_allow_plug (tmp) == 0) rc_mark_service (tmp, rc_service_coldplugged); CHAR_FREE (tmp); } @@ -1084,7 +1083,7 @@ int main (int argc, char **argv) j = (strlen ("moused.") + strlen (service) + 1); tmp = rc_xmalloc (sizeof (char *) * j); snprintf (tmp, j, "moused.%s", service); - if (rc_service_exists (tmp) && rc_allow_plug (tmp)) + if (rc_service_exists (tmp) == 0 && rc_allow_plug (tmp) == 0) rc_mark_service (tmp, rc_service_coldplugged); CHAR_FREE (tmp); } @@ -1180,7 +1179,7 @@ int main (int argc, char **argv) char *svc2 = NULL; int k; - if (rc_service_state (service, rc_service_stopped)) + if (rc_service_state (service, rc_service_stopped) == 0) continue; /* We always stop the service when in these runlevels */ @@ -1208,7 +1207,7 @@ int main (int argc, char **argv) tmp = rc_xmalloc (sizeof (char *) * len); snprintf (tmp, len, "%s.%s", service, runlevel); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); - found = rc_exists (conf); + found = (rc_exists (conf) == 0); CHAR_FREE (conf); CHAR_FREE (tmp); if (! found) { @@ -1216,7 +1215,7 @@ int main (int argc, char **argv) tmp = rc_xmalloc (sizeof (char *) * len); snprintf (tmp, len, "%s.%s", service, newlevel); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); - found = rc_exists (conf); + found = (rc_exists (conf) == 0); CHAR_FREE (conf); CHAR_FREE (tmp); if (!found) @@ -1224,7 +1223,7 @@ int main (int argc, char **argv) } } else { /* Allow coldplugged services not to be in the runlevels list */ - if (rc_service_state (service, rc_service_coldplugged)) + if (rc_service_state (service, rc_service_coldplugged) == 0) continue; } @@ -1284,7 +1283,7 @@ int main (int argc, char **argv) /* Single user is done now */ if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { - if (rc_exists (INTERACTIVE)) + if (rc_exists (INTERACTIVE) == 0) unlink (INTERACTIVE); sulogin (false); } @@ -1324,7 +1323,7 @@ int main (int argc, char **argv) STRLIST_FOREACH (start_services, service, i) { - if (rc_service_state (service, rc_service_stopped)) { + if (rc_service_state (service, rc_service_stopped) == 0) { pid_t pid; if (! interactive) @@ -1382,7 +1381,7 @@ interactive_option: if (interactive && strcmp (runlevel, bootlevel) == 0) mark_interactive (); else { - if (rc_exists (INTERACTIVE)) + if (rc_exists (INTERACTIVE) == 0) unlink (INTERACTIVE); } diff --git a/src/rc.h b/src/rc.h index a4d88d77..3ba84c8b 100644 --- a/src/rc.h +++ b/src/rc.h @@ -60,8 +60,8 @@ typedef enum char *rc_resolve_service (const char *service); /*! Checks if a service exists or not. * @param service to check - * @return true if service exists, otherwise false */ -bool rc_service_exists (const char *service); + * @return 0 if service exists, otherwise -1 */ +int rc_service_exists (const char *service); /*! Lists the extra options a service has * @param service to load the options from @@ -77,20 +77,20 @@ char *rc_service_description (const char *service, const char *option); /*! Checks if a service is in a runlevel * @param service to check * @param runlevel it should be in - * @return true if service is in the runlevel, otherwise false */ -bool rc_service_in_runlevel (const char *service, const char *runlevel); + * @return 0 if service is in the runlevel, otherwise -1 */ +int rc_service_in_runlevel (const char *service, const char *runlevel); /*! Checks if a service in in a state * @param service to check * @param state service should be in - * @return true if service is in the requested state, otherwise false */ -bool rc_service_state (const char *service, rc_service_state_t state); + * @return 0 if service is in the requested state, otherwise -1 */ +int rc_service_state (const char *service, rc_service_state_t state); /*! Marks the service state * @param service to mark * @param state service should be in - * @return true if service state change was successful, otherwise false */ -bool rc_mark_service (const char *service, rc_service_state_t state); + * @return 0 if service state change was successful, otherwise -1 */ +int rc_mark_service (const char *service, rc_service_state_t state); /*! Stop a service * @param service to stop @@ -124,8 +124,8 @@ void rc_schedule_clear (const char *service); /*! Wait for a service to finish * @param service to wait for - * @return true if service finished before timeout, otherwise false */ -bool rc_wait_service (const char *service); + * @return 0 if service finished before timeout, otherwise -1 */ +int rc_wait_service (const char *service); /*! Return a saved value for a service * @param service to check @@ -136,30 +136,31 @@ char *rc_get_service_option (const char *service, const char *option); * @param service to save for * @param option to save * @param value of the option - * @return true if saved, otherwise false */ -bool rc_set_service_option (const char *service, const char *option, - const char *value); + * @return 0 if saved, otherwise -1 */ +int rc_set_service_option (const char *service, const char *option, + const char *value); /*! Save the arguments to find a running daemon * @param service to save arguments for * @param exec that we started * @param name of the process (optional) * @param pidfile of the process (optional) - * @param started if true, add the arguments otherwise remove existing matching arguments */ -void rc_set_service_daemon (const char *service, const char *exec, - const char *name, const char *pidfile, - bool started); + * @param started if true, add the arguments otherwise remove existing matching arguments + * @return 0 if successful, otherwise -1 */ +int rc_set_service_daemon (const char *service, const char *exec, + const char *name, const char *pidfile, + bool started); /*! Check if the service started the daemon * @param service to check * @param exec to check * @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc) - * @return true if started by this service, otherwise false */ -bool rc_service_started_daemon (const char *service, const char *exec, - int indx); + * @return 0 if started by this service, otherwise -1 */ +int rc_service_started_daemon (const char *service, const char *exec, + int indx); /*! Check if the service is allowed to be hot/cold plugged * @param service to check - * @return true if allowed, otherwise false */ -bool rc_allow_plug (char *service); + * @return 0 if allowed, otherwise -1 */ +int rc_allow_plug (char *service); /*! Return the current runlevel. * @return the current runlevel */ @@ -171,30 +172,30 @@ void rc_set_runlevel (const char *runlevel); /*! Checks if the runlevel exists or not * @param runlevel to check - * @return true if the runlevel exists, otherwise false */ -bool rc_runlevel_exists (const char *runlevel); + * @return 0 if the runlevel exists, otherwise -1 */ +int rc_runlevel_exists (const char *runlevel); /*! Return a NULL terminated list of runlevels * @return a NULL terminated list of runlevels */ char **rc_get_runlevels (void); /*! Is the runlevel starting? - * @return true if yes, otherwise false */ -bool rc_runlevel_starting (void); + * @return 0 if yes, otherwise -1 */ +int rc_runlevel_starting (void); /*! Is the runlevel stopping? - * @return true if yes, otherwise false */ -bool rc_runlevel_stopping (void); + * @return 0 if yes, otherwise -1 */ +int rc_runlevel_stopping (void); /*! Add the service to the runlevel * @param runlevel to add to * @param service to add - * @return true if successful, otherwise false */ -bool rc_service_add (const char *runlevel, const char *service); + * @return 0 if successful, otherwise -1 */ +int rc_service_add (const char *runlevel, const char *service); /*! Remove the service from the runlevel * @param runlevel to remove from * @param service to remove - * @return true if sucessful, otherwise false */ -bool rc_service_delete (const char *runlevel, const char *service); + * @return 0 if sucessful, otherwise -1 */ +int rc_service_delete (const char *runlevel, const char *service); /*! List the services in a runlevel * @param runlevel to list * @return NULL terminated list of services */ @@ -222,8 +223,8 @@ pid_t *rc_find_pids (const char *exec, const char *cmd, /*! Checks that all daemons started with start-stop-daemon by the service * are still running. * @param service to check - * @return true if all daemons started are still running, otherwise false */ -bool rc_service_daemons_crashed (const char *service); + * @return 0 if all daemons started are still running, otherwise -1 */ +int rc_service_daemons_crashed (const char *service); /*! @name Dependency options * These options can change the services found by the rc_get_depinfo and @@ -370,28 +371,28 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) SENTINEL; /*! Check if an environment variable matches the given value * @param variable to check * @param value it should be - * @return true if it matches */ -bool rc_is_env (const char *variable, const char *value); + * @return 0 if it matches, otherwise -1 */ +int rc_is_env (const char *variable, const char *value); /*! Check if the file exists or not * @param pathname to check - * @return true if it exists, otherwise false */ -bool rc_exists (const char *pathname); + * @return 0 if it exists, otherwise -1 */ +int rc_exists (const char *pathname); /*! Check if the file is a real file * @param pathname to check - * @return true if it's a real file, otherwise false */ -bool rc_is_file (const char *pathname); + * @return 0 if it's a real file, otherwise -1 */ +int rc_is_file (const char *pathname); /*! Check if the file is a symbolic link or not * @param pathname to check - * @return true if it's a symbolic link, otherwise false */ -bool rc_is_link (const char *pathname); + * @return 0 if it's a symbolic link, otherwise -1 */ +int rc_is_link (const char *pathname); /*! Check if the file is a directory or not * @param pathname to check - * @return true if it's a directory, otherwise false */ -bool rc_is_dir (const char *pathname); + * @return 0 if it's a directory, otherwise -1 */ +int rc_is_dir (const char *pathname); /*! Check if the file is marked executable or not * @param pathname to check - * @return true if it's marked executable, otherwise false */ -bool rc_is_exec (const char *pathname); + * @return 0 if it's marked executable, otherwise -1 */ +int rc_is_exec (const char *pathname); /*! Return a NULL terminted sorted list of the contents of the directory * @param dir to list @@ -402,8 +403,8 @@ char **rc_ls_dir (const char *dir, int options); /*! Remove a directory * @param pathname to remove * @param top remove the top level directory too - * @return true if successful, otherwise false */ -bool rc_rm_dir (const char *pathname, bool top); + * @return 0 if successful, otherwise -1 */ +int rc_rm_dir (const char *pathname, bool top); /*! @name Configuration */ /*! Return a NULL terminated list of non comment lines from a file. */ 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); } } diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 1b4c7f28..fc5fccb8 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -733,7 +733,7 @@ int start_stop_daemon (int argc, char **argv) tmp = rc_strcatpaths (ch_root, exec, (char *) NULL); else tmp = exec; - if (! rc_is_file (tmp)) { + if (rc_is_file (tmp) != 0) { eerror ("%s: %s does not exist", applet, tmp); if (ch_root) free (tmp); @@ -759,7 +759,7 @@ int start_stop_daemon (int argc, char **argv) if (result < 1) exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); - if (pidfile && rc_is_file (pidfile)) + if (pidfile && rc_is_file (pidfile) == 0) unlink (pidfile); if (svcname) -- cgit v1.2.3