enums are now fixed to specific values and are in UPPER CASE.

This commit is contained in:
Roy Marples 2007-09-28 12:29:23 +00:00
parent e89c2c5d60
commit 6f7f447978
9 changed files with 302 additions and 277 deletions

View File

@ -1,6 +1,10 @@
# 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
28 Sep 2007; Roy Marples <uberlord@gentoo.org>:
enums are now fixed to specific values and are in UPPER CASE.
26 Sep 2007; Roy Marples <uberlord@gentoo.org>: 26 Sep 2007; Roy Marples <uberlord@gentoo.org>:
rc_is_env is now rc_env_bool and just works with boolean values. rc_is_env is now rc_env_bool and just works with boolean values.

View File

@ -25,12 +25,12 @@
/*! @brief Color types to use */ /*! @brief Color types to use */
typedef enum typedef enum
{ {
ecolor_good, ECOLOR_NORMAL = 1,
ecolor_warn, ECOLOR_GOOD = 2,
ecolor_bad, ECOLOR_WARN = 3,
ecolor_hilite, ECOLOR_BAD = 4,
ecolor_bracket, ECOLOR_HILITE = 5,
ecolor_normal ECOLOR_BRACKET = 6
} einfo_color_t; } einfo_color_t;
/*! @brief Returns the ASCII code for the color */ /*! @brief Returns the ASCII code for the color */

View File

