aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-09-28 12:29:23 +0000
committerRoy Marples <roy@marples.name>2007-09-28 12:29:23 +0000
commit6f7f447978025c9d49a0d2a0a5a6a29384ba80c8 (patch)
tree8efb8c146d53799bee35d6cb3acf62c25abdc40d
parente89c2c5d60ad97f60e6dfecabc39acef8bc03525 (diff)
enums are now fixed to specific values and are in UPPER CASE.
-rw-r--r--ChangeLog4
-rw-r--r--src/einfo.h12
-rw-r--r--src/libeinfo.c56
-rw-r--r--src/librc-depend.c44
-rw-r--r--src/librc.c111
-rw-r--r--src/rc-status.c26
-rw-r--r--src/rc.c78
-rw-r--r--src/rc.h54
-rw-r--r--src/runscript.c194
9 files changed, 302 insertions, 277 deletions
diff --git a/ChangeLog b/ChangeLog
index 62251162..59f03833 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
# ChangeLog for Gentoo System Intialization ("rc") scripts
# 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>:
rc_is_env is now rc_env_bool and just works with boolean values.
diff --git a/src/einfo.h b/src/einfo.h
index 9c9bc7a3..f9769af5 100644
--- a/src/einfo.h
+++ b/src/einfo.h
@@ -25,12 +25,12 @@
/*! @brief Color types to use */
typedef enum
{
- ecolor_good,
- ecolor_warn,
- ecolor_bad,
- ecolor_hilite,
- ecolor_bracket,
- ecolor_normal
+ ECOLOR_NORMAL = 1,
+ ECOLOR_GOOD = 2,
+ ECOLOR_WARN = 3,
+ ECOLOR_BAD = 4,
+ ECOLOR_HILITE = 5,
+ ECOLOR_BRACKET = 6
} einfo_color_t;
/*! @brief Returns the ASCII code for the color */
diff --git a/src/libeinfo.c b/src/libeinfo.c
index 5025f339..f7b62b5c 100644
--- a/src/libeinfo.c
+++ b/src/libeinfo.c
@@ -64,13 +64,13 @@ hidden_proto(ewendv)
#define INDENT_MAX 40
/* Default colours */
-#define ECOLOR_GOOD "\033[32;01m"
-#define ECOLOR_WARN "\033[33;01m"
-#define ECOLOR_BAD "\033[31;01m"
-#define ECOLOR_HILITE "\033[36;01m"
-#define ECOLOR_BRACKET "\033[34;01m"
-#define ECOLOR_NORMAL "\033[0m"
-#define ECOLOR_FLUSH "\033[K"
+#define ECOLOR_GOOD_A "\033[32;01m"
+#define ECOLOR_WARN_A "\033[33;01m"
+#define ECOLOR_BAD_A "\033[31;01m"
+#define ECOLOR_HILITE_A "\033[36;01m"
+#define ECOLOR_BRACKET_A "\033[34;01m"
+#define ECOLOR_NORMAL_A "\033[0m"
+#define ECOLOR_FLUSH_A "\033[K"
/* A cheat sheet of colour capable terminals
This is taken from DIR_COLORS from GNU coreutils
@@ -242,28 +242,28 @@ const char *ecolor (einfo_color_t color) {
return ("");
switch (color) {
- case ecolor_good:
+ case ECOLOR_GOOD:
if (! (col = getenv ("ECOLOR_GOOD")))
- col = ECOLOR_GOOD;
+ col = ECOLOR_GOOD_A;
break;
- case ecolor_warn:
+ case ECOLOR_WARN:
if (! (col = getenv ("ECOLOR_WARN")))
- col = ECOLOR_WARN;
+ col = ECOLOR_WARN_A;
break;
- case ecolor_bad:
+ case ECOLOR_BAD:
if (! (col = getenv ("ECOLOR_BAD")))
- col = ECOLOR_BAD;
+ col = ECOLOR_BAD_A;
break;
- case ecolor_hilite:
+ case ECOLOR_HILITE:
if (! (col = getenv ("ECOLOR_HILITE")))
- col = ECOLOR_HILITE;
+ col = ECOLOR_HILITE_A;
break;
- case ecolor_bracket:
+ case ECOLOR_BRACKET:
if (! (col = getenv ("ECOLOR_BRACKET")))
- col = ECOLOR_BRACKET;
+ col = ECOLOR_BRACKET_A;
break;
- case ecolor_normal:
- col = ECOLOR_NORMAL;
+ case ECOLOR_NORMAL:
+ col = ECOLOR_NORMAL_A;
break;
}
@@ -273,8 +273,8 @@ hidden_def(ecolor)
#define EINFOVN(_file, _color) \
if (_eprefix) \
- fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ecolor_normal)); \
- fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ecolor_normal)); \
+ fprintf (_file, "%s%s%s|", ecolor (_color), _eprefix, ecolor (ECOLOR_NORMAL)); \
+ fprintf (_file, " %s*%s ", ecolor (_color), ecolor (ECOLOR_NORMAL)); \
retval += _eindent (_file); \
{ \
va_list _ap; \
@@ -283,13 +283,13 @@ hidden_def(ecolor)
va_end (_ap); \
} \
if (colour_terminal ()) \
- fprintf (_file, ECOLOR_FLUSH);
+ fprintf (_file, ECOLOR_FLUSH_A);
static int _einfovn (const char *fmt, va_list ap)
{
int retval = 0;
- EINFOVN (stdout, ecolor_good);
+ EINFOVN (stdout, ECOLOR_GOOD);
return (retval);
}
@@ -297,7 +297,7 @@ static int _ewarnvn (const char *fmt, va_list ap)
{
int retval = 0;
- EINFOVN (stdout, ecolor_warn);
+ EINFOVN (stdout, ECOLOR_WARN);
return (retval);
}
@@ -305,7 +305,7 @@ static int _eerrorvn (const char *fmt, va_list ap)
{
int retval = 0;
- EINFOVN (stderr, ecolor_bad);
+ EINFOVN (stderr, ECOLOR_BAD);
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 ()) {
fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols,
- ecolor (ecolor_bracket), ecolor (color), msg,
- ecolor (ecolor_bracket), ecolor (ecolor_normal));
+ ecolor (ECOLOR_BRACKET), ecolor (color), msg,
+ ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL));
} else {
if (col > 0)
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,
- retval == 0 ? ecolor_good : ecolor_bad,
+ retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
retval == 0 ? OK : NOT_OK);
return (retval);
}
diff --git a/src/librc-depend.c b/src/librc-depend.c
index 4df64635..4bab21cd 100644
--- a/src/librc-depend.c
+++ b/src/librc-depend.c
@@ -187,8 +187,8 @@ static bool valid_service (const char *runlevel, const char *service)
return ((strcmp (runlevel, bootlevel) != 0 &&
rc_service_in_runlevel (service, bootlevel)) ||
rc_service_in_runlevel (service, runlevel) ||
- rc_service_state (service, rc_service_coldplugged) ||
- rc_service_state (service, rc_service_started));
+ rc_service_state (service, RC_SERVICE_COLDPLUGGED) ||
+ rc_service_state (service, RC_SERVICE_STARTED));
}
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)
ok = rc_service_in_runlevel (service, level);
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, bootlevel));
@@ -214,15 +214,15 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
continue;
switch (state) {
- case rc_service_started:
+ case RC_SERVICE_STARTED:
ok = rc_service_state (service, state);
break;
- case rc_service_inactive:
- case rc_service_starting:
- case rc_service_stopping:
- ok = (rc_service_state (service, rc_service_starting) ||
- rc_service_state (service, rc_service_stopping) ||
- rc_service_state (service, rc_service_inactive));
+ case RC_SERVICE_INACTIVE:
+ case RC_SERVICE_STARTING:
+ case RC_SERVICE_STOPPING:
+ ok = (rc_service_state (service, RC_SERVICE_STARTING) ||
+ rc_service_state (service, RC_SERVICE_STOPPING) ||
+ rc_service_state (service, RC_SERVICE_INACTIVE));
break;
default:
break;
@@ -306,44 +306,44 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
return providers.list; \
/* 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 }
- 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);
- 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);
/* 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 }
- 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);
/* Check bootlevel if we're not in it */
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 }
- 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);
}
/* 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 }
/* 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 }
- 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);
/* 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);
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);
/* Still nothing? OK, list all services */
diff --git a/src/librc.c b/src/librc.c
index 46ad9d0a..366c7c49 100644
--- a/src/librc.c
+++ b/src/librc.c
@@ -18,19 +18,36 @@
/* File stream used for plugins to write environ vars to */
FILE *rc_environ_fd = NULL;
-static const char *rc_service_state_names[] = {
- "started",
- "stopped",
- "starting",
- "stopping",
- "inactive",
- "wasinactive",
- "coldplugged",
- "failed",
- "scheduled",
- NULL
+typedef struct rc_service_state_name {
+ rc_service_state_t state;
+ const char *name;
+} rc_service_state_name_t;
+
+static const rc_service_state_name_t rc_service_state_names[] = {
+ { RC_SERVICE_STARTED, "started" },
+ { RC_SERVICE_STOPPED, "stopped" },
+ { RC_SERVICE_STARTING, "starting" },
+ { RC_SERVICE_STOPPING, "stopping" },
+ { 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)
{
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);
base = basename (svc);
- if (state != rc_service_stopped) {
+ if (state != RC_SERVICE_STOPPED) {
if (! rc_is_file(init)) {
free (init);
free (svc);
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);
if (rc_exists (file))
unlink (file);
@@ -307,31 +324,32 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
skip_state = state;
}
- if (state == rc_service_coldplugged) {
+ if (state == RC_SERVICE_COLDPLUGGED) {
free (init);
free (svc);
return (true);
}
/* Remove any old states now */
- i = 0;
- while (rc_service_state_names[i]) {
- if ((i != skip_state &&
- i != rc_service_stopped &&
- i != rc_service_coldplugged &&
- i != rc_service_scheduled &&
- i != rc_service_crashed) &&
- (! skip_wasinactive || i != rc_service_wasinactive))
+ for (i = 0; rc_service_state_names[i].name; i++) {
+ int s = rc_service_state_names[i].state;
+
+ if ((s != skip_state &&
+ s != RC_SERVICE_STOPPED &&
+ s != RC_SERVICE_COLDPLUGGED &&
+ s != RC_SERVICE_SCHEDULED &&
+ 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);
if (rc_exists (file)) {
- if ((state == rc_service_starting ||
- state == rc_service_stopping) &&
- i == rc_service_inactive)
+ if ((state == RC_SERVICE_STARTING ||
+ state == RC_SERVICE_STOPPING) &&
+ s == RC_SERVICE_INACTIVE)
{
char *wasfile = rc_strcatpaths (RC_SVCDIR,
- rc_service_state_names[rc_service_wasinactive],
+ rc_parse_service_state (RC_SERVICE_WASINACTIVE),
base, (char *) NULL);
if (symlink (init, wasfile) != 0)
@@ -349,13 +367,12 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
}
free (file);
}
- i++;
}
/* Remove the exclusive state if we're inactive */
- if (state == rc_service_started ||
- state == rc_service_stopped ||
- state == rc_service_inactive)
+ if (state == RC_SERVICE_STARTED ||
+ state == RC_SERVICE_STOPPED ||
+ state == RC_SERVICE_INACTIVE)
{
file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
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 */
- if (state == rc_service_stopped) {
+ if (state == RC_SERVICE_STOPPED) {
char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL);
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 */
- 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 **dirs = rc_ls_dir (sdir, 0);
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 (! 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 */
- if (state == rc_service_stopped)
- return ( ! (rc_service_state (service, rc_service_started) ||
- rc_service_state (service, rc_service_starting) ||
- rc_service_state (service, rc_service_stopping) ||
- rc_service_state (service, rc_service_inactive)));
+ if (state == RC_SERVICE_STOPPED)
+ return ( ! (rc_service_state (service, RC_SERVICE_STARTED) ||
+ rc_service_state (service, RC_SERVICE_STARTING) ||
+ rc_service_state (service, RC_SERVICE_STOPPING) ||
+ rc_service_state (service, RC_SERVICE_INACTIVE)));
/* The crashed state and scheduled states are virtual */
- if (state == rc_service_crashed)
+ if (state == RC_SERVICE_CRASHED)
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);
retval = (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
in the state dir */
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);
free (svc);
retval = rc_exists (file);
@@ -516,7 +533,7 @@ static pid_t _exec_service (const char *service, const char *arg)
file = rc_resolve_service (service);
if (! rc_is_file (file)) {
- rc_mark_service (service, rc_service_stopped);
+ rc_mark_service (service, RC_SERVICE_STOPPED);
free (file);
return (0);
}
@@ -568,7 +585,7 @@ librc_hidden_def(rc_waitpid)
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 (_exec_service (service, "stop"));
@@ -577,7 +594,7 @@ librc_hidden_def(rc_stop_service)
pid_t rc_start_service (const char *service)
{
- if (! rc_service_state (service, rc_service_stopped))
+ if (! rc_service_state (service, RC_SERVICE_STOPPED))
return (0);
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 *dir = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state],
+ char *dir = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state),
(char *) NULL);
char **list = NULL;
- if (state == rc_service_scheduled) {
+ if (state == RC_SERVICE_SCHEDULED) {
char **dirs = rc_ls_dir (dir, 0);
char *d;
int i;
diff --git a/src/rc-status.c b/src/rc-status.c
index 9ebd56c8..be0f23ab 100644
--- a/src/rc-status.c
+++ b/src/rc-status.c
@@ -22,33 +22,33 @@
static void print_level (char *level)
{
printf ("Runlevel: %s%s%s\n",
- ecolor (ecolor_hilite),
+ ecolor (ECOLOR_HILITE),
level,
- ecolor (ecolor_normal));
+ ecolor (ECOLOR_NORMAL));
}
static void print_service (char *service)
{
char status[10];
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 ");
- else if (rc_service_state (service, rc_service_starting)) {
+ else if (rc_service_state (service, RC_SERVICE_STARTING)) {
snprintf (status, sizeof (status), "starting ");
- color = ecolor_warn;
- } else if (rc_service_state (service, rc_service_inactive)) {
+ color = ECOLOR_WARN;
+ } else if (rc_service_state (service, RC_SERVICE_INACTIVE)) {
snprintf (status, sizeof (status), "inactive ");
- color = ecolor_warn;
- } else if (geteuid () == 0 && rc_service_state (service, rc_service_crashed))
+ color = ECOLOR_WARN;
+ } else if (geteuid () == 0 && rc_service_state (service, RC_SERVICE_CRASHED))
snprintf (status, sizeof (status), " crashed ");
- else if (rc_service_state (service, rc_service_started)) {
+ else if (rc_service_state (service, RC_SERVICE_STARTED)) {
snprintf (status, sizeof (status), " started ");
- color = ecolor_good;
- } else if (rc_service_state (service, rc_service_scheduled)) {
+ color = ECOLOR_GOOD;
+ } else if (rc_service_state (service, RC_SERVICE_SCHEDULED)) {
snprintf (status, sizeof (status), "scheduled");
- color = ecolor_warn;
+ color = ECOLOR_WARN;
} else
snprintf (status, sizeof (status), " stopped ");
ebracket (cols, color, status);
diff --git a/src/rc.c b/src/rc.c
index 9b142076..9d3206dd 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -145,12 +145,12 @@ static int do_e (int argc, char **argv)
if (strcmp (applet, "eval_ecolors") == 0) {
printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
- ecolor (ecolor_good),
- ecolor (ecolor_warn),
- ecolor (ecolor_bad),
- ecolor (ecolor_hilite),
- ecolor (ecolor_bracket),
- ecolor (ecolor_normal));
+ ecolor (ECOLOR_GOOD),
+ ecolor (ECOLOR_WARN),
+ ecolor (ECOLOR_BAD),
+ ecolor (ECOLOR_HILITE),
+ ecolor (ECOLOR_BRACKET),
+ ecolor (ECOLOR_NORMAL));
exit (EXIT_SUCCESS);
}
@@ -269,19 +269,19 @@ static int do_service (int argc, char **argv)
eerrorx ("%s: no service specified", applet);
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)
- 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)
- 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)
- 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)
- 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)
- 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)
- 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) {
int idx = 0;
if (argc > 2)
@@ -303,17 +303,17 @@ static int do_mark_service (int argc, char **argv)
eerrorx ("%s: no service specified", applet);
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)
- 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)
- 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)
- 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)
- 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)
- ok = rc_mark_service (argv[0], rc_service_coldplugged);
+ ok = rc_mark_service (argv[0], RC_SERVICE_COLDPLUGGED);
else
eerrorx ("%s: unknown applet", applet);
@@ -664,7 +664,7 @@ static void handle_signal (int sig)
kill (pl->pid, SIGTERM);
/* 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 */
if ((PREVLEVEL &&
@@ -916,15 +916,15 @@ int main (int argc, char **argv)
printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s"
"\n Copyright 1999-2007 Gentoo Foundation; "
"Distributed under the GPLv2\n\n",
- ecolor (ecolor_good), uts.sysname, ecolor (ecolor_bracket),
- ecolor (ecolor_normal));
+ ecolor (ECOLOR_GOOD), uts.sysname, ecolor (ECOLOR_BRACKET),
+ ecolor (ECOLOR_NORMAL));
if (rc_env_bool ("RC_INTERACTIVE"))
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);
- rc_plugin_run (rc_hook_runlevel_start_in, newlevel);
+ rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, newlevel);
run_script (INITSH);
#ifdef __linux__
@@ -936,7 +936,7 @@ int main (int argc, char **argv)
}
#endif
- rc_plugin_run (rc_hook_runlevel_start_out, newlevel);
+ rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, newlevel);
if (want_interactive ())
mark_interactive ();
@@ -1007,9 +1007,9 @@ int main (int argc, char **argv)
going_down = true;
rc_set_runlevel (newlevel);
setenv ("RC_SOFTLEVEL", newlevel, 1);
- rc_plugin_run (rc_hook_runlevel_stop_in, newlevel);
+ rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_IN, newlevel);
} 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 */
@@ -1041,7 +1041,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i)
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.
This may seem redunant, but only Linux needs this and saves on
code bloat. */
@@ -1066,7 +1066,7 @@ int main (int argc, char **argv)
tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "net.%s", service);
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);
}
rc_strlist_free (start_services);
@@ -1085,7 +1085,7 @@ int main (int argc, char **argv)
tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "moused.%s", service);
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);
}
}
@@ -1180,7 +1180,7 @@ int main (int argc, char **argv)
char *svc2 = NULL;
int k;
- if (rc_service_state (service, rc_service_stopped))
+ if (rc_service_state (service, RC_SERVICE_STOPPED))
continue;
/* We always stop the service when in these runlevels */
@@ -1224,7 +1224,7 @@ int main (int argc, char **argv)
}
} else {
/* Allow coldplugged services not to be in the runlevels list */
- if (rc_service_state (service, rc_service_coldplugged))
+ if (rc_service_state (service, RC_SERVICE_COLDPLUGGED))
continue;
}
@@ -1262,7 +1262,7 @@ int main (int argc, char **argv)
wait_for_services ();
/* 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);
@@ -1290,11 +1290,11 @@ int main (int argc, char **argv)
}
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 */
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 */
rc_strlist_add (&types, "ineed");
@@ -1316,7 +1316,7 @@ int main (int argc, char **argv)
char *token;
while ((token = strsep (&p, ",")))
- rc_mark_service (token, rc_service_started);
+ rc_mark_service (token, RC_SERVICE_STARTED);
free (service);
}
}
@@ -1324,7 +1324,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i) {
- if (rc_service_state (service, rc_service_stopped)) {
+ if (rc_service_state (service, RC_SERVICE_STOPPED)) {
pid_t pid;
if (! interactive)
@@ -1362,7 +1362,7 @@ interactive_option:
/* Wait for our services to finish */
wait_for_services ();
- rc_plugin_run (rc_hook_runlevel_start_out, runlevel);
+ rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, runlevel);
#ifdef __linux__
/* mark any services skipped as stopped */
@@ -1372,7 +1372,7 @@ interactive_option:
char *token;
while ((token = strsep (&p, ",")))
- rc_mark_service (token, rc_service_stopped);
+ rc_mark_service (token, RC_SERVICE_STOPPED);
free (service);
}
}
diff --git a/src/rc.h b/src/rc.h
index 88adef1e..b9c79c21 100644
--- a/src/rc.h
+++ b/src/rc.h
@@ -42,16 +42,24 @@
/*! @brief States a service can be in */
typedef enum
{
- rc_service_started,
- rc_service_stopped,
- rc_service_starting,
- rc_service_stopping,
- rc_service_inactive,
- rc_service_wasinactive,
- rc_service_coldplugged,
- rc_service_failed,
- rc_service_scheduled,
- rc_service_crashed
+ /* These are actual states
+ * The service has to be in one only at all times */
+ RC_SERVICE_STARTED = 0x0001,
+ RC_SERVICE_STOPPED = 0x0002,
+ RC_SERVICE_STARTING = 0x0003,
+ RC_SERVICE_STOPPING = 0x0004,
+ RC_SERVICE_INACTIVE = 0x0005,
+
+ /* Service may or may not have been coldplugged */
+ 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;
/*! 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 */
typedef enum
{
- rc_hook_runlevel_stop_in = 1,
- rc_hook_runlevel_stop_out = 4,
- rc_hook_runlevel_start_in = 5,
- rc_hook_runlevel_start_out = 8,
+ RC_HOOK_RUNLEVEL_STOP_IN = 1,
+ RC_HOOK_RUNLEVEL_STOP_OUT = 4,
+ RC_HOOK_RUNLEVEL_START_IN = 5,
+ RC_HOOK_RUNLEVEL_START_OUT = 8,
/*! We send the abort if an init script requests we abort and drop
* into single user mode if system not fully booted */
- rc_hook_abort = 99,
- rc_hook_service_stop_in = 101,
- rc_hook_service_stop_now,
- rc_hook_service_stop_done,
- rc_hook_service_stop_out,
- rc_hook_service_start_in,
- rc_hook_service_start_now,
- rc_hook_service_start_done,
- rc_hook_service_start_out
+ RC_HOOK_ABORT = 99,
+ RC_HOOK_SERVICE_STOP_IN = 101,
+ RC_HOOK_SERVICE_STOP_NOW = 102,
+ RC_HOOK_SERVICE_STOP_DONE = 103,
+ RC_HOOK_SERVICE_STOP_OUT = 104,
+ RC_HOOK_SERVICE_START_IN = 105,
+ RC_HOOK_SERVICE_START_NOW = 106,
+ RC_HOOK_SERVICE_START_DONE = 107,
+ RC_HOOK_SERVICE_START_OUT = 108
} rc_hook_t;
/*! Plugin entry point
diff --git a/src/runscript.c b/src/runscript.c
index dab01ebb..e8e6d484 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -189,7 +189,7 @@ static bool in_control ()
if (! mtime_test || ! rc_exists (mtime_test))
return (false);
- if (rc_service_state (applet, rc_service_stopped))
+ if (rc_service_state (applet, RC_SERVICE_STOPPED))
return (false);
if (! (mtime = get_mtime (mtime_test, false)))
@@ -227,16 +227,16 @@ static void start_services (char **list) {
if (! list)
return;
- inactive = rc_service_state (service, rc_service_inactive);
+ inactive = rc_service_state (service, RC_SERVICE_INACTIVE);
if (! inactive)
- inactive = rc_service_state (service, rc_service_wasinactive);
+ inactive = rc_service_state (service, RC_SERVICE_WASINACTIVE);
if (inactive ||
- rc_service_state (service, rc_service_starting) ||
- rc_service_state (service, rc_service_started))
+ rc_service_state (service, RC_SERVICE_STARTING) ||
+ rc_service_state (service, RC_SERVICE_STARTED))
{
STRLIST_FOREACH (list, svc, i) {
- if (rc_service_state (svc, rc_service_stopped)) {
+ if (rc_service_state (svc, RC_SERVICE_STOPPED)) {
if (inactive) {
rc_schedule_start_service (service, svc);
ewarn ("WARNING: %s is scheduled to started when %s has started",
@@ -272,24 +272,24 @@ static void cleanup (void)
free (ibsave);
if (! rc_in_plugin && in_control ()) {
- if (rc_service_state (applet, rc_service_stopping)) {
+ if (rc_service_state (applet, RC_SERVICE_STOPPING)) {
/* If the we're shutting down, do it cleanly */
if ((softlevel &&
rc_runlevel_stopping () &&
(strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (softlevel, RC_LEVEL_REBOOT) == 0)))
- rc_mark_service (applet, rc_service_stopped);
- else if (rc_service_state (applet, rc_service_wasinactive))
- rc_mark_service (applet, rc_service_inactive);
+ rc_mark_service (applet, RC_SERVICE_STOPPED);
+ else if (rc_service_state (applet, RC_SERVICE_WASINACTIVE))
+ rc_mark_service (applet, RC_SERVICE_INACTIVE);
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))
- rc_mark_service (applet, rc_service_inactive);
+ if (rc_service_state (applet, RC_SERVICE_WASINACTIVE))
+ rc_mark_service (applet, RC_SERVICE_INACTIVE);
else
- rc_mark_service (applet, rc_service_stopped);
+ rc_mark_service (applet, RC_SERVICE_STOPPED);
}
if (exclusive && rc_exists (exclusive))
unlink (exclusive);
@@ -312,8 +312,8 @@ static void cleanup (void)
static int write_prefix (const char *buffer, size_t bytes, bool *prefixed) {
unsigned int i;
- const char *ec = ecolor (ecolor_hilite);
- const char *ec_normal = ecolor (ecolor_normal);
+ const char *ec = ecolor (ECOLOR_HILITE);
+ const char *ec_normal = ecolor (ECOLOR_NORMAL);
ssize_t ret = 0;
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;
while (1) {
FD_ZERO (&rset);
@@ -459,27 +455,27 @@ static rc_service_state_t svc_status ()
char status[10];
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");
e = &ewarn;
- retval = rc_service_stopping;
- } else if (rc_service_state (service, rc_service_starting)) {
+ retval = RC_SERVICE_STOPPING;
+ } else if (rc_service_state (service, RC_SERVICE_STOPPING)) {
snprintf (status, sizeof (status), "starting");
e = &ewarn;
- retval = rc_service_starting;
- } else if (rc_service_state (service, rc_service_inactive)) {
+ retval = RC_SERVICE_STOPPING;
+ } else if (rc_service_state (service, RC_SERVICE_INACTIVE)) {
snprintf (status, sizeof (status), "inactive");
e = &ewarn;
- retval = rc_service_inactive;
- } else if (rc_service_state (service, rc_service_crashed)) {
+ retval = RC_SERVICE_INACTIVE;
+ } else if (rc_service_state (service, RC_SERVICE_CRASHED)) {
snprintf (status, sizeof (status), "crashed");
e = &eerror;
- retval = rc_service_crashed;
- } else if (rc_service_state (service, rc_service_started)) {
+ retval = RC_SERVICE_CRASHED;
+ } else if (rc_service_state (service, RC_SERVICE_STARTED)) {
snprintf (status, sizeof (status), "started");
- retval = rc_service_started;
+ retval = RC_SERVICE_STARTED;
} else
snprintf (status, sizeof (status), "stopped");
@@ -537,10 +533,10 @@ static void get_started_services ()
int i;
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);
- restart_services = rc_services_in_state (rc_service_started);
+ restart_services = rc_services_in_state (RC_SERVICE_STARTED);
STRLIST_FOREACH (tmplist, svc, i)
rc_strlist_addsort (&restart_services, svc);
@@ -559,27 +555,27 @@ static void svc_start (bool deps)
int j;
int depoptions = RC_DEP_TRACE;
- rc_plugin_run (rc_hook_service_start_in, applet);
- hook_out = rc_hook_service_start_out;
+ rc_plugin_run (RC_HOOK_SERVICE_START_IN, applet);
+ hook_out = RC_HOOK_SERVICE_START_OUT;
if (rc_env_bool ("IN_HOTPLUG") || in_background) {
- if (! rc_service_state (service, rc_service_inactive) &&
- ! rc_service_state (service, rc_service_stopped))
+ if (! rc_service_state (service, RC_SERVICE_INACTIVE) &&
+ ! rc_service_state (service, RC_SERVICE_STOPPED))
exit (EXIT_FAILURE);
background = true;
}
- if (rc_service_state (service, rc_service_started)) {
+ if (rc_service_state (service, RC_SERVICE_STARTED)) {
ewarn ("WARNING: %s has already been started", applet);
return;
- } else if (rc_service_state (service, rc_service_starting))
+ } else if (rc_service_state (service, RC_SERVICE_STOPPING))
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);
- 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);
- 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);
make_exclusive (service);
@@ -628,7 +624,7 @@ static void svc_start (bool deps)
if (! rc_runlevel_starting ()) {
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);
if (! rc_env_bool ("RC_PARALLEL"))
rc_waitpid (pid);
@@ -645,13 +641,13 @@ static void svc_start (bool deps)
tmplist = NULL;
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_started))
+ if (rc_service_state (svc, RC_SERVICE_STARTED))
continue;
/* Don't wait for services which went inactive but are now in
* starting state which we are after */
- if (rc_service_state (svc, rc_service_starting) &&
- rc_service_state(svc, rc_service_wasinactive)) {
+ if (rc_service_state (svc, RC_SERVICE_STOPPING) &&
+ rc_service_state(svc, RC_SERVICE_WASINACTIVE)) {
bool use = false;
STRLIST_FOREACH (use_services, svc2, j)
if (strcmp (svc, svc2) == 0) {
@@ -664,13 +660,13 @@ static void svc_start (bool deps)
if (! rc_wait_service (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;
STRLIST_FOREACH (need_services, svc2, j)
if (strcmp (svc, svc2) == 0) {
- if (rc_service_state (svc, rc_service_inactive) ||
- rc_service_state (svc, rc_service_wasinactive))
+ if (rc_service_state (svc, RC_SERVICE_INACTIVE) ||
+ rc_service_state (svc, RC_SERVICE_WASINACTIVE))
rc_strlist_add (&tmplist, svc);
else
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
our scheduled list is preserved */
- rc_mark_service (service, rc_service_stopped);
+ rc_mark_service (service, RC_SERVICE_STOPPED);
unlink_mtime_test ();
rc_strlist_free (types);
@@ -733,29 +729,29 @@ static void svc_start (bool deps)
if (ibsave)
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);
if (ibsave)
unsetenv ("IN_BACKGROUND");
if (in_control ()) {
if (! started) {
- if (rc_service_state (service, rc_service_wasinactive))
- rc_mark_service (service, rc_service_inactive);
+ if (rc_service_state (service, RC_SERVICE_WASINACTIVE))
+ rc_mark_service (service, RC_SERVICE_INACTIVE);
else {
- rc_mark_service (service, rc_service_stopped);
+ rc_mark_service (service, RC_SERVICE_STOPPED);
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);
}
- rc_mark_service (service, rc_service_started);
+ rc_mark_service (service, RC_SERVICE_STARTED);
unlink_mtime_test ();
- rc_plugin_run (rc_hook_service_start_done, applet);
+ rc_plugin_run (RC_HOOK_SERVICE_START_DONE, applet);
} else {
- rc_plugin_run (rc_hook_service_start_done, applet);
- if (rc_service_state (service, rc_service_inactive))
+ rc_plugin_run (RC_HOOK_SERVICE_START_DONE, applet);
+ if (rc_service_state (service, RC_SERVICE_INACTIVE))
ewarnx ("WARNING: %s has started, but is inactive", applet);
else
ewarnx ("WARNING: %s not under our control, aborting", applet);
@@ -765,7 +761,7 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = rc_services_scheduled (service);
STRLIST_FOREACH (services, svc, i)
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, RC_SERVICE_STOPPED))
rc_start_service (svc);
rc_strlist_free (services);
services = NULL;
@@ -784,36 +780,36 @@ static void svc_start (bool deps)
rc_strlist_free (services);
services = rc_services_scheduled (svc2);
STRLIST_FOREACH (services, svc, i)
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, RC_SERVICE_STOPPED))
rc_start_service (svc);
}
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)
{
bool stopped;
- hook_out = rc_hook_service_stop_out;
+ hook_out = RC_HOOK_SERVICE_STOP_OUT;
if (rc_runlevel_stopping () &&
- rc_service_state (service, rc_service_failed))
+ rc_service_state (service, RC_SERVICE_FAILED))
exit (EXIT_FAILURE);
if (rc_env_bool ("IN_HOTPLUG") || in_background)
- if (! rc_service_state (service, rc_service_started) &&
- ! rc_service_state (service, rc_service_inactive))
+ if (! rc_service_state (service, RC_SERVICE_STARTED) &&
+ ! rc_service_state (service, RC_SERVICE_INACTIVE))
exit (EXIT_FAILURE);
- if (rc_service_state (service, rc_service_stopped)) {
+ if (rc_service_state (service, RC_SERVICE_STOPPED)) {
ewarn ("WARNING: %s is already stopped", applet);
return;
- } else if (rc_service_state (service, rc_service_stopping))
+ } else if (rc_service_state (service, RC_SERVICE_STOPPING))
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);
make_exclusive (service);
@@ -822,7 +818,7 @@ static void svc_stop (bool deps)
rc_service_in_runlevel (service, RC_LEVEL_BOOT))
ewarn ("WARNING: you are stopping a boot service");
- if (deps && ! rc_service_state (service, rc_service_wasinactive)) {
+ if (deps && ! rc_service_state (service, RC_SERVICE_WASINACTIVE)) {
int depoptions = RC_DEP_TRACE;
char *svc;
int i;
@@ -849,12 +845,12 @@ static void svc_stop (bool deps)
softlevel, depoptions);
rc_strlist_reverse (services);
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_started) ||
- rc_service_state (svc, rc_service_inactive))
+ if (rc_service_state (svc, RC_SERVICE_STARTED) ||
+ rc_service_state (svc, RC_SERVICE_INACTIVE))
{
rc_wait_service (svc);
- if (rc_service_state (svc, rc_service_started) ||
- rc_service_state (svc, rc_service_inactive))
+ if (rc_service_state (svc, RC_SERVICE_STARTED) ||
+ rc_service_state (svc, RC_SERVICE_INACTIVE))
{
pid_t pid = rc_stop_service (svc);
if (! rc_env_bool ("RC_PARALLEL"))
@@ -867,12 +863,12 @@ static void svc_stop (bool deps)
services = NULL;
STRLIST_FOREACH (tmplist, svc, i) {
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, RC_SERVICE_STOPPED))
continue;
/* We used to loop 3 times here - maybe re-do this if needed */
rc_wait_service (svc);
- if (! rc_service_state (svc, rc_service_stopped)) {
+ if (! rc_service_state (svc, RC_SERVICE_STOPPED)) {
if (rc_runlevel_stopping ()) {
/* 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_SINGLE) == 0))
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",
@@ -898,7 +894,7 @@ static void svc_stop (bool deps)
services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) {
- if (rc_service_state (svc, rc_service_stopped))
+ if (rc_service_state (svc, RC_SERVICE_STOPPED))
continue;
rc_wait_service (svc);
}
@@ -911,34 +907,34 @@ static void svc_stop (bool deps)
if (ibsave)
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);
if (ibsave)
unsetenv ("IN_BACKGROUND");
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);
}
if (! stopped) {
- if (rc_service_state (service, rc_service_wasinactive))
- rc_mark_service (service, rc_service_inactive);
+ if (rc_service_state (service, RC_SERVICE_WASINACTIVE))
+ rc_mark_service (service, RC_SERVICE_INACTIVE);
else
- rc_mark_service (service, rc_service_started);
- rc_plugin_run (rc_hook_service_stop_done, applet);
+ rc_mark_service (service, RC_SERVICE_STARTED);
+ rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
eerrorx ("ERROR: %s failed to stop", applet);
}
if (in_background)
- rc_mark_service (service, rc_service_inactive);
+ rc_mark_service (service, RC_SERVICE_INACTIVE);
else
- rc_mark_service (service, rc_service_stopped);
+ rc_mark_service (service, RC_SERVICE_STOPPED);
unlink_mtime_test ();
- rc_plugin_run (rc_hook_service_stop_done, applet);
+ rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
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)
@@ -952,15 +948,15 @@ static void svc_restart (bool deps)
our status is invalid.
One workaround would be to introduce a new status, or status locking. */
if (! deps) {
- if (rc_service_state (service, rc_service_started) ||
- rc_service_state (service, rc_service_inactive))
+ if (rc_service_state (service, RC_SERVICE_STARTED) ||
+ rc_service_state (service, RC_SERVICE_INACTIVE))
svc_exec ("stop", "start");
else
svc_exec ("start", NULL);
return;
}
- if (! rc_service_state (service, rc_service_stopped)) {
+ if (! rc_service_state (service, RC_SERVICE_STOPPED)) {
get_started_services ();
svc_stop (deps);
}
@@ -1126,7 +1122,7 @@ int runscript (int argc, char **argv)
setenv ("RC_DEBUG", "yes", 1);
break;
case 's':
- if (! rc_service_state (service, rc_service_started))
+ if (! rc_service_state (service, RC_SERVICE_STARTED))
exit (EXIT_FAILURE);
break;
case 'D':
@@ -1230,7 +1226,7 @@ int runscript (int argc, char **argv)
if (strcmp (optarg, "conditionalrestart") == 0 ||
strcmp (optarg, "condrestart") == 0)
{
- if (rc_service_state (service, rc_service_started))
+ if (rc_service_state (service, RC_SERVICE_STARTED))
svc_restart (deps);
} else if (strcmp (optarg, "restart") == 0) {
svc_restart (deps);
@@ -1245,21 +1241,21 @@ int runscript (int argc, char **argv)
if (deps) {
if (! in_background &&
! rc_runlevel_stopping () &&
- rc_service_state (service, rc_service_stopped))
+ rc_service_state (service, RC_SERVICE_STOPPED))
uncoldplug ();
if (in_background &&
- rc_service_state (service, rc_service_inactive))
+ rc_service_state (service, RC_SERVICE_INACTIVE))
{
int 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);
}
}
} else if (strcmp (optarg, "zap") == 0) {
einfo ("Manually resetting %s to stopped state", applet);
- rc_mark_service (applet, rc_service_stopped);
+ rc_mark_service (applet, RC_SERVICE_STOPPED);
uncoldplug ();
} else
svc_exec (optarg, NULL);