diff --git a/ChangeLog b/ChangeLog index 1ef80760..e72fd33f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,6 @@ # 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 254a0348..c9739a78 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) != 0 && + if (! rc_is_dir (path) && 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) == 0) { + if (rc_exists (LDSOCONF)) { char **lines = rc_get_list (LDSOCONF); char *line; ld = false; diff --git a/src/librc-daemon.c b/src/librc-daemon.c index 42192f45..5b1e0239 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 int _match_daemon (const char *path, const char *file, - const char *mexec, const char *mname, - const char *mpidfile) +static bool _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 int _match_daemon (const char *path, const char *file, int lc = 0; int m = 0; - if (rc_exists (ffile) != 0) { + if (! rc_exists (ffile)) { free (ffile); - return (-1); + return (false); } if ((fp = fopen (ffile, "r")) == NULL) { eerror ("fopen `%s': %s", ffile, strerror (errno)); free (ffile); - return (-1); + return (false); } if (! mname) @@ -277,12 +277,12 @@ static int _match_daemon (const char *path, const char *file, fclose (fp); free (ffile); - return (m == 111 ? 0 : -1); + return (m == 111 ? true : false); } -int rc_set_service_daemon (const char *service, const char *exec, - const char *name, const char *pidfile, - bool started) +void 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,11 +295,10 @@ int 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 (-1); + return; if (exec) { i = strlen (exec) + 6; @@ -323,7 +322,7 @@ int 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) == 0) { + if (rc_is_dir (dirpath)) { char *oldfile = NULL; files = rc_ls_dir (dirpath, 0); STRLIST_FOREACH (files, file, i) { @@ -331,7 +330,7 @@ int rc_set_service_daemon (const char *service, const char *exec, nfiles++; if (! oldfile) { - if (_match_daemon (dirpath, file, mexec, mname, mpidfile) == 0) { + if (_match_daemon (dirpath, file, mexec, mname, mpidfile)) { unlink (ffile); oldfile = ffile; nfiles--; @@ -351,7 +350,7 @@ int rc_set_service_daemon (const char *service, const char *exec, char buffer[10]; FILE *fp; - if (rc_is_dir (dirpath) != 0) + if (! rc_is_dir (dirpath)) if (mkdir (dirpath, 0755) != 0) eerror ("mkdir `%s': %s", dirpath, strerror (errno)); @@ -361,7 +360,6 @@ int 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); @@ -371,32 +369,30 @@ int 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) -int rc_service_started_daemon (const char *service, const char *exec, - int indx) +bool rc_service_started_daemon (const char *service, const char *exec, + int indx) { char *dirpath; char *file; int i; char *mexec; - int retval = -1; + bool retval = false; char *svc; if (! service || ! exec) - return (-1); + return (false); svc = rc_xstrdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); - if (rc_is_dir (dirpath) != 0) { + if (! rc_is_dir (dirpath)) { free (dirpath); - return (-1); + return (false); } i = strlen (exec) + 6; @@ -413,7 +409,7 @@ int 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 == 0) + if (retval) break; } rc_strlist_free (files); @@ -424,7 +420,7 @@ int rc_service_started_daemon (const char *service, const char *exec, } librc_hidden_def(rc_service_started_daemon) -int rc_service_daemons_crashed (const char *service) +bool rc_service_daemons_crashed (const char *service) { char *dirpath; char **files; @@ -440,20 +436,20 @@ int rc_service_daemons_crashed (const char *service) pid_t *pids = NULL; char *p; char *token; - int retval = -1; + bool retval = false; char *svc; if (! service) - return (-1); + return (false); svc = rc_xstrdup (service); dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), (char *) NULL); free (svc); - if (rc_is_dir (dirpath) != 0) { + if (! rc_is_dir (dirpath)) { free (dirpath); - return (-1); + return (false); } memset (buffer, 0, sizeof (buffer)); @@ -497,21 +493,21 @@ int rc_service_daemons_crashed (const char *service) pid = 0; if (pidfile) { - if (rc_exists (pidfile) != 0) { - retval = 0; + if (! rc_exists (pidfile)) { + retval = true; break; } if ((fp = fopen (pidfile, "r")) == NULL) { eerror ("fopen `%s': %s", pidfile, strerror (errno)); - retval = 0; + retval = true; break; } if (fscanf (fp, "%d", &pid) != 1) { eerror ("no pid found in `%s'", pidfile); fclose (fp); - retval = 0; + retval = true; break; } @@ -527,7 +523,7 @@ int rc_service_daemons_crashed (const char *service) } if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) { - retval = 0; + retval = true; break; } free (pids); diff --git a/src/librc-depend.c b/src/librc-depend.c index cc6fcbdd..4df64635 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) == 0) || - rc_service_in_runlevel (service, runlevel) == 0 || - rc_service_state (service, rc_service_coldplugged) == 0 || - rc_service_state (service, rc_service_started) == 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)); } 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) == 0); + ok = rc_service_in_runlevel (service, level); else if (coldplugged) - ok = (rc_service_state (service, rc_service_coldplugged) == 0 && - rc_service_in_runlevel (service, runlevel) != 0 && - rc_service_in_runlevel (service, bootlevel) != 0); + ok = (rc_service_state (service, rc_service_coldplugged) && + ! rc_service_in_runlevel (service, runlevel) && + ! rc_service_in_runlevel (service, bootlevel)); if (! ok) continue; switch (state) { case rc_service_started: - ok = (rc_service_state (service, state) == 0); + ok = rc_service_state (service, state); break; case rc_service_inactive: case rc_service_starting: case rc_service_stopping: - 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); + ok = (rc_service_state (service, rc_service_starting) || + rc_service_state (service, rc_service_stopping) || + rc_service_state (service, rc_service_inactive)); 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) == -1) + if (rc_service_exists (depinfo->service)) 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) == 0 || - rc_service_in_runlevel (service, bootlevel) == 0) + if (rc_service_in_runlevel (service, runlevel) || + rc_service_in_runlevel (service, bootlevel)) 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) == 0) + if (rc_is_dir (target)) { 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]) != 0) + if (! rc_is_dir (depdirs[i])) 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) != 0) + if (! rc_exists (RC_DEPCONFIG)) return 0; config = rc_get_list (RC_DEPCONFIG); diff --git a/src/librc-misc.c b/src/librc-misc.c index b0d654ca..bd92e584 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) -int rc_is_env (const char *var, const char *val) +bool rc_is_env (const char *var, const char *val) { char *v; if (! var) - return (-1); + return (false); v = getenv (var); if (! v) - return (val == NULL ? 0 : -1); + return (val == NULL ? true : false); - return (strcasecmp (v, val)); + return (strcasecmp (v, val) == 0 ? true : false); } librc_hidden_def(rc_is_env) @@ -123,58 +123,78 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...) } librc_hidden_def(rc_strcatpaths) -int rc_exists (const char *pathname) +bool rc_exists (const char *pathname) { struct stat buf; if (! pathname) - return (-1); + return (false); - return (stat (pathname, &buf)); + if (stat (pathname, &buf) == 0) + return (true); + + errno = 0; + return (false); } librc_hidden_def(rc_exists) -int rc_is_file (const char *pathname) +bool rc_is_file (const char *pathname) { struct stat buf; - if (pathname && stat (pathname, &buf) == 0) - return (S_ISREG (buf.st_mode) ? 0 : -1); + if (! pathname) + return (false); - return (-1); + if (stat (pathname, &buf) == 0) + return (S_ISREG (buf.st_mode)); + + errno = 0; + return (false); } librc_hidden_def(rc_is_file) -int rc_is_dir (const char *pathname) +bool rc_is_dir (const char *pathname) { struct stat buf; - if (pathname && stat (pathname, &buf) == 0) - return (S_ISDIR (buf.st_mode) ? 0 : -1); + if (! pathname) + return (false); - return (-1); + if (stat (pathname, &buf) == 0) + return (S_ISDIR (buf.st_mode)); + + errno = 0; + return (false); } librc_hidden_def(rc_is_dir) -int rc_is_link (const char *pathname) +bool rc_is_link (const char *pathname) { struct stat buf; - if (pathname && lstat (pathname, &buf) == 0) - return (S_ISLNK (buf.st_mode) ? 0 : -1); + if (! pathname) + return (false); - return (-1); + if (lstat (pathname, &buf) == 0) + return (S_ISLNK (buf.st_mode)); + + errno = 0; + return (false); } librc_hidden_def(rc_is_link) -int rc_is_exec (const char *pathname) +bool rc_is_exec (const char *pathname) { struct stat buf; - if (pathname && lstat (pathname, &buf) == 0) - return (buf.st_mode & S_IXUGO ? 0 : -1); + if (! pathname) + return (false); - return (-1); + if (lstat (pathname, &buf) == 0) + return (buf.st_mode & S_IXUGO); + + errno = 0; + return (false); } librc_hidden_def(rc_is_exec) @@ -199,9 +219,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); - int ok = rc_exists (init); + bool ok = rc_exists (init); free (init); - if (ok != 0) + if (! ok) continue; /* .sh files are not init scripts */ @@ -225,17 +245,17 @@ char **rc_ls_dir (const char *dir, int options) } librc_hidden_def(rc_ls_dir) -int rc_rm_dir (const char *pathname, bool top) +bool rc_rm_dir (const char *pathname, bool top) { DIR *dp; struct dirent *d; if (! pathname) - return (-1); + return (false); if ((dp = opendir (pathname)) == NULL) { eerror ("failed to opendir `%s': %s", pathname, strerror (errno)); - return (-1); + return (false); } errno = 0; @@ -243,18 +263,18 @@ int 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) != 0) + if (! rc_rm_dir (tmp, true)) { free (tmp); closedir (dp); - return (-1); + return (false); } } else { if (unlink (tmp)) { eerror ("failed to unlink `%s': %s", tmp, strerror (errno)); free (tmp); closedir (dp); - return (-1); + return (false); } } free (tmp); @@ -266,10 +286,10 @@ int rc_rm_dir (const char *pathname, bool top) if (top && rmdir (pathname) != 0) { eerror ("failed to rmdir `%s': %s", pathname, strerror (errno)); - return (-1); + return false; } - return (0); + return (true); } librc_hidden_def(rc_rm_dir) @@ -442,7 +462,7 @@ char **rc_filter_env (void) if (! whitelist) return (NULL); - if (rc_is_file (PROFILE_ENV) == 0) + if (rc_is_file (PROFILE_ENV)) profile = rc_get_config (PROFILE_ENV); STRLIST_FOREACH (whitelist, env_name, count) { @@ -524,7 +544,7 @@ static bool file_regex (const char *file, const char *regex) bool retval = false; int result; - if (rc_exists (file) != 0) + if (! rc_exists (file)) return (false); if (! (fp = fopen (file, "r"))) { @@ -572,7 +592,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) == 0) + if (rc_exists (buffer)) config = rc_get_config (buffer); else config = rc_get_config (RC_CONFIG); @@ -619,7 +639,7 @@ char **rc_make_env (void) rc_strlist_add (&env, line); free (line); - if (rc_exists (RC_KSOFTLEVEL) == 0) { + if (rc_exists (RC_KSOFTLEVEL)) { if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno)); else { @@ -645,7 +665,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") == 0) { + if (rc_is_dir ("/proc/xen")) { fp = fopen ("/proc/xen/capabilities", "r"); if (fp) { fclose (fp); diff --git a/src/librc.c b/src/librc.c index 632f35fc..dd2e0b6b 100644 --- a/src/librc.c +++ b/src/librc.c @@ -31,13 +31,13 @@ static const char *rc_service_state_names[] = { NULL }; -int rc_runlevel_starting (void) +bool rc_runlevel_starting (void) { return (rc_is_dir (RC_STARTING)); } librc_hidden_def(rc_runlevel_starting) -int rc_runlevel_stopping (void) +bool 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) == 0) + if (rc_is_dir (path)) rc_strlist_addsort (&runlevels, dir); free (path); } @@ -95,13 +95,13 @@ void rc_set_runlevel (const char *runlevel) } librc_hidden_def(rc_set_runlevel) -int rc_runlevel_exists (const char *runlevel) +bool rc_runlevel_exists (const char *runlevel) { char *path; - int retval; + bool retval; if (! runlevel) - return (-1); + return (false); 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) != 0) { + if (! rc_is_link (file)) { free (file); file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL); - if (rc_is_link (file) != 0) { + if (! rc_is_link (file)) { free (file); file = NULL; } @@ -146,14 +146,14 @@ char *rc_resolve_service (const char *service) } librc_hidden_def(rc_resolve_service) -int rc_service_exists (const char *service) +bool rc_service_exists (const char *service) { char *file; - int retval = -1; + bool retval = false; int len; if (! service) - return (-1); + return (false); len = strlen (service); @@ -161,10 +161,11 @@ int rc_service_exists (const char *service) if (len > 2 && service[len - 3] == '.' && service[len - 2] == 's' && service[len - 1] == 'h') - return (-1); + return (false); file = rc_resolve_service (service); - retval = rc_is_exec (file); + if (rc_exists (file)) + retval = rc_is_exec (file); free (file); return (retval); } @@ -246,14 +247,14 @@ char *rc_service_description (const char *service, const char *option) } librc_hidden_def(rc_service_description) -int rc_service_in_runlevel (const char *service, const char *runlevel) +bool rc_service_in_runlevel (const char *service, const char *runlevel) { char *file; - int retval; + bool retval; char *svc; if (! runlevel || ! service) - return (-1); + return (false); svc = rc_xstrdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), @@ -266,7 +267,7 @@ int rc_service_in_runlevel (const char *service, const char *runlevel) } librc_hidden_def(rc_service_in_runlevel) -int rc_mark_service (const char *service, const rc_service_state_t state) +bool rc_mark_service (const char *service, const rc_service_state_t state) { char *file; int i = 0; @@ -277,21 +278,21 @@ int rc_mark_service (const char *service, const rc_service_state_t state) bool skip_wasinactive = false; if (! service) - return (-1); + return (false); svc = rc_xstrdup (service); base = basename (svc); if (state != rc_service_stopped) { - if (rc_is_file(init) != 0) { + if (! rc_is_file(init)) { free (init); free (svc); - return (-1); + return (false); } file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base, (char *) NULL); - if (rc_exists (file) == 0) + if (rc_exists (file)) unlink (file); i = symlink (init, file); if (i != 0) { @@ -299,7 +300,7 @@ int rc_mark_service (const char *service, const rc_service_state_t state) free (file); free (init); free (svc); - return (-1); + return (false); } free (file); @@ -309,7 +310,7 @@ int rc_mark_service (const char *service, const rc_service_state_t state) if (state == rc_service_coldplugged) { free (init); free (svc); - return (0); + return (true); } /* Remove any old states now */ @@ -324,7 +325,7 @@ int 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) == 0) { + if (rc_exists (file)) { if ((state == rc_service_starting || state == rc_service_stopping) && i == rc_service_inactive) @@ -357,7 +358,7 @@ int 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) == 0) + if (rc_exists (file)) if (unlink (file) != 0) eerror ("unlink `%s': %s", file, strerror (errno)); free (file); @@ -367,12 +368,12 @@ int 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) == 0) + if (rc_is_dir (dir)) rc_rm_dir (dir, true); free (dir); dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL); - if (rc_is_dir (dir) == 0) + if (rc_is_dir (dir)) rc_rm_dir (dir, true); free (dir); @@ -389,7 +390,7 @@ int 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) == 0) + if (rc_exists (file)) if (unlink (file) != 0) eerror ("unlink `%s': %s", file, strerror (errno)); free (file); @@ -406,11 +407,11 @@ int rc_mark_service (const char *service, const rc_service_state_t state) free (svc); free (init); - return (0); + return (true); } librc_hidden_def(rc_mark_service) -int rc_service_state (const char *service, const rc_service_state_t state) +bool rc_service_state (const char *service, const rc_service_state_t state) { char *file; bool retval; @@ -418,22 +419,24 @@ int 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 ? 0 : -1); + return (state == rc_service_stopped ? true : false); /* 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); - rc_strlist_free (services); - return (services ? 0 : -1); + retval = (services); + if (services) + free (services); + return (retval); } /* Now we just check if a file by the service name rc_exists @@ -456,7 +459,7 @@ char *rc_get_service_option (const char *service, const char *option) (char *) NULL); char *value = NULL; - if (rc_exists (file) == 0) { + if (rc_exists (file)) { if ((fp = fopen (file, "r")) == NULL) eerror ("fopen `%s': %s", file, strerror (errno)); else { @@ -472,20 +475,20 @@ char *rc_get_service_option (const char *service, const char *option) } librc_hidden_def(rc_get_service_option) -int rc_set_service_option (const char *service, const char *option, +bool 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); - int retval = -1; + bool retval = false; - if (rc_is_dir (path) != 0) { + if (! rc_is_dir (path)) { if (mkdir (path, 0755) != 0) { eerror ("mkdir `%s': %s", path, strerror (errno)); free (path); free (file); - return (-1); + return (false); } } @@ -495,7 +498,7 @@ int rc_set_service_option (const char *service, const char *option, if (value) fprintf (fp, "%s", value); fclose (fp); - retval = 0; + retval = true; } free (path); @@ -512,7 +515,7 @@ static pid_t _exec_service (const char *service, const char *arg) char *svc; file = rc_resolve_service (service); - if (rc_is_file (file) != 0) { + if (! rc_is_file (file)) { rc_mark_service (service, rc_service_stopped); free (file); return (0); @@ -563,7 +566,7 @@ int rc_waitpid (pid_t pid) { pid_t rc_stop_service (const char *service) { - if (rc_service_state (service, rc_service_stopped) == 0) + if (rc_service_state (service, rc_service_stopped)) return (0); return (_exec_service (service, "stop")); @@ -572,7 +575,7 @@ librc_hidden_def(rc_stop_service) pid_t rc_start_service (const char *service) { - if (! rc_service_state (service, rc_service_stopped) == 0) + if (! rc_service_state (service, rc_service_stopped)) return (0); return (_exec_service (service, "start")); @@ -595,7 +598,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) != 0) + if (! rc_is_dir (dir)) if (mkdir (dir, 0755) != 0) { eerror ("mkdir `%s': %s", dir, strerror (errno)); free (dir); @@ -606,7 +609,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) != 0 && symlink (init, file) != 0) + if (! rc_exists (file) && symlink (init, file) != 0) eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno)); free (init); @@ -622,24 +625,24 @@ void rc_schedule_clear (const char *service) (char *) NULL); free (svc); - if (rc_is_dir (dir) == 0) + if (rc_is_dir (dir)) rc_rm_dir (dir, true); free (dir); } librc_hidden_def(rc_schedule_clear) -int rc_wait_service (const char *service) +bool rc_wait_service (const char *service) { char *svc; char *base; char *fifo; struct timespec ts; int nloops = WAIT_MAX / WAIT_INTERVAL; - int retval = -1; + bool retval = false; bool forever = false; if (! service) - return (-1); + return (false); svc = rc_xstrdup (service); base = basename (svc); @@ -654,8 +657,8 @@ int rc_wait_service (const char *service) ts.tv_nsec = WAIT_INTERVAL; while (nloops) { - if (rc_exists (fifo) != 0) { - retval = 0; + if (! rc_exists (fifo)) { + retval = true; break; } @@ -689,7 +692,7 @@ char **rc_services_in_runlevel (const char *runlevel) return (NULL); dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); - if (rc_is_dir (dir) != 0) + if (! rc_is_dir (dir)) eerror ("runlevel `%s' does not exist", runlevel); else list = rc_ls_dir (dir, RC_LS_INITD); @@ -726,7 +729,7 @@ char **rc_services_in_state (rc_service_state_t state) if (dirs) free (dirs); } else { - if (rc_is_dir (dir) == 0) + if (rc_is_dir (dir)) list = rc_ls_dir (dir, RC_LS_INITD); } @@ -735,21 +738,21 @@ char **rc_services_in_state (rc_service_state_t state) } librc_hidden_def(rc_services_in_state) -int rc_service_add (const char *runlevel, const char *service) +bool rc_service_add (const char *runlevel, const char *service) { - int retval; + bool retval; char *init; char *file; char *svc; if (! rc_runlevel_exists (runlevel)) { errno = ENOENT; - return (-1); + return (false); } - if (rc_service_in_runlevel (service, runlevel) == 0) { + if (rc_service_in_runlevel (service, runlevel)) { errno = EEXIST; - return (-1); + return (false); } init = rc_resolve_service (service); @@ -757,27 +760,29 @@ int 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); + retval = (symlink (init, file) == 0); free (init); free (file); return (retval); } librc_hidden_def(rc_service_add) -int rc_service_delete (const char *runlevel, const char *service) +bool rc_service_delete (const char *runlevel, const char *service) { char *file; char *svc; - int retval; + bool retval = false; if (! runlevel || ! service) - return (-1); + return (false); svc = rc_xstrdup (service); file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), (char *) NULL); free (svc); - retval = unlink (file); + if (unlink (file) == 0) + retval = true; + free (file); return (retval); } @@ -793,7 +798,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) == 0) + if (rc_exists (file)) rc_strlist_add (&list, file); free (file); } @@ -810,7 +815,7 @@ char **rc_services_scheduled (const char *service) (char *) NULL); char **list = NULL; - if (rc_is_dir (dir) == 0) + if (rc_is_dir (dir)) list = rc_ls_dir (dir, RC_LS_INITD); free (svc); @@ -819,23 +824,23 @@ char **rc_services_scheduled (const char *service) } librc_hidden_def(rc_services_scheduled) -int rc_allow_plug (char *service) +bool rc_allow_plug (char *service) { char *list; char *p; char *star; char *token; - int allow = 0; + bool allow = true; char *match = getenv ("RC_PLUG_SERVICES"); if (! match) - return (0); + return true; list = rc_xstrdup (match); p = list; while ((token = strsep (&p, " "))) { - int truefalse = 0; + bool truefalse = true; if (token[0] == '!') { - truefalse = -1; + truefalse = false; token++; } diff --git a/src/mountinfo.c b/src/mountinfo.c index 11a94bfc..a0250e83 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") != 0) + if (! rc_is_env ("RC_QUIET", "yes")) printf ("%s\n", n); result = EXIT_SUCCESS; } diff --git a/src/rc-plugin.c b/src/rc-plugin.c index 637768ca..76b8e08e 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) != 0) + if (! rc_exists (RC_PLUGINDIR)) return; files = rc_ls_dir (RC_PLUGINDIR, 0); diff --git a/src/rc-status.c b/src/rc-status.c index 00612177..9ebd56c8 100644 --- a/src/rc-status.c +++ b/src/rc-status.c @@ -33,21 +33,20 @@ 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) == 0) + if (rc_service_state (service, rc_service_stopping)) snprintf (status, sizeof (status), "stopping "); - else if (rc_service_state (service, rc_service_starting) == 0) { + else if (rc_service_state (service, rc_service_starting)) { snprintf (status, sizeof (status), "starting "); color = ecolor_warn; - } else if (rc_service_state (service, rc_service_inactive) == 0) { + } else if (rc_service_state (service, rc_service_inactive)) { snprintf (status, sizeof (status), "inactive "); color = ecolor_warn; - } else if (geteuid () == 0 && - rc_service_state (service, rc_service_crashed) == 0) + } else if (geteuid () == 0 && rc_service_state (service, rc_service_crashed)) snprintf (status, sizeof (status), " crashed "); - else if (rc_service_state (service, rc_service_started) == 0) { + else if (rc_service_state (service, rc_service_started)) { snprintf (status, sizeof (status), " started "); color = ecolor_good; - } else if (rc_service_state (service, rc_service_scheduled) == 0) { + } else if (rc_service_state (service, rc_service_scheduled)) { snprintf (status, sizeof (status), "scheduled"); color = ecolor_warn; } else @@ -108,7 +107,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) == 0) { + if (rc_service_in_runlevel (service, level)) { found = true; break; } diff --git a/src/rc-update.c b/src/rc-update.c index a9d48feb..e0dc0867 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) != 0) + if (! rc_service_exists (service)) eerror ("%s: service `%s' does not exist", applet, service); - else if (rc_runlevel_exists (runlevel) != 0) + else if (! rc_runlevel_exists (runlevel)) eerror ("%s: runlevel `%s' does not exist", applet, runlevel); - else if (rc_service_in_runlevel (service, runlevel) == 0) { + else if (rc_service_in_runlevel (service, runlevel)) { ewarn ("%s: %s already installed in runlevel `%s'; skipping", applet, service, runlevel); retval = 0; - } else if (rc_service_add (runlevel, service) == 0) { + } else if (rc_service_add (runlevel, service)) { 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) == 0) { - if (rc_service_delete (runlevel, service) == 0) { + if (rc_service_in_runlevel (service, runlevel)) { + if (rc_service_delete (runlevel, service)) { 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) == -1) + } else if (! rc_service_exists (service)) eerror ("%s: service `%s' does not exist", applet, service); - else if (rc_runlevel_exists (runlevel) != 0) + else if (! rc_runlevel_exists (runlevel)) 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) == 0) { + if (rc_service_in_runlevel (service, runlevel)) { 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]) == 0) + if (rc_runlevel_exists (argv[optind])) rc_strlist_add (&runlevels, argv[optind++]); else { rc_strlist_free (runlevels); diff --git a/src/rc.c b/src/rc.c index 95761280..da805ccb 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) == 0) + if (rc_is_dir (RC_STARTING)) rc_rm_dir (RC_STARTING, true); - if (rc_is_dir (RC_STOPPING) == 0) + if (rc_is_dir (RC_STOPPING)) 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) { - int ok = -1; + bool ok = false; if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) eerrorx ("%s: no service specified", applet); @@ -286,16 +286,17 @@ static int do_service (int argc, char **argv) int idx = 0; if (argc > 2) sscanf (argv[2], "%d", &idx); - ok = rc_service_started_daemon (argv[0], argv[1], idx); + exit (rc_service_started_daemon (argv[0], argv[1], idx) + ? 0 : 1); } else eerrorx ("%s: unknown applet", applet); - return (ok); + return (ok ? EXIT_SUCCESS : EXIT_FAILURE); } static int do_mark_service (int argc, char **argv) { - int ok = -1; + bool ok = false; char *svcname = getenv ("SVCNAME"); if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) @@ -318,7 +319,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 == 0 && svcname && strcmp (svcname, argv[0]) == 0) { + if (ok && svcname && strcmp (svcname, argv[0]) == 0) { char *runscript_pid = getenv ("RC_RUNSCRIPT_PID"); char *mtime; pid_t pid = 0; @@ -338,17 +339,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) == 0 && unlink (mtime) != 0) + if (rc_exists (mtime) && unlink (mtime) != 0) eerror ("%s: unlink: %s", applet, strerror (errno)); free (mtime); } - return (ok); + return (ok ? EXIT_SUCCESS : EXIT_FAILURE); } static int do_options (int argc, char **argv) { - int ok = -1; + bool ok = false; char *service = getenv ("SVCNAME"); if (! service) @@ -362,14 +363,14 @@ static int do_options (int argc, char **argv) if (option) { printf ("%s", option); free (option); - ok = 0; + ok = true; } } 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); + return (ok ? EXIT_SUCCESS : EXIT_FAILURE); } #ifdef __linux__ @@ -381,7 +382,7 @@ static char *proc_getent (const char *ent) char *value = NULL; int i; - if (rc_exists ("/proc/cmdline") != 0) + if (! rc_exists ("/proc/cmdline")) return (NULL); if (! (fp = fopen ("/proc/cmdline", "r"))) { @@ -544,7 +545,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) == 0 && + if (rc_exists (RC_KSOFTLEVEL) && unlink (RC_KSOFTLEVEL) != 0) eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); return; @@ -564,7 +565,7 @@ static int get_ksoftlevel (char *buffer, int buffer_len) FILE *fp; int i = 0; - if (rc_exists (RC_KSOFTLEVEL) != 0) + if (! rc_exists (RC_KSOFTLEVEL)) return (0); if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { @@ -783,9 +784,9 @@ int main (int argc, char **argv) exit (do_mark_service (argc, argv)); if (strcmp (applet, "is_runlevel_start") == 0) - exit (rc_runlevel_starting ()); + exit (rc_runlevel_starting () ? 0 : 1); else if (strcmp (applet, "is_runlevel_stop") == 0) - exit (rc_runlevel_stopping ()); + exit (rc_runlevel_stopping () ? 0 : 1); if (strcmp (applet, "rc-abort") == 0) { char *p = getenv ("RC_PID"); @@ -879,7 +880,7 @@ int main (int argc, char **argv) snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); setenv ("RC_PID", pidstr, 1); - interactive = (rc_exists (INTERACTIVE) == 0); + interactive = rc_exists (INTERACTIVE); rc_plugin_load (); /* Load current softlevel */ @@ -906,7 +907,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) == 0) + if (rc_exists (INITEARLYSH)) run_script (INITEARLYSH); uname (&uts); @@ -1014,7 +1015,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) != 0) + if (! rc_is_dir (tmp)) eerrorx ("%s: is not a valid runlevel", newlevel); CHAR_FREE (tmp); } @@ -1024,7 +1025,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") == 0) + if (rc_is_dir (RC_SVCDIR "/failed")) rc_rm_dir (RC_SVCDIR "/failed", false); mkdir (RC_STOPPING, 0755); @@ -1034,12 +1035,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) == 0) { + if (rc_is_dir (DEVBOOT)) { 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) == 0) + if (rc_allow_plug (service)) 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 @@ -1064,7 +1065,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) == 0 && rc_allow_plug (tmp) == 0) + if (rc_service_exists (tmp) && rc_allow_plug (tmp)) rc_mark_service (tmp, rc_service_coldplugged); CHAR_FREE (tmp); } @@ -1083,7 +1084,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) == 0 && rc_allow_plug (tmp) == 0) + if (rc_service_exists (tmp) && rc_allow_plug (tmp)) rc_mark_service (tmp, rc_service_coldplugged); CHAR_FREE (tmp); } @@ -1179,7 +1180,7 @@ int main (int argc, char **argv) char *svc2 = NULL; int k; - if (rc_service_state (service, rc_service_stopped) == 0) + if (rc_service_state (service, rc_service_stopped)) continue; /* We always stop the service when in these runlevels */ @@ -1207,7 +1208,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) == 0); + found = rc_exists (conf); CHAR_FREE (conf); CHAR_FREE (tmp); if (! found) { @@ -1215,7 +1216,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) == 0); + found = rc_exists (conf); CHAR_FREE (conf); CHAR_FREE (tmp); if (!found) @@ -1223,7 +1224,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) == 0) + if (rc_service_state (service, rc_service_coldplugged)) continue; } @@ -1283,7 +1284,7 @@ int main (int argc, char **argv) /* Single user is done now */ if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { - if (rc_exists (INTERACTIVE) == 0) + if (rc_exists (INTERACTIVE)) unlink (INTERACTIVE); sulogin (false); } @@ -1323,7 +1324,7 @@ int main (int argc, char **argv) STRLIST_FOREACH (start_services, service, i) { - if (rc_service_state (service, rc_service_stopped) == 0) { + if (rc_service_state (service, rc_service_stopped)) { pid_t pid; if (! interactive) @@ -1381,7 +1382,7 @@ interactive_option: if (interactive && strcmp (runlevel, bootlevel) == 0) mark_interactive (); else { - if (rc_exists (INTERACTIVE) == 0) + if (rc_exists (INTERACTIVE)) unlink (INTERACTIVE); } diff --git a/src/rc.h b/src/rc.h index 3ba84c8b..a4d88d77 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 0 if service exists, otherwise -1 */ -int rc_service_exists (const char *service); + * @return true if service exists, otherwise false */ +bool 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 0 if service is in the runlevel, otherwise -1 */ -int rc_service_in_runlevel (const char *service, const char *runlevel); + * @return true if service is in the runlevel, otherwise false */ +bool 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 0 if service is in the requested state, otherwise -1 */ -int rc_service_state (const char *service, rc_service_state_t state); + * @return true if service is in the requested state, otherwise false */ +bool 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 0 if service state change was successful, otherwise -1 */ -int rc_mark_service (const char *service, rc_service_state_t state); + * @return true if service state change was successful, otherwise false */ +bool 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 0 if service finished before timeout, otherwise -1 */ -int rc_wait_service (const char *service); + * @return true if service finished before timeout, otherwise false */ +bool rc_wait_service (const char *service); /*! Return a saved value for a service * @param service to check @@ -136,31 +136,30 @@ 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 0 if saved, otherwise -1 */ -int rc_set_service_option (const char *service, const char *option, - const char *value); + * @return true if saved, otherwise false */ +bool 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 - * @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); + * @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); /*! 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 0 if started by this service, otherwise -1 */ -int rc_service_started_daemon (const char *service, const char *exec, - int indx); + * @return true if started by this service, otherwise false */ +bool 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 0 if allowed, otherwise -1 */ -int rc_allow_plug (char *service); + * @return true if allowed, otherwise false */ +bool rc_allow_plug (char *service); /*! Return the current runlevel. * @return the current runlevel */ @@ -172,30 +171,30 @@ void rc_set_runlevel (const char *runlevel); /*! Checks if the runlevel exists or not * @param runlevel to check - * @return 0 if the runlevel exists, otherwise -1 */ -int rc_runlevel_exists (const char *runlevel); + * @return true if the runlevel exists, otherwise false */ +bool 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 0 if yes, otherwise -1 */ -int rc_runlevel_starting (void); + * @return true if yes, otherwise false */ +bool rc_runlevel_starting (void); /*! Is the runlevel stopping? - * @return 0 if yes, otherwise -1 */ -int rc_runlevel_stopping (void); + * @return true if yes, otherwise false */ +bool rc_runlevel_stopping (void); /*! Add the service to the runlevel * @param runlevel to add to * @param service to add - * @return 0 if successful, otherwise -1 */ -int rc_service_add (const char *runlevel, const char *service); + * @return true if successful, otherwise false */ +bool 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 0 if sucessful, otherwise -1 */ -int rc_service_delete (const char *runlevel, const char *service); + * @return true if sucessful, otherwise false */ +bool 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 */ @@ -223,8 +222,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 0 if all daemons started are still running, otherwise -1 */ -int rc_service_daemons_crashed (const char *service); + * @return true if all daemons started are still running, otherwise false */ +bool rc_service_daemons_crashed (const char *service); /*! @name Dependency options * These options can change the services found by the rc_get_depinfo and @@ -371,28 +370,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 0 if it matches, otherwise -1 */ -int rc_is_env (const char *variable, const char *value); + * @return true if it matches */ +bool rc_is_env (const char *variable, const char *value); /*! Check if the file exists or not * @param pathname to check - * @return 0 if it exists, otherwise -1 */ -int rc_exists (const char *pathname); + * @return true if it exists, otherwise false */ +bool rc_exists (const char *pathname); /*! Check if the file is a real file * @param pathname to check - * @return 0 if it's a real file, otherwise -1 */ -int rc_is_file (const char *pathname); + * @return true if it's a real file, otherwise false */ +bool rc_is_file (const char *pathname); /*! Check if the file is a symbolic link or not * @param pathname to check - * @return 0 if it's a symbolic link, otherwise -1 */ -int rc_is_link (const char *pathname); + * @return true if it's a symbolic link, otherwise false */ +bool rc_is_link (const char *pathname); /*! Check if the file is a directory or not * @param pathname to check - * @return 0 if it's a directory, otherwise -1 */ -int rc_is_dir (const char *pathname); + * @return true if it's a directory, otherwise false */ +bool rc_is_dir (const char *pathname); /*! Check if the file is marked executable or not * @param pathname to check - * @return 0 if it's marked executable, otherwise -1 */ -int rc_is_exec (const char *pathname); + * @return true if it's marked executable, otherwise false */ +bool rc_is_exec (const char *pathname); /*! Return a NULL terminted sorted list of the contents of the directory * @param dir to list @@ -403,8 +402,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 0 if successful, otherwise -1 */ -int rc_rm_dir (const char *pathname, bool top); + * @return true if successful, otherwise false */ +bool 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 9645116a..4bbc0dab 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) != 0) + if (! rc_exists (SELINUX_LIB)) 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) != 0) + if (! mtime_test || ! rc_exists (mtime_test)) return (false); - if (rc_service_state (applet, rc_service_stopped) == 0) + if (rc_service_state (applet, rc_service_stopped)) 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) == 0) { + if (rc_exists (path)) { 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) == 0 && unlink (cold) != 0) + if (rc_exists (cold) && unlink (cold) != 0) eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno)); free (cold); } static void start_services (char **list) { - int inactive; + bool 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 != 0) + if (! inactive) inactive = rc_service_state (service, rc_service_wasinactive); - if (inactive != 0 || - rc_service_state (service, rc_service_starting) == 0 || - rc_service_state (service, rc_service_started) == 0) + if (inactive || + rc_service_state (service, rc_service_starting) || + rc_service_state (service, rc_service_started)) { STRLIST_FOREACH (list, svc, i) { - if (rc_service_state (svc, rc_service_stopped) == 0) { - if (inactive != 0) { + if (rc_service_state (svc, rc_service_stopped)) { + if (inactive) { 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) == 0) { + if (rc_service_state (applet, rc_service_stopping)) { /* If the we're shutting down, do it cleanly */ if ((softlevel && - rc_runlevel_stopping () == 0 && + rc_runlevel_stopping () && (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) == 0) + else if (rc_service_state (applet, rc_service_wasinactive)) rc_mark_service (applet, rc_service_inactive); else rc_mark_service (applet, rc_service_started); } - else if (rc_service_state (applet, rc_service_starting) == 0) + else if (rc_service_state (applet, rc_service_starting)) { - if (rc_service_state (applet, rc_service_wasinactive) == 0) + if (rc_service_state (applet, rc_service_wasinactive)) rc_mark_service (applet, rc_service_inactive); else rc_mark_service (applet, rc_service_stopped); } - if (exclusive && rc_exists (exclusive) == 0) + if (exclusive && rc_exists (exclusive)) 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") == 0) { + if (rc_exists (RC_SVCDIR "/runscript.sh")) { 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) == 0) { + if (rc_service_state (service, rc_service_stopping)) { snprintf (status, sizeof (status), "stopping"); e = &ewarn; retval = rc_service_stopping; - } else if (rc_service_state (service, rc_service_starting) == 0) { + } else if (rc_service_state (service, rc_service_starting)) { snprintf (status, sizeof (status), "starting"); e = &ewarn; retval = rc_service_starting; - } else if (rc_service_state (service, rc_service_inactive) == 0) { + } else if (rc_service_state (service, rc_service_inactive)) { snprintf (status, sizeof (status), "inactive"); e = &ewarn; retval = rc_service_inactive; - } else if (rc_service_state (service, rc_service_crashed) == 0) { + } else if (rc_service_state (service, rc_service_crashed)) { snprintf (status, sizeof (status), "crashed"); e = &eerror; retval = rc_service_crashed; - } else if (rc_service_state (service, rc_service_started) == 0) { + } else if (rc_service_state (service, rc_service_started)) { 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) == 0 && unlink (mtime_test) != 0) { + if (rc_exists (mtime_test) && unlink (mtime_test) != 0) { eerror ("%s: unlink `%s': %s", applet, mtime_test, strerror (errno)); free (mtime_test); @@ -562,33 +562,32 @@ 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") == 0 || in_background) { - if (rc_service_state (service, rc_service_inactive) != 0 && - rc_service_state (service, rc_service_stopped) != 0) + if (rc_is_env ("IN_HOTPLUG", "1") || in_background) { + if (! rc_service_state (service, rc_service_inactive) && + ! rc_service_state (service, rc_service_stopped)) exit (EXIT_FAILURE); background = true; } - if (rc_service_state (service, rc_service_started) == 0) { + if (rc_service_state (service, rc_service_started)) { ewarn ("WARNING: %s has already been started", applet); return; - } else if (rc_service_state (service, rc_service_starting) == 0) + } else if (rc_service_state (service, rc_service_starting)) ewarnx ("WARNING: %s is already starting", applet); - else if (rc_service_state (service, rc_service_stopping) == 0) + else if (rc_service_state (service, rc_service_stopping)) ewarnx ("WARNING: %s is stopping", applet); - else if (rc_service_state (service, rc_service_inactive) == 0 && - ! background) + else if (rc_service_state (service, rc_service_inactive) && ! background) ewarnx ("WARNING: %s has already started, but is inactive", applet); - if (rc_mark_service (service, rc_service_starting) != 0) + if (! rc_mark_service (service, rc_service_starting)) eerrorx ("ERROR: %s has been started by something else", applet); make_exclusive (service); - if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0) + if (rc_is_env ("RC_DEPEND_STRICT", "yes")) depoptions |= RC_DEP_STRICT; - if (rc_runlevel_starting () == 0) + if (rc_runlevel_starting ()) depoptions |= RC_DEP_START; if (deps) { @@ -627,11 +626,11 @@ static void svc_start (bool deps) use_services = rc_get_depends (deptree, types, svclist, softlevel, depoptions); - if (! rc_runlevel_starting () == 0) { + if (! rc_runlevel_starting ()) { STRLIST_FOREACH (use_services, svc, i) - if (rc_service_state (svc, rc_service_stopped) == 0) { + if (rc_service_state (svc, rc_service_stopped)) { pid_t pid = rc_start_service (svc); - if (rc_is_env ("RC_PARALLEL", "yes") != 0) + if (! rc_is_env ("RC_PARALLEL", "yes")) rc_waitpid (pid); } } @@ -646,14 +645,13 @@ static void svc_start (bool deps) tmplist = NULL; STRLIST_FOREACH (services, svc, i) { - if (rc_service_state (svc, rc_service_started) == 0) + if (rc_service_state (svc, rc_service_started)) 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) == 0 && - rc_service_state (svc, rc_service_wasinactive) == 0) - { + if (rc_service_state (svc, rc_service_starting) && + rc_service_state(svc, rc_service_wasinactive)) { bool use = false; STRLIST_FOREACH (use_services, svc2, j) if (strcmp (svc, svc2) == 0) { @@ -664,15 +662,15 @@ static void svc_start (bool deps) continue; } - if (rc_wait_service (svc) != 0) + if (! rc_wait_service (svc)) eerror ("%s: timed out waiting for %s", applet, svc); - if (rc_service_state (svc, rc_service_started) == 0) + if (rc_service_state (svc, rc_service_started)) continue; STRLIST_FOREACH (need_services, svc2, j) if (strcmp (svc, svc2) == 0) { - if (rc_service_state (svc, rc_service_inactive) == 0 || - rc_service_state (svc, rc_service_wasinactive) == 0) + if (rc_service_state (svc, rc_service_inactive) || + rc_service_state (svc, rc_service_wasinactive)) rc_strlist_add (&tmplist, svc); else eerrorx ("ERROR: cannot start %s as %s would not start", @@ -742,11 +740,11 @@ static void svc_start (bool deps) if (in_control ()) { if (! started) { - if (rc_service_state (service, rc_service_wasinactive) == 0) + if (rc_service_state (service, rc_service_wasinactive)) rc_mark_service (service, rc_service_inactive); else { rc_mark_service (service, rc_service_stopped); - if (rc_runlevel_starting () == 0) + if (rc_runlevel_starting ()) rc_mark_service (service, rc_service_failed); } rc_plugin_run (rc_hook_service_start_done, applet); @@ -757,7 +755,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) == 0) + if (rc_service_state (service, rc_service_inactive)) ewarnx ("WARNING: %s has started, but is inactive", applet); else ewarnx ("WARNING: %s not under our control, aborting", applet); @@ -767,7 +765,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) == 0) + if (rc_service_state (svc, rc_service_stopped)) rc_start_service (svc); rc_strlist_free (services); services = NULL; @@ -786,7 +784,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) == 0) + if (rc_service_state (svc, rc_service_stopped)) rc_start_service (svc); } @@ -800,39 +798,39 @@ static void svc_stop (bool deps) hook_out = rc_hook_service_stop_out; - if (rc_runlevel_stopping () == 0 && - rc_service_state (service, rc_service_failed) == 0) + if (rc_runlevel_stopping () && + rc_service_state (service, rc_service_failed)) exit (EXIT_FAILURE); - 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) + if (rc_is_env ("IN_HOTPLUG", "1") || in_background) + if (! rc_service_state (service, rc_service_started) && + ! rc_service_state (service, rc_service_inactive)) exit (EXIT_FAILURE); - if (rc_service_state (service, rc_service_stopped) == 0) { + if (rc_service_state (service, rc_service_stopped)) { ewarn ("WARNING: %s is already stopped", applet); return; - } else if (rc_service_state (service, rc_service_stopping) == 0) + } else if (rc_service_state (service, rc_service_stopping)) ewarnx ("WARNING: %s is already stopping", applet); - if (rc_mark_service (service, rc_service_stopping) != 0) + if (! rc_mark_service (service, rc_service_stopping)) eerrorx ("ERROR: %s has been stopped by something else", applet); make_exclusive (service); - if (rc_runlevel_stopping () != 0 && - rc_service_in_runlevel (service, RC_LEVEL_BOOT) == 0) + if (! rc_runlevel_stopping () && + rc_service_in_runlevel (service, RC_LEVEL_BOOT)) ewarn ("WARNING: you are stopping a boot service"); - if (deps && rc_service_state (service, rc_service_wasinactive) != 0) { + if (deps && ! rc_service_state (service, rc_service_wasinactive)) { int depoptions = RC_DEP_TRACE; char *svc; int i; - if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0) + if (rc_is_env ("RC_DEPEND_STRICT", "yes")) depoptions |= RC_DEP_STRICT; - if (rc_runlevel_stopping () == 0) + if (rc_runlevel_stopping ()) depoptions |= RC_DEP_STOP; if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) @@ -851,15 +849,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) == 0 || - rc_service_state (svc, rc_service_inactive) == 0) + if (rc_service_state (svc, rc_service_started) || + rc_service_state (svc, rc_service_inactive)) { rc_wait_service (svc); - if (rc_service_state (svc, rc_service_started) == 0 || - rc_service_state (svc, rc_service_inactive) == 0) + if (rc_service_state (svc, rc_service_started) || + rc_service_state (svc, rc_service_inactive)) { pid_t pid = rc_stop_service (svc); - if (rc_is_env ("RC_PARALLEL", "yes") == 0) + if (! rc_is_env ("RC_PARALLEL", "yes")) rc_waitpid (pid); rc_strlist_add (&tmplist, svc); } @@ -869,14 +867,14 @@ static void svc_stop (bool deps) services = NULL; STRLIST_FOREACH (tmplist, svc, i) { - if (rc_service_state (svc, rc_service_stopped) == 0) + if (rc_service_state (svc, rc_service_stopped)) 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) == 0) { + if (! rc_service_state (svc, rc_service_stopped)) { - if (rc_runlevel_stopping () == 0) { + if (rc_runlevel_stopping ()) { /* If shutting down, we should stop even if a dependant failed */ if (softlevel && (strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 || @@ -900,7 +898,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) == 0) + if (rc_service_state (svc, rc_service_stopped)) continue; rc_wait_service (svc); } @@ -924,7 +922,7 @@ static void svc_stop (bool deps) } if (! stopped) { - if (rc_service_state (service, rc_service_wasinactive) == 0) + if (rc_service_state (service, rc_service_wasinactive)) rc_mark_service (service, rc_service_inactive); else rc_mark_service (service, rc_service_started); @@ -954,15 +952,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) == 0 || - rc_service_state (service, rc_service_inactive) == 0) + if (rc_service_state (service, rc_service_started) || + rc_service_state (service, rc_service_inactive)) svc_exec ("stop", "start"); else svc_exec ("start", NULL); return; } - if (! rc_service_state (service, rc_service_stopped) == 0) { + if (! rc_service_state (service, rc_service_stopped)) { get_started_services (); svc_stop (deps); } @@ -1030,7 +1028,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") == 0) { + if (rc_exists ("/dev/.rcsysinit")) { 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)); @@ -1090,7 +1088,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") == 0) { + if (rc_is_env ("RC_PARALLEL", "yes")) { int l = 0; int ll; @@ -1132,7 +1130,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) != 0) + if (! rc_service_state (service, rc_service_started)) exit (EXIT_FAILURE); break; case 'C': @@ -1154,13 +1152,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") == 0); + in_background = rc_is_env ("IN_BACKGROUND", "true"); ibsave = rc_xstrdup (getenv ("IN_BACKGROUND")); unsetenv ("IN_BACKGROUND"); } - if (rc_is_env ("IN_HOTPLUG", "1") == 0) { - if (rc_is_env ("RC_HOTPLUG", "yes") != 0 || rc_allow_plug (applet) != 0) + if (rc_is_env ("IN_HOTPLUG", "1")) { + if (! rc_is_env ("RC_HOTPLUG", "yes") || ! rc_allow_plug (applet)) eerrorx ("%s: not allowed to be hotplugged", applet); } @@ -1212,7 +1210,7 @@ int runscript (int argc, char **argv) strcmp (optarg, "iprovide") == 0) { int depoptions = RC_DEP_TRACE; - if (rc_is_env ("RC_DEPEND_STRICT", "yes") == 0) + if (rc_is_env ("RC_DEPEND_STRICT", "yes")) depoptions |= RC_DEP_STRICT; if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) @@ -1246,7 +1244,7 @@ int runscript (int argc, char **argv) if (strcmp (optarg, "conditionalrestart") == 0 || strcmp (optarg, "condrestart") == 0) { - if (rc_service_state (service, rc_service_started) == 0) + if (rc_service_state (service, rc_service_started)) svc_restart (deps); } else if (strcmp (optarg, "restart") == 0) { svc_restart (deps); @@ -1260,16 +1258,16 @@ int runscript (int argc, char **argv) if (deps) { if (! in_background && - rc_runlevel_stopping () != 0 && - rc_service_state (service, rc_service_stopped) == 0) + ! rc_runlevel_stopping () && + rc_service_state (service, rc_service_stopped)) uncoldplug (); if (in_background && - rc_service_state (service, rc_service_inactive) == 0) + rc_service_state (service, rc_service_inactive)) { int j; STRLIST_FOREACH (restart_services, svc, j) - if (rc_service_state (svc, rc_service_stopped) == 0) + if (rc_service_state (svc, rc_service_stopped)) rc_schedule_start_service (service, svc); } } diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index fc5fccb8..1b4c7f28 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) != 0) { + if (! rc_is_file (tmp)) { 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) == 0) + if (pidfile && rc_is_file (pidfile)) unlink (pidfile); if (svcname)