@ -64,13 +64,13 @@ hidden_proto(ewendv)
#define INDENT_MAX 40 #define INDENT_MAX 40
/* Default colours */ /* Default colours */
#define ECOLOR_GOOD "\033[32;01m" #define ECOLOR_GOOD_A "\033[32;01m"
#define ECOLOR_WARN "\033[33;01m" #define ECOLOR_WARN_A "\033[33;01m"
#define ECOLOR_BAD "\033[31;01m" #define ECOLOR_BAD_A "\033[31;01m"
#define ECOLOR_HILITE "\033[36;01m" #define ECOLOR_HILITE_A "\033[36;01m"
#define ECOLOR_BRACKET "\033[34;01m" #define ECOLOR_BRACKET_A "\033[34;01m"
#define ECOLOR_NORMAL "\033[0m" #define ECOLOR_NORMAL_A "\033[0m"
#define ECOLOR_FLUSH "\033[K" #define ECOLOR_FLUSH_A "\033[K"
/* A cheat sheet of colour capable terminals /* A cheat sheet of colour capable terminals
This is taken from DIR_COLORS from GNU coreutils This is taken from DIR_COLORS from GNU coreutils
@ -242,28 +242,28 @@ const char *ecolor (einfo_color_t color) {
return (""); return ("");
switch (color) { switch (color) {
case ecolor_good: case ECOLOR_GOOD:
if (! (col = getenv ("ECOLOR_GOOD"))) if (! (col = getenv ("ECOLOR_GOOD")))
col = ECOLOR_GOOD; col = ECOLOR_GOOD_A;
break; break;
case ecolor_warn: case ECOLOR_WARN:
if (! (col = getenv ("ECOLOR_WARN"))) if (! (col = getenv ("ECOLOR_WARN")))
col = ECOLOR_WARN; col = ECOLOR_WARN_A;
break; break;
case ecolor_bad: case ECOLOR_BAD:
if (! (col = getenv ("ECOLOR_BAD"))) if (! (col = getenv ("ECOLOR_BAD")))
col = ECOLOR_BAD; col = ECOLOR_BAD_A;
break; break;
case ecolor_hilite: case ECOLOR_HILITE:
if (! (col = getenv ("ECOLOR_HILITE"))) if (! (col = getenv ("ECOLOR_HILITE")))
col = ECOLOR_HILITE; col = ECOLOR_HILITE_A;
break; break;
case ecolor_bracket: case ECOLOR_BRACKET:
if (! (col = getenv ("ECOLOR_BRACKET"))) if (! (col = getenv ("ECOLOR_BRACKET")))
col = ECOLOR_BRACKET; col = ECOLOR_BRACKET_A;
break; break;
case ecolor_normal: case ECOLOR_NORMAL:
col = ECOLOR_NORMAL; col = ECOLOR_NORMAL_A;
break; break;
} }
@ -273,8 +273,8 @@ hidden_def(ecolor)
#define EINFOVN(_file, _color) \ #define EINFOVN(_file, _color) \
if (_eprefix) \ if (_eprefix) \
fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ecolor_normal)); \ fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ECOLOR_NORMAL)); \
fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ecolor_normal)); \ fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ECOLOR_NORMAL)); \
retval += _eindent (_file); \ retval += _eindent (_file); \
{ \ { \
va_list _ap; \ va_list _ap; \
@ -283,13 +283,13 @@ hidden_def(ecolor)
va_end (_ap); \ va_end (_ap); \
} \ } \
if (colour_terminal ()) \ if (colour_terminal ()) \
fprintf (_file, ECOLOR_FLUSH); fprintf (_file, ECOLOR_FLUSH_A);
static int _einfovn (const char *fmt, va_list ap) static int _einfovn (const char *fmt, va_list ap)
{ {
int retval = 0; int retval = 0;
EINFOVN (stdout, ecolor_good); EINFOVN (stdout, ECOLOR_GOOD);
return (retval); return (retval);
} }
@ -297,7 +297,7 @@ static int _ewarnvn (const char *fmt, va_list ap)
{ {
int retval = 0; int retval = 0;
EINFOVN (stdout, ecolor_warn); EINFOVN (stdout, ECOLOR_WARN);
return (retval); return (retval);
} }
@ -305,7 +305,7 @@ static int _eerrorvn (const char *fmt, va_list ap)
{ {
int retval = 0; int retval = 0;
EINFOVN (stderr, ecolor_bad); EINFOVN (stderr, ECOLOR_BAD);
return (retval); return (retval);
} }
@ -482,8 +482,8 @@ static void _eend (FILE *fp, int col, einfo_color_t color, const char *msg)
if (cols > 0 && colour_terminal ()) { if (cols > 0 && colour_terminal ()) {
fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols, fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols,
ecolor (ecolor_bracket), ecolor (color), msg, ecolor (ECOLOR_BRACKET), ecolor (color), msg,
ecolor (ecolor_bracket), ecolor (ecolor_normal)); ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL));
} else { } else {
if (col > 0) if (col > 0)
for (i = 0; i < cols - col; i++) for (i = 0; i < cols - col; i++)
@ -512,7 +512,7 @@ static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap)
} }
_eend (fp, col, _eend (fp, col,
retval == 0 ? ecolor_good : ecolor_bad, retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
retval == 0 ? OK : NOT_OK); retval == 0 ? OK : NOT_OK);
return (retval); return (retval);
} }

View File

@ -187,8 +187,8 @@ 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)) ||
rc_service_in_runlevel (service, runlevel) || rc_service_in_runlevel (service, runlevel) ||
rc_service_state (service, rc_service_coldplugged) || rc_service_state (service, RC_SERVICE_COLDPLUGGED) ||
rc_service_state (service, rc_service_started)); rc_service_state (service, RC_SERVICE_STARTED));
} }
static bool get_provided1 (const char *runlevel, struct lhead *providers, static bool get_provided1 (const char *runlevel, struct lhead *providers,
@ -206,7 +206,7 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
if (level) if (level)
ok = rc_service_in_runlevel (service, level); ok = rc_service_in_runlevel (service, level);
else if (coldplugged) else if (coldplugged)
ok = (rc_service_state (service, rc_service_coldplugged) && ok = (rc_service_state (service, RC_SERVICE_COLDPLUGGED) &&
! rc_service_in_runlevel (service, runlevel) && ! rc_service_in_runlevel (service, runlevel) &&
! rc_service_in_runlevel (service, bootlevel)); ! rc_service_in_runlevel (service, bootlevel));
@ -214,15 +214,15 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
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);
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) ||
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));
break; break;
default: default:
break; break;
@ -306,44 +306,44 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
return providers.list; \ return providers.list; \
/* Anything in the runlevel has to come first */ /* Anything in the runlevel has to come first */
if (get_provided1 (runlevel, &providers, dt, runlevel, false, rc_service_started)) if (get_provided1 (runlevel, &providers, dt, runlevel, false, RC_SERVICE_STARTED))
{ DO } { DO }
if (get_provided1 (runlevel, &providers, dt, runlevel, false, rc_service_starting)) if (get_provided1 (runlevel, &providers, dt, runlevel, false, RC_SERVICE_STARTING))
return (providers.list); return (providers.list);
if (get_provided1 (runlevel, &providers, dt, runlevel, false, rc_service_stopped)) if (get_provided1 (runlevel, &providers, dt, runlevel, false, RC_SERVICE_STOPPED))
return (providers.list); return (providers.list);
/* Check coldplugged services */ /* Check coldplugged services */
if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_started)) if (get_provided1 (runlevel, &providers, dt, NULL, true, RC_SERVICE_STARTED))
{ DO } { DO }
if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_starting)) if (get_provided1 (runlevel, &providers, dt, NULL, true, RC_SERVICE_STARTING))
return (providers.list); return (providers.list);
/* Check bootlevel if we're not in it */ /* Check bootlevel if we're not in it */
if (bootlevel && strcmp (runlevel, bootlevel) != 0) if (bootlevel && strcmp (runlevel, bootlevel) != 0)
{ {
if (get_provided1 (runlevel, &providers, dt, bootlevel, false, rc_service_started)) if (get_provided1 (runlevel, &providers, dt, bootlevel, false, RC_SERVICE_STARTED))
{ DO } { DO }
if (get_provided1 (runlevel, &providers, dt, bootlevel, false, rc_service_starting)) if (get_provided1 (runlevel, &providers, dt, bootlevel, false, RC_SERVICE_STARTING))
return (providers.list); return (providers.list);
} }
/* Check coldplugged services */ /* Check coldplugged services */
if (get_provided1 (runlevel, &providers, dt, NULL, true, rc_service_stopped)) if (get_provided1 (runlevel, &providers, dt, NULL, true, RC_SERVICE_STOPPED))
{ DO } { DO }
/* Check manually started */ /* Check manually started */
if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_started)) if (get_provided1 (runlevel, &providers, dt, NULL, false, RC_SERVICE_STARTED))
{ DO } { DO }
if (get_provided1 (runlevel, &providers, dt, NULL, false, rc_service_starting)) if (get_provided1 (runlevel, &providers, dt, NULL, false, RC_SERVICE_STARTING))
return (providers.list); return (providers.list);
/* Nothing started then. OK, lets get the stopped services */ /* Nothing started then. OK, lets get the stopped services */
if (get_provided1 (runlevel, &providers, dt, runlevel, false, rc_service_stopped)) if (get_provided1 (runlevel, &providers, dt, runlevel, false, RC_SERVICE_STOPPED))
return (providers.list); return (providers.list);
if (bootlevel && (strcmp (runlevel, bootlevel) != 0) if (bootlevel && (strcmp (runlevel, bootlevel) != 0)
&& (get_provided1 (runlevel, &providers, dt, bootlevel, false, rc_service_stopped))) && (get_provided1 (runlevel, &providers, dt, bootlevel, false, RC_SERVICE_STOPPED)))
return (providers.list); return (providers.list);
/* Still nothing? OK, list all services */ /* Still nothing? OK, list all services */

View File

