We no longer use bool in our public headers, using int instead.

This commit is contained in:
Roy Marples 2007-09-25 17:19:02 +00:00
parent b24e877948
commit 1a6451654f
14 changed files with 365 additions and 378 deletions

View File

@ -1,6 +1,11 @@
# ChangeLog for Gentoo System Intialization ("rc") scripts # ChangeLog for Gentoo System Intialization ("rc") scripts
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2 # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPLv2
25 Sep 2007; Roy Marples <uberlord@gentoo.org>:
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 <vapier@gentoo.org>: 25 Sep 2007; Mike Frysinger <vapier@gentoo.org>:
Skip consolefont setup when RC_TTY_NUMBER is set to 0. Skip consolefont setup when RC_TTY_NUMBER is set to 0.

View File

@ -134,7 +134,7 @@ int env_update (int argc, char **argv)
char **entries = NULL; char **entries = NULL;
j = strlen (file); j = strlen (file);
if (! rc_is_dir (path) && if (rc_is_dir (path) != 0 &&
j > 2 && j > 2 &&
*file >= '0' && *file >= '0' &&
*file <= '9' && *file <= '9' &&
@ -297,7 +297,7 @@ int env_update (int argc, char **argv)
if (ldconfig) { if (ldconfig) {
/* Update ld.so.conf only if different */ /* Update ld.so.conf only if different */
if (rc_exists (LDSOCONF)) { if (rc_exists (LDSOCONF) == 0) {
char **lines = rc_get_list (LDSOCONF); char **lines = rc_get_list (LDSOCONF);
char *line; char *line;
ld = false; ld = false;

View File

@ -147,7 +147,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
librc_hidden_def(rc_find_pids) librc_hidden_def(rc_find_pids)
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \ #elif defined(__DragonFly__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__OpenBSD__) defined(__NetBSD__) || defined(__OpenBSD__)
# if defined(__DragonFly__) || defined(__FreeBSD__) # if defined(__DragonFly__) || defined(__FreeBSD__)
# ifndef KERN_PROC_PROC # ifndef KERN_PROC_PROC
@ -228,9 +228,9 @@ librc_hidden_def(rc_find_pids)
# error "Platform not supported!" # error "Platform not supported!"
#endif #endif
static bool _match_daemon (const char *path, const char *file, static int _match_daemon (const char *path, const char *file,
const char *mexec, const char *mname, const char *mexec, const char *mname,
const char *mpidfile) const char *mpidfile)
{ {
char buffer[RC_LINEBUFFER]; char buffer[RC_LINEBUFFER];
char *ffile = rc_strcatpaths (path, file, (char *) NULL); 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 lc = 0;
int m = 0; int m = 0;
if (! rc_exists (ffile)) { if (rc_exists (ffile) != 0) {
free (ffile); free (ffile);
return (false); return (-1);
} }
if ((fp = fopen (ffile, "r")) == NULL) { if ((fp = fopen (ffile, "r")) == NULL) {
eerror ("fopen `%s': %s", ffile, strerror (errno)); eerror ("fopen `%s': %s", ffile, strerror (errno));
free (ffile); free (ffile);
return (false); return (-1);
} }
if (! mname) if (! mname)
@ -277,12 +277,12 @@ static bool _match_daemon (const char *path, const char *file,
fclose (fp); fclose (fp);
free (ffile); free (ffile);
return (m == 111 ? true : false); return (m == 111 ? 0 : -1);
} }
void rc_set_service_daemon (const char *service, const char *exec, int rc_set_service_daemon (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started) bool started)
{ {
char *svc = rc_xstrdup (service); char *svc = rc_xstrdup (service);
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), 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 *mname;
char *mpidfile; char *mpidfile;
int nfiles = 0; int nfiles = 0;
int retval = -1;
free (svc); free (svc);
if (! exec && ! name && ! pidfile) if (! exec && ! name && ! pidfile)
return; return (-1);
if (exec) { if (exec) {
i = strlen (exec) + 6; i = strlen (exec) + 6;
@ -322,7 +323,7 @@ void rc_set_service_daemon (const char *service, const char *exec,
mpidfile = rc_xstrdup ("pidfile="); mpidfile = rc_xstrdup ("pidfile=");
/* Regardless, erase any existing daemon info */ /* Regardless, erase any existing daemon info */
if (rc_is_dir (dirpath)) { if (rc_is_dir (dirpath) == 0) {
char *oldfile = NULL; char *oldfile = NULL;
files = rc_ls_dir (dirpath, 0); files = rc_ls_dir (dirpath, 0);
STRLIST_FOREACH (files, file, i) { STRLIST_FOREACH (files, file, i) {
@ -330,7 +331,7 @@ void rc_set_service_daemon (const char *service, const char *exec,
nfiles++; nfiles++;
if (! oldfile) { if (! oldfile) {
if (_match_daemon (dirpath, file, mexec, mname, mpidfile)) { if (_match_daemon (dirpath, file, mexec, mname, mpidfile) == 0) {
unlink (ffile); unlink (ffile);
oldfile = ffile; oldfile = ffile;
nfiles--; nfiles--;
@ -350,7 +351,7 @@ void rc_set_service_daemon (const char *service, const char *exec,
char buffer[10]; char buffer[10];
FILE *fp; FILE *fp;
if (! rc_is_dir (dirpath)) if (rc_is_dir (dirpath) != 0)
if (mkdir (dirpath, 0755) != 0) if (mkdir (dirpath, 0755) != 0)
eerror ("mkdir `%s': %s", dirpath, strerror (errno)); 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)); eerror ("fopen `%s': %s", file, strerror (errno));
else { else {
fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
retval = 0;
fclose (fp); fclose (fp);
} }
free (file); free (file);
@ -369,30 +371,32 @@ void rc_set_service_daemon (const char *service, const char *exec,
free (mname); free (mname);
free (mpidfile); free (mpidfile);
free (dirpath); free (dirpath);
return (retval);
} }
librc_hidden_def(rc_set_service_daemon) librc_hidden_def(rc_set_service_daemon)
bool rc_service_started_daemon (const char *service, const char *exec, int rc_service_started_daemon (const char *service, const char *exec,
int indx) int indx)
{ {
char *dirpath; char *dirpath;
char *file; char *file;
int i; int i;
char *mexec; char *mexec;
bool retval = false; int retval = -1;
char *svc; char *svc;
if (! service || ! exec) if (! service || ! exec)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
if (! rc_is_dir (dirpath)) { if (rc_is_dir (dirpath) != 0) {
free (dirpath); free (dirpath);
return (false); return (-1);
} }
i = strlen (exec) + 6; 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); char **files = rc_ls_dir (dirpath, 0);
STRLIST_FOREACH (files, file, i) { STRLIST_FOREACH (files, file, i) {
retval = _match_daemon (dirpath, file, mexec, NULL, NULL); retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
if (retval) if (retval == 0)
break; break;
} }
rc_strlist_free (files); 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) 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 *dirpath;
char **files; char **files;
@ -436,20 +440,20 @@ bool rc_service_daemons_crashed (const char *service)
pid_t *pids = NULL; pid_t *pids = NULL;
char *p; char *p;
char *token; char *token;
bool retval = false; int retval = -1;
char *svc; char *svc;
if (! service) if (! service)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
if (! rc_is_dir (dirpath)) { if (rc_is_dir (dirpath) != 0) {
free (dirpath); free (dirpath);
return (false); return (-1);
} }
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
@ -493,21 +497,21 @@ bool rc_service_daemons_crashed (const char *service)
pid = 0; pid = 0;
if (pidfile) { if (pidfile) {
if (! rc_exists (pidfile)) { if (rc_exists (pidfile) != 0) {
retval = true; retval = 0;
break; break;
} }
if ((fp = fopen (pidfile, "r")) == NULL) { if ((fp = fopen (pidfile, "r")) == NULL) {
eerror ("fopen `%s': %s", pidfile, strerror (errno)); eerror ("fopen `%s': %s", pidfile, strerror (errno));
retval = true; retval = 0;
break; break;
} }
if (fscanf (fp, "%d", &pid) != 1) { if (fscanf (fp, "%d", &pid) != 1) {
eerror ("no pid found in `%s'", pidfile); eerror ("no pid found in `%s'", pidfile);
fclose (fp); fclose (fp);
retval = true; retval = 0;
break; break;
} }
@ -523,7 +527,7 @@ bool rc_service_daemons_crashed (const char *service)
} }
if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) { if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) {
retval = true; retval = 0;
break; break;
} }
free (pids); free (pids);

View File

@ -185,10 +185,10 @@ librc_hidden_def(rc_get_deptype)
static bool valid_service (const char *runlevel, const char *service) static bool valid_service (const char *runlevel, const char *service)
{ {
return ((strcmp (runlevel, bootlevel) != 0 && return ((strcmp (runlevel, bootlevel) != 0 &&
rc_service_in_runlevel (service, bootlevel)) || rc_service_in_runlevel (service, bootlevel) == 0) ||
rc_service_in_runlevel (service, runlevel) || rc_service_in_runlevel (service, runlevel) == 0 ||
rc_service_state (service, rc_service_coldplugged) || rc_service_state (service, rc_service_coldplugged) == 0 ||
rc_service_state (service, rc_service_started)); rc_service_state (service, rc_service_started) == 0);
} }
static bool get_provided1 (const char *runlevel, struct lhead *providers, 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; bool ok = true;
if (level) if (level)
ok = rc_service_in_runlevel (service, level); ok = (rc_service_in_runlevel (service, level) == 0);
else if (coldplugged) else if (coldplugged)
ok = (rc_service_state (service, rc_service_coldplugged) && ok = (rc_service_state (service, rc_service_coldplugged) == 0 &&
! rc_service_in_runlevel (service, runlevel) && rc_service_in_runlevel (service, runlevel) != 0 &&
! rc_service_in_runlevel (service, bootlevel)); rc_service_in_runlevel (service, bootlevel) != 0);
if (! ok) if (! ok)
continue; continue;
switch (state) { switch (state) {
case rc_service_started: case rc_service_started:
ok = rc_service_state (service, state); ok = (rc_service_state (service, state) == 0);
break; break;
case rc_service_inactive: case rc_service_inactive:
case rc_service_starting: case rc_service_starting:
case rc_service_stopping: case rc_service_stopping:
ok = (rc_service_state (service, rc_service_starting) || ok = (rc_service_state (service, rc_service_starting) == 0 ||
rc_service_state (service, rc_service_stopping) || rc_service_state (service, rc_service_stopping) == 0 ||
rc_service_state (service, rc_service_inactive)); rc_service_state (service, rc_service_inactive) == 0);
break; break;
default: default:
break; break;
@ -257,7 +257,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (! deptree || ! depinfo) if (! deptree || ! depinfo)
return (NULL); return (NULL);
if (rc_service_exists (depinfo->service)) if (rc_service_exists (depinfo->service) == -1)
return (NULL); return (NULL);
dt = rc_get_deptype (depinfo, "providedby"); 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) if (options & RC_DEP_STRICT)
{ {
STRLIST_FOREACH (dt->services, service, i) STRLIST_FOREACH (dt->services, service, i)
if (rc_service_in_runlevel (service, runlevel) || if (rc_service_in_runlevel (service, runlevel) == 0 ||
rc_service_in_runlevel (service, bootlevel)) rc_service_in_runlevel (service, bootlevel) == 0)
rc_strlist_add (&providers.list, service); rc_strlist_add (&providers.list, service);
if (providers.list) if (providers.list)
@ -556,7 +556,7 @@ static bool is_newer_than (const char *file, const char *target)
if (mtime < buf.st_mtime) if (mtime < buf.st_mtime)
return (false); return (false);
if (rc_is_dir (target)) if (rc_is_dir (target) == 0)
{ {
char **targets = rc_ls_dir (target, 0); char **targets = rc_ls_dir (target, 0);
char *t; char *t;
@ -641,7 +641,7 @@ int rc_update_deptree (bool force)
/* Create base directories if needed */ /* Create base directories if needed */
for (i = 0; depdirs[i]; i++) 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) if (mkdir (depdirs[i], 0755) != 0)
eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno)); 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 /* Some init scripts dependencies change depending on config files
* outside of baselayout, like syslog-ng, so we check those too. */ * outside of baselayout, like syslog-ng, so we check those too. */
if (! rc_exists (RC_DEPCONFIG)) if (rc_exists (RC_DEPCONFIG) != 0)
return 0; return 0;
config = rc_get_list (RC_DEPCONFIG); config = rc_get_list (RC_DEPCONFIG);

View File

@ -57,18 +57,18 @@ char *rc_xstrdup (const char *str)
} }
librc_hidden_def(rc_xstrdup) 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; char *v;
if (! var) if (! var)
return (false); return (-1);
v = getenv (var); v = getenv (var);
if (! v) 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) librc_hidden_def(rc_is_env)
@ -123,78 +123,58 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
} }
librc_hidden_def(rc_strcatpaths) librc_hidden_def(rc_strcatpaths)
bool rc_exists (const char *pathname) int rc_exists (const char *pathname)
{ {
struct stat buf; struct stat buf;
if (! pathname) if (! pathname)
return (false); return (-1);
if (stat (pathname, &buf) == 0) return (stat (pathname, &buf));
return (true);
errno = 0;
return (false);
} }
librc_hidden_def(rc_exists) librc_hidden_def(rc_exists)
bool rc_is_file (const char *pathname) int rc_is_file (const char *pathname)
{ {
struct stat buf; struct stat buf;
if (! pathname) if (pathname && stat (pathname, &buf) == 0)
return (false); return (S_ISREG (buf.st_mode) ? 0 : -1);
if (stat (pathname, &buf) == 0) return (-1);
return (S_ISREG (buf.st_mode));
errno = 0;
return (false);
} }
librc_hidden_def(rc_is_file) librc_hidden_def(rc_is_file)
bool rc_is_dir (const char *pathname) int rc_is_dir (const char *pathname)
{ {
struct stat buf; struct stat buf;
if (! pathname) if (pathname && stat (pathname, &buf) == 0)
return (false); return (S_ISDIR (buf.st_mode) ? 0 : -1);
if (stat (pathname, &buf) == 0) return (-1);
return (S_ISDIR (buf.st_mode));
errno = 0;
return (false);
} }
librc_hidden_def(rc_is_dir) librc_hidden_def(rc_is_dir)
bool rc_is_link (const char *pathname) int rc_is_link (const char *pathname)
{ {
struct stat buf; struct stat buf;
if (! pathname) if (pathname && lstat (pathname, &buf) == 0)
return (false); return (S_ISLNK (buf.st_mode) ? 0 : -1);
if (lstat (pathname, &buf) == 0) return (-1);
return (S_ISLNK (buf.st_mode));
errno = 0;
return (false);
} }
librc_hidden_def(rc_is_link) librc_hidden_def(rc_is_link)
bool rc_is_exec (const char *pathname) int rc_is_exec (const char *pathname)
{ {
struct stat buf; struct stat buf;
if (! pathname) if (pathname && lstat (pathname, &buf) == 0)
return (false); return (buf.st_mode & S_IXUGO ? 0 : -1);
if (lstat (pathname, &buf) == 0) return (-1);
return (buf.st_mode & S_IXUGO);
errno = 0;
return (false);
} }
librc_hidden_def(rc_is_exec) 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); int l = strlen (d->d_name);
char *init = rc_strcatpaths (RC_INITDIR, d->d_name, char *init = rc_strcatpaths (RC_INITDIR, d->d_name,
(char *) NULL); (char *) NULL);
bool ok = rc_exists (init); int ok = rc_exists (init);
free (init); free (init);
if (! ok) if (ok != 0)
continue; continue;
/* .sh files are not init scripts */ /* .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) 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; DIR *dp;
struct dirent *d; struct dirent *d;
if (! pathname) if (! pathname)
return (false); return (-1);
if ((dp = opendir (pathname)) == NULL) { if ((dp = opendir (pathname)) == NULL) {
eerror ("failed to opendir `%s': %s", pathname, strerror (errno)); eerror ("failed to opendir `%s': %s", pathname, strerror (errno));
return (false); return (-1);
} }
errno = 0; 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) { if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) {
char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL); char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
if (d->d_type == DT_DIR) { if (d->d_type == DT_DIR) {
if (! rc_rm_dir (tmp, true)) if (rc_rm_dir (tmp, true) != 0)
{ {
free (tmp); free (tmp);
closedir (dp); closedir (dp);
return (false); return (-1);
} }
} else { } else {
if (unlink (tmp)) { if (unlink (tmp)) {
eerror ("failed to unlink `%s': %s", tmp, strerror (errno)); eerror ("failed to unlink `%s': %s", tmp, strerror (errno));
free (tmp); free (tmp);
closedir (dp); closedir (dp);
return (false); return (-1);
} }
} }
free (tmp); free (tmp);
@ -286,10 +266,10 @@ bool rc_rm_dir (const char *pathname, bool top)
if (top && rmdir (pathname) != 0) { if (top && rmdir (pathname) != 0) {
eerror ("failed to rmdir `%s': %s", pathname, strerror (errno)); eerror ("failed to rmdir `%s': %s", pathname, strerror (errno));
return false; return (-1);
} }
return (true); return (0);
} }
librc_hidden_def(rc_rm_dir) librc_hidden_def(rc_rm_dir)
@ -462,7 +442,7 @@ char **rc_filter_env (void)
if (! whitelist) if (! whitelist)
return (NULL); return (NULL);
if (rc_is_file (PROFILE_ENV)) if (rc_is_file (PROFILE_ENV) == 0)
profile = rc_get_config (PROFILE_ENV); profile = rc_get_config (PROFILE_ENV);
STRLIST_FOREACH (whitelist, env_name, count) { STRLIST_FOREACH (whitelist, env_name, count) {
@ -544,7 +524,7 @@ static bool file_regex (const char *file, const char *regex)
bool retval = false; bool retval = false;
int result; int result;
if (! rc_exists (file)) if (rc_exists (file) != 0)
return (false); return (false);
if (! (fp = fopen (file, "r"))) { if (! (fp = fopen (file, "r"))) {
@ -592,7 +572,7 @@ char **rc_make_env (void)
/* Don't trust environ for softlevel yet */ /* Don't trust environ for softlevel yet */
snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel); snprintf (buffer, PATH_MAX, "%s.%s", RC_CONFIG, runlevel);
if (rc_exists (buffer)) if (rc_exists (buffer) == 0)
config = rc_get_config (buffer); config = rc_get_config (buffer);
else else
config = rc_get_config (RC_CONFIG); config = rc_get_config (RC_CONFIG);
@ -639,7 +619,7 @@ char **rc_make_env (void)
rc_strlist_add (&env, line); rc_strlist_add (&env, line);
free (line); free (line);
if (rc_exists (RC_KSOFTLEVEL)) { if (rc_exists (RC_KSOFTLEVEL) == 0) {
if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) if (! (fp = fopen (RC_KSOFTLEVEL, "r")))
eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno)); eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno));
else { else {
@ -665,7 +645,7 @@ char **rc_make_env (void)
We store this special system in RC_SYS so our scripts run fast */ We store this special system in RC_SYS so our scripts run fast */
memset (sys, 0, sizeof (sys)); memset (sys, 0, sizeof (sys));
if (rc_is_dir ("/proc/xen")) { if (rc_is_dir ("/proc/xen") == 0) {
fp = fopen ("/proc/xen/capabilities", "r"); fp = fopen ("/proc/xen/capabilities", "r");
if (fp) { if (fp) {
fclose (fp); fclose (fp);

View File

@ -31,13 +31,13 @@ static const char *rc_service_state_names[] = {
NULL NULL
}; };
bool rc_runlevel_starting (void) int rc_runlevel_starting (void)
{ {
return (rc_is_dir (RC_STARTING)); return (rc_is_dir (RC_STARTING));
} }
librc_hidden_def(rc_runlevel_starting) librc_hidden_def(rc_runlevel_starting)
bool rc_runlevel_stopping (void) int rc_runlevel_stopping (void)
{ {
return (rc_is_dir (RC_STOPPING)); return (rc_is_dir (RC_STOPPING));
} }
@ -52,7 +52,7 @@ char **rc_get_runlevels (void)
STRLIST_FOREACH (dirs, dir, i) { STRLIST_FOREACH (dirs, dir, i) {
char *path = rc_strcatpaths (RC_RUNLEVELDIR, dir, (char *) NULL); 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); rc_strlist_addsort (&runlevels, dir);
free (path); free (path);
} }
@ -95,13 +95,13 @@ void rc_set_runlevel (const char *runlevel)
} }
librc_hidden_def(rc_set_runlevel) librc_hidden_def(rc_set_runlevel)
bool rc_runlevel_exists (const char *runlevel) int rc_runlevel_exists (const char *runlevel)
{ {
char *path; char *path;
bool retval; int retval;
if (! runlevel) if (! runlevel)
return (false); return (-1);
path = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); path = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL);
retval = rc_is_dir (path); retval = rc_is_dir (path);
@ -124,10 +124,10 @@ char *rc_resolve_service (const char *service)
return (rc_xstrdup (service)); return (rc_xstrdup (service));
file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "started", service, (char *) NULL);
if (! rc_is_link (file)) { if (rc_is_link (file) != 0) {
free (file); free (file);
file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL);
if (! rc_is_link (file)) { if (rc_is_link (file) != 0) {
free (file); free (file);
file = NULL; file = NULL;
} }
@ -146,14 +146,14 @@ char *rc_resolve_service (const char *service)
} }
librc_hidden_def(rc_resolve_service) librc_hidden_def(rc_resolve_service)
bool rc_service_exists (const char *service) int rc_service_exists (const char *service)
{ {
char *file; char *file;
bool retval = false; int retval = -1;
int len; int len;
if (! service) if (! service)
return (false); return (-1);
len = strlen (service); len = strlen (service);
@ -161,11 +161,10 @@ bool rc_service_exists (const char *service)
if (len > 2 && service[len - 3] == '.' && if (len > 2 && service[len - 3] == '.' &&
service[len - 2] == 's' && service[len - 2] == 's' &&
service[len - 1] == 'h') service[len - 1] == 'h')
return (false); return (-1);
file = rc_resolve_service (service); file = rc_resolve_service (service);
if (rc_exists (file)) retval = rc_is_exec (file);
retval = rc_is_exec (file);
free (file); free (file);
return (retval); return (retval);
} }
@ -247,14 +246,14 @@ char *rc_service_description (const char *service, const char *option)
} }
librc_hidden_def(rc_service_description) 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; char *file;
bool retval; int retval;
char *svc; char *svc;
if (! runlevel || ! service) if (! runlevel || ! service)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), 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) 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; char *file;
int i = 0; int i = 0;
@ -278,21 +277,21 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
bool skip_wasinactive = false; bool skip_wasinactive = false;
if (! service) if (! service)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
base = basename (svc); base = basename (svc);
if (state != rc_service_stopped) { if (state != rc_service_stopped) {
if (! rc_is_file(init)) { if (rc_is_file(init) != 0) {
free (init); free (init);
free (svc); free (svc);
return (false); return (-1);
} }
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base, file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file) == 0)
unlink (file); unlink (file);
i = symlink (init, file); i = symlink (init, file);
if (i != 0) { if (i != 0) {
@ -300,7 +299,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
free (file); free (file);
free (init); free (init);
free (svc); free (svc);
return (false); return (-1);
} }
free (file); free (file);
@ -310,7 +309,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
if (state == rc_service_coldplugged) { if (state == rc_service_coldplugged) {
free (init); free (init);
free (svc); free (svc);
return (true); return (0);
} }
/* Remove any old states now */ /* 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, file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) { if (rc_exists (file) == 0) {
if ((state == rc_service_starting || if ((state == rc_service_starting ||
state == rc_service_stopping) && state == rc_service_stopping) &&
i == rc_service_inactive) 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) state == rc_service_inactive)
{ {
file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
if (rc_exists (file)) if (rc_exists (file) == 0)
if (unlink (file) != 0) if (unlink (file) != 0)
eerror ("unlink `%s': %s", file, strerror (errno)); eerror ("unlink `%s': %s", file, strerror (errno));
free (file); free (file);
@ -368,12 +367,12 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
if (state == rc_service_stopped) { if (state == rc_service_stopped) {
char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL); 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); rc_rm_dir (dir, true);
free (dir); free (dir);
dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL); 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); rc_rm_dir (dir, true);
free (dir); free (dir);
@ -390,7 +389,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
STRLIST_FOREACH (dirs, dir, i) { STRLIST_FOREACH (dirs, dir, i) {
char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL); char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL);
file = rc_strcatpaths (bdir, base, (char *) NULL); file = rc_strcatpaths (bdir, base, (char *) NULL);
if (rc_exists (file)) if (rc_exists (file) == 0)
if (unlink (file) != 0) if (unlink (file) != 0)
eerror ("unlink `%s': %s", file, strerror (errno)); eerror ("unlink `%s': %s", file, strerror (errno));
free (file); free (file);
@ -407,11 +406,11 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
free (svc); free (svc);
free (init); free (init);
return (true); return (0);
} }
librc_hidden_def(rc_mark_service) 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; char *file;
bool retval; 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 the init script does not exist then we are stopped */
if (! rc_service_exists (service)) 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 */ /* We check stopped state by not being in any of the others */
if (state == rc_service_stopped) if (state == rc_service_stopped)
return ( ! (rc_service_state (service, rc_service_started) || return (rc_service_state (service, rc_service_started) |
rc_service_state (service, rc_service_starting) || rc_service_state (service, rc_service_starting) |
rc_service_state (service, rc_service_stopping) || rc_service_state (service, rc_service_stopping) |
rc_service_state (service, rc_service_inactive))); rc_service_state (service, rc_service_inactive));
/* The crashed state and scheduled states are virtual */ /* The crashed state and scheduled states are virtual */
if (state == rc_service_crashed) if (state == rc_service_crashed)
return (rc_service_daemons_crashed (service)); return (rc_service_daemons_crashed (service));
else if (state == rc_service_scheduled) { else if (state == rc_service_scheduled) {
char **services = rc_services_scheduled_by (service); char **services = rc_services_scheduled_by (service);
retval = (services); rc_strlist_free (services);
if (services) return (services ? 0 : -1);
free (services);
return (retval);
} }
/* Now we just check if a file by the service name rc_exists /* 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 *) NULL);
char *value = NULL; char *value = NULL;
if (rc_exists (file)) { if (rc_exists (file) == 0) {
if ((fp = fopen (file, "r")) == NULL) if ((fp = fopen (file, "r")) == NULL)
eerror ("fopen `%s': %s", file, strerror (errno)); eerror ("fopen `%s': %s", file, strerror (errno));
else { else {
@ -475,20 +472,20 @@ char *rc_get_service_option (const char *service, const char *option)
} }
librc_hidden_def(rc_get_service_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) const char *value)
{ {
FILE *fp; FILE *fp;
char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL); char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL);
char *file = rc_strcatpaths (path, option, (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) { if (mkdir (path, 0755) != 0) {
eerror ("mkdir `%s': %s", path, strerror (errno)); eerror ("mkdir `%s': %s", path, strerror (errno));
free (path); free (path);
free (file); free (file);
return (false); return (-1);
} }
} }
@ -498,7 +495,7 @@ bool rc_set_service_option (const char *service, const char *option,
if (value) if (value)
fprintf (fp, "%s", value); fprintf (fp, "%s", value);
fclose (fp); fclose (fp);
retval = true; retval = 0;
} }
free (path); free (path);
@ -515,7 +512,7 @@ static pid_t _exec_service (const char *service, const char *arg)
char *svc; char *svc;
file = rc_resolve_service (service); file = rc_resolve_service (service);
if (! rc_is_file (file)) { if (rc_is_file (file) != 0) {
rc_mark_service (service, rc_service_stopped); rc_mark_service (service, rc_service_stopped);
free (file); free (file);
return (0); return (0);
@ -566,7 +563,7 @@ int rc_waitpid (pid_t pid) {
pid_t rc_stop_service (const char *service) 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 (0);
return (_exec_service (service, "stop")); return (_exec_service (service, "stop"));
@ -575,7 +572,7 @@ librc_hidden_def(rc_stop_service)
pid_t rc_start_service (const char *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 (0);
return (_exec_service (service, "start")); 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), dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
if (! rc_is_dir (dir)) if (rc_is_dir (dir) != 0)
if (mkdir (dir, 0755) != 0) { if (mkdir (dir, 0755) != 0) {
eerror ("mkdir `%s': %s", dir, strerror (errno)); eerror ("mkdir `%s': %s", dir, strerror (errno));
free (dir); free (dir);
@ -609,7 +606,7 @@ void rc_schedule_start_service (const char *service,
svc = rc_xstrdup (service_to_start); svc = rc_xstrdup (service_to_start);
file = rc_strcatpaths (dir, basename (svc), (char *) NULL); file = rc_strcatpaths (dir, basename (svc), (char *) NULL);
free (svc); 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)); eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno));
free (init); free (init);
@ -625,24 +622,24 @@ void rc_schedule_clear (const char *service)
(char *) NULL); (char *) NULL);
free (svc); free (svc);
if (rc_is_dir (dir)) if (rc_is_dir (dir) == 0)
rc_rm_dir (dir, true); rc_rm_dir (dir, true);
free (dir); free (dir);
} }
librc_hidden_def(rc_schedule_clear) librc_hidden_def(rc_schedule_clear)
bool rc_wait_service (const char *service) int rc_wait_service (const char *service)
{ {
char *svc; char *svc;
char *base; char *base;
char *fifo; char *fifo;
struct timespec ts; struct timespec ts;
int nloops = WAIT_MAX / WAIT_INTERVAL; int nloops = WAIT_MAX / WAIT_INTERVAL;
bool retval = false; int retval = -1;
bool forever = false; bool forever = false;
if (! service) if (! service)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
base = basename (svc); base = basename (svc);
@ -657,8 +654,8 @@ bool rc_wait_service (const char *service)
ts.tv_nsec = WAIT_INTERVAL; ts.tv_nsec = WAIT_INTERVAL;
while (nloops) { while (nloops) {
if (! rc_exists (fifo)) { if (rc_exists (fifo) != 0) {
retval = true; retval = 0;
break; break;
} }
@ -692,7 +689,7 @@ char **rc_services_in_runlevel (const char *runlevel)
return (NULL); return (NULL);
dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) 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); eerror ("runlevel `%s' does not exist", runlevel);
else else
list = rc_ls_dir (dir, RC_LS_INITD); list = rc_ls_dir (dir, RC_LS_INITD);
@ -729,7 +726,7 @@ char **rc_services_in_state (rc_service_state_t state)
if (dirs) if (dirs)
free (dirs); free (dirs);
} else { } else {
if (rc_is_dir (dir)) if (rc_is_dir (dir) == 0)
list = rc_ls_dir (dir, RC_LS_INITD); 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) 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 *init;
char *file; char *file;
char *svc; char *svc;
if (! rc_runlevel_exists (runlevel)) { if (! rc_runlevel_exists (runlevel)) {
errno = ENOENT; errno = ENOENT;
return (false); return (-1);
} }
if (rc_service_in_runlevel (service, runlevel)) { if (rc_service_in_runlevel (service, runlevel) == 0) {
errno = EEXIST; errno = EEXIST;
return (false); return (-1);
} }
init = rc_resolve_service (service); 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), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
retval = (symlink (init, file) == 0); retval = symlink (init, file);
free (init); free (init);
free (file); free (file);
return (retval); return (retval);
} }
librc_hidden_def(rc_service_add) 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 *file;
char *svc; char *svc;
bool retval = false; int retval;
if (! runlevel || ! service) if (! runlevel || ! service)
return (false); return (-1);
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (svc),
(char *) NULL); (char *) NULL);
free (svc); free (svc);
if (unlink (file) == 0) retval = unlink (file);
retval = true;
free (file); free (file);
return (retval); return (retval);
} }
@ -798,7 +793,7 @@ char **rc_services_scheduled_by (const char *service)
STRLIST_FOREACH (dirs, dir, i) { STRLIST_FOREACH (dirs, dir, i) {
char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service, char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file) == 0)
rc_strlist_add (&list, file); rc_strlist_add (&list, file);
free (file); free (file);
} }
@ -815,7 +810,7 @@ char **rc_services_scheduled (const char *service)
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
if (rc_is_dir (dir)) if (rc_is_dir (dir) == 0)
list = rc_ls_dir (dir, RC_LS_INITD); list = rc_ls_dir (dir, RC_LS_INITD);
free (svc); free (svc);
@ -824,23 +819,23 @@ char **rc_services_scheduled (const char *service)
} }
librc_hidden_def(rc_services_scheduled) librc_hidden_def(rc_services_scheduled)
bool rc_allow_plug (char *service) int rc_allow_plug (char *service)
{ {
char *list; char *list;
char *p; char *p;
char *star; char *star;
char *token; char *token;
bool allow = true; int allow = 0;
char *match = getenv ("RC_PLUG_SERVICES"); char *match = getenv ("RC_PLUG_SERVICES");
if (! match) if (! match)
return true; return (0);
list = rc_xstrdup (match); list = rc_xstrdup (match);
p = list; p = list;
while ((token = strsep (&p, " "))) { while ((token = strsep (&p, " "))) {
bool truefalse = true; int truefalse = 0;
if (token[0] == '!') { if (token[0] == '!') {
truefalse = false; truefalse = -1;
token++; token++;
} }

View File

@ -364,7 +364,7 @@ int mountinfo (int argc, char **argv)
continue; continue;
if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0) if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0)
continue; continue;
if (! rc_is_env ("RC_QUIET", "yes")) if (rc_is_env ("RC_QUIET", "yes") != 0)
printf ("%s\n", n); printf ("%s\n", n);
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }

View File

@ -61,7 +61,7 @@ void rc_plugin_load (void)
/* Ensure some sanity here */ /* Ensure some sanity here */
rc_plugin_unload (); rc_plugin_unload ();
if (! rc_exists (RC_PLUGINDIR)) if (rc_exists (RC_PLUGINDIR) != 0)
return; return;
files = rc_ls_dir (RC_PLUGINDIR, 0); files = rc_ls_dir (RC_PLUGINDIR, 0);

View File

@ -33,20 +33,21 @@ static void print_service (char *service)
int cols = printf (" %s\n", service); int cols = printf (" %s\n", service);
einfo_color_t color = ecolor_bad; 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 "); 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 "); snprintf (status, sizeof (status), "starting ");
color = ecolor_warn; 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 "); snprintf (status, sizeof (status), "inactive ");
color = ecolor_warn; 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 "); 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 "); snprintf (status, sizeof (status), " started ");
color = ecolor_good; 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"); snprintf (status, sizeof (status), "scheduled");
color = ecolor_warn; color = ecolor_warn;
} else } else
@ -107,7 +108,7 @@ int rc_status (int argc, char **argv)
STRLIST_FOREACH (services, service, i) { STRLIST_FOREACH (services, service, i) {
bool found = false; bool found = false;
STRLIST_FOREACH (levels, level, j) STRLIST_FOREACH (levels, level, j)
if (rc_service_in_runlevel (service, level)) { if (rc_service_in_runlevel (service, level) == 0) {
found = true; found = true;
break; break;
} }

View File

@ -33,15 +33,15 @@ static ssize_t add (const char *runlevel, const char *service)
{ {
ssize_t retval = -1; ssize_t retval = -1;
if (! rc_service_exists (service)) if (rc_service_exists (service) != 0)
eerror ("%s: service `%s' does not exist", applet, service); 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); 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", ewarn ("%s: %s already installed in runlevel `%s'; skipping",
applet, service, runlevel); applet, service, runlevel);
retval = 0; 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); einfo ("%s added to runlevel %s", service, runlevel);
retval = 1; retval = 1;
} else } else
@ -55,16 +55,16 @@ static ssize_t delete (const char *runlevel, const char *service)
{ {
ssize_t retval = -1; ssize_t retval = -1;
if (rc_service_in_runlevel (service, runlevel)) { if (rc_service_in_runlevel (service, runlevel) == 0) {
if (rc_service_delete (runlevel, service)) { if (rc_service_delete (runlevel, service) == 0) {
einfo ("%s removed from runlevel %s", service, runlevel); einfo ("%s removed from runlevel %s", service, runlevel);
retval = 1; retval = 1;
} else } else
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s", eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
applet, service, runlevel, strerror (errno)); 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); 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); eerror ("%s: runlevel `%s' does not exist", applet, runlevel);
else else
retval = 0; retval = 0;
@ -85,7 +85,7 @@ static void show (char **runlevels, bool verbose)
bool inone = false; bool inone = false;
STRLIST_FOREACH (runlevels, runlevel, j) { 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); rc_strlist_add (&in, runlevel);
inone = true; inone = true;
} else { } else {
@ -198,7 +198,7 @@ int rc_update (int argc, char **argv)
optind++; optind++;
while (optind < argc) while (optind < argc)
if (rc_runlevel_exists (argv[optind])) if (rc_runlevel_exists (argv[optind]) == 0)
rc_strlist_add (&runlevels, argv[optind++]); rc_strlist_add (&runlevels, argv[optind++]);
else { else {
rc_strlist_free (runlevels); rc_strlist_free (runlevels);

View File

@ -109,9 +109,9 @@ static void cleanup (void)
/* Clean runlevel start, stop markers */ /* Clean runlevel start, stop markers */
if (! rc_in_plugin) { if (! rc_in_plugin) {
if (rc_is_dir (RC_STARTING)) if (rc_is_dir (RC_STARTING) == 0)
rc_rm_dir (RC_STARTING, true); 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); 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) static int do_service (int argc, char **argv)
{ {
bool ok = false; int ok = -1;
if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
eerrorx ("%s: no service specified", applet); eerrorx ("%s: no service specified", applet);
@ -286,17 +286,16 @@ static int do_service (int argc, char **argv)
int idx = 0; int idx = 0;
if (argc > 2) if (argc > 2)
sscanf (argv[2], "%d", &idx); sscanf (argv[2], "%d", &idx);
exit (rc_service_started_daemon (argv[0], argv[1], idx) ok = rc_service_started_daemon (argv[0], argv[1], idx);
? 0 : 1);
} else } else
eerrorx ("%s: unknown applet", applet); eerrorx ("%s: unknown applet", applet);
return (ok ? EXIT_SUCCESS : EXIT_FAILURE); return (ok);
} }
static int do_mark_service (int argc, char **argv) static int do_mark_service (int argc, char **argv)
{ {
bool ok = false; int ok = -1;
char *svcname = getenv ("SVCNAME"); char *svcname = getenv ("SVCNAME");
if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) 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 /* 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 */ 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 *runscript_pid = getenv ("RC_RUNSCRIPT_PID");
char *mtime; char *mtime;
pid_t pid = 0; pid_t pid = 0;
@ -339,17 +338,17 @@ static int do_mark_service (int argc, char **argv)
mtime = rc_xmalloc (l); mtime = rc_xmalloc (l);
snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
svcname, runscript_pid); 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)); eerror ("%s: unlink: %s", applet, strerror (errno));
free (mtime); free (mtime);
} }
return (ok ? EXIT_SUCCESS : EXIT_FAILURE); return (ok);
} }
static int do_options (int argc, char **argv) static int do_options (int argc, char **argv)
{ {
bool ok = false; int ok = -1;
char *service = getenv ("SVCNAME"); char *service = getenv ("SVCNAME");
if (! service) if (! service)
@ -363,14 +362,14 @@ static int do_options (int argc, char **argv)
if (option) { if (option) {
printf ("%s", option); printf ("%s", option);
free (option); free (option);
ok = true; ok = 0;
} }
} else if (strcmp (applet, "save_options") == 0) } else if (strcmp (applet, "save_options") == 0)
ok = rc_set_service_option (service, argv[0], argv[1]); ok = rc_set_service_option (service, argv[0], argv[1]);
else else
eerrorx ("%s: unknown applet", applet); eerrorx ("%s: unknown applet", applet);
return (ok ? EXIT_SUCCESS : EXIT_FAILURE); return (ok);
} }
#ifdef __linux__ #ifdef __linux__
@ -382,7 +381,7 @@ static char *proc_getent (const char *ent)
char *value = NULL; char *value = NULL;
int i; int i;
if (! rc_exists ("/proc/cmdline")) if (rc_exists ("/proc/cmdline") != 0)
return (NULL); return (NULL);
if (! (fp = fopen ("/proc/cmdline", "r"))) { 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_SINGLE) == 0 ||
strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) strcmp (runlevel, RC_LEVEL_SYSINIT) == 0)
{ {
if (rc_exists (RC_KSOFTLEVEL) && if (rc_exists (RC_KSOFTLEVEL) == 0 &&
unlink (RC_KSOFTLEVEL) != 0) unlink (RC_KSOFTLEVEL) != 0)
eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
return; return;
@ -565,7 +564,7 @@ static int get_ksoftlevel (char *buffer, int buffer_len)
FILE *fp; FILE *fp;
int i = 0; int i = 0;
if (! rc_exists (RC_KSOFTLEVEL)) if (rc_exists (RC_KSOFTLEVEL) != 0)
return (0); return (0);
if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) {
@ -784,9 +783,9 @@ int main (int argc, char **argv)
exit (do_mark_service (argc, argv)); exit (do_mark_service (argc, argv));
if (strcmp (applet, "is_runlevel_start") == 0) 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) else if (strcmp (applet, "is_runlevel_stop") == 0)
exit (rc_runlevel_stopping () ? 0 : 1); exit (rc_runlevel_stopping ());
if (strcmp (applet, "rc-abort") == 0) { if (strcmp (applet, "rc-abort") == 0) {
char *p = getenv ("RC_PID"); char *p = getenv ("RC_PID");
@ -880,7 +879,7 @@ int main (int argc, char **argv)
snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
setenv ("RC_PID", pidstr, 1); setenv ("RC_PID", pidstr, 1);
interactive = rc_exists (INTERACTIVE); interactive = (rc_exists (INTERACTIVE) == 0);
rc_plugin_load (); rc_plugin_load ();
/* Load current softlevel */ /* Load current softlevel */
@ -907,7 +906,7 @@ int main (int argc, char **argv)
/* exec init-early.sh if it exists /* exec init-early.sh if it exists
* This should just setup the console to use the correct * This should just setup the console to use the correct
* font. Maybe it should setup the keyboard too? */ * font. Maybe it should setup the keyboard too? */
if (rc_exists (INITEARLYSH)) if (rc_exists (INITEARLYSH) == 0)
run_script (INITEARLYSH); run_script (INITEARLYSH);
uname (&uts); uname (&uts);
@ -1015,7 +1014,7 @@ int main (int argc, char **argv)
/* Check if runlevel is valid if we're changing */ /* Check if runlevel is valid if we're changing */
if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) { if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) {
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL); 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); eerrorx ("%s: is not a valid runlevel", newlevel);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@ -1025,7 +1024,7 @@ int main (int argc, char **argv)
eerrorx ("failed to load deptree"); eerrorx ("failed to load deptree");
/* Clean the failed services state dir now */ /* 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); rc_rm_dir (RC_SVCDIR "/failed", false);
mkdir (RC_STOPPING, 0755); 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 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 stores a list of coldplugged services in DEVBOOT for us to pick up
here when we are ready for them */ 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); start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD);
rc_rm_dir (DEVBOOT, true); rc_rm_dir (DEVBOOT, true);
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
if (rc_allow_plug (service)) if (rc_allow_plug (service) == 0)
rc_mark_service (service, rc_service_coldplugged); rc_mark_service (service, rc_service_coldplugged);
/* We need to dump this list now. /* We need to dump this list now.
This may seem redunant, but only Linux needs this and saves on 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); j = (strlen ("net.") + strlen (service) + 1);
tmp = rc_xmalloc (sizeof (char *) * j); tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "net.%s", service); 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); rc_mark_service (tmp, rc_service_coldplugged);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@ -1084,7 +1083,7 @@ int main (int argc, char **argv)
j = (strlen ("moused.") + strlen (service) + 1); j = (strlen ("moused.") + strlen (service) + 1);
tmp = rc_xmalloc (sizeof (char *) * j); tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "moused.%s", service); 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); rc_mark_service (tmp, rc_service_coldplugged);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@ -1180,7 +1179,7 @@ int main (int argc, char **argv)
char *svc2 = NULL; char *svc2 = NULL;
int k; int k;
if (rc_service_state (service, rc_service_stopped)) if (rc_service_state (service, rc_service_stopped) == 0)
continue; continue;
/* We always stop the service when in these runlevels */ /* 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); tmp = rc_xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, runlevel); snprintf (tmp, len, "%s.%s", service, runlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = (rc_exists (conf) == 0);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (! found) { if (! found) {
@ -1216,7 +1215,7 @@ int main (int argc, char **argv)
tmp = rc_xmalloc (sizeof (char *) * len); tmp = rc_xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, newlevel); snprintf (tmp, len, "%s.%s", service, newlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = (rc_exists (conf) == 0);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (!found) if (!found)
@ -1224,7 +1223,7 @@ int main (int argc, char **argv)
} }
} else { } else {
/* Allow coldplugged services not to be in the runlevels list */ /* 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; continue;
} }
@ -1284,7 +1283,7 @@ int main (int argc, char **argv)
/* Single user is done now */ /* Single user is done now */
if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) {
if (rc_exists (INTERACTIVE)) if (rc_exists (INTERACTIVE) == 0)
unlink (INTERACTIVE); unlink (INTERACTIVE);
sulogin (false); sulogin (false);
} }
@ -1324,7 +1323,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i) { 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; pid_t pid;
if (! interactive) if (! interactive)
@ -1382,7 +1381,7 @@ interactive_option:
if (interactive && strcmp (runlevel, bootlevel) == 0) if (interactive && strcmp (runlevel, bootlevel) == 0)
mark_interactive (); mark_interactive ();
else { else {
if (rc_exists (INTERACTIVE)) if (rc_exists (INTERACTIVE) == 0)
unlink (INTERACTIVE); unlink (INTERACTIVE);
} }

View File

@ -60,8 +60,8 @@ typedef enum
char *rc_resolve_service (const char *service); char *rc_resolve_service (const char *service);
/*! Checks if a service exists or not. /*! Checks if a service exists or not.
* @param service to check * @param service to check
* @return true if service exists, otherwise false */ * @return 0 if service exists, otherwise -1 */
bool rc_service_exists (const char *service); int rc_service_exists (const char *service);
/*! Lists the extra options a service has /*! Lists the extra options a service has
* @param service to load the options from * @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 /*! Checks if a service is in a runlevel
* @param service to check * @param service to check
* @param runlevel it should be in * @param runlevel it should be in
* @return true if service is in the runlevel, otherwise false */ * @return 0 if service is in the runlevel, otherwise -1 */
bool rc_service_in_runlevel (const char *service, const char *runlevel); int rc_service_in_runlevel (const char *service, const char *runlevel);
/*! Checks if a service in in a state /*! Checks if a service in in a state
* @param service to check * @param service to check
* @param state service should be in * @param state service should be in
* @return true if service is in the requested state, otherwise false */ * @return 0 if service is in the requested state, otherwise -1 */
bool rc_service_state (const char *service, rc_service_state_t state); int rc_service_state (const char *service, rc_service_state_t state);
/*! Marks the service state /*! Marks the service state
* @param service to mark * @param service to mark
* @param state service should be in * @param state service should be in
* @return true if service state change was successful, otherwise false */ * @return 0 if service state change was successful, otherwise -1 */
bool rc_mark_service (const char *service, rc_service_state_t state); int rc_mark_service (const char *service, rc_service_state_t state);
/*! Stop a service /*! Stop a service
* @param service to stop * @param service to stop
@ -124,8 +124,8 @@ void rc_schedule_clear (const char *service);
/*! Wait for a service to finish /*! Wait for a service to finish
* @param service to wait for * @param service to wait for
* @return true if service finished before timeout, otherwise false */ * @return 0 if service finished before timeout, otherwise -1 */
bool rc_wait_service (const char *service); int rc_wait_service (const char *service);
/*! Return a saved value for a service /*! Return a saved value for a service
* @param service to check * @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 service to save for
* @param option to save * @param option to save
* @param value of the option * @param value of the option
* @return true if saved, otherwise false */ * @return 0 if saved, otherwise -1 */
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); const char *value);
/*! Save the arguments to find a running daemon /*! Save the arguments to find a running daemon
* @param service to save arguments for * @param service to save arguments for
* @param exec that we started * @param exec that we started
* @param name of the process (optional) * @param name of the process (optional)
* @param pidfile of the process (optional) * @param pidfile of the process (optional)
* @param started if true, add the arguments otherwise remove existing matching arguments */ * @param started if true, add the arguments otherwise remove existing matching arguments
void rc_set_service_daemon (const char *service, const char *exec, * @return 0 if successful, otherwise -1 */
const char *name, const char *pidfile, int rc_set_service_daemon (const char *service, const char *exec,
bool started); const char *name, const char *pidfile,
bool started);
/*! Check if the service started the daemon /*! Check if the service started the daemon
* @param service to check * @param service to check
* @param exec to check * @param exec to check
* @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc) * @param indx of the daemon (optional - 1st daemon, 2nd daemon, etc)
* @return true if started by this service, otherwise false */ * @return 0 if started by this service, otherwise -1 */
bool rc_service_started_daemon (const char *service, const char *exec, int rc_service_started_daemon (const char *service, const char *exec,
int indx); int indx);
/*! Check if the service is allowed to be hot/cold plugged /*! Check if the service is allowed to be hot/cold plugged
* @param service to check * @param service to check
* @return true if allowed, otherwise false */ * @return 0 if allowed, otherwise -1 */
bool rc_allow_plug (char *service); int rc_allow_plug (char *service);
/*! Return the current runlevel. /*! Return the current runlevel.
* @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 /*! Checks if the runlevel exists or not
* @param runlevel to check * @param runlevel to check
* @return true if the runlevel exists, otherwise false */ * @return 0 if the runlevel exists, otherwise -1 */
bool rc_runlevel_exists (const char *runlevel); int rc_runlevel_exists (const char *runlevel);
/*! Return a NULL terminated list of runlevels /*! Return a NULL terminated list of runlevels
* @return a NULL terminated list of runlevels */ * @return a NULL terminated list of runlevels */
char **rc_get_runlevels (void); char **rc_get_runlevels (void);
/*! Is the runlevel starting? /*! Is the runlevel starting?
* @return true if yes, otherwise false */ * @return 0 if yes, otherwise -1 */
bool rc_runlevel_starting (void); int rc_runlevel_starting (void);
/*! Is the runlevel stopping? /*! Is the runlevel stopping?
* @return true if yes, otherwise false */ * @return 0 if yes, otherwise -1 */
bool rc_runlevel_stopping (void); int rc_runlevel_stopping (void);
/*! Add the service to the runlevel /*! Add the service to the runlevel
* @param runlevel to add to * @param runlevel to add to
* @param service to add * @param service to add
* @return true if successful, otherwise false */ * @return 0 if successful, otherwise -1 */
bool rc_service_add (const char *runlevel, const char *service); int rc_service_add (const char *runlevel, const char *service);
/*! Remove the service from the runlevel /*! Remove the service from the runlevel
* @param runlevel to remove from * @param runlevel to remove from
* @param service to remove * @param service to remove
* @return true if sucessful, otherwise false */ * @return 0 if sucessful, otherwise -1 */
bool rc_service_delete (const char *runlevel, const char *service); int rc_service_delete (const char *runlevel, const char *service);
/*! List the services in a runlevel /*! List the services in a runlevel
* @param runlevel to list * @param runlevel to list
* @return NULL terminated list of services */ * @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 /*! Checks that all daemons started with start-stop-daemon by the service
* are still running. * are still running.
* @param service to check * @param service to check
* @return true if all daemons started are still running, otherwise false */ * @return 0 if all daemons started are still running, otherwise -1 */
bool rc_service_daemons_crashed (const char *service); int rc_service_daemons_crashed (const char *service);
/*! @name Dependency options /*! @name Dependency options
* These options can change the services found by the rc_get_depinfo and * 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 /*! Check if an environment variable matches the given value
* @param variable to check * @param variable to check
* @param value it should be * @param value it should be
* @return true if it matches */ * @return 0 if it matches, otherwise -1 */
bool rc_is_env (const char *variable, const char *value); int rc_is_env (const char *variable, const char *value);
/*! Check if the file exists or not /*! Check if the file exists or not
* @param pathname to check * @param pathname to check
* @return true if it exists, otherwise false */ * @return 0 if it exists, otherwise -1 */
bool rc_exists (const char *pathname); int rc_exists (const char *pathname);
/*! Check if the file is a real file /*! Check if the file is a real file
* @param pathname to check * @param pathname to check
* @return true if it's a real file, otherwise false */ * @return 0 if it's a real file, otherwise -1 */
bool rc_is_file (const char *pathname); int rc_is_file (const char *pathname);
/*! Check if the file is a symbolic link or not /*! Check if the file is a symbolic link or not
* @param pathname to check * @param pathname to check
* @return true if it's a symbolic link, otherwise false */ * @return 0 if it's a symbolic link, otherwise -1 */
bool rc_is_link (const char *pathname); int rc_is_link (const char *pathname);
/*! Check if the file is a directory or not /*! Check if the file is a directory or not
* @param pathname to check * @param pathname to check
* @return true if it's a directory, otherwise false */ * @return 0 if it's a directory, otherwise -1 */
bool rc_is_dir (const char *pathname); int rc_is_dir (const char *pathname);
/*! Check if the file is marked executable or not /*! Check if the file is marked executable or not
* @param pathname to check * @param pathname to check
* @return true if it's marked executable, otherwise false */ * @return 0 if it's marked executable, otherwise -1 */
bool rc_is_exec (const char *pathname); int rc_is_exec (const char *pathname);
/*! Return a NULL terminted sorted list of the contents of the directory /*! Return a NULL terminted sorted list of the contents of the directory
* @param dir to list * @param dir to list
@ -402,8 +403,8 @@ char **rc_ls_dir (const char *dir, int options);
/*! Remove a directory /*! Remove a directory
* @param pathname to remove * @param pathname to remove
* @param top remove the top level directory too * @param top remove the top level directory too
* @return true if successful, otherwise false */ * @return 0 if successful, otherwise -1 */
bool rc_rm_dir (const char *pathname, bool top); int rc_rm_dir (const char *pathname, bool top);
/*! @name Configuration */ /*! @name Configuration */
/*! Return a NULL terminated list of non comment lines from a file. */ /*! Return a NULL terminated list of non comment lines from a file. */

View File

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

View File

@ -733,7 +733,7 @@ int start_stop_daemon (int argc, char **argv)
tmp = rc_strcatpaths (ch_root, exec, (char *) NULL); tmp = rc_strcatpaths (ch_root, exec, (char *) NULL);
else else
tmp = exec; tmp = exec;
if (! rc_is_file (tmp)) { if (rc_is_file (tmp) != 0) {
eerror ("%s: %s does not exist", applet, tmp); eerror ("%s: %s does not exist", applet, tmp);
if (ch_root) if (ch_root)
free (tmp); free (tmp);
@ -759,7 +759,7 @@ int start_stop_daemon (int argc, char **argv)
if (result < 1) if (result < 1)
exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (pidfile && rc_is_file (pidfile)) if (pidfile && rc_is_file (pidfile) == 0)
unlink (pidfile); unlink (pidfile);
if (svcname) if (svcname)