@ -18,19 +18,36 @@
/* File stream used for plugins to write environ vars to */ /* File stream used for plugins to write environ vars to */
FILE *rc_environ_fd = NULL; FILE *rc_environ_fd = NULL;
static const char *rc_service_state_names[] = { typedef struct rc_service_state_name {
"started", rc_service_state_t state;
"stopped", const char *name;
"starting", } rc_service_state_name_t;
"stopping",
"inactive", static const rc_service_state_name_t rc_service_state_names[] = {
"wasinactive", { RC_SERVICE_STARTED, "started" },
"coldplugged", { RC_SERVICE_STOPPED, "stopped" },
"failed", { RC_SERVICE_STARTING, "starting" },
"scheduled", { RC_SERVICE_STOPPING, "stopping" },
NULL { RC_SERVICE_INACTIVE, "inactive" },
{ RC_SERVICE_WASINACTIVE, "wasinactive" },
{ RC_SERVICE_COLDPLUGGED, "coldplugged" },
{ RC_SERVICE_FAILED, "failed" },
{ RC_SERVICE_SCHEDULED, "scheduled"},
{ 0, NULL}
}; };
static const char *rc_parse_service_state (rc_service_state_t state)
{
int i;
for (i = 0; rc_service_state_names[i].name; i++) {
if (rc_service_state_names[i].state == state)
return (rc_service_state_names[i].name);
}
return (NULL);
}
bool rc_runlevel_starting (void) bool rc_runlevel_starting (void)
{ {
return (rc_is_dir (RC_STARTING)); return (rc_is_dir (RC_STARTING));
@ -283,14 +300,14 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
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)) {
free (init); free (init);
free (svc); free (svc);
return (false); return (false);
} }
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
unlink (file); unlink (file);
@ -307,31 +324,32 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
skip_state = state; skip_state = state;
} }
if (state == rc_service_coldplugged) { if (state == RC_SERVICE_COLDPLUGGED) {
free (init); free (init);
free (svc); free (svc);
return (true); return (true);
} }
/* Remove any old states now */ /* Remove any old states now */
i = 0; for (i = 0; rc_service_state_names[i].name; i++) {
while (rc_service_state_names[i]) { int s = rc_service_state_names[i].state;
if ((i != skip_state &&
i != rc_service_stopped && if ((s != skip_state &&
i != rc_service_coldplugged && s != RC_SERVICE_STOPPED &&
i != rc_service_scheduled && s != RC_SERVICE_COLDPLUGGED &&
i != rc_service_crashed) && s != RC_SERVICE_SCHEDULED &&
(! skip_wasinactive || i != rc_service_wasinactive)) s != RC_SERVICE_CRASHED) &&
(! skip_wasinactive || i != RC_SERVICE_WASINACTIVE))
{ {
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state(s), base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) { if (rc_exists (file)) {
if ((state == rc_service_starting || if ((state == RC_SERVICE_STARTING ||
state == rc_service_stopping) && state == RC_SERVICE_STOPPING) &&
i == rc_service_inactive) s == RC_SERVICE_INACTIVE)
{ {
char *wasfile = rc_strcatpaths (RC_SVCDIR, char *wasfile = rc_strcatpaths (RC_SVCDIR,
rc_service_state_names[rc_service_wasinactive], rc_parse_service_state (RC_SERVICE_WASINACTIVE),
base, (char *) NULL); base, (char *) NULL);
if (symlink (init, wasfile) != 0) if (symlink (init, wasfile) != 0)
@ -349,13 +367,12 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
} }
free (file); free (file);
} }
i++;
} }
/* Remove the exclusive state if we're inactive */ /* Remove the exclusive state if we're inactive */
if (state == rc_service_started || if (state == RC_SERVICE_STARTED ||
state == rc_service_stopped || state == RC_SERVICE_STOPPED ||
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))
@ -365,7 +382,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
} }
/* Remove any options and daemons the service may have stored */ /* Remove any options and daemons the service may have stored */
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))
@ -381,7 +398,7 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
} }
/* These are final states, so remove us from scheduled */ /* These are final states, so remove us from scheduled */
if (state == rc_service_started || state == rc_service_stopped) { if (state == RC_SERVICE_STARTED || state == RC_SERVICE_STOPPED) {
char *sdir = rc_strcatpaths (RC_SVCDIR, "scheduled", (char *) NULL); char *sdir = rc_strcatpaths (RC_SVCDIR, "scheduled", (char *) NULL);
char **dirs = rc_ls_dir (sdir, 0); char **dirs = rc_ls_dir (sdir, 0);
char *dir; char *dir;
@ -419,19 +436,19 @@ 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 ? true : false);
/* 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); retval = (services);
if (services) if (services)
@ -442,7 +459,7 @@ bool rc_service_state (const char *service, const rc_service_state_t state)
/* 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
in the state dir */ in the state dir */
svc = rc_xstrdup (service); svc = rc_xstrdup (service);
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state),
basename (svc), (char*) NULL); basename (svc), (char*) NULL);
free (svc); free (svc);
retval = rc_exists (file); retval = rc_exists (file);
@ -516,7 +533,7 @@ static pid_t _exec_service (const char *service, const char *arg)
file = rc_resolve_service (service); file = rc_resolve_service (service);
if (! rc_is_file (file)) { if (! rc_is_file (file)) {
rc_mark_service (service, rc_service_stopped); rc_mark_service (service, RC_SERVICE_STOPPED);
free (file); free (file);
return (0); return (0);
} }
@ -568,7 +585,7 @@ librc_hidden_def(rc_waitpid)
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))
return (0); return (0);
return (_exec_service (service, "stop")); return (_exec_service (service, "stop"));
@ -577,7 +594,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))
return (0); return (0);
return (_exec_service (service, "start")); return (_exec_service (service, "start"));
@ -706,11 +723,11 @@ librc_hidden_def(rc_services_in_runlevel)
char **rc_services_in_state (rc_service_state_t state) char **rc_services_in_state (rc_service_state_t state)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], char *dir = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state),
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
if (state == rc_service_scheduled) { if (state == RC_SERVICE_SCHEDULED) {
char **dirs = rc_ls_dir (dir, 0); char **dirs = rc_ls_dir (dir, 0);
char *d; char *d;
int i; int i;

View File

@ -22,33 +22,33 @@
static void print_level (char *level) static void print_level (char *level)
{ {
printf ("Runlevel: %s%s%s\n", printf ("Runlevel: %s%s%s\n",
ecolor (ecolor_hilite), ecolor (ECOLOR_HILITE),
level, level,
ecolor (ecolor_normal)); ecolor (ECOLOR_NORMAL));
} }
static void print_service (char *service) static void print_service (char *service)
{ {
char status[10]; char status[10];
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))
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)) {
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)) {
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))
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)) {
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)) {
snprintf (status, sizeof (status), "scheduled"); snprintf (status, sizeof (status), "scheduled");
color = ecolor_warn; color = ECOLOR_WARN;
} else } else
snprintf (status, sizeof (status), " stopped "); snprintf (status, sizeof (status), " stopped ");
ebracket (cols, color, status); ebracket (cols, color, status);

View File

@ -145,12 +145,12 @@ static int do_e (int argc, char **argv)
if (strcmp (applet, "eval_ecolors") == 0) { if (strcmp (applet, "eval_ecolors") == 0) {
printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n", printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
ecolor (ecolor_good), ecolor (ECOLOR_GOOD),
ecolor (ecolor_warn), ecolor (ECOLOR_WARN),
ecolor (ecolor_bad), ecolor (ECOLOR_BAD),
ecolor (ecolor_hilite), ecolor (ECOLOR_HILITE),
ecolor (ecolor_bracket), ecolor (ECOLOR_BRACKET),
ecolor (ecolor_normal)); ecolor (ECOLOR_NORMAL));
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
@ -269,19 +269,19 @@ static int do_service (int argc, char **argv)
eerrorx ("%s: no service specified", applet); eerrorx ("%s: no service specified", applet);
if (strcmp (applet, "service_started") == 0) if (strcmp (applet, "service_started") == 0)
ok = rc_service_state (argv[0], rc_service_started); ok = rc_service_state (argv[0], RC_SERVICE_STARTED);
else if (strcmp (applet, "service_stopped") == 0) else if (strcmp (applet, "service_stopped") == 0)
ok = rc_service_state (argv[0], rc_service_stopped); ok = rc_service_state (argv[0], RC_SERVICE_STOPPED);
else if (strcmp (applet, "service_inactive") == 0) else if (strcmp (applet, "service_inactive") == 0)
ok = rc_service_state (argv[0], rc_service_inactive); ok = rc_service_state (argv[0], RC_SERVICE_INACTIVE);
else if (strcmp (applet, "service_starting") == 0) else if (strcmp (applet, "service_starting") == 0)
ok = rc_service_state (argv[0], rc_service_starting); ok = rc_service_state (argv[0], RC_SERVICE_STOPPING);
else if (strcmp (applet, "service_stopping") == 0) else if (strcmp (applet, "service_stopping") == 0)
ok = rc_service_state (argv[0], rc_service_stopping); ok = rc_service_state (argv[0], RC_SERVICE_STOPPING);
else if (strcmp (applet, "service_coldplugged") == 0) else if (strcmp (applet, "service_coldplugged") == 0)
ok = rc_service_state (argv[0], rc_service_coldplugged); ok = rc_service_state (argv[0], RC_SERVICE_COLDPLUGGED);
else if (strcmp (applet, "service_wasinactive") == 0) else if (strcmp (applet, "service_wasinactive") == 0)
ok = rc_service_state (argv[0], rc_service_wasinactive); ok = rc_service_state (argv[0], RC_SERVICE_WASINACTIVE);
else if (strcmp (applet, "service_started_daemon") == 0) { else if (strcmp (applet, "service_started_daemon") == 0) {
int idx = 0; int idx = 0;
if (argc > 2) if (argc > 2)
@ -303,17 +303,17 @@ static int do_mark_service (int argc, char **argv)
eerrorx ("%s: no service specified", applet); eerrorx ("%s: no service specified", applet);
if (strcmp (applet, "mark_service_started") == 0) if (strcmp (applet, "mark_service_started") == 0)
ok = rc_mark_service (argv[0], rc_service_started); ok = rc_mark_service (argv[0], RC_SERVICE_STARTED);
else if (strcmp (applet, "mark_service_stopped") == 0) else if (strcmp (applet, "mark_service_stopped") == 0)
ok = rc_mark_service (argv[0], rc_service_stopped); ok = rc_mark_service (argv[0], RC_SERVICE_STOPPED);
else if (strcmp (applet, "mark_service_inactive") == 0) else if (strcmp (applet, "mark_service_inactive") == 0)
ok = rc_mark_service (argv[0], rc_service_inactive); ok = rc_mark_service (argv[0], RC_SERVICE_INACTIVE);
else if (strcmp (applet, "mark_service_starting") == 0) else if (strcmp (applet, "mark_service_starting") == 0)
ok = rc_mark_service (argv[0], rc_service_starting); ok = rc_mark_service (argv[0], RC_SERVICE_STOPPING);
else if (strcmp (applet, "mark_service_stopping") == 0) else if (strcmp (applet, "mark_service_stopping") == 0)
ok = rc_mark_service (argv[0], rc_service_stopping); ok = rc_mark_service (argv[0], RC_SERVICE_STOPPING);
else if (strcmp (applet, "mark_service_coldplugged") == 0) else if (strcmp (applet, "mark_service_coldplugged") == 0)
ok = rc_mark_service (argv[0], rc_service_coldplugged); ok = rc_mark_service (argv[0], RC_SERVICE_COLDPLUGGED);
else else
eerrorx ("%s: unknown applet", applet); eerrorx ("%s: unknown applet", applet);
@ -664,7 +664,7 @@ static void handle_signal (int sig)
kill (pl->pid, SIGTERM); kill (pl->pid, SIGTERM);
/* Notify plugins we are aborting */ /* Notify plugins we are aborting */
rc_plugin_run (rc_hook_abort, NULL); rc_plugin_run (RC_HOOK_ABORT, NULL);
/* Only drop into single user mode if we're booting */ /* Only drop into single user mode if we're booting */
if ((PREVLEVEL && if ((PREVLEVEL &&
@ -916,15 +916,15 @@ int main (int argc, char **argv)
printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s" printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s"
"\n Copyright 1999-2007 Gentoo Foundation; " "\n Copyright 1999-2007 Gentoo Foundation; "
"Distributed under the GPLv2\n\n", "Distributed under the GPLv2\n\n",
ecolor (ecolor_good), uts.sysname, ecolor (ecolor_bracket), ecolor (ECOLOR_GOOD), uts.sysname, ecolor (ECOLOR_BRACKET),
ecolor (ecolor_normal)); ecolor (ECOLOR_NORMAL));
if (rc_env_bool ("RC_INTERACTIVE")) if (rc_env_bool ("RC_INTERACTIVE"))
printf ("Press %sI%s to enter interactive boot mode\n\n", printf ("Press %sI%s to enter interactive boot mode\n\n",
ecolor (ecolor_good), ecolor (ecolor_normal)); ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL));
setenv ("RC_SOFTLEVEL", newlevel, 1); setenv ("RC_SOFTLEVEL", newlevel, 1);
rc_plugin_run (rc_hook_runlevel_start_in, newlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, newlevel);
run_script (INITSH); run_script (INITSH);
#ifdef __linux__ #ifdef __linux__
@ -936,7 +936,7 @@ int main (int argc, char **argv)
} }
#endif #endif
rc_plugin_run (rc_hook_runlevel_start_out, newlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, newlevel);
if (want_interactive ()) if (want_interactive ())
mark_interactive (); mark_interactive ();
@ -1007,9 +1007,9 @@ int main (int argc, char **argv)
going_down = true; going_down = true;
rc_set_runlevel (newlevel); rc_set_runlevel (newlevel);
setenv ("RC_SOFTLEVEL", newlevel, 1); setenv ("RC_SOFTLEVEL", newlevel, 1);
rc_plugin_run (rc_hook_runlevel_stop_in, newlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_IN, newlevel);
} else { } else {
rc_plugin_run (rc_hook_runlevel_stop_in, runlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_IN, runlevel);
} }
/* Check if runlevel is valid if we're changing */ /* Check if runlevel is valid if we're changing */
@ -1041,7 +1041,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
if (rc_allow_plug (service)) if (rc_allow_plug (service))
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
code bloat. */ code bloat. */
@ -1066,7 +1066,7 @@ int main (int argc, char **argv)
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) && rc_allow_plug (tmp))
rc_mark_service (tmp, rc_service_coldplugged); rc_mark_service (tmp, RC_SERVICE_COLDPLUGGED);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
rc_strlist_free (start_services); rc_strlist_free (start_services);
@ -1085,7 +1085,7 @@ int main (int argc, char **argv)
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) && rc_allow_plug (tmp))
rc_mark_service (tmp, rc_service_coldplugged); rc_mark_service (tmp, RC_SERVICE_COLDPLUGGED);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
} }
@ -1180,7 +1180,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))
continue; continue;
/* We always stop the service when in these runlevels */ /* We always stop the service when in these runlevels */
@ -1224,7 +1224,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))
continue; continue;
} }
@ -1262,7 +1262,7 @@ int main (int argc, char **argv)
wait_for_services (); wait_for_services ();
/* Notify the plugins we have finished */ /* Notify the plugins we have finished */
rc_plugin_run (rc_hook_runlevel_stop_out, runlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_OUT, runlevel);
rmdir (RC_STOPPING); rmdir (RC_STOPPING);
@ -1290,11 +1290,11 @@ int main (int argc, char **argv)
} }
mkdir (RC_STARTING, 0755); mkdir (RC_STARTING, 0755);
rc_plugin_run (rc_hook_runlevel_start_in, runlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, runlevel);
/* Re-add our coldplugged services if they stopped */ /* Re-add our coldplugged services if they stopped */
STRLIST_FOREACH (coldplugged_services, service, i) STRLIST_FOREACH (coldplugged_services, service, i)
rc_mark_service (service, rc_service_coldplugged); rc_mark_service (service, RC_SERVICE_COLDPLUGGED);
/* Order the services to start */ /* Order the services to start */
rc_strlist_add (&types, "ineed"); rc_strlist_add (&types, "ineed");
@ -1316,7 +1316,7 @@ int main (int argc, char **argv)
char *token; char *token;
while ((token = strsep (&p, ","))) while ((token = strsep (&p, ",")))
rc_mark_service (token, rc_service_started); rc_mark_service (token, RC_SERVICE_STARTED);
free (service); free (service);
} }
} }
@ -1324,7 +1324,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)) {
pid_t pid; pid_t pid;
if (! interactive) if (! interactive)
@ -1362,7 +1362,7 @@ interactive_option:
/* Wait for our services to finish */ /* Wait for our services to finish */
wait_for_services (); wait_for_services ();
rc_plugin_run (rc_hook_runlevel_start_out, runlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, runlevel);
#ifdef __linux__ #ifdef __linux__
/* mark any services skipped as stopped */ /* mark any services skipped as stopped */
@ -1372,7 +1372,7 @@ interactive_option:
char *token; char *token;
while ((token = strsep (&p, ","))) while ((token = strsep (&p, ",")))
rc_mark_service (token, rc_service_stopped); rc_mark_service (token, RC_SERVICE_STOPPED);
free (service); free (service);
} }
} }

View File

@ -42,16 +42,24 @@
/*! @brief States a service can be in */ /*! @brief States a service can be in */
typedef enum typedef enum
{ {
rc_service_started, /* These are actual states
rc_service_stopped, * The service has to be in one only at all times */
rc_service_starting, RC_SERVICE_STARTED = 0x0001,
rc_service_stopping, RC_SERVICE_STOPPED = 0x0002,
rc_service_inactive, RC_SERVICE_STARTING = 0x0003,
rc_service_wasinactive, RC_SERVICE_STOPPING = 0x0004,
rc_service_coldplugged, RC_SERVICE_INACTIVE = 0x0005,
rc_service_failed,
rc_service_scheduled, /* Service may or may not have been coldplugged */
rc_service_crashed RC_SERVICE_COLDPLUGGED = 0x0010,
/* Optional states service could also be in */
RC_SERVICE_FAILED = 0x0100,
RC_SERVICE_SCHEDULED = 0x0101,
RC_SERVICE_WASINACTIVE = 0x0102,
/* Regardless of state, service may have crashed daemons */
RC_SERVICE_CRASHED = 0x1000
} rc_service_state_t; } rc_service_state_t;
/*! Resolves a service name to its full path. /*! Resolves a service name to its full path.
@ -297,21 +305,21 @@ void rc_free_deptree (rc_depinfo_t *deptree);
/*! Points at which a plugin can hook into RC */ /*! Points at which a plugin can hook into RC */
typedef enum typedef enum
{ {
rc_hook_runlevel_stop_in = 1, RC_HOOK_RUNLEVEL_STOP_IN = 1,
rc_hook_runlevel_stop_out = 4, RC_HOOK_RUNLEVEL_STOP_OUT = 4,
rc_hook_runlevel_start_in = 5, RC_HOOK_RUNLEVEL_START_IN = 5,
rc_hook_runlevel_start_out = 8, RC_HOOK_RUNLEVEL_START_OUT = 8,
/*! We send the abort if an init script requests we abort and drop /*! We send the abort if an init script requests we abort and drop
* into single user mode if system not fully booted */ * into single user mode if system not fully booted */
rc_hook_abort = 99, RC_HOOK_ABORT = 99,
rc_hook_service_stop_in = 101, RC_HOOK_SERVICE_STOP_IN = 101,
rc_hook_service_stop_now, RC_HOOK_SERVICE_STOP_NOW = 102,
rc_hook_service_stop_done, RC_HOOK_SERVICE_STOP_DONE = 103,
rc_hook_service_stop_out, RC_HOOK_SERVICE_STOP_OUT = 104,
rc_hook_service_start_in, RC_HOOK_SERVICE_START_IN = 105,
rc_hook_service_start_now, RC_HOOK_SERVICE_START_NOW = 106,
rc_hook_service_start_done, RC_HOOK_SERVICE_START_DONE = 107,
rc_hook_service_start_out RC_HOOK_SERVICE_START_OUT = 108
} rc_hook_t; } rc_hook_t;
/*! Plugin entry point /*! Plugin entry point

View File

@ -189,7 +189,7 @@ static bool in_control ()
if (! mtime_test || ! rc_exists (mtime_test)) if (! mtime_test || ! rc_exists (mtime_test))
return (false); return (false);
if (rc_service_state (applet, rc_service_stopped)) if (rc_service_state (applet, RC_SERVICE_STOPPED))
return (false); return (false);
if (! (mtime = get_mtime (mtime_test, false))) if (! (mtime = get_mtime (mtime_test, false)))
@ -227,16 +227,16 @@ static void start_services (char **list) {
if (! list) if (! list)
return; return;
inactive = rc_service_state (service, rc_service_inactive); inactive = rc_service_state (service, RC_SERVICE_INACTIVE);
if (! inactive) if (! inactive)
inactive = rc_service_state (service, rc_service_wasinactive); inactive = rc_service_state (service, RC_SERVICE_WASINACTIVE);
if (inactive || if (inactive ||
rc_service_state (service, rc_service_starting) || rc_service_state (service, RC_SERVICE_STARTING) ||
rc_service_state (service, rc_service_started)) rc_service_state (service, RC_SERVICE_STARTED))
{ {
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)) {
if (inactive) { if (inactive) {
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",
@ -272,24 +272,24 @@ 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)) {
/* 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 () &&
(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))
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_STOPPING))
{ {
if (rc_service_state (applet, rc_service_wasinactive)) if (rc_service_state (applet, RC_SERVICE_WASINACTIVE))
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))
unlink (exclusive); unlink (exclusive);
@ -312,8 +312,8 @@ static void cleanup (void)
static int write_prefix (const char *buffer, size_t bytes, bool *prefixed) { static int write_prefix (const char *buffer, size_t bytes, bool *prefixed) {
unsigned int i; unsigned int i;
const char *ec = ecolor (ecolor_hilite); const char *ec = ecolor (ECOLOR_HILITE);
const char *ec_normal = ecolor (ecolor_normal); const char *ec_normal = ecolor (ECOLOR_NORMAL);
ssize_t ret = 0; ssize_t ret = 0;
int fd = fileno (stdout); int fd = fileno (stdout);
@ -408,10 +408,6 @@ static bool svc_exec (const char *arg1, const char *arg2)
} }
} }
/* We need to notify the child of window resizes now */
if (master_tty >= 0)
signal (SIGWINCH, handle_signal);
selfd = MAX (master_tty, signal_pipe[0]) + 1; selfd = MAX (master_tty, signal_pipe[0]) + 1;
while (1) { while (1) {
FD_ZERO (&rset); FD_ZERO (&rset);
@ -459,27 +455,27 @@ static rc_service_state_t svc_status ()
char status[10]; char status[10];
int (*e) (const char *fmt, ...) = &einfo; int (*e) (const char *fmt, ...) = &einfo;
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)) {
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_STOPPING)) {
snprintf (status, sizeof (status), "starting"); snprintf (status, sizeof (status), "starting");
e = &ewarn; e = &ewarn;
retval = rc_service_starting; retval = RC_SERVICE_STOPPING;
} else if (rc_service_state (service, rc_service_inactive)) { } else if (rc_service_state (service, RC_SERVICE_INACTIVE)) {
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)) {
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)) {
snprintf (status, sizeof (status), "started"); snprintf (status, sizeof (status), "started");
retval = rc_service_started; retval = RC_SERVICE_STARTED;
} else } else
snprintf (status, sizeof (status), "stopped"); snprintf (status, sizeof (status), "stopped");
@ -537,10 +533,10 @@ static void get_started_services ()
int i; int i;
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
tmplist = rc_services_in_state (rc_service_inactive); tmplist = rc_services_in_state (RC_SERVICE_INACTIVE);
rc_strlist_free (restart_services); rc_strlist_free (restart_services);
restart_services = rc_services_in_state (rc_service_started); restart_services = rc_services_in_state (RC_SERVICE_STARTED);
STRLIST_FOREACH (tmplist, svc, i) STRLIST_FOREACH (tmplist, svc, i)
rc_strlist_addsort (&restart_services, svc); rc_strlist_addsort (&restart_services, svc);
@ -559,27 +555,27 @@ static void svc_start (bool deps)
int j; int j;
int depoptions = RC_DEP_TRACE; int depoptions = RC_DEP_TRACE;
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_env_bool ("IN_HOTPLUG") || in_background) { if (rc_env_bool ("IN_HOTPLUG") || in_background) {
if (! rc_service_state (service, rc_service_inactive) && if (! rc_service_state (service, RC_SERVICE_INACTIVE) &&
! rc_service_state (service, rc_service_stopped)) ! rc_service_state (service, RC_SERVICE_STOPPED))
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)) {
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_STOPPING))
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))
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) && ! 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_STOPPING))
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);
@ -628,7 +624,7 @@ static void svc_start (bool deps)
if (! rc_runlevel_starting ()) { if (! rc_runlevel_starting ()) {
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)) {
pid_t pid = rc_start_service (svc); pid_t pid = rc_start_service (svc);
if (! rc_env_bool ("RC_PARALLEL")) if (! rc_env_bool ("RC_PARALLEL"))
rc_waitpid (pid); rc_waitpid (pid);
@ -645,13 +641,13 @@ 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))
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_STOPPING) &&
rc_service_state(svc, rc_service_wasinactive)) { rc_service_state(svc, RC_SERVICE_WASINACTIVE)) {
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) {
@ -664,13 +660,13 @@ static void svc_start (bool deps)
if (! rc_wait_service (svc)) if (! rc_wait_service (svc))
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))
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) ||
rc_service_state (svc, rc_service_wasinactive)) rc_service_state (svc, RC_SERVICE_WASINACTIVE))
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",
@ -685,7 +681,7 @@ static void svc_start (bool deps)
/* Set the state now, then unlink our exclusive so that /* Set the state now, then unlink our exclusive so that
our scheduled list is preserved */ our scheduled list is preserved */
rc_mark_service (service, rc_service_stopped); rc_mark_service (service, RC_SERVICE_STOPPED);
unlink_mtime_test (); unlink_mtime_test ();
rc_strlist_free (types); rc_strlist_free (types);
@ -733,29 +729,29 @@ static void svc_start (bool deps)
if (ibsave) if (ibsave)
setenv ("IN_BACKGROUND", ibsave, 1); setenv ("IN_BACKGROUND", ibsave, 1);
rc_plugin_run (rc_hook_service_start_now, applet); rc_plugin_run (RC_HOOK_SERVICE_START_NOW, applet);
started = svc_exec ("start", NULL); started = svc_exec ("start", NULL);
if (ibsave) if (ibsave)
unsetenv ("IN_BACKGROUND"); unsetenv ("IN_BACKGROUND");
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))
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 ())
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);
eerrorx ("ERROR: %s failed to start", applet); eerrorx ("ERROR: %s failed to start", applet);
} }
rc_mark_service (service, rc_service_started); rc_mark_service (service, RC_SERVICE_STARTED);
unlink_mtime_test (); unlink_mtime_test ();
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))
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 +761,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))
rc_start_service (svc); rc_start_service (svc);
rc_strlist_free (services); rc_strlist_free (services);
services = NULL; services = NULL;
@ -784,36 +780,36 @@ 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))
rc_start_service (svc); rc_start_service (svc);
} }
hook_out = 0; hook_out = 0;
rc_plugin_run (rc_hook_service_start_out, applet); rc_plugin_run (RC_HOOK_SERVICE_START_OUT, applet);
} }
static void svc_stop (bool deps) static void svc_stop (bool deps)
{ {
bool stopped; bool stopped;
hook_out = rc_hook_service_stop_out; hook_out = RC_HOOK_SERVICE_STOP_OUT;
if (rc_runlevel_stopping () && if (rc_runlevel_stopping () &&
rc_service_state (service, rc_service_failed)) rc_service_state (service, RC_SERVICE_FAILED))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (rc_env_bool ("IN_HOTPLUG") || in_background) if (rc_env_bool ("IN_HOTPLUG") || in_background)
if (! rc_service_state (service, rc_service_started) && if (! rc_service_state (service, RC_SERVICE_STARTED) &&
! rc_service_state (service, rc_service_inactive)) ! rc_service_state (service, RC_SERVICE_INACTIVE))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (rc_service_state (service, rc_service_stopped)) { if (rc_service_state (service, RC_SERVICE_STOPPED)) {
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))
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))
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);
@ -822,7 +818,7 @@ static void svc_stop (bool deps)
rc_service_in_runlevel (service, RC_LEVEL_BOOT)) rc_service_in_runlevel (service, RC_LEVEL_BOOT))
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)) {
int depoptions = RC_DEP_TRACE; int depoptions = RC_DEP_TRACE;
char *svc; char *svc;
int i; int i;
@ -849,12 +845,12 @@ 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) ||
rc_service_state (svc, rc_service_inactive)) rc_service_state (svc, RC_SERVICE_INACTIVE))
{ {
rc_wait_service (svc); rc_wait_service (svc);
if (rc_service_state (svc, rc_service_started) || if (rc_service_state (svc, RC_SERVICE_STARTED) ||
rc_service_state (svc, rc_service_inactive)) rc_service_state (svc, RC_SERVICE_INACTIVE))
{ {
pid_t pid = rc_stop_service (svc); pid_t pid = rc_stop_service (svc);
if (! rc_env_bool ("RC_PARALLEL")) if (! rc_env_bool ("RC_PARALLEL"))
@ -867,12 +863,12 @@ 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))
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)) {
if (rc_runlevel_stopping ()) { if (rc_runlevel_stopping ()) {
/* If shutting down, we should stop even if a dependant failed */ /* If shutting down, we should stop even if a dependant failed */
@ -881,7 +877,7 @@ static void svc_stop (bool deps)
strcmp (softlevel, RC_LEVEL_REBOOT) == 0 || strcmp (softlevel, RC_LEVEL_REBOOT) == 0 ||
strcmp (softlevel, RC_LEVEL_SINGLE) == 0)) strcmp (softlevel, RC_LEVEL_SINGLE) == 0))
continue; continue;
rc_mark_service (service, rc_service_failed); rc_mark_service (service, RC_SERVICE_FAILED);
} }
eerrorx ("ERROR: cannot stop %s as %s is still up", eerrorx ("ERROR: cannot stop %s as %s is still up",
@ -898,7 +894,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))
continue; continue;
rc_wait_service (svc); rc_wait_service (svc);
} }
@ -911,34 +907,34 @@ static void svc_stop (bool deps)
if (ibsave) if (ibsave)
setenv ("IN_BACKGROUND", ibsave, 1); setenv ("IN_BACKGROUND", ibsave, 1);
rc_plugin_run (rc_hook_service_stop_now, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_NOW, applet);
stopped = svc_exec ("stop", NULL); stopped = svc_exec ("stop", NULL);
if (ibsave) if (ibsave)
unsetenv ("IN_BACKGROUND"); unsetenv ("IN_BACKGROUND");
if (! in_control ()) { if (! in_control ()) {
rc_plugin_run (rc_hook_service_stop_done, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
ewarnx ("WARNING: %s not under our control, aborting", applet); ewarnx ("WARNING: %s not under our control, aborting", applet);
} }
if (! stopped) { if (! stopped) {
if (rc_service_state (service, rc_service_wasinactive)) if (rc_service_state (service, RC_SERVICE_WASINACTIVE))
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);
rc_plugin_run (rc_hook_service_stop_done, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
eerrorx ("ERROR: %s failed to stop", applet); eerrorx ("ERROR: %s failed to stop", applet);
} }
if (in_background) if (in_background)
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);
unlink_mtime_test (); unlink_mtime_test ();
rc_plugin_run (rc_hook_service_stop_done, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
hook_out = 0; hook_out = 0;
rc_plugin_run (rc_hook_service_stop_out, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_OUT, applet);
} }
static void svc_restart (bool deps) static void svc_restart (bool deps)
@ -952,15 +948,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) ||
rc_service_state (service, rc_service_inactive)) rc_service_state (service, RC_SERVICE_INACTIVE))
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)) {
get_started_services (); get_started_services ();
svc_stop (deps); svc_stop (deps);
} }
@ -1126,7 +1122,7 @@ int runscript (int argc, char **argv)
setenv ("RC_DEBUG", "yes", 1); setenv ("RC_DEBUG", "yes", 1);
break; break;
case 's': case 's':
if (! rc_service_state (service, rc_service_started)) if (! rc_service_state (service, RC_SERVICE_STARTED))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
break; break;
case 'D': case 'D':
@ -1230,7 +1226,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))
svc_restart (deps); svc_restart (deps);
} else if (strcmp (optarg, "restart") == 0) { } else if (strcmp (optarg, "restart") == 0) {
svc_restart (deps); svc_restart (deps);
@ -1245,21 +1241,21 @@ int runscript (int argc, char **argv)
if (deps) { if (deps) {
if (! in_background && if (! in_background &&
! rc_runlevel_stopping () && ! rc_runlevel_stopping () &&
rc_service_state (service, rc_service_stopped)) rc_service_state (service, RC_SERVICE_STOPPED))
uncoldplug (); uncoldplug ();
if (in_background && if (in_background &&
rc_service_state (service, rc_service_inactive)) rc_service_state (service, RC_SERVICE_INACTIVE))
{ {
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))
rc_schedule_start_service (service, svc); rc_schedule_start_service (service, svc);
} }
} }
} else if (strcmp (optarg, "zap") == 0) { } else if (strcmp (optarg, "zap") == 0) {
einfo ("Manually resetting %s to stopped state", applet); einfo ("Manually resetting %s to stopped state", applet);
rc_mark_service (applet, rc_service_stopped); rc_mark_service (applet, RC_SERVICE_STOPPED);
uncoldplug (); uncoldplug ();
} else } else
svc_exec (optarg, NULL); svc_exec (optarg, NULL);