aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/env-update.c178
-rw-r--r--src/fstabinfo.c116
-rw-r--r--src/libeinfo.c218
-rw-r--r--src/librc-daemon.c322
-rw-r--r--src/librc-depend.c552
-rw-r--r--src/librc-misc.c340
-rw-r--r--src/librc-strlist.c16
-rw-r--r--src/librc.c308
-rw-r--r--src/mountinfo.c202
-rw-r--r--src/rc-depend.c78
-rw-r--r--src/rc-plugin.c48
-rw-r--r--src/rc-status.c72
-rw-r--r--src/rc-update.c114
-rw-r--r--src/rc.c784
-rw-r--r--src/rc.h18
-rw-r--r--src/runscript.c648
-rw-r--r--src/start-stop-daemon.c780
17 files changed, 2397 insertions, 2397 deletions
diff --git a/src/env-update.c b/src/env-update.c
index e01c8c48..1df55386 100644
--- a/src/env-update.c
+++ b/src/env-update.c
@@ -25,12 +25,12 @@
#define CSH_ENV "/etc/csh.env"
#define LDSOCONF "/etc/ld.so.conf"
-#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \
- "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \
- "# GO INTO %s NOT %s\n\n"
+#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \
+ "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \
+"# GO INTO %s NOT %s\n\n"
-#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
- "# changes to contents of /etc/env.d directory\n"
+#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
+ "# changes to contents of /etc/env.d directory\n"
static const char *specials[] =
{
@@ -85,78 +85,78 @@ int main (int argc, char **argv)
int j;
if (! rc_is_dir (path))
- entries = rc_get_config (NULL, path);
+ entries = rc_get_config (NULL, path);
free (path);
STRLIST_FOREACH (entries, entry, j)
- {
- char *tmpent = rc_xstrdup (entry);
- char *value = tmpent;
- char *var = strsep (&value, "=");
- int k;
- bool isspecial = false;
- bool isspecial_spaced = false;
- bool replaced = false;
-
- for (k = 0; special_spaces[k]; k++)
- if (strcmp (special_spaces[k], var) == 0)
- {
- isspecial = true;
- isspecial_spaced = true;
- break;
- }
-
- if (! isspecial)
- {
- for (k = 0; specials[k]; k++)
- if (strcmp (specials[k], var) == 0)
- {
- isspecial = true;
- break;
- }
- }
-
- /* Skip blank vars */
- if (isspecial &&
- (! value || strlen (value)) == 0)
- {
- free (tmpent);
- continue;
- }
-
- STRLIST_FOREACH (envs, env, k)
- {
- char *tmpenv = rc_xstrdup (env);
- char *tmpvalue = tmpenv;
- char *tmpentry = strsep (&tmpvalue, "=");
-
- if (strcmp (tmpentry, var) == 0)
- {
- if (isspecial)
- {
- int len = strlen (envs[k - 1]) + strlen (entry) + 1;
- envs[k - 1] = rc_xrealloc (envs[k - 1], len);
- snprintf (envs[k - 1] + strlen (envs[k - 1]), len,
- "%s%s", isspecial_spaced ? " " : ":", value);
- }
- else
- {
- free (envs[k - 1]);
- envs[k - 1] = strdup (entry);
- }
- replaced = true;
- }
- free (tmpenv);
-
- if (replaced)
- break;
- }
-
- if (! replaced)
- envs = rc_strlist_addsort (envs, entry);
-
- free (tmpent);
- }
+ {
+ char *tmpent = rc_xstrdup (entry);
+ char *value = tmpent;
+ char *var = strsep (&value, "=");
+ int k;
+ bool isspecial = false;
+ bool isspecial_spaced = false;
+ bool replaced = false;
+
+ for (k = 0; special_spaces[k]; k++)
+ if (strcmp (special_spaces[k], var) == 0)
+ {
+ isspecial = true;
+ isspecial_spaced = true;
+ break;
+ }
+
+ if (! isspecial)
+ {
+ for (k = 0; specials[k]; k++)
+ if (strcmp (specials[k], var) == 0)
+ {
+ isspecial = true;
+ break;
+ }
+ }
+
+ /* Skip blank vars */
+ if (isspecial &&
+ (! value || strlen (value)) == 0)
+ {
+ free (tmpent);
+ continue;
+ }
+
+ STRLIST_FOREACH (envs, env, k)
+ {
+ char *tmpenv = rc_xstrdup (env);
+ char *tmpvalue = tmpenv;
+ char *tmpentry = strsep (&tmpvalue, "=");
+
+ if (strcmp (tmpentry, var) == 0)
+ {
+ if (isspecial)
+ {
+ int len = strlen (envs[k - 1]) + strlen (entry) + 1;
+ envs[k - 1] = rc_xrealloc (envs[k - 1], len);
+ snprintf (envs[k - 1] + strlen (envs[k - 1]), len,
+ "%s%s", isspecial_spaced ? " " : ":", value);
+ }
+ else
+ {
+ free (envs[k - 1]);
+ envs[k - 1] = strdup (entry);
+ }
+ replaced = true;
+ }
+ free (tmpenv);
+
+ if (replaced)
+ break;
+ }
+
+ if (! replaced)
+ envs = rc_strlist_addsort (envs, entry);
+
+ free (tmpent);
+ }
}
if ((fp = fopen (PROFILE_ENV, "w")) == NULL)
@@ -168,7 +168,7 @@ int main (int argc, char **argv)
char *value = tmpent;
char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0)
- fprintf (fp, "export %s='%s'\n", var, value);
+ fprintf (fp, "export %s='%s'\n", var, value);
free (tmpent);
}
fclose (fp);
@@ -182,24 +182,24 @@ int main (int argc, char **argv)
char *value = tmpent;
char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0)
- fprintf (fp, "setenv %s '%s'\n", var, value);
+ fprintf (fp, "setenv %s '%s'\n", var, value);
free (tmpent);
}
fclose (fp);
ldent = rc_get_config_entry (envs, "LDPATH");
- if (! ldent ||
- (argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
- {
- free (envs);
- return (EXIT_SUCCESS);
- }
+ if (! ldent ||
+ (argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
+ {
+ free (envs);
+ return (EXIT_SUCCESS);
+ }
while ((file = strsep (&ldent, ":")))
{
if (strlen (file) == 0)
- continue;
+ continue;
ldents = rc_strlist_add (ldents, file);
nents++;
@@ -213,12 +213,12 @@ int main (int argc, char **argv)
ld = false;
STRLIST_FOREACH (lines, line, i)
if (i > nents || strcmp (line, ldents[i - 1]) != 0)
- {
- ld = true;
- break;
- }
+ {
+ ld = true;
+ break;
+ }
if (i - 1 != nents)
- ld = true;
+ ld = true;
}
if (ld)
@@ -226,7 +226,7 @@ int main (int argc, char **argv)
int retval = 0;
if ((fp = fopen (LDSOCONF, "w")) == NULL)
- eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno));
+ eerrorx ("%s: fopen `%s': %s", applet, LDSOCONF, strerror (errno));
fprintf (fp, LDNOTICE);
STRLIST_FOREACH (ldents, ldent, i)
fprintf (fp, "%s\n", ldent);
diff --git a/src/fstabinfo.c b/src/fstabinfo.c
index 6f45cc70..de37383b 100644
--- a/src/fstabinfo.c
+++ b/src/fstabinfo.c
@@ -46,8 +46,8 @@ static struct mntent *getmntfile (FILE *fp, const char *file)
struct mntent *ent;
while ((ent = getmntent (fp)))
- if (strcmp (file, ent->mnt_dir) == 0)
- return (ent);
+ if (strcmp (file, ent->mnt_dir) == 0)
+ return (ent);
return (NULL);
}
@@ -74,71 +74,71 @@ int main (int argc, char **argv)
#endif
if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc)
- {
- i++;
- p = argv[i];
- while ((token = strsep (&p, ",")))
- while ((ent = GET_ENT))
- if (strcmp (token, ENT_TYPE (ent)) == 0)
- printf ("%s\n", ENT_FILE (ent));
- result = EXIT_SUCCESS;
- }
+ {
+ i++;
+ p = argv[i];
+ while ((token = strsep (&p, ",")))
+ while ((ent = GET_ENT))
+ if (strcmp (token, ENT_TYPE (ent)) == 0)
+ printf ("%s\n", ENT_FILE (ent));
+ result = EXIT_SUCCESS;
+ }
if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc)
- {
- i++;
- if ((ent = GET_ENT_FILE (argv[i])) == NULL)
- continue;
- printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
- ENT_DEVICE (ent), ENT_FILE (ent));
- result = EXIT_SUCCESS;
- }
+ {
+ i++;
+ if ((ent = GET_ENT_FILE (argv[i])) == NULL)
+ continue;
+ printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
+ ENT_DEVICE (ent), ENT_FILE (ent));
+ result = EXIT_SUCCESS;
+ }
if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc)
- {
- i++;
- if ((ent = GET_ENT_FILE (argv[i])) == NULL)
- continue;
- printf ("%s\n", ENT_OPTS (ent));
- result = EXIT_SUCCESS;
- }
-
+ {
+ i++;
+ if ((ent = GET_ENT_FILE (argv[i])) == NULL)
+ continue;
+ printf ("%s\n", ENT_OPTS (ent));
+ result = EXIT_SUCCESS;
+ }
+
if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc)
- {
- i++;
- switch (argv[i][0])
- {
- case '=':
- case '<':
- case '>':
- if (sscanf (argv[i] + 1, "%d", &n) != 1)
- eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
-
- while ((ent = GET_ENT))
- {
- if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
- (argv[i][0] == '<' && n > ENT_PASS (ent)) ||
- (argv[i][0] == '>' && n < ENT_PASS (ent))) &&
- strcmp (ENT_FILE (ent), "none") != 0)
- printf ("%s\n", ENT_FILE (ent));
- }
-
- default:
- if ((ent = GET_ENT_FILE (argv[i])) == NULL)
- continue;
- printf ("%d\n", ENT_PASS (ent));
- result = EXIT_SUCCESS;
- }
- }
+ {
+ i++;
+ switch (argv[i][0])
+ {
+ case '=':
+ case '<':
+ case '>':
+ if (sscanf (argv[i] + 1, "%d", &n) != 1)
+ eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
+
+ while ((ent = GET_ENT))
+ {
+ if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
+ (argv[i][0] == '<' && n > ENT_PASS (ent)) ||
+ (argv[i][0] == '>' && n < ENT_PASS (ent))) &&
+ strcmp (ENT_FILE (ent), "none") != 0)
+ printf ("%s\n", ENT_FILE (ent));
+ }
+
+ default:
+ if ((ent = GET_ENT_FILE (argv[i])) == NULL)
+ continue;
+ printf ("%d\n", ENT_PASS (ent));
+ result = EXIT_SUCCESS;
+ }
+ }
END_ENT;
if (result != EXIT_SUCCESS)
- {
- eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
- break;
- }
-
+ {
+ eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
+ break;
+ }
+
}
exit (result);
diff --git a/src/libeinfo.c b/src/libeinfo.c
index f5237eb8..b756d119 100644
--- a/src/libeinfo.c
+++ b/src/libeinfo.c
@@ -116,10 +116,10 @@ bool colour_terminal (void)
while (colour_terms[i])
{
if (strcmp (colour_terms[i], term) == 0)
- {
- in_colour = 1;
- return (true);
- }
+ {
+ in_colour = 1;
+ return (true);
+ }
i++;
}
@@ -235,12 +235,12 @@ void eflush (void)
{
snprintf (newfile, sizeof (newfile), "%s.%d", file, i);
if (stat (newfile, &buf) != 0)
- {
- if (rename (file, newfile))
- fprintf (stderr, "rename `%s' `%s': %s\n", file, newfile,
- strerror (errno));
- break;
- }
+ {
+ if (rename (file, newfile))
+ fprintf (stderr, "rename `%s' `%s': %s\n", file, newfile,
+ strerror (errno));
+ break;
+ }
i++;
}
@@ -263,10 +263,10 @@ void eflush (void)
select (0, NULL, NULL, NULL, &tv);
errno = 0;
if (link (newfile, EBUFFER_LOCK) == 0)
- break;
+ break;
if (errno != EEXIST)
- fprintf (stderr, "link `%s' `%s': %s\n", newfile, EBUFFER_LOCK,
- strerror (errno));
+ fprintf (stderr, "link `%s' `%s': %s\n", newfile, EBUFFER_LOCK,
+ strerror (errno));
}
if (! (fp = fopen (newfile, "r")))
@@ -282,62 +282,62 @@ void eflush (void)
{
i = strlen (buffer) - 1;
if (i < 1)
- continue;
+ continue;
if (buffer[i] == '\n')
- buffer[i] = 0;
+ buffer[i] = 0;
p = buffer;
cmd = strsep (&p, " ");
token = strsep (&p, " ");
if (sscanf (token, "%d", &retval) != 1)
- {
- fprintf (stderr, "eflush `%s': not a number", token);
- continue;
- }
+ {
+ fprintf (stderr, "eflush `%s': not a number", token);
+ continue;
+ }
token = strsep (&p, " ");
if (sscanf (token, "%d", &length) != 1)
- {
- fprintf (stderr, "eflush `%s': not a number", token);
- continue;
- }
+ {
+ fprintf (stderr, "eflush `%s': not a number", token);
+ continue;
+ }
i = 0;
while (funcmap[i].name)
- {
- if (strcmp (funcmap[i].name, cmd) == 0)
- {
- if (funcmap[i].efunc)
- {
- if (p)
- funcmap[i].efunc ("%s", p);
- else
- funcmap[i].efunc (NULL, NULL);
- }
- else if (funcmap[i].eefunc)
- {
- if (p)
- funcmap[i].eefunc (retval, "%s", p);
- else
- funcmap[i].eefunc (retval, NULL, NULL);
- }
- else if (funcmap[i].eind)
- funcmap[i].eind ();
- else
- fprintf (stderr, "eflush `%s': no function defined\n", cmd);
- break;
- }
- i++;
- }
+ {
+ if (strcmp (funcmap[i].name, cmd) == 0)
+ {
+ if (funcmap[i].efunc)
+ {
+ if (p)
+ funcmap[i].efunc ("%s", p);
+ else
+ funcmap[i].efunc (NULL, NULL);
+ }
+ else if (funcmap[i].eefunc)
+ {
+ if (p)
+ funcmap[i].eefunc (retval, "%s", p);
+ else
+ funcmap[i].eefunc (retval, NULL, NULL);
+ }
+ else if (funcmap[i].eind)
+ funcmap[i].eind ();
+ else
+ fprintf (stderr, "eflush `%s': no function defined\n", cmd);
+ break;
+ }
+ i++;
+ }
if (! funcmap[i].name)
- fprintf (stderr, "eflush `%s': invalid function\n", cmd);
+ fprintf (stderr, "eflush `%s': invalid function\n", cmd);
}
fclose (fp);
if (unlink (EBUFFER_LOCK))
fprintf (stderr, "unlink `%s': %s", EBUFFER_LOCK, strerror (errno));
-
+
if (unlink (newfile))
fprintf (stderr, "unlink `%s': %s", newfile, strerror (errno));
@@ -348,7 +348,7 @@ void eflush (void)
{ \
int _i = ebuffer (_cmd, _retval, _fmt, _ap); \
if (_i) \
- return (_i); \
+ return (_i); \
}
static void elog (int level, const char *fmt, va_list ap)
@@ -377,12 +377,12 @@ static int _eindent (FILE *stream)
errno = 0;
amount = strtol (env, NULL, 0);
if (errno != 0 || amount < 0)
- amount = 0;
+ amount = 0;
else if (amount > INDENT_MAX)
- amount = INDENT_MAX;
+ amount = INDENT_MAX;
if (amount > 0)
- memset (indent, ' ', amount);
+ memset (indent, ' ', amount);
}
/* Terminate it */
@@ -392,19 +392,19 @@ static int _eindent (FILE *stream)
}
#define VEINFON(_file, _colour) \
- if (colour_terminal ()) \
- fprintf (_file, " " _colour "*" EINFO_NORMAL " "); \
- else \
- fprintf (_file, " * "); \
- retval += _eindent (_file); \
- { \
- va_list _ap; \
- va_copy (_ap, ap); \
- retval += vfprintf (_file, fmt, _ap) + 3; \
- va_end (_ap); \
- } \
- if (colour_terminal ()) \
- fprintf (_file, "\033[K");
+ if (colour_terminal ()) \
+fprintf (_file, " " _colour "*" EINFO_NORMAL " "); \
+else \
+fprintf (_file, " * "); \
+retval += _eindent (_file); \
+{ \
+ va_list _ap; \
+ va_copy (_ap, ap); \
+ retval += vfprintf (_file, fmt, _ap) + 3; \
+ va_end (_ap); \
+} \
+if (colour_terminal ()) \
+fprintf (_file, "\033[K");
static int _veinfon (const char *fmt, va_list ap)
{
@@ -453,7 +453,7 @@ int ewarnn (const char *fmt, ...)
if (! fmt || is_env ("RC_QUIET", "yes"))
return (0);
-
+
va_start (ap, fmt);
if (! (retval = ebuffer ("ewarnn", 0, fmt, ap)))
retval = _vewarnn (fmt, ap);
@@ -591,45 +591,45 @@ static void _eend (int col, einfo_color_t color, const char *msg)
FILE *fp = stdout;
int i;
int cols;
-
+
if (! msg)
return;
if (color == einfo_bad)
fp = stderr;
-
+
cols = get_term_columns () - (strlen (msg) + 6);
if (cols > 0 && colour_terminal ())
{
fprintf (fp, "\033[A\033[%dC %s[ ", cols, EINFO_BRACKET);
switch (color)
- {
- case einfo_good:
- fprintf (fp, EINFO_GOOD);
- break;
- case einfo_warn:
- fprintf (fp, EINFO_WARN);
- break;
- case einfo_bad:
- fprintf (fp, EINFO_BAD);
- break;
- case einfo_hilite:
- fprintf (fp, EINFO_HILITE);
- break;
- case einfo_bracket:
- fprintf (fp, EINFO_BRACKET);
- break;
- case einfo_normal:
- fprintf (fp, EINFO_NORMAL);
- break;
- }
+ {
+ case einfo_good:
+ fprintf (fp, EINFO_GOOD);
+ break;
+ case einfo_warn:
+ fprintf (fp, EINFO_WARN);
+ break;
+ case einfo_bad:
+ fprintf (fp, EINFO_BAD);
+ break;
+ case einfo_hilite:
+ fprintf (fp, EINFO_HILITE);
+ break;
+ case einfo_bracket:
+ fprintf (fp, EINFO_BRACKET);
+ break;
+ case einfo_normal:
+ fprintf (fp, EINFO_NORMAL);
+ break;
+ }
fprintf (fp, "%s%s ]%s\n", msg, EINFO_BRACKET, EINFO_NORMAL);
}
else
{
for (i = -1; i < cols - col; i++)
- fprintf (fp, " ");
+ fprintf (fp, " ");
fprintf (fp, "[ %s ]\n", msg);
}
}
@@ -647,25 +647,25 @@ static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap)
eb = ebuffer (cmd, retval, fmt, apc);
va_end (apc);
if (eb)
- return (retval);
+ return (retval);
}
if (fmt && retval != 0)
{
va_copy (apc, ap);
if (strcmp (cmd, "ewend") == 0)
- {
- col = _vewarnn (fmt, apc);
- fp = stdout;
- }
+ {
+ col = _vewarnn (fmt, apc);
+ fp = stdout;
+ }
else
- {
- col = _veerrorn (fmt, apc);
- fp = stderr;
- }
+ {
+ col = _veerrorn (fmt, apc);
+ fp = stderr;
+ }
va_end (apc);
if (colour_terminal ())
- fprintf (fp, "\n");
+ fprintf (fp, "\n");
}
_eend (col, retval == 0 ? einfo_good : einfo_bad, retval == 0 ? OK : NOT_OK);
@@ -685,7 +685,7 @@ int eend (int retval, const char *fmt, ...)
return (retval);
}
-
+
int ewend (int retval, const char *fmt, ...)
{
va_list ap;
@@ -719,7 +719,7 @@ void eindent (void)
errno = 0;
amount = strtol (env, NULL, 0);
if (errno != 0)
- amount = 0;
+ amount = 0;
}
amount += INDENT_WIDTH;
@@ -738,10 +738,10 @@ void eoutdent (void)
if (ebuffer ("eoutdent", 0, NULL, NULL))
return;
-
+
if (! env)
return;
-
+
errno = 0;
amount = strtol (env, NULL, 0);
if (errno != 0)
@@ -785,7 +785,7 @@ int vewarnn (const char *fmt, ...)
if (! fmt)
return (0);
-
+
va_start (ap, fmt);
if (! (retval = ebuffer ("vewarnn", 0, fmt, ap)))
retval = _vewarnn (fmt, ap);
@@ -810,7 +810,7 @@ int veinfo (const char *fmt, ...)
retval = _veinfon (fmt, ap);
retval += printf ("\n");
}
- va_end (ap);
+ va_end (ap);
return (retval);
}
@@ -831,7 +831,7 @@ int vewarn (const char *fmt, ...)
retval = _vewarnn (fmt, ap);
retval += printf ("\n");
}
- va_end (ap);
+ va_end (ap);
retval += printf ("\n");
return (retval);
@@ -853,7 +853,7 @@ int vebegin (const char *fmt, ...)
retval = _veinfon (fmt, ap);
retval += printf (" ...");
if (colour_terminal ())
- retval += printf ("\n");
+ retval += printf ("\n");
}
va_end (ap);
diff --git a/src/librc-daemon.c b/src/librc-daemon.c
index dcac300c..3add7e4c 100644
--- a/src/librc-daemon.c
+++ b/src/librc-daemon.c
@@ -75,19 +75,19 @@ static bool pid_is_exec (pid_t pid, const char *exec)
if (readlink (cmdline, buffer, sizeof (buffer)) != -1)
{
if (strcmp (exec, buffer) == 0)
- return (true);
+ return (true);
/* We should cater for deleted binaries too */
if (strlen (buffer) > 10)
- {
- p = buffer + (strlen (buffer) - 10);
- if (strcmp (p, " (deleted)") == 0)
- {
- *p = 0;
- if (strcmp (buffer, exec) == 0)
- return (true);
- }
- }
+ {
+ p = buffer + (strlen (buffer) - 10);
+ if (strcmp (p, " (deleted)") == 0)
+ {
+ *p = 0;
+ if (strcmp (buffer, exec) == 0)
+ return (true);
+ }
+ }
}
snprintf (cmdline, sizeof (cmdline), "/proc/%u/cmdline", pid);
@@ -105,7 +105,7 @@ static bool pid_is_exec (pid_t pid, const char *exec)
}
pid_t *rc_find_pids (const char *exec, const char *cmd,
- uid_t uid, pid_t pid)
+ uid_t uid, pid_t pid)
{
DIR *procdir;
struct dirent *entry;
@@ -130,42 +130,42 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
catching /etc/init.d/ntpd stop
nasty
- */
+ */
if ((pp = getenv ("RC_RUNSCRIPT_PID")))
{
if (sscanf (pp, "%d", &runscript_pid) != 1)
- runscript_pid = 0;
+ runscript_pid = 0;
}
while ((entry = readdir (procdir)) != NULL)
{
if (sscanf (entry->d_name, "%d", &p) != 1)
- continue;
+ continue;
foundany = true;
if (runscript_pid != 0 && runscript_pid == p)
- continue;
+ continue;
if (pid != 0 && pid != p)
- continue;
+ continue;
if (uid)
- {
- snprintf (buffer, sizeof (buffer), "/proc/%d", pid);
- if (stat (buffer, &sb) != 0 || sb.st_uid != uid)
- continue;
- }
+ {
+ snprintf (buffer, sizeof (buffer), "/proc/%d", pid);
+ if (stat (buffer, &sb) != 0 || sb.st_uid != uid)
+ continue;
+ }
if (cmd && ! pid_is_cmd (p, cmd))
- continue;
-
+ continue;
+
if (exec && ! cmd && ! pid_is_exec (p, exec))
- continue;
+ continue;
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
if (! pids)
- eerrorx ("memory exhausted");
+ eerrorx ("memory exhausted");
pids[npids] = p;
pids[npids + 1] = 0;
@@ -200,7 +200,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
# endif
pid_t *rc_find_pids (const char *exec, const char *cmd,
- uid_t uid, pid_t pid)
+ uid_t uid, pid_t pid)
{
static kvm_t *kd = NULL;
char errbuf[_POSIX2_LINE_MAX];
@@ -219,36 +219,36 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
#else
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
- &processes);
+ &processes);
#endif
for (i = 0; i < processes; i++)
{
pid_t p = _GET_KINFO_PID (kp[i]);
if (pid != 0 && pid != p)
- continue;
+ continue;
if (uid != 0 && uid != _GET_KINFO_UID (kp[i]))
- continue;
+ continue;
if (cmd)
- {
- if (! _GET_KINFO_COMM (kp[i]) ||
- strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
- continue;
- }
+ {
+ if (! _GET_KINFO_COMM (kp[i]) ||
+ strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
+ continue;
+ }
if (exec && ! cmd)
- {
- if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv)
- continue;
+ {
+ if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv)
+ continue;
- if (strcmp (*argv, exec) != 0)
- continue;
- }
+ if (strcmp (*argv, exec) != 0)
+ continue;
+ }
pids = realloc (pids, sizeof (pid_t) * (npids + 2));
if (! pids)
- eerrorx ("memory exhausted");
+ eerrorx ("memory exhausted");
pids[npids] = p;
pids[npids + 1] = 0;
@@ -264,8 +264,8 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
#endif
static bool _match_daemon (const char *path, const char *file,
- const char *mexec, const char *mname,
- const char *mpidfile)
+ const char *mexec, const char *mname,
+ const char *mpidfile)
{
char buffer[RC_LINEBUFFER];
char *ffile = rc_strcatpaths (path, file, (char *) NULL);
@@ -296,21 +296,21 @@ static bool _match_daemon (const char *path, const char *file,
{
int lb = strlen (buffer) - 1;
if (buffer[lb] == '\n')
- buffer[lb] = 0;
+ buffer[lb] = 0;
if (strcmp (buffer, mexec) == 0)
- m += 1;
+ m += 1;
else if (mname && strcmp (buffer, mname) == 0)
- m += 10;
+ m += 10;
else if (mpidfile && strcmp (buffer, mpidfile) == 0)
- m += 100;
+ m += 100;
if (m == 111)
- break;
+ break;
lc++;
if (lc > 5)
- break;
+ break;
}
fclose (fp);
free (ffile);
@@ -319,11 +319,11 @@ static bool _match_daemon (const char *path, const char *file,
}
void rc_set_service_daemon (const char *service, const char *exec,
- const char *name, const char *pidfile,
- bool started)
+ const char *name, const char *pidfile,
+ bool started)
{
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
- (char *) NULL);
+ (char *) NULL);
char **files = NULL;
char *file;
char *ffile = NULL;
@@ -369,28 +369,28 @@ void rc_set_service_daemon (const char *service, const char *exec,
char *oldfile = NULL;
files = rc_ls_dir (NULL, dirpath, 0);
STRLIST_FOREACH (files, file, i)
- {
- ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
- nfiles++;
-
- if (! oldfile)
- {
- if (_match_daemon (dirpath, file, mexec, mname, mpidfile))
- {
- unlink (ffile);
- oldfile = ffile;
- nfiles--;
- }
- }
- else
- {
- rename (ffile, oldfile);
- free (oldfile);
- oldfile = ffile;
- }
- }
+ {
+ ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
+ nfiles++;
+
+ if (! oldfile)
+ {
+ if (_match_daemon (dirpath, file, mexec, mname, mpidfile))
+ {
+ unlink (ffile);
+ oldfile = ffile;
+ nfiles--;
+ }
+ }
+ else
+ {
+ rename (ffile, oldfile);
+ free (oldfile);
+ oldfile = ffile;
+ }
+ }
if (ffile)
- free (ffile);
+ free (ffile);
free (files);
}
@@ -401,18 +401,18 @@ void rc_set_service_daemon (const char *service, const char *exec,
FILE *fp;
if (! rc_is_dir (dirpath))
- if (mkdir (dirpath, 0755) != 0)
- eerror ("mkdir `%s': %s", dirpath, strerror (errno));
+ if (mkdir (dirpath, 0755) != 0)
+ eerror ("mkdir `%s': %s", dirpath, strerror (errno));
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
file = rc_strcatpaths (dirpath, buffer, (char *) NULL);
if ((fp = fopen (file, "w")) == NULL)
- eerror ("fopen `%s': %s", file, strerror (errno));
+ eerror ("fopen `%s': %s", file, strerror (errno));
else
- {
- fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
- fclose (fp);
- }
+ {
+ fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
+ fclose (fp);
+ }
free (file);
}
@@ -423,7 +423,7 @@ void rc_set_service_daemon (const char *service, const char *exec,
}
bool rc_service_started_daemon (const char *service, const char *exec,
- int indx)
+ int indx)
{
char *dirpath;
char *file;
@@ -435,7 +435,7 @@ bool rc_service_started_daemon (const char *service, const char *exec,
return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (! rc_is_dir (dirpath))
{
free (dirpath);
@@ -458,11 +458,11 @@ bool rc_service_started_daemon (const char *service, const char *exec,
{
char **files = rc_ls_dir (NULL, dirpath, 0);
STRLIST_FOREACH (files, file, i)
- {
- retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
- if (retval)
- break;
- }
+ {
+ retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
+ if (retval)
+ break;
+ }
free (files);
}
@@ -492,7 +492,7 @@ bool rc_service_daemons_crashed (const char *service)
return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (! rc_is_dir (dirpath))
{
free (dirpath);
@@ -507,91 +507,91 @@ bool rc_service_daemons_crashed (const char *service)
fp = fopen (path, "r");
free (path);
if (! fp)
- {
- eerror ("fopen `%s': %s", file, strerror (errno));
- continue;
- }
+ {
+ eerror ("fopen `%s': %s", file, strerror (errno));
+ continue;
+ }
while ((fgets (buffer, RC_LINEBUFFER, fp)))
- {
- int lb = strlen (buffer) - 1;
- if (buffer[lb] == '\n')
- buffer[lb] = 0;
-
- p = buffer;
- if ((token = strsep (&p, "=")) == NULL || ! p)
- continue;
-
- if (strlen (p) == 0)
- continue;
-
- if (strcmp (token, "exec") == 0)
- {
- if (exec)
- free (exec);
- exec = strdup (p);
- }
- else if (strcmp (token, "name") == 0)
- {
- if (name)
- free (name);
- name = strdup (p);
- }
- else if (strcmp (token, "pidfile") == 0)
- {
- if (pidfile)
- free (pidfile);
- pidfile = strdup (p);
- }
- }
+ {
+ int lb = strlen (buffer) - 1;
+ if (buffer[lb] == '\n')
+ buffer[lb] = 0;
+
+ p = buffer;
+ if ((token = strsep (&p, "=")) == NULL || ! p)
+ continue;
+
+ if (strlen (p) == 0)
+ continue;
+
+ if (strcmp (token, "exec") == 0)
+ {
+ if (exec)
+ free (exec);
+ exec = strdup (p);
+ }
+ else if (strcmp (token, "name") == 0)
+ {
+ if (name)
+ free (name);
+ name = strdup (p);
+ }
+ else if (strcmp (token, "pidfile") == 0)
+ {
+ if (pidfile)
+ free (pidfile);
+ pidfile = strdup (p);
+ }
+ }
fclose (fp);
pid = 0;
if (pidfile)
- {
- if (! rc_exists (pidfile))
- {
- retval = true;
- break;
- }
-
- if ((fp = fopen (pidfile, "r")) == NULL)
- {
- eerror ("fopen `%s': %s", pidfile, strerror (errno));
- retval = true;
- break;
- }
-
- if (fscanf (fp, "%d", &pid) != 1)
- {
- eerror ("no pid found in `%s'", pidfile);
- fclose (fp);
- retval = true;
- break;
- }
-
- fclose (fp);
- free (pidfile);
- pidfile = NULL;
- }
+ {
+ if (! rc_exists (pidfile))
+ {
+ retval = true;
+ break;
+ }
+
+ if ((fp = fopen (pidfile, "r")) == NULL)
+ {
+ eerror ("fopen `%s': %s", pidfile, strerror (errno));
+ retval = true;
+ break;
+ }
+
+ if (fscanf (fp, "%d", &pid) != 1)
+ {
+ eerror ("no pid found in `%s'", pidfile);
+ fclose (fp);
+ retval = true;
+ break;
+ }
+
+ fclose (fp);
+ free (pidfile);
+ pidfile = NULL;
+ }
if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL)
- {
- retval = true;
- break;
- }
+ {
+ retval = true;
+ break;
+ }
free (pids);
if (exec)
- {
- free (exec);
- exec = NULL;
- }
+ {
+ free (exec);
+ exec = NULL;
+ }
if (name)
- {
- free (name);
- name = NULL;
- }
+ {
+ free (name);
+ name = NULL;
+ }
}
if (exec)
diff --git a/src/librc-depend.c b/src/librc-depend.c
index c8967f0b..9c3a9c3f 100644
--- a/src/librc-depend.c
+++ b/src/librc-depend.c
@@ -59,13 +59,13 @@ void rc_free_deptree (rc_depinfo_t *deptree)
rc_deptype_t *dt = di->depends;
free (di->service);
while (dt)
- {
- rc_deptype_t *dtp = dt->next;
- free (dt->type);
- rc_strlist_free (dt->services);
- free (dt);
- dt = dtp;
- }
+ {
+ rc_deptype_t *dtp = dt->next;
+ free (dt->type);
+ rc_strlist_free (dt->services);
+ free (dt);
+ dt = dtp;
+ }
free (di);
di = dip;
}
@@ -94,63 +94,63 @@ rc_depinfo_t *rc_load_deptree (void)
p = buffer;
e = strsep (&p, "_");
if (! e || strcmp (e, "depinfo") != 0)
- continue;
+ continue;
e = strsep (&p, "_");
if (! e || sscanf (e, "%d", &i) != 1)
- continue;
+ continue;
if (! (type = strsep (&p, "_=")))
- continue;
+ continue;
if (strcmp (type, "service") == 0)
- {
- /* Sanity */
- e = get_shell_value (p);
- if (! e || strlen (e) == 0)
- continue;
-
- if (! deptree)
- {
- deptree = rc_xmalloc (sizeof (rc_depinfo_t));
- depinfo = deptree;
- }
- else
- {
- depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
- depinfo = depinfo->next;
- }
- memset (depinfo, 0, sizeof (rc_depinfo_t));
- depinfo->service = strdup (e);
- deptype = NULL;
- continue;
- }
+ {
+ /* Sanity */
+ e = get_shell_value (p);
+ if (! e || strlen (e) == 0)
+ continue;
+
+ if (! deptree)
+ {
+ deptree = rc_xmalloc (sizeof (rc_depinfo_t));
+ depinfo = deptree;
+ }
+ else
+ {
+ depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
+ depinfo = depinfo->next;
+ }
+ memset (depinfo, 0, sizeof (rc_depinfo_t));
+ depinfo->service = strdup (e);
+ deptype = NULL;
+ continue;
+ }
e = strsep (&p, "=");
if (! e || sscanf (e, "%d", &i) != 1)
- continue;
+ continue;
/* Sanity */
e = get_shell_value (p);
if (! e || strlen (e) == 0)
- continue;
+ continue;
if (! deptype)
- {
- depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
- deptype = depinfo->depends;
- memset (deptype, 0, sizeof (rc_deptype_t));
- }
+ {
+ depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
+ deptype = depinfo->depends;
+ memset (deptype, 0, sizeof (rc_deptype_t));
+ }
else
- if (strcmp (deptype->type, type) != 0)
- {
- deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
- deptype = deptype->next;
- memset (deptype, 0, sizeof (rc_deptype_t));
- }
+ if (strcmp (deptype->type, type) != 0)
+ {
+ deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
+ deptype = deptype->next;
+ memset (deptype, 0, sizeof (rc_deptype_t));
+ }
if (! deptype->type)
- deptype->type = strdup (type);
+ deptype->type = strdup (type);
deptype->services = rc_strlist_addsort (deptype->services, e);
}
@@ -190,16 +190,16 @@ rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type)
static bool valid_service (const char *runlevel, const char *service)
{
return ((strcmp (runlevel, RC_LEVEL_BOOT) != 0 &&
- rc_service_in_runlevel (service, RC_LEVEL_BOOT)) ||
- rc_service_in_runlevel (service, runlevel) ||
- rc_service_state (service, rc_service_coldplugged) ||
- rc_service_state (service, rc_service_started));
+ rc_service_in_runlevel (service, RC_LEVEL_BOOT)) ||
+ rc_service_in_runlevel (service, runlevel) ||
+ rc_service_state (service, rc_service_coldplugged) ||
+ rc_service_state (service, rc_service_started));
}
static bool get_provided1 (const char *runlevel, struct lhead *providers,
- rc_deptype_t *deptype,
- const char *level, bool coldplugged,
- bool started, bool inactive)
+ rc_deptype_t *deptype,
+ const char *level, bool coldplugged,
+ bool started, bool inactive)
{
char *service;
int i;
@@ -209,25 +209,25 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
{
bool ok = true;
if (level)
- ok = rc_service_in_runlevel (service, level);
+ ok = rc_service_in_runlevel (service, level);
else if (coldplugged)
- ok = (rc_service_state (service, rc_service_coldplugged) &&
- ! rc_service_in_runlevel (service, runlevel) &&
- ! rc_service_in_runlevel (service, RC_LEVEL_BOOT));
+ ok = (rc_service_state (service, rc_service_coldplugged) &&
+ ! rc_service_in_runlevel (service, runlevel) &&
+ ! rc_service_in_runlevel (service, RC_LEVEL_BOOT));
if (! ok)
- continue;
+ continue;
if (started)
- ok = (rc_service_state (service, rc_service_starting) ||
- rc_service_state (service, rc_service_started) ||
- rc_service_state (service, rc_service_stopping));
+ ok = (rc_service_state (service, rc_service_starting) ||
+ rc_service_state (service, rc_service_started) ||
+ rc_service_state (service, rc_service_stopping));
else if (inactive)
- ok = rc_service_state (service, rc_service_inactive);
+ ok = rc_service_state (service, rc_service_inactive);
if (! ok)
- continue;
-
+ continue;
+
retval = true;
providers->list = rc_strlist_add (providers->list, service);
}
@@ -245,7 +245,7 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
provided dependancy can change depending on runlevel state.
*/
static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
- const char *runlevel, int options)
+ const char *runlevel, int options)
{
rc_deptype_t *dt;
struct lhead providers;
@@ -268,7 +268,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (options & RC_DEP_STOP)
{
STRLIST_FOREACH (dt->services, service, i)
- providers.list = rc_strlist_add (providers.list, service);
+ providers.list = rc_strlist_add (providers.list, service);
return (providers.list);
}
@@ -277,11 +277,11 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (options & RC_DEP_STRICT)
{
STRLIST_FOREACH (dt->services, service, i)
- if (rc_service_in_runlevel (service, runlevel))
- providers.list = rc_strlist_add (providers.list, service);
+ if (rc_service_in_runlevel (service, runlevel))
+ providers.list = rc_strlist_add (providers.list, service);
if (providers.list)
- return (providers.list);
+ return (providers.list);
}
/* OK, we're not strict or there were no services in our runlevel.
@@ -298,7 +298,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
return (NULL); \
} \
else if (providers.list) \
- return providers.list; \
+ return providers.list; \
/* Anything in the runlevel has to come first */
if (get_provided1 (runlevel, &providers, dt, runlevel, false, true, false))
@@ -316,9 +316,9 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (strcmp (runlevel, RC_LEVEL_BOOT) != 0)
{
if (get_provided1 (runlevel, &providers, dt, RC_LEVEL_BOOT, false, true, false))
- { DO }
+ { DO }
if (get_provided1 (runlevel, &providers, dt, RC_LEVEL_BOOT, false, false, true))
- { DO }
+ { DO }
}
/* Check coldplugged inactive services */
@@ -340,15 +340,15 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
/* Still nothing? OK, list all services */
STRLIST_FOREACH (dt->services, service, i)
- providers.list = rc_strlist_add (providers.list, service);
+ providers.list = rc_strlist_add (providers.list, service);
return (providers.list);
}
static void visit_service (rc_depinfo_t *deptree, char **types,
- struct lhead *sorted, struct lhead *visited,
- rc_depinfo_t *depinfo,
- const char *runlevel, int options)
+ struct lhead *sorted, struct lhead *visited,
+ rc_depinfo_t *depinfo,
+ const char *runlevel, int options)
{
int i, j, k;
char *lp, *item;
@@ -372,55 +372,55 @@ static void visit_service (rc_depinfo_t *deptree, char **types,
STRLIST_FOREACH (types, item, i)
{
if ((dt = rc_get_deptype (depinfo, item)))
- {
- STRLIST_FOREACH (dt->services, service, j)
- {
- if (! options & RC_DEP_TRACE || strcmp (item, "iprovide") == 0)
- {
- sorted->list = rc_strlist_add (sorted->list, service);
- continue;
- }
-
- di = rc_get_depinfo (deptree, service);
- if ((provides = get_provided (deptree, di, runlevel, options)))
- {
- STRLIST_FOREACH (provides, lp, k)
- {
- di = rc_get_depinfo (deptree, lp);
- if (di && (strcmp (item, "ineed") == 0 ||
- valid_service (runlevel, di->service)))
- visit_service (deptree, types, sorted, visited, di,
- runlevel, options | RC_DEP_TRACE);
- }
- rc_strlist_free (provides);
- }
- else
- if (di && (strcmp (item, "ineed") == 0 ||
- valid_service (runlevel, service)))
- visit_service (deptree, types, sorted, visited, di,
- runlevel, options | RC_DEP_TRACE);
- }
- }
+ {
+ STRLIST_FOREACH (dt->services, service, j)
+ {
+ if (! options & RC_DEP_TRACE || strcmp (item, "iprovide") == 0)
+ {
+ sorted->list = rc_strlist_add (sorted->list, service);
+ continue;
+ }
+
+ di = rc_get_depinfo (deptree, service);
+ if ((provides = get_provided (deptree, di, runlevel, options)))
+ {
+ STRLIST_FOREACH (provides, lp, k)
+ {
+ di = rc_get_depinfo (deptree, lp);
+ if (di && (strcmp (item, "ineed") == 0 ||
+ valid_service (runlevel, di->service)))
+ visit_service (deptree, types, sorted, visited, di,
+ runlevel, options | RC_DEP_TRACE);
+ }
+ rc_strlist_free (provides);
+ }
+ else
+ if (di && (strcmp (item, "ineed") == 0 ||
+ valid_service (runlevel, service)))
+ visit_service (deptree, types, sorted, visited, di,
+ runlevel, options | RC_DEP_TRACE);
+ }
+ }
}
/* Now visit the stuff we provide for */
if (options & RC_DEP_TRACE && (dt = rc_get_deptype (depinfo, "iprovide")))
{
STRLIST_FOREACH (dt->services, service, i)
- {
- if ((di = rc_get_depinfo (deptree, service)))
- if ((provides = get_provided (deptree, di, runlevel, options)))
- {
- STRLIST_FOREACH (provides, lp, j)
- if (strcmp (lp, depinfo->service) == 0)
- {
- visit_service (deptree, types, sorted, visited, di,
- runlevel, options | RC_DEP_TRACE);
- break;
- }
- rc_strlist_free (provides);
- }
- }
+ {
+ if ((di = rc_get_depinfo (deptree, service)))
+ if ((provides = get_provided (deptree, di, runlevel, options)))
+ {
+ STRLIST_FOREACH (provides, lp, j)
+ if (strcmp (lp, depinfo->service) == 0)
+ {
+ visit_service (deptree, types, sorted, visited, di,
+ runlevel, options | RC_DEP_TRACE);
+ break;
+ }
+ rc_strlist_free (provides);
+ }
+ }
}
/* We've visited everything we need, so add ourselves unless we
@@ -432,8 +432,8 @@ static void visit_service (rc_depinfo_t *deptree, char **types,
}
char **rc_get_depends (rc_depinfo_t *deptree,
- char **types, char **services,
- const char *runlevel, int options)
+ char **types, char **services,
+ const char *runlevel, int options)
{
struct lhead sorted;
struct lhead visited;
@@ -458,7 +458,7 @@ char **rc_get_depends (rc_depinfo_t *deptree,
}
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
- int options)
+ int options)
{
char **list = NULL;
char **types = NULL;
@@ -487,12 +487,12 @@ char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
/* If we're not the boot runlevel then add that too */
if (strcmp (runlevel, RC_LEVEL_BOOT) != 0)
- {
- char *path = rc_strcatpaths (RC_RUNLEVELDIR, RC_LEVEL_BOOT,
- (char *) NULL);
- list = rc_ls_dir (list, path, RC_LS_INITD);
- free (path);
- }
+ {
+ char *path = rc_strcatpaths (RC_RUNLEVELDIR, RC_LEVEL_BOOT,
+ (char *) NULL);
+ list = rc_ls_dir (list, path, RC_LS_INITD);
+ free (path);
+ }
}
/* Now we have our lists, we need to pull in any dependencies
@@ -501,7 +501,7 @@ char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
types = rc_strlist_add (types, "iuse");
types = rc_strlist_add (types, "iafter");
services = rc_get_depends (deptree, types, list, runlevel,
- RC_DEP_STRICT | RC_DEP_TRACE | options);
+ RC_DEP_STRICT | RC_DEP_TRACE | options);
rc_strlist_free (list);
rc_strlist_free (types);
@@ -533,13 +533,13 @@ static bool is_newer_than (const char *file, const char *target)
int i;
bool newer = true;
STRLIST_FOREACH (targets, t, i)
- {
- char *path = rc_strcatpaths (target, t, (char *) NULL);
- newer = is_newer_than (file, path);
- free (path);
- if (! newer)
- break;
- }
+ {
+ char *path = rc_strcatpaths (target, t, (char *) NULL);
+ newer = is_newer_than (file, path);
+ free (path);
+ if (! newer)
+ break;
+ }
rc_strlist_free (targets);
return (newer);
}
@@ -613,13 +613,13 @@ int rc_update_deptree (bool force)
for (i = 0; depdirs[i]; i++)
if (! rc_is_dir (depdirs[i]))
if (mkdir (depdirs[i], 0755) != 0)
- eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno));
+ eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno));
if (! force)
if (is_newer_than (RC_DEPTREE, RC_INITDIR) &&
- is_newer_than (RC_DEPTREE, RC_CONFDIR) &&
- is_newer_than (RC_DEPTREE, "/etc/rc.conf"))
- return 0;
+ is_newer_than (RC_DEPTREE, RC_CONFDIR) &&
+ is_newer_than (RC_DEPTREE, "/etc/rc.conf"))
+ return 0;
ebegin ("Caching service dependencies");
@@ -641,79 +641,79 @@ int rc_update_deptree (bool force)
{
/* Trim the newline */
if (buffer[strlen (buffer) - 1] == '\n')
- buffer[strlen(buffer) -1] = 0;
+ buffer[strlen(buffer) -1] = 0;
depends = buffer;
service = strsep (&depends, " ");
if (! service)
- continue;
+ continue;
type = strsep (&depends, " ");
for (depinfo = deptree; depinfo; depinfo = depinfo->next)
- {
- last_depinfo = depinfo;
- if (depinfo->service && strcmp (depinfo->service, service) == 0)
- break;
- }
+ {
+ last_depinfo = depinfo;
+ if (depinfo->service && strcmp (depinfo->service, service) == 0)
+ break;
+ }
if (! depinfo)
- {
- if (! last_depinfo->service)
- depinfo = last_depinfo;
- else
- {
- last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
- depinfo = last_depinfo->next;
- }
- memset (depinfo, 0, sizeof (rc_depinfo_t));
- depinfo->service = strdup (service);
- }
+ {
+ if (! last_depinfo->service)
+ depinfo = last_depinfo;
+ else
+ {
+ last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
+ depinfo = last_depinfo->next;
+ }
+ memset (depinfo, 0, sizeof (rc_depinfo_t));
+ depinfo->service = strdup (service);
+ }
/* We may not have any depends */
if (! type || ! depends)
- continue;
+ continue;
last_deptype = NULL;
for (deptype = depinfo->depends; deptype; deptype = deptype->next)
- {
- last_deptype = deptype;
- if (strcmp (deptype->type, type) == 0)
- break;
- }
+ {
+ last_deptype = deptype;
+ if (strcmp (deptype->type, type) == 0)
+ break;
+ }
if (! deptype)
- {
- if (! last_deptype)
- {
- depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
- deptype = depinfo->depends;
- }
- else
- {
- last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
- deptype = last_deptype->next;
- }
- memset (deptype, 0, sizeof (rc_deptype_t));
- deptype->type = strdup (type);
- }
+ {
+ if (! last_deptype)
+ {
+ depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
+ deptype = depinfo->depends;
+ }
+ else
+ {
+ last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
+ deptype = last_deptype->next;
+ }
+ memset (deptype, 0, sizeof (rc_deptype_t));
+ deptype->type = strdup (type);
+ }
/* Now add each depend to our type.
- We do this individually so we handle multiple spaces gracefully */
+ We do this individually so we handle multiple spaces gracefully */
while ((depend = strsep (&depends, " ")))
- {
- if (depend[0] == 0)
- continue;
+ {
+ if (depend[0] == 0)
+ continue;
- /* .sh files are not init scripts */
- len = strlen (depend);
- if (len > 2 &&
- depend[len - 3] == '.' &&
- depend[len - 2] == 's' &&
- depend[len - 1] == 'h')
- continue;
+ /* .sh files are not init scripts */
+ len = strlen (depend);
+ if (len > 2 &&
+ depend[len - 3] == '.' &&
+ depend[len - 2] == 's' &&
+ depend[len - 1] == 'h')
+ continue;
- deptype->services = rc_strlist_addsort (deptype->services, depend);
- }
+ deptype->services = rc_strlist_addsort (deptype->services, depend);
+ }
}
pclose (fp);
@@ -722,84 +722,84 @@ int rc_update_deptree (bool force)
for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{
if ((deptype = rc_get_deptype (depinfo, "iprovide")))
- STRLIST_FOREACH (deptype->services, service, i)
- {
- for (di = deptree; di; di = di->next)
- {
- last_depinfo = di;
- if (strcmp (di->service, service) == 0)
- break;
- }
- if (! di)
- {
- last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
- di = last_depinfo->next;
- memset (di, 0, sizeof (rc_depinfo_t));
- di->service = strdup (service);
- }
- }
+ STRLIST_FOREACH (deptype->services, service, i)
+ {
+ for (di = deptree; di; di = di->next)
+ {
+ last_depinfo = di;
+ if (strcmp (di->service, service) == 0)
+ break;
+ }
+ if (! di)
+ {
+ last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
+ di = last_depinfo->next;
+ memset (di, 0, sizeof (rc_depinfo_t));
+ di->service = strdup (service);
+ }
+ }
}
/* Phase 4 - backreference our depends */
for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{
for (i = 0; deppairs[i].depend; i++)
- {
- deptype = rc_get_deptype (depinfo, deppairs[i].depend);
- if (! deptype)
- continue;
-
- STRLIST_FOREACH (deptype->services, service, j)
- {
- di = rc_get_depinfo (deptree, service);
- if (! di)
- {
- if (strcmp (deptype->type, "ineed") == 0)
- {
- eerror ("Service `%s' needs non existant service `%s'",
- depinfo->service, service);
- retval = -1;
- }
- continue;
- }
-
- /* Add our deptype now */
- last_deptype = NULL;
- for (dt = di->depends; dt; dt = dt->next)
- {
- last_deptype = dt;
- if (strcmp (dt->type, deppairs[i].addto) == 0)
- break;
- }
- if (! dt)
- {
- if (! last_deptype)
- {
- di->depends = rc_xmalloc (sizeof (rc_deptype_t));
- dt = di->depends;
- }
- else
- {
- last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
- dt = last_deptype->next;
- }
- memset (dt, 0, sizeof (rc_deptype_t));
- dt->type = strdup (deppairs[i].addto);
- }
-
- already_added = false;
- STRLIST_FOREACH (dt->services, service, k)
- if (strcmp (service, depinfo->service) == 0)
- {
- already_added = true;
- break;
- }
-
- if (! already_added)
- dt->services = rc_strlist_addsort (dt->services,
- depinfo->service);
- }
- }
+ {
+ deptype = rc_get_deptype (depinfo, deppairs[i].depend);
+ if (! deptype)
+ continue;
+
+ STRLIST_FOREACH (deptype->services, service, j)
+ {
+ di = rc_get_depinfo (deptree, service);
+ if (! di)
+ {
+ if (strcmp (deptype->type, "ineed") == 0)
+ {
+ eerror ("Service `%s' needs non existant service `%s'",
+ depinfo->service, service);
+ retval = -1;
+ }
+ continue;
+ }
+
+ /* Add our deptype now */
+ last_deptype = NULL;
+ for (dt = di->depends; dt; dt = dt->next)
+ {
+ last_deptype = dt;
+ if (strcmp (dt->type, deppairs[i].addto) == 0)
+ break;
+ }
+ if (! dt)
+ {
+ if (! last_deptype)
+ {
+ di->depends = rc_xmalloc (sizeof (rc_deptype_t));
+ dt = di->depends;
+ }
+ else
+ {
+ last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
+ dt = last_deptype->next;
+ }
+ memset (dt, 0, sizeof (rc_deptype_t));
+ dt->type = strdup (deppairs[i].addto);
+ }
+
+ already_added = false;
+ STRLIST_FOREACH (dt->services, service, k)
+ if (strcmp (service, depinfo->service) == 0)
+ {
+ already_added = true;
+ break;
+ }
+
+ if (! already_added)
+ dt->services = rc_strlist_addsort (dt->services,
+ depinfo->service);
+ }
+ }
}
/* Phase 5 - save to disk
@@ -814,20 +814,20 @@ int rc_update_deptree (bool force)
{
i = 0;
for (depinfo = deptree; depinfo; depinfo = depinfo->next)
- {
- fprintf (fp, "depinfo_%d_service='%s'\n", i, depinfo->service);
- for (deptype = depinfo->depends; deptype; deptype = deptype->next)
- {
- k = 0;
- STRLIST_FOREACH (deptype->services, service, j)
- {
- fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type,
- k, service);
- k++;
- }
- }
- i++;
- }
+ {
+ fprintf (fp, "depinfo_%d_service='%s'\n", i, depinfo->service);
+ for (deptype = depinfo->depends; deptype; deptype = deptype->next)
+ {
+ k = 0;
+ STRLIST_FOREACH (deptype->services, service, j)
+ {
+ fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type,
+ k, service);
+ k++;
+ }
+ }
+ i++;
+ }
fclose (fp);
}
diff --git a/src/librc-misc.c b/src/librc-misc.c
index b367ccc3..39b003ba 100644
--- a/src/librc-misc.c
+++ b/src/librc-misc.c
@@ -133,7 +133,7 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
while ((p = va_arg (ap, char *)) != NULL)
{
if (*pathp != '/')
- *pathp++ = '/';
+ *pathp++ = '/';
i = strlen (p);
memcpy (pathp, p, i);
pathp += i;
@@ -168,7 +168,7 @@ bool rc_is_file (const char *pathname)
if (stat (pathname, &buf) == 0)
return (S_ISREG (buf.st_mode));
-
+
errno = 0;
return (false);
}
@@ -196,7 +196,7 @@ bool rc_is_link (const char *pathname)
if (lstat (pathname, &buf) == 0)
return (S_ISLNK (buf.st_mode));
-
+
errno = 0;
return (false);
}
@@ -207,7 +207,7 @@ bool rc_is_exec (const char *pathname)
if (! pathname)
return (false);
-
+
if (lstat (pathname, &buf) == 0)
return (buf.st_mode & S_IXUGO);
@@ -233,25 +233,25 @@ char **rc_ls_dir (char **list, const char *dir, int options)
while (((d = readdir (dp)) != NULL) && errno == 0)
{
if (d->d_name[0] != '.')
- {
- if (options & RC_LS_INITD)
- {
- int l = strlen (d->d_name);
- char *init = rc_strcatpaths (RC_INITDIR, d->d_name,
- (char *) NULL);
- bool ok = rc_exists (init);
- free (init);
- if (! ok)
- continue;
-
- /* .sh files are not init scripts */
- if (l > 2 && d->d_name[l - 3] == '.' &&
- d->d_name[l - 2] == 's' &&
- d->d_name[l - 1] == 'h')
- continue;
- }
- list = rc_strlist_addsort (list, d->d_name);
- }
+ {
+ if (options & RC_LS_INITD)
+ {
+ int l = strlen (d->d_name);
+ char *init = rc_strcatpaths (RC_INITDIR, d->d_name,
+ (char *) NULL);
+ bool ok = rc_exists (init);
+ free (init);
+ if (! ok)
+ continue;
+
+ /* .sh files are not init scripts */
+ if (l > 2 && d->d_name[l - 3] == '.' &&
+ d->d_name[l - 2] == 's' &&
+ d->d_name[l - 1] == 'h')
+ continue;
+ }
+ list = rc_strlist_addsort (list, d->d_name);
+ }
}
closedir (dp);
@@ -283,29 +283,29 @@ bool rc_rm_dir (const char *pathname, bool top)
while (((d = readdir (dp)) != NULL) && errno == 0)
{
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
- {
- char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
- if (d->d_type == DT_DIR)
- {
- if (! rc_rm_dir (tmp, true))
- {
- free (tmp);
- closedir (dp);
- return (false);
- }
- }
- else
- {
- if (unlink (tmp))
- {
- eerror ("failed to unlink `%s': %s", tmp, strerror (errno));
- free (tmp);
- closedir (dp);
- return (false);
- }
- }
- free (tmp);
- }
+ {
+ char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
+ if (d->d_type == DT_DIR)
+ {
+ if (! rc_rm_dir (tmp, true))
+ {
+ free (tmp);
+ closedir (dp);
+ return (false);
+ }
+ }
+ else
+ {
+ if (unlink (tmp))
+ {
+ eerror ("failed to unlink `%s': %s", tmp, strerror (errno));
+ free (tmp);
+ closedir (dp);
+ return (false);
+ }
+ }
+ free (tmp);
+ }
}
if (errno != 0)
eerror ("failed to readdir `%s': %s", pathname, strerror (errno));
@@ -346,29 +346,29 @@ char **rc_get_config (char **list, const char *file)
/* Strip leading spaces/tabs */
while ((*p == ' ') || (*p == '\t'))
- p++;
+ p++;
if (! p || strlen (p) < 3 || p[0] == '#')
- continue;
+ continue;
/* Get entry */
token = strsep (&p, "=");
if (! token)
- continue;
+ continue;
entry = rc_xstrdup (token);
do
- {
- /* Bash variables are usually quoted */
- token = strsep (&p, "\"\'");
- }
+ {
+ /* Bash variables are usually quoted */
+ token = strsep (&p, "\"\'");
+ }
while ((token) && (strlen (token) == 0));
/* Drop a newline if that's all we have */
i = strlen (token) - 1;
if (token[i] == 10)
- token[i] = 0;
+ token[i] = 0;
i = strlen (entry) + strlen (token) + 2;
newline = rc_xmalloc (i);
@@ -376,29 +376,29 @@ char **rc_get_config (char **list, const char *file)
replaced = false;
/* In shells the last item takes precedence, so we need to remove
- any prior values we may already have */
+ any prior values we may already have */
STRLIST_FOREACH (list, line, i)
- {
- char *tmp = rc_xstrdup (line);
- linep = tmp;
- linetok = strsep (&linep, "=");
- if (strcmp (linetok, entry) == 0)
- {
- /* We have a match now - to save time we directly replace it */
- free (list[i - 1]);
- list[i - 1] = newline;
- replaced = true;
- free (tmp);
- break;
- }
- free (tmp);
- }
+ {
+ char *tmp = rc_xstrdup (line);
+ linep = tmp;
+ linetok = strsep (&linep, "=");
+ if (strcmp (linetok, entry) == 0)
+ {
+ /* We have a match now - to save time we directly replace it */
+ free (list[i - 1]);
+ list[i - 1] = newline;
+ replaced = true;
+ free (tmp);
+ break;
+ }
+ free (tmp);
+ }
if (! replaced)
- {
- list = rc_strlist_addsort (list, newline);
- free (newline);
- }
+ {
+ list = rc_strlist_addsort (list, newline);
+ free (newline);
+ }
free (entry);
}
fclose (fp);
@@ -416,7 +416,7 @@ char *rc_get_config_entry (char **list, const char *entry)
{
p = strchr (line, '=');
if (p && strncmp (entry, line, p - line) == 0)
- return (p += 1);
+ return (p += 1);
}
return (NULL);
@@ -441,18 +441,18 @@ char **rc_get_list (char **list, const char *file)
/* Strip leading spaces/tabs */
while ((*p == ' ') || (*p == '\t'))
- p++;
+ p++;
/* Get entry - we do not want comments */
token = strsep (&p, "#");
if (token && (strlen (token) > 1))
- {
- /* Stip the newline if present */
- if (token[strlen (token) - 1] == '\n')
- token[strlen (token) - 1] = 0;
+ {
+ /* Stip the newline if present */
+ if (token[strlen (token) - 1] == '\n')
+ token[strlen (token) - 1] = 0;
- list = rc_strlist_add (list, token);
- }
+ list = rc_strlist_add (list, token);
+ }
}
fclose (fp);
@@ -491,54 +491,54 @@ char **rc_filter_env (void)
{
char *space = strchr (env_name, ' ');
if (space)
- *space = 0;
+ *space = 0;
env_var = getenv (env_name);
if (! env_var && profile)
- {
- env_len = strlen (env_name) + strlen ("export ") + 1;
- p = rc_xmalloc (sizeof (char *) * env_len);
- snprintf (p, env_len, "export %s", env_name);
- env_var = rc_get_config_entry (profile, p);
- free (p);
- }
+ {
+ env_len = strlen (env_name) + strlen ("export ") + 1;
+ p = rc_xmalloc (sizeof (char *) * env_len);
+ snprintf (p, env_len, "export %s", env_name);
+ env_var = rc_get_config_entry (profile, p);
+ free (p);
+ }
if (! env_var)
- continue;
+ continue;
/* Ensure our PATH is prefixed with the system locations first
- for a little extra security */
- if (strcmp (env_name, "PATH") == 0 &&
- strncmp (PATH_PREFIX, env_var, pplen) != 0)
- {
- got_path = true;
- env_len = strlen (env_name) + strlen (env_var) + pplen + 2;
- e = p = rc_xmalloc (sizeof (char *) * env_len);
- p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX);
-
- /* Now go through the env var and only add bits not in our PREFIX */
- sep = env_var;
- while ((token = strsep (&sep, ":")))
- {
- char *np = strdup (PATH_PREFIX);
- char *npp = np;
- char *tok = NULL;
- while ((tok = strsep (&npp, ":")))
- if (strcmp (tok, token) == 0)
- break;
- if (! tok)
- p += snprintf (p, env_len - (p - e), ":%s", token);
- free (np);
- }
- *p++ = 0;
- }
+ for a little extra security */
+ if (strcmp (env_name, "PATH") == 0 &&
+ strncmp (PATH_PREFIX, env_var, pplen) != 0)
+ {
+ got_path = true;
+ env_len = strlen (env_name) + strlen (env_var) + pplen + 2;
+ e = p = rc_xmalloc (sizeof (char *) * env_len);
+ p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX);
+
+ /* Now go through the env var and only add bits not in our PREFIX */
+ sep = env_var;
+ while ((token = strsep (&sep, ":")))
+ {
+ char *np = strdup (PATH_PREFIX);
+ char *npp = np;
+ char *tok = NULL;
+ while ((tok = strsep (&npp, ":")))
+ if (strcmp (tok, token) == 0)
+ break;
+ if (! tok)
+ p += snprintf (p, env_len - (p - e), ":%s", token);
+ free (np);
+ }
+ *p++ = 0;
+ }
else
- {
- env_len = strlen (env_name) + strlen (env_var) + 2;
- e = rc_xmalloc (sizeof (char *) * env_len);
- snprintf (e, env_len, "%s=%s", env_name, env_var);
- }
+ {
+ env_len = strlen (env_name) + strlen (env_var) + 2;
+ e = rc_xmalloc (sizeof (char *) * env_len);
+ snprintf (e, env_len, "%s=%s", env_name, env_var);
+ }
env = rc_strlist_add (env, e);
free (e);
@@ -591,10 +591,10 @@ static bool file_regex (const char *file, const char *regex)
while (fgets (buffer, RC_LINEBUFFER, fp))
{
if (regexec (&re, buffer, 0, NULL, 0) == 0)
- {
- retval = true;
- break;
- }
+ {
+ retval = true;
+ break;
+ }
}
fclose (fp);
regfree (&re);
@@ -620,23 +620,23 @@ char **rc_config_env (char **env)
{
p = strchr (line, '=');
if (! p)
- continue;
+ continue;
*p = 0;
e = getenv (line);
if (! e)
- {
- *p = '=';
- env = rc_strlist_add (env, line);
- }
+ {
+ *p = '=';
+ env = rc_strlist_add (env, line);
+ }
else
- {
- int len = strlen (line) + strlen (e) + 2;
- char *new = rc_xmalloc (sizeof (char *) * len);
- snprintf (new, len, "%s=%s", line, e);
- env = rc_strlist_add (env, new);
- free (new);
- }
+ {
+ int len = strlen (line) + strlen (e) + 2;
+ char *new = rc_xmalloc (sizeof (char *) * len);
+ snprintf (new, len, "%s=%s", line, e);
+ env = rc_strlist_add (env, new);
+ free (new);
+ }
}
rc_strlist_free (config);
@@ -666,59 +666,59 @@ char **rc_config_env (char **env)
if (rc_exists (RC_SVCDIR "ksoftlevel"))
{
if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
- eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
- strerror (errno));
+ eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
+ strerror (errno));
else
- {
- memset (buffer, 0, sizeof (buffer));
- if (fgets (buffer, sizeof (buffer), fp))
- {
- i = strlen (buffer) - 1;
- if (buffer[i] == '\n')
- buffer[i] = 0;
- i += strlen ("RC_DEFAULTLEVEL=") + 2;
- line = rc_xmalloc (sizeof (char *) * i);
- snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer);
- env = rc_strlist_add (env, line);
- free (line);
- }
- fclose (fp);
- }
+ {
+ memset (buffer, 0, sizeof (buffer));
+ if (fgets (buffer, sizeof (buffer), fp))
+ {
+ i = strlen (buffer) - 1;
+ if (buffer[i] == '\n')
+ buffer[i] = 0;
+ i += strlen ("RC_DEFAULTLEVEL=") + 2;
+ line = rc_xmalloc (sizeof (char *) * i);
+ snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer);
+ env = rc_strlist_add (env, line);
+ free (line);
+ }
+ fclose (fp);
+ }
}
else
env = rc_strlist_add (env, "RC_DEFAULTLEVEL=" RC_LEVEL_DEFAULT);
memset (sys, 0, sizeof (sys));
-/* Linux can run some funky stuff like Xen, VServer, UML, etc
- We store this special system in RC_SYS so our scripts run fast */
+ /* Linux can run some funky stuff like Xen, VServer, UML, etc
+ We store this special system in RC_SYS so our scripts run fast */
#ifdef __linux__
if (rc_is_dir ("/proc/xen"))
{
fp = fopen ("/proc/xen/capabilities", "r");
if (fp)
- {
- fclose (fp);
- if (file_regex ("/proc/xen/capabilities", "control_d"))
- snprintf (sys, sizeof (sys), "XENU");
- }
+ {
+ fclose (fp);
+ if (file_regex ("/proc/xen/capabilities", "control_d"))
+ snprintf (sys, sizeof (sys), "XENU");
+ }
if (! sys)
- snprintf (sys, sizeof (sys), "XEN0");
+ snprintf (sys, sizeof (sys), "XEN0");
}
else if (file_regex ("/proc/cpuinfo", "UML"))
snprintf (sys, sizeof (sys), "UML");
else if (file_regex ("/proc/self/status",
- "(s_context|VxID|envID):[[:space:]]*[1-9]"))
- snprintf (sys, sizeof (sys), "VPS");
+ "(s_context|VxID|envID):[[:space:]]*[1-9]"))
+ snprintf (sys, sizeof (sys), "VPS");
#endif
/* Only add a NET_FS list if not defined */
STRLIST_FOREACH (env, line, i)
- if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0)
- {
- has_net_fs_list = true;
- break;
- }
+ if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0)
+ {
+ has_net_fs_list = true;
+ break;
+ }
if (! has_net_fs_list)
{
i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1;
@@ -736,7 +736,7 @@ char **rc_config_env (char **env)
env = rc_strlist_add (env, line);
free (line);
}
-
+
/* Some scripts may need to take a different code path if Linux/FreeBSD, etc
To save on calling uname, we store it in an environment variable */
if (uname (&uts) == 0)
diff --git a/src/librc-strlist.c b/src/librc-strlist.c
index 126ec78e..042b2097 100644
--- a/src/librc-strlist.c
+++ b/src/librc-strlist.c
@@ -33,8 +33,8 @@ char **rc_strlist_add (char **list, const char *item)
}
static char **_rc_strlist_addsort (char **list, const char *item,
- int (*sortfunc) (const char *s1,
- const char *s2))
+ int (*sortfunc) (const char *s1,
+ const char *s2))
{
char **newlist;
int i = 0;
@@ -90,12 +90,12 @@ char **rc_strlist_delete (char **list, const char *item)
while (list[i])
if (! strcmp (list[i], item))
{
- free (list[i]);
- do
- {
- list[i] = list[i + 1];
- i++;
- } while (list[i]);
+ free (list[i]);
+ do
+ {
+ list[i] = list[i + 1];
+ i++;
+ } while (list[i]);
}
return (list);
diff --git a/src/librc.c b/src/librc.c
index e6b16820..60e5e1bd 100644
--- a/src/librc.c
+++ b/src/librc.c
@@ -71,7 +71,7 @@ char **rc_get_runlevels (void)
{
char *path = rc_strcatpaths (RC_RUNLEVELDIR, dir, (char *) NULL);
if (rc_is_dir (path))
- runlevels = rc_strlist_addsort (runlevels, dir);
+ runlevels = rc_strlist_addsort (runlevels, dir);
free (path);
}
rc_strlist_free (dirs);
@@ -94,7 +94,7 @@ char *rc_get_runlevel (void)
{
int i = strlen (buffer) - 1;
if (buffer[i] == '\n')
- buffer[i] = 0;
+ buffer[i] = 0;
fclose (fp);
return (buffer);
}
@@ -146,10 +146,10 @@ char *rc_resolve_service (const char *service)
free (file);
file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL);
if (! rc_is_link (file))
- {
- free (file);
- file = NULL;
- }
+ {
+ free (file);
+ file = NULL;
+ }
}
memset (buffer, 0, sizeof (buffer));
@@ -158,7 +158,7 @@ char *rc_resolve_service (const char *service)
r = readlink (file, buffer, sizeof (buffer));
free (file);
if (r > 0)
- return strdup (buffer);
+ return strdup (buffer);
}
snprintf (buffer, sizeof (buffer), RC_INITDIR "%s", service);
@@ -201,7 +201,7 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel)
return (false);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
- (char *) NULL);
+ (char *) NULL);
retval = rc_exists (file);
free (file);
@@ -225,24 +225,24 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
if (state != rc_service_stopped)
{
if (! rc_is_file(init))
- {
- free (init);
- return (false);
- }
+ {
+ free (init);
+ return (false);
+ }
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base,
- (char *) NULL);
+ (char *) NULL);
if (rc_exists (file))
- unlink (file);
+ unlink (file);
i = symlink (init, file);
if (i != 0)
- {
- free (file);
- free (init);
- einfo ("%d %s %s", state, rc_service_state_names[state], base);
- eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno));
- return (false);
- }
+ {
+ free (file);
+ free (init);
+ einfo ("%d %s %s", state, rc_service_state_names[state], base);
+ eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno));
+ return (false);
+ }
free (file);
skip_state = state;
@@ -259,38 +259,38 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
while (rc_service_state_names[i])
{
if ((i != skip_state &&
- i != rc_service_stopped &&
- i != rc_service_coldplugged &&
- i != rc_service_crashed) &&
- (! skip_wasinactive || i != rc_service_wasinactive))
- {
- file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base,
- (char *) NULL);
- if (rc_exists (file))
- {
- if ((state == rc_service_starting ||
- state == rc_service_stopping) &&
- i == rc_service_inactive)
- {
- char *wasfile = rc_strcatpaths (RC_SVCDIR,
- rc_service_state_names[rc_service_wasinactive],
- base, (char *) NULL);
-
- if (symlink (init, wasfile) != 0)
- eerror ("symlink `%s' to `%s': %s", init, wasfile,
- strerror (errno));
-
- skip_wasinactive = true;
- free (wasfile);
- }
-
- errno = 0;
- if (unlink (file) != 0 && errno != ENOENT)
- eerror ("failed to delete `%s': %s", file,
- strerror (errno));
- }
- free (file);
- }
+ i != rc_service_stopped &&
+ i != rc_service_coldplugged &&
+ i != rc_service_crashed) &&
+ (! skip_wasinactive || i != rc_service_wasinactive))
+ {
+ file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base,
+ (char *) NULL);
+ if (rc_exists (file))
+ {
+ if ((state == rc_service_starting ||
+ state == rc_service_stopping) &&
+ i == rc_service_inactive)
+ {
+ char *wasfile = rc_strcatpaths (RC_SVCDIR,
+ rc_service_state_names[rc_service_wasinactive],
+ base, (char *) NULL);
+
+ if (symlink (init, wasfile) != 0)
+ eerror ("symlink `%s' to `%s': %s", init, wasfile,
+ strerror (errno));
+
+ skip_wasinactive = true;
+ free (wasfile);
+ }
+
+ errno = 0;
+ if (unlink (file) != 0 && errno != ENOENT)
+ eerror ("failed to delete `%s': %s", file,
+ strerror (errno));
+ }
+ free (file);
+ }
i++;
}
@@ -301,8 +301,8 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
{
file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
if (rc_exists (file))
- if (unlink (file) != 0)
- eerror ("unlink `%s': %s", file, strerror (errno));
+ if (unlink (file) != 0)
+ eerror ("unlink `%s': %s", file, strerror (errno));
free (file);
}
@@ -312,14 +312,14 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL);
if (rc_is_dir (dir))
- rc_rm_dir (dir, true);
+ rc_rm_dir (dir, true);
free (dir);
dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL);
if (rc_is_dir (dir))
- rc_rm_dir (dir, true);
+ rc_rm_dir (dir, true);
free (dir);
-
+
rc_schedule_clear (service);
}
@@ -332,20 +332,20 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
int serrno;
STRLIST_FOREACH (dirs, dir, i)
- {
- char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL);
- file = rc_strcatpaths (bdir, base, (char *) NULL);
- if (rc_exists (file))
- if (unlink (file) != 0)
- eerror ("unlink `%s': %s", file, strerror (errno));
- free (file);
-
- /* Try and remove the dir - we don't care about errors */
- serrno = errno;
- rmdir (bdir);
- errno = serrno;
- free (bdir);
- }
+ {
+ char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL);
+ file = rc_strcatpaths (bdir, base, (char *) NULL);
+ if (rc_exists (file))
+ if (unlink (file) != 0)
+ eerror ("unlink `%s': %s", file, strerror (errno));
+ free (file);
+
+ /* Try and remove the dir - we don't care about errors */
+ serrno = errno;
+ rmdir (bdir);
+ errno = serrno;
+ free (bdir);
+ }
rc_strlist_free (dirs);
free (sdir);
}
@@ -366,9 +366,9 @@ bool rc_service_state (const char *service, const rc_service_state_t state)
/* 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)));
+ 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)
@@ -378,43 +378,43 @@ bool rc_service_state (const char *service, const rc_service_state_t state)
char **services = rc_services_scheduled_by (service);
retval = (services);
if (services)
- free (services);
+ free (services);
return (retval);
}
/* Now we just check if a file by the service name rc_exists
in the state dir */
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state],
- basename (service), (char*) NULL);
+ basename (service), (char*) NULL);
retval = rc_exists (file);
free (file);
return (retval);
}
bool rc_get_service_option (const char *service, const char *option,
- char *value)
+ char *value)
{
FILE *fp;
char buffer[RC_LINEBUFFER];
char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option,
- (char *) NULL);
+ (char *) NULL);
bool retval = false;
if (rc_exists (file))
{
if ((fp = fopen (file, "r")) == NULL)
- eerror ("fopen `%s': %s", file, strerror (errno));
+ eerror ("fopen `%s': %s", file, strerror (errno));
else
- {
- memset (buffer, 0, sizeof (buffer));
- while (fgets (buffer, RC_LINEBUFFER, fp))
- {
- memcpy (value, buffer, strlen (buffer));
- value += strlen (buffer);
- }
- fclose (fp);
- retval = true;
- }
+ {
+ memset (buffer, 0, sizeof (buffer));
+ while (fgets (buffer, RC_LINEBUFFER, fp))
+ {
+ memcpy (value, buffer, strlen (buffer));
+ value += strlen (buffer);
+ }
+ fclose (fp);
+ retval = true;
+ }
}
free (file);
@@ -422,7 +422,7 @@ bool rc_get_service_option (const char *service, const char *option,
}
bool rc_set_service_option (const char *service, const char *option,
- const char *value)
+ const char *value)
{
FILE *fp;
char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL);
@@ -432,12 +432,12 @@ bool rc_set_service_option (const char *service, const char *option,
if (! rc_is_dir (path))
{
if (mkdir (path, 0755) != 0)
- {
- eerror ("mkdir `%s': %s", path, strerror (errno));
- free (path);
- free (file);
- return (false);
- }
+ {
+ eerror ("mkdir `%s': %s", path, strerror (errno));
+ free (path);
+ free (file);
+ return (false);
+ }
}
if ((fp = fopen (file, "w")) == NULL)
@@ -445,7 +445,7 @@ bool rc_set_service_option (const char *service, const char *option,
else
{
if (value)
- fprintf (fp, "%s", value);
+ fprintf (fp, "%s", value);
fclose (fp);
retval = true;
}
@@ -473,7 +473,7 @@ static pid_t _exec_service (const char *service, const char *arg)
/* We create a fifo so that other services can wait until we complete */
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (mkfifo (fifo, 0600) != 0 && errno != EEXIST)
{
@@ -513,11 +513,11 @@ static pid_t _exec_service (const char *service, const char *arg)
{
pid = waitpid (savedpid, &status, 0);
if (pid < 0)
- {
- if (errno != ECHILD)
- eerror ("waitpid %d: %s", savedpid, strerror (errno));
- return (-1);
- }
+ {
+ if (errno != ECHILD)
+ eerror ("waitpid %d: %s", savedpid, strerror (errno));
+ return (-1);
+ }
} while (! WIFEXITED (status) && ! WIFSIGNALED (status));
return (0);
@@ -541,7 +541,7 @@ pid_t rc_start_service (const char *service)
}
void rc_schedule_start_service (const char *service,
- const char *service_to_start)
+ const char *service_to_start)
{
char *dir;
char *init;
@@ -551,13 +551,13 @@ void rc_schedule_start_service (const char *service,
return;
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (! rc_is_dir (dir))
if (mkdir (dir, 0755) != 0)
{
- eerror ("mkdir `%s': %s", dir, strerror (errno));
- free (dir);
- return;
+ eerror ("mkdir `%s': %s", dir, strerror (errno));
+ free (dir);
+ return;
}
init = rc_resolve_service (service_to_start);
@@ -573,7 +573,7 @@ void rc_schedule_start_service (const char *service,
void rc_schedule_clear (const char *service)
{
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (rc_is_dir (dir))
rc_rm_dir (dir, true);
@@ -583,7 +583,7 @@ void rc_schedule_clear (const char *service)
bool rc_wait_service (const char *service)
{
char *fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service),
- (char *) NULL);
+ (char *) NULL);
struct timeval tv;
struct timeval stopat;
struct timeval now;
@@ -599,28 +599,28 @@ bool rc_wait_service (const char *service)
while (true)
{
if (! rc_exists (fifo))
- {
- retval = true;
- break;
- }
+ {
+ retval = true;
+ break;
+ }
tv.tv_sec = 0;
tv.tv_usec = WAIT_INTERVAL;
if (select (0, 0, 0, 0, &tv) < 0)
- {
- if (errno != EINTR)
- eerror ("select: %s",strerror (errno));
- break;
- }
+ {
+ if (errno != EINTR)
+ eerror ("select: %s",strerror (errno));
+ break;
+ }
/* Don't hang around forever */
if (gettimeofday (&now, NULL) != 0)
- {
- eerror ("gettimeofday: %s", strerror (errno));
- break;
- }
+ {
+ eerror ("gettimeofday: %s", strerror (errno));
+ break;
+ }
if (timercmp (&now, &stopat, >))
- break;
+ break;
}
free (fifo);
@@ -642,7 +642,7 @@ char **rc_services_in_runlevel (const char *runlevel)
dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL);
if (! rc_is_dir (dir))
- eerror ("runlevel `%s' does not exist", runlevel);
+ eerror ("runlevel `%s' does not exist", runlevel);
else
list = rc_ls_dir (list, dir, RC_LS_INITD);
@@ -653,7 +653,7 @@ char **rc_services_in_runlevel (const char *runlevel)
char **rc_services_in_state (rc_service_state_t state)
{
char *dir = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state],
- (char *) NULL);
+ (char *) NULL);
char **list = NULL;
if (rc_is_dir (dir))
@@ -674,7 +674,7 @@ bool rc_service_add (const char *runlevel, const char *service)
errno = ENOENT;
return (false);
}
-
+
if (rc_service_in_runlevel (service, runlevel))
{
errno = EEXIST;
@@ -683,7 +683,7 @@ bool rc_service_add (const char *runlevel, const char *service)
init = rc_resolve_service (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
- (char *) NULL);
+ (char *) NULL);
retval = (symlink (init, file) == 0);
free (init);
free (file);
@@ -697,12 +697,12 @@ bool rc_service_delete (const char *runlevel, const char *service)
if (! runlevel || ! service)
return (false);
-
+
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
- (char *) NULL);
+ (char *) NULL);
if (unlink (file) == 0)
retval = true;
-
+
free (file);
return (retval);
}
@@ -717,20 +717,20 @@ char **rc_services_scheduled_by (const char *service)
STRLIST_FOREACH (dirs, dir, i)
{
char *file = rc_strcatpaths (RC_SVCDIR "scheduled", dir, service,
- (char *) NULL);
+ (char *) NULL);
if (rc_exists (file))
- list = rc_strlist_add (list, file);
+ list = rc_strlist_add (list, file);
free (file);
}
rc_strlist_free (dirs);
-
+
return (list);
}
char **rc_services_scheduled (const char *service)
{
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
- (char *) NULL);
+ (char *) NULL);
char **list = NULL;
if (rc_is_dir (dir))
@@ -757,28 +757,28 @@ bool rc_allow_plug (char *service)
{
bool truefalse = true;
if (token[0] == '!')
- {
- truefalse = false;
- token++;
- }
+ {
+ truefalse = false;
+ token++;
+ }
star = strchr (token, '*');
if (star)
- {
- if (strncmp (service, token, star - token) == 0)
- {
- allow = truefalse;
- break;
- }
- }
+ {
+ if (strncmp (service, token, star - token) == 0)
+ {
+ allow = truefalse;
+ break;
+ }
+ }
else
- {
- if (strcmp (service, token) == 0)
- {
- allow = truefalse;
- break;
- }
- }
+ {
+ if (strcmp (service, token) == 0)
+ {
+ allow = truefalse;
+ break;
+ }
+ }
}
free (list);
diff --git a/src/mountinfo.c b/src/mountinfo.c
index 1fc84420..c5dc60ff 100644
--- a/src/mountinfo.c
+++ b/src/mountinfo.c
@@ -28,7 +28,7 @@
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__)
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
- char **mounts, bool list_nodes, bool list_fstype)
+ char **mounts, bool list_nodes, bool list_fstype)
{
struct statfs *mnts;
int nmnts;
@@ -36,36 +36,36 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
char **list = NULL;
if ((nmnts = getmntinfo (&mnts, MNT_NOWAIT)) == 0)
- eerrorx ("getmntinfo: %s", strerror (errno));
+ eerrorx ("getmntinfo: %s", strerror (errno));
for (i = 0; i < nmnts; i++)
{
if (node_regex &&
- regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0)
- continue;
+ regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0)
+ continue;
if (fstype_regex &&
- regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0)
- continue;
+ regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0)
+ continue;
if (mounts)
- {
- bool found = false;
- int j;
- char *mnt;
- STRLIST_FOREACH (mounts, mnt, j)
- if (strcmp (mnt, mnts[i].f_mntonname) == 0)
- {
- found = true;
- break;
- }
- if (! found)
- continue;
- }
+ {
+ bool found = false;
+ int j;
+ char *mnt;
+ STRLIST_FOREACH (mounts, mnt, j)
+ if (strcmp (mnt, mnts[i].f_mntonname) == 0)
+ {
+ found = true;
+ break;
+ }
+ if (! found)
+ continue;
+ }
list = rc_strlist_addsortc (list, list_nodes ?
- mnts[i].f_mntfromname :
- list_fstype ? mnts[i].f_fstypename :
- mnts[i].f_mntonname);
+ mnts[i].f_mntfromname :
+ list_fstype ? mnts[i].f_fstypename :
+ mnts[i].f_mntonname);
}
return (list);
@@ -73,7 +73,7 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
#elif defined (__linux__)
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
- char **mounts, bool list_nodes, bool list_fstype)
+ char **mounts, bool list_nodes, bool list_fstype)
{
FILE *fp;
char buffer[PATH_MAX * 3];
@@ -82,46 +82,46 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
char *to;
char *fstype;
char **list = NULL;
-
+
if ((fp = fopen ("/proc/mounts", "r")) == NULL)
- eerrorx ("getmntinfo: %s", strerror (errno));
+ eerrorx ("getmntinfo: %s", strerror (errno));
while (fgets (buffer, sizeof (buffer), fp))
{
p = buffer;
from = strsep (&p, " ");
if (node_regex &&
- regexec (node_regex, from, 0, NULL, 0) != 0)
- continue;
-
+ regexec (node_regex, from, 0, NULL, 0) != 0)
+ continue;
+
to = strsep (&p, " ");
fstype = strsep (&p, " ");
/* Skip the really silly rootfs */
if (strcmp (fstype, "rootfs") == 0)
- continue;
+ continue;
if (fstype_regex &&
- regexec (fstype_regex, fstype, 0, NULL, 0) != 0)
- continue;
+ regexec (fstype_regex, fstype, 0, NULL, 0) != 0)
+ continue;
if (mounts)
- {
- bool found = false;
- int j;
- char *mnt;
- STRLIST_FOREACH (mounts, mnt, j)
- if (strcmp (mnt, to) == 0)
- {
- found = true;
- break;
- }
- if (! found)
- continue;
- }
+ {
+ bool found = false;
+ int j;
+ char *mnt;
+ STRLIST_FOREACH (mounts, mnt, j)
+ if (strcmp (mnt, to) == 0)
+ {
+ found = true;
+ break;
+ }
+ if (! found)
+ continue;
+ }
list = rc_strlist_addsortc (list,
- list_nodes ?
- list_fstype ? fstype :
- from : to);
+ list_nodes ?
+ list_fstype ? fstype :
+ from : to);
}
fclose (fp);
@@ -150,75 +150,75 @@ int main (int argc, char **argv)
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "--fstype-regex") == 0 && (i + 1 < argc))
- {
- i++;
- if (fstype_regex)
- free (fstype_regex);
- fstype_regex = rc_xmalloc (sizeof (regex_t));
- if ((result = regcomp (fstype_regex, argv[i],
- REG_EXTENDED | REG_NOSUB)) != 0)
- {
- regerror (result, fstype_regex, buffer, sizeof (buffer));
- eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
- }
- continue;
- }
+ {
+ i++;
+ if (fstype_regex)
+ free (fstype_regex);
+ fstype_regex = rc_xmalloc (sizeof (regex_t));
+ if ((result = regcomp (fstype_regex, argv[i],
+ REG_EXTENDED | REG_NOSUB)) != 0)
+ {
+ regerror (result, fstype_regex, buffer, sizeof (buffer));
+ eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
+ }
+ continue;
+ }
if (strcmp (argv[i], "--node-regex") == 0 && (i + 1 < argc))
- {
- i++;
- if (node_regex)
- free (node_regex);
- node_regex = rc_xmalloc (sizeof (regex_t));
- if ((result = regcomp (node_regex, argv[i],
- REG_EXTENDED | REG_NOSUB)) != 0)
- {
- regerror (result, node_regex, buffer, sizeof (buffer));
- eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
- }
- continue;
- }
+ {
+ i++;
+ if (node_regex)
+ free (node_regex);
+ node_regex = rc_xmalloc (sizeof (regex_t));
+ if ((result = regcomp (node_regex, argv[i],
+ REG_EXTENDED | REG_NOSUB)) != 0)
+ {
+ regerror (result, node_regex, buffer, sizeof (buffer));
+ eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
+ }
+ continue;
+ }
if (strcmp (argv[i], "--skip-regex") == 0 && (i + 1 < argc))
- {
- i++;
- if (skip_regex)
- free (skip_regex);
- skip_regex = rc_xmalloc (sizeof (regex_t));
- if ((result = regcomp (skip_regex, argv[i],
- REG_EXTENDED | REG_NOSUB)) != 0)
- {
- regerror (result, skip_regex, buffer, sizeof (buffer));
- eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
- }
- continue;
- }
+ {
+ i++;
+ if (skip_regex)
+ free (skip_regex);
+ skip_regex = rc_xmalloc (sizeof (regex_t));
+ if ((result = regcomp (skip_regex, argv[i],
+ REG_EXTENDED | REG_NOSUB)) != 0)
+ {
+ regerror (result, skip_regex, buffer, sizeof (buffer));
+ eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
+ }
+ continue;
+ }
if (strcmp (argv[i], "--fstype") == 0)
- {
- list_fstype = true;
- continue;
- }
+ {
+ list_fstype = true;
+ continue;
+ }
if (strcmp (argv[i], "--node") == 0)
- {
- list_nodes = true;
- continue;
- }
+ {
+ list_nodes = true;
+ continue;
+ }
if (strcmp (argv[i], "--reverse") == 0)
- {
- reverse = true;
- continue;
- }
+ {
+ reverse = true;
+ continue;
+ }
if (argv[i][0] != '/')
- eerrorx ("%s: `%s' is not a mount point", argv[0], argv[i]);
+ eerrorx ("%s: `%s' is not a mount point", argv[0], argv[i]);
mounts = rc_strlist_add (mounts, argv[i]);
}
nodes = find_mounts (node_regex, fstype_regex, mounts,
- list_nodes, list_fstype);
+ list_nodes, list_fstype);
if (node_regex)
regfree (node_regex);
@@ -232,7 +232,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (nodes, node, i)
{
if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0)
- continue;
+ continue;
printf ("%s\n", node);
result = EXIT_SUCCESS;
}
diff --git a/src/rc-depend.c b/src/rc-depend.c
index 9d0b3af8..c6d0356b 100644
--- a/src/rc-depend.c
+++ b/src/rc-depend.c
@@ -38,43 +38,43 @@ int main (int argc, char **argv)
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "--update") == 0)
- {
- if (! update)
- {
- rc_update_deptree (true);
- update = true;
- }
- continue;
- }
+ {
+ if (! update)
+ {
+ rc_update_deptree (true);
+ update = true;
+ }
+ continue;
+ }
if (strcmp (argv[i], "--strict") == 0)
- {
- options |= RC_DEP_STRICT;
- continue;
- }
+ {
+ options |= RC_DEP_STRICT;
+ continue;
+ }
if (strcmp (argv[i], "--notrace") == 0)
- {
- options &= RC_DEP_TRACE;
- continue;
- }
+ {
+ options &= RC_DEP_TRACE;
+ continue;
+ }
if (argv[i][0] == '-')
- {
- argv[i]++;
- types = rc_strlist_add (types, argv[i]);
- }
+ {
+ argv[i]++;
+ types = rc_strlist_add (types, argv[i]);
+ }
else
- {
- if ((deptree = rc_load_deptree ()) == NULL)
- eerrorx ("failed to load deptree");
-
- di = rc_get_depinfo (deptree, argv[i]);
- if (! di)
- eerror ("no dependency info for service `%s'", argv[i]);
- else
- services = rc_strlist_add (services, argv[i]);
- }
+ {
+ if ((deptree = rc_load_deptree ()) == NULL)
+ eerrorx ("failed to load deptree");
+
+ di = rc_get_depinfo (deptree, argv[i]);
+ if (! di)
+ eerror ("no dependency info for service `%s'", argv[i]);
+ else
+ services = rc_strlist_add (services, argv[i]);
+ }
}
if (! services)
@@ -82,7 +82,7 @@ int main (int argc, char **argv)
rc_strlist_free (types);
rc_free_deptree (deptree);
if (update)
- return (EXIT_SUCCESS);
+ return (EXIT_SUCCESS);
eerrorx ("no services specified");
}
@@ -98,16 +98,16 @@ int main (int argc, char **argv)
if (depends)
{
STRLIST_FOREACH (depends, service, i)
- {
- if (first)
- first = false;
- else
- printf (" ");
+ {
+ if (first)
+ first = false;
+ else
+ printf (" ");
- if (service)
- printf ("%s", service);
+ if (service)
+ printf ("%s", service);
- }
+ }
printf ("\n");
}
diff --git a/src/rc-plugin.c b/src/rc-plugin.c
index b742eadd..f7cd3686 100644
--- a/src/rc-plugin.c
+++ b/src/rc-plugin.c
@@ -50,11 +50,11 @@ void rc_plugin_load (void)
int len;
if (! h)
- {
- eerror ("dlopen `%s': %s", p, dlerror ());
- free (p);
- continue;
- }
+ {
+ eerror ("dlopen `%s': %s", p, dlerror ());
+ free (p);
+ continue;
+ }
func = file;
file = strsep (&func, ".");
@@ -64,25 +64,25 @@ void rc_plugin_load (void)
f = dlsym (h, func);
if (! f)
- {
- eerror ("`%s' does not expose the symbol `%s'", p, func);
- dlclose (h);
- }
+ {
+ eerror ("`%s' does not expose the symbol `%s'", p, func);
+ dlclose (h);
+ }
else
- {
- if (plugin)
- {
- plugin->next = rc_xmalloc (sizeof (plugin_t));
- plugin = plugin->next;
- }
- else
- plugin = plugins = rc_xmalloc (sizeof (plugin_t));
-
- memset (plugin, 0, sizeof (plugin_t));
- plugin->name = strdup (file);
- plugin->handle = h;
- plugin->hook = f;
- }
+ {
+ if (plugin)
+ {
+ plugin->next = rc_xmalloc (sizeof (plugin_t));
+ plugin = plugin->next;
+ }
+ else
+ plugin = plugins = rc_xmalloc (sizeof (plugin_t));
+
+ memset (plugin, 0, sizeof (plugin_t));
+ plugin->name = strdup (file);
+ plugin->handle = h;
+ plugin->hook = f;
+ }
free (func);
free (p);
@@ -98,7 +98,7 @@ void rc_plugin_run (rc_hook_t hook, const char *value)
while (plugin)
{
if (plugin->hook)
- plugin->hook (hook, value);
+ plugin->hook (hook, value);
plugin = plugin->next;
}
diff --git a/src/rc-status.c b/src/rc-status.c
index 5f2f9b1d..f1ea52ee 100644
--- a/src/rc-status.c
+++ b/src/rc-status.c
@@ -72,53 +72,53 @@ int main (int argc, char **argv)
const struct option longopts[] =
{
- {"all", no_argument, NULL, 'a'},
- {"list", no_argument, NULL, 'l'},
- {"servicelist", no_argument, NULL, 's'},
- {"unused", no_argument, NULL, 'u'},
- {NULL, 0, NULL, 0}
+ {"all", no_argument, NULL, 'a'},
+ {"list", no_argument, NULL, 'l'},
+ {"servicelist", no_argument, NULL, 's'},
+ {"unused", no_argument, NULL, 'u'},
+ {NULL, 0, NULL, 0}
};
while ((c = getopt_long(argc, argv, "alsu", longopts, &option_index)) != -1)
switch (c)
{
case 'a':
- levels = rc_get_runlevels ();
- break;
+ levels = rc_get_runlevels ();
+ break;
case 'l':
- levels = rc_get_runlevels ();
- STRLIST_FOREACH (levels, level, i)
- printf ("%s\n", level);
- rc_strlist_free (levels);
- exit (EXIT_SUCCESS);
+ levels = rc_get_runlevels ();
+ STRLIST_FOREACH (levels, level, i)
+ printf ("%s\n", level);
+ rc_strlist_free (levels);
+ exit (EXIT_SUCCESS);
case 's':
- services = rc_services_in_runlevel (NULL);
- STRLIST_FOREACH (services, service, i)
- print_service (service);
- rc_strlist_free (services);
- exit (EXIT_SUCCESS);
+ services = rc_services_in_runlevel (NULL);
+ STRLIST_FOREACH (services, service, i)
+ print_service (service);
+ rc_strlist_free (services);
+ exit (EXIT_SUCCESS);
case 'u':
- services = rc_services_in_runlevel (NULL);
- levels = rc_get_runlevels ();
- STRLIST_FOREACH (services, service, i)
- {
- bool found = false;
- STRLIST_FOREACH (levels, level, j)
- if (rc_service_in_runlevel (service, level))
- {
- found = true;
- break;
- }
- if (! found)
- print_service (service);
- }
- rc_strlist_free (levels);
- rc_strlist_free (services);
- exit (EXIT_SUCCESS);
+ services = rc_services_in_runlevel (NULL);
+ levels = rc_get_runlevels ();
+ STRLIST_FOREACH (services, service, i)
+ {
+ bool found = false;
+ STRLIST_FOREACH (levels, level, j)
+ if (rc_service_in_runlevel (service, level))
+ {
+ found = true;
+ break;
+ }
+ if (! found)
+ print_service (service);
+ }
+ rc_strlist_free (levels);
+ rc_strlist_free (services);
+ exit (EXIT_SUCCESS);
case '?':
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
default:
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
}
while (optind < argc)
diff --git a/src/rc-update.c b/src/rc-update.c
index 8d50a4af..78054136 100644
--- a/src/rc-update.c
+++ b/src/rc-update.c
@@ -32,16 +32,16 @@ static bool add (const char *runlevel, const char *service)
if (rc_service_in_runlevel (service, runlevel))
{
ewarn ("%s already installed in runlevel `%s'; skipping",
- service, runlevel);
+ service, runlevel);
return (false);
}
if (rc_service_add (runlevel, service))
einfo ("%s added to runlevel %s", service, runlevel);
else
- {
+ {
eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
- applet, service, runlevel, strerror (errno));
+ applet, service, runlevel, strerror (errno));
retval = false;
}
@@ -65,53 +65,53 @@ int main (int argc, char **argv)
char **services = rc_services_in_runlevel (NULL);
for (i = 2; i < argc; i++)
- {
- if (strcmp (argv[i], "--verbose") == 0 ||
- strcmp (argv[i], "-v") == 0)
- verbose = true;
- else
- runlevels = rc_strlist_add (runlevels, argv[i]);
- }
+ {
+ if (strcmp (argv[i], "--verbose") == 0 ||
+ strcmp (argv[i], "-v") == 0)
+ verbose = true;
+ else
+ runlevels = rc_strlist_add (runlevels, argv[i]);
+ }
if (! runlevels)
- runlevels = rc_get_runlevels ();
+ runlevels = rc_get_runlevels ();
STRLIST_FOREACH (services, service, i)
- {
- char **in = NULL;
- bool inone = false;
-
- STRLIST_FOREACH (runlevels, runlevel, j)
- {
- if (rc_service_in_runlevel (service, runlevel))
- {
- in = rc_strlist_add (in, runlevel);
- inone = true;
- }
- else
- {
- char buffer[PATH_MAX];
- memset (buffer, ' ', strlen (runlevel));
- buffer[strlen (runlevel)] = 0;
- in = rc_strlist_add (in, buffer);
- }
- }
-
- if (! inone && ! verbose)
- continue;
-
- printf (" %20s |", service);
- STRLIST_FOREACH (in, runlevel, j)
- printf (" %s", runlevel);
- printf ("\n");
- }
-
+ {
+ char **in = NULL;
+ bool inone = false;
+
+ STRLIST_FOREACH (runlevels, runlevel, j)
+ {
+ if (rc_service_in_runlevel (service, runlevel))
+ {
+ in = rc_strlist_add (in, runlevel);
+ inone = true;
+ }
+ else
+ {
+ char buffer[PATH_MAX];
+ memset (buffer, ' ', strlen (runlevel));
+ buffer[strlen (runlevel)] = 0;
+ in = rc_strlist_add (in, buffer);
+ }
+ }
+
+ if (! inone && ! verbose)
+ continue;
+
+ printf (" %20s |", service);
+ STRLIST_FOREACH (in, runlevel, j)
+ printf (" %s", runlevel);
+ printf ("\n");
+ }
+
return (EXIT_SUCCESS);
}
if (geteuid () != 0)
eerrorx ("%s: must be root to add or delete services from runlevels",
- applet);
+ applet);
if (! (service = argv[2]))
eerrorx ("%s: no service specified", applet);
@@ -120,15 +120,15 @@ int main (int argc, char **argv)
strcmp (argv[1], "-a") == 0)
{
if (! service)
- eerrorx ("%s: no service specified", applet);
+ eerrorx ("%s: no service specified", applet);
if (! rc_service_exists (service))
- eerrorx ("%s: service `%s' does not exist", applet, service);
+ eerrorx ("%s: service `%s' does not exist", applet, service);
if (argc < 4)
- add (rc_get_runlevel (), service);
+ add (rc_get_runlevel (), service);
for (i = 3; i < argc; i++)
- add (argv[i], service);
+ add (argv[i], service);
return (EXIT_SUCCESS);
}
@@ -138,22 +138,22 @@ int main (int argc, char **argv)
strcmp (argv[1], "-d") == 0)
{
for (i = 3; i < argc; i++)
- runlevels = rc_strlist_add (runlevels, argv[i]);
+ runlevels = rc_strlist_add (runlevels, argv[i]);
if (! runlevels)
- runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
+ runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
STRLIST_FOREACH (runlevels, runlevel, i)
- {
- if (rc_service_in_runlevel (service, runlevel))
- {
- if (rc_service_delete (runlevel, service))
- einfo ("%s removed from runlevel %s", service, runlevel);
- else
- eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
- applet, service, runlevel, strerror (errno));
- }
- }
+ {
+ if (rc_service_in_runlevel (service, runlevel))
+ {
+ if (rc_service_delete (runlevel, service))
+ einfo ("%s removed from runlevel %s", service, runlevel);
+ else
+ eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
+ applet, service, runlevel, strerror (errno));
+ }
+ }
return (EXIT_SUCCESS);
}
diff --git a/src/rc.c b/src/rc.c
index 16d45eb5..ac41e91d 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -6,7 +6,7 @@
Also a multicall binary for various commands that can be used in shell
scripts to query service state, mark service state and provide the
Gentoo einfo family of informational functions.
-
+
Copyright 2007 Gentoo Foundation
Released under the GPLv2
*/
@@ -123,36 +123,36 @@ static int do_e (int argc, char **argv)
strcmp (applet, "vweend") == 0)
{
if (argc > 0)
- {
- errno = 0;
- retval = strtol (argv[0], NULL, 0);
- if (errno != 0)
- retval = EXIT_FAILURE;
- else
- {
- argc--;
- argv++;
- }
- }
+ {
+ errno = 0;
+ retval = strtol (argv[0], NULL, 0);
+ if (errno != 0)
+ retval = EXIT_FAILURE;
+ else
+ {
+ argc--;
+ argv++;
+ }
+ }
else
- retval = EXIT_FAILURE;
- }
+ retval = EXIT_FAILURE;
+ }
if (argc > 0)
{
for (i = 0; i < argc; i++)
- l += strlen (argv[i]) + 1;
+ l += strlen (argv[i]) + 1;
message = rc_xmalloc (l);
p = message;
for (i = 0; i < argc; i++)
- {
- if (i > 0)
- *p++ = ' ';
- memcpy (p, argv[i], strlen (argv[i]));
- p += strlen (argv[i]);
- }
+ {
+ if (i > 0)
+ *p++ = ' ';
+ memcpy (p, argv[i], strlen (argv[i]));
+ p += strlen (argv[i]);
+ }
*p = 0;
}
@@ -245,9 +245,9 @@ static int do_service (int argc, char **argv)
{
int idx = 0;
if (argc > 2)
- sscanf (argv[2], "%d", &idx);
+ sscanf (argv[2], "%d", &idx);
exit (rc_service_started_daemon (argv[0], argv[1], idx)
- ? 0 : 1);
+ ? 0 : 1);
}
else
eerrorx ("%s: unknown applet", applet);
@@ -288,21 +288,21 @@ static int do_mark_service (int argc, char **argv)
int l;
if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1)
- if (kill (pid, SIGHUP) != 0)
- eerror ("%s: failed to signal parent %d: %s",
- applet, pid, strerror (errno));
+ if (kill (pid, SIGHUP) != 0)
+ eerror ("%s: failed to signal parent %d: %s",
+ applet, pid, strerror (errno));
/* Remove the exclsive time test. This ensures that it's not
- in control as well */
+ in control as well */
l = strlen (RC_SVCDIR "exclusive") +
strlen (svcname) +
strlen (runscript_pid) +
4;
mtime = rc_xmalloc (l);
snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
- svcname, runscript_pid);
+ svcname, runscript_pid);
if (rc_exists (mtime) && unlink (mtime) != 0)
- eerror ("%s: unlink: %s", applet, strerror (errno));
+ eerror ("%s: unlink: %s", applet, strerror (errno));
free (mtime);
}
@@ -326,7 +326,7 @@ static int do_options (int argc, char **argv)
memset (buffer, 0, 1024);
ok = rc_get_service_option (service, argv[0], buffer);
if (ok)
- printf ("%s", buffer);
+ printf ("%s", buffer);
}
else if (strcmp (applet, "save_options") == 0)
ok = rc_set_service_option (service, argv[0], argv[1]);
@@ -392,15 +392,15 @@ static void sulogin (bool cont)
pid_t pid = fork();
if (pid == -1)
- eerrorx ("%s: fork: %s", applet, strerror (errno));
+ eerrorx ("%s: fork: %s", applet, strerror (errno));
if (pid == 0)
- {
- newenv = rc_filter_env ();
- mycmd = rc_xstrdup ("/sbin/sulogin");
- myarg = rc_xstrdup (getenv ("CONSOLE"));
- execle (mycmd, mycmd, myarg, (char *) NULL, newenv);
- eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno));
- }
+ {
+ newenv = rc_filter_env ();
+ mycmd = rc_xstrdup ("/sbin/sulogin");
+ myarg = rc_xstrdup (getenv ("CONSOLE"));
+ execle (mycmd, mycmd, myarg, (char *) NULL, newenv);
+ eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno));
+ }
waitpid (pid, &status, 0);
}
else
@@ -429,8 +429,8 @@ static void set_ksoftlevel (const char *runlevel)
strcmp (runlevel, RC_LEVEL_SYSINIT) == 0)
{
if (rc_exists (RC_SVCDIR "ksoftlevel") &&
- unlink (RC_SVCDIR "ksoftlevel") != 0)
- eerror ("unlink `%s': %s", RC_SVCDIR "ksoftlevel", strerror (errno));
+ unlink (RC_SVCDIR "ksoftlevel") != 0)
+ eerror ("unlink `%s': %s", RC_SVCDIR "ksoftlevel", strerror (errno));
return;
}
@@ -439,7 +439,7 @@ static void set_ksoftlevel (const char *runlevel)
eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel", strerror (errno));
return;
}
-
+
fprintf (fp, "%s", runlevel);
fclose (fp);
}
@@ -465,13 +465,13 @@ static void handle_signal (int sig)
{
case SIGINT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGINT");
+ snprintf (signame, sizeof (signame), "SIGINT");
case SIGTERM:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGTERM");
+ snprintf (signame, sizeof (signame), "SIGTERM");
case SIGQUIT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGQUIT");
+ snprintf (signame, sizeof (signame), "SIGQUIT");
eerrorx ("%s: caught %s, aborting", applet, signame);
default:
@@ -554,28 +554,28 @@ int main (int argc, char **argv)
#ifdef __linux__
/* clearenv isn't portable, but there's no harm in using it
- if we have it */
+ if we have it */
clearenv ();
#else
char *var;
/* No clearenv present here then.
- We could manipulate environ directly ourselves, but it seems that
- some kernels bitch about this according to the environ man pages
- so we walk though environ and call unsetenv for each value. */
+ We could manipulate environ directly ourselves, but it seems that
+ some kernels bitch about this according to the environ man pages
+ so we walk though environ and call unsetenv for each value. */
while (environ[0])
- {
- tmp = rc_xstrdup (environ[0]);
- p = tmp;
- var = strsep (&p, "=");
- unsetenv (var);
- free (tmp);
- }
+ {
+ tmp = rc_xstrdup (environ[0]);
+ p = tmp;
+ var = strsep (&p, "=");
+ unsetenv (var);
+ free (tmp);
+ }
tmp = NULL;
#endif
STRLIST_FOREACH (env, p, i)
if (strcmp (p, "RC_SOFTLEVEL") != 0 && strcmp (p, "SOFTLEVEL") != 0)
- putenv (p);
+ putenv (p);
/* We don't free our list as that would be null in environ */
}
@@ -595,151 +595,151 @@ int main (int argc, char **argv)
if (RUNLEVEL && newlevel)
{
if (strcmp (RUNLEVEL, "S") == 0 || strcmp (RUNLEVEL, "1") == 0)
- {
- /* OK, we're either in runlevel 1 or single user mode */
- if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0)
- {
- struct utsname uts;
- pid_t pid;
- pid_t wpid;
- int status = 0;
+ {
+ /* OK, we're either in runlevel 1 or single user mode */
+ if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0)
+ {
+ struct utsname uts;
+ pid_t pid;
+ pid_t wpid;
+ int status = 0;
#ifdef __linux__
- FILE *fp;
+ FILE *fp;
#endif
- uname (&uts);
-
- printf ("\n");
- PEINFO_GOOD;
- printf (" Gentoo/%s; ", uts.sysname);
- PEINFO_BRACKET;
- printf ("http://www.gentoo.org/");
- PEINFO_NORMAL;
- printf ("\n Copyright 1999-2007 Gentoo Foundation; "
- "Distributed under the GPLv2\n\n");
-
- printf ("Press ");
- PEINFO_GOOD;
- printf ("I");
- PEINFO_NORMAL;
- printf (" to enter interactive boot mode\n\n");
-
- setenv ("RC_SOFTLEVEL", newlevel, 1);
- rc_plugin_run (rc_hook_runlevel_start_in, newlevel);
-
- if ((pid = fork ()) == -1)
- eerrorx ("%s: fork: %s", applet, strerror (errno));
-
- if (pid == 0)
- {
- mycmd = rc_xstrdup (INITSH);
- execl (mycmd, mycmd, (char *) NULL);
- eerrorx ("%s: unable to exec `" INITSH "': %s",
- applet, strerror (errno));
- }
-
- do
- {
- wpid = waitpid (pid, &status, 0);
- if (wpid < 1)
- eerror ("waitpid: %s", strerror (errno));
- } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
-
- if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0)
- exit (EXIT_FAILURE);
-
- /* If we requested a softlevel, save it now */
+ uname (&uts);
+
+ printf ("\n");
+ PEINFO_GOOD;
+ printf (" Gentoo/%s; ", uts.sysname);
+ PEINFO_BRACKET;
+ printf ("http://www.gentoo.org/");
+ PEINFO_NORMAL;
+ printf ("\n Copyright 1999-2007 Gentoo Foundation; "
+ "Distributed under the GPLv2\n\n");
+
+ printf ("Press ");
+ PEINFO_GOOD;
+ printf ("I");
+ PEINFO_NORMAL;
+ printf (" to enter interactive boot mode\n\n");
+
+ setenv ("RC_SOFTLEVEL", newlevel, 1);
+ rc_plugin_run (rc_hook_runlevel_start_in, newlevel);
+
+ if ((pid = fork ()) == -1)
+ eerrorx ("%s: fork: %s", applet, strerror (errno));
+
+ if (pid == 0)
+ {
+ mycmd = rc_xstrdup (INITSH);
+ execl (mycmd, mycmd, (char *) NULL);
+ eerrorx ("%s: unable to exec `" INITSH "': %s",
+ applet, strerror (errno));
+ }
+
+ do
+ {
+ wpid = waitpid (pid, &status, 0);
+ if (wpid < 1)
+ eerror ("waitpid: %s", strerror (errno));
+ } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
+
+ if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0)
+ exit (EXIT_FAILURE);
+
+ /* If we requested a softlevel, save it now */
#ifdef __linux__
- set_ksoftlevel (NULL);
-
- if ((fp = fopen ("/proc/cmdline", "r")))
- {
- char buffer[RC_LINEBUFFER];
- char *soft;
-
- memset (buffer, 0, sizeof (buffer));
- if (fgets (buffer, RC_LINEBUFFER, fp) &&
- (soft = strstr (buffer, "softlevel=")))
- {
- i = soft - buffer;
- if (i == 0 || buffer[i - 1] == ' ')
- {
- char *level;
-
- /* Trim the trailing carriage return if present */
- i = strlen (buffer) - 1;
- if (buffer[i] == '\n')
- buffer[i] = 0;
-
- soft += strlen ("softlevel=");
- level = strsep (&soft, " ");
- set_ksoftlevel (level);
- }
- }
- fclose (fp);
- }
+ set_ksoftlevel (NULL);
+
+ if ((fp = fopen ("/proc/cmdline", "r")))
+ {
+ char buffer[RC_LINEBUFFER];
+ char *soft;
+
+ memset (buffer, 0, sizeof (buffer));
+ if (fgets (buffer, RC_LINEBUFFER, fp) &&
+ (soft = strstr (buffer, "softlevel=")))
+ {
+ i = soft - buffer;
+ if (i == 0 || buffer[i - 1] == ' ')
+ {
+ char *level;
+
+ /* Trim the trailing carriage return if present */
+ i = strlen (buffer) - 1;
+ if (buffer[i] == '\n')
+ buffer[i] = 0;
+
+ soft += strlen ("softlevel=");
+ level = strsep (&soft, " ");
+ set_ksoftlevel (level);
+ }
+ }
+ fclose (fp);
+ }
#endif
- rc_plugin_run (rc_hook_runlevel_start_out, newlevel);
+ rc_plugin_run (rc_hook_runlevel_start_out, newlevel);
- if (want_interactive ())
- mark_interactive ();
+ if (want_interactive ())
+ mark_interactive ();
- exit (EXIT_SUCCESS);
- }
+ exit (EXIT_SUCCESS);
+ }
#ifdef __linux__
- /* Parse the inittab file so we can work out the level to telinit */
- if (strcmp (newlevel, RC_LEVEL_BOOT) != 0 &&
- strcmp (newlevel, RC_LEVEL_SINGLE) != 0)
- {
- char **inittab = rc_get_list (NULL, "/etc/inittab");
- char *line;
- char *p;
- char *token;
- char lvl[2] = {0, 0};
-
- STRLIST_FOREACH (inittab, line, i)
- {
- p = line;
- token = strsep (&p, ":");
- if (! token || token[0] != 'l')
- continue;
-
- if ((token = strsep (&p, ":")) == NULL)
- continue;
-
- /* Snag the level */
- lvl[0] = token[0];
-
- /* The name is spaced after this */
- if ((token = strsep (&p, " ")) == NULL)
- continue;
-
- if ((token = strsep (&p, " ")) == NULL)
- continue;
-
- if (strcmp (token, newlevel) == 0)
- break;
- }
- rc_strlist_free (inittab);
-
- /* We have a level, so telinit into it */
- if (lvl[0] == 0)
- {
- eerrorx ("%s: couldn't find a runlevel called `%s'",
- applet, newlevel);
- }
- else
- {
- mycmd = rc_xstrdup ("/sbin/telinit");
- myarg = rc_xstrdup (lvl);
- execl (mycmd, mycmd, myarg, (char *) NULL);
- eerrorx ("%s: unable to exec `/sbin/telinit': %s",
- applet, strerror (errno));
- }
- }
+ /* Parse the inittab file so we can work out the level to telinit */
+ if (strcmp (newlevel, RC_LEVEL_BOOT) != 0 &&
+ strcmp (newlevel, RC_LEVEL_SINGLE) != 0)
+ {
+ char **inittab = rc_get_list (NULL, "/etc/inittab");
+ char *line;
+ char *p;
+ char *token;
+ char lvl[2] = {0, 0};
+
+ STRLIST_FOREACH (inittab, line, i)
+ {
+ p = line;
+ token = strsep (&p, ":");
+ if (! token || token[0] != 'l')
+ continue;
+
+ if ((token = strsep (&p, ":")) == NULL)
+ continue;
+
+ /* Snag the level */
+ lvl[0] = token[0];
+
+ /* The name is spaced after this */
+ if ((token = strsep (&p, " ")) == NULL)
+ continue;
+
+ if ((token = strsep (&p, " ")) == NULL)
+ continue;
+
+ if (strcmp (token, newlevel) == 0)
+ break;
+ }
+ rc_strlist_free (inittab);
+
+ /* We have a level, so telinit into it */
+ if (lvl[0] == 0)
+ {
+ eerrorx ("%s: couldn't find a runlevel called `%s'",
+ applet, newlevel);
+ }
+ else
+ {
+ mycmd = rc_xstrdup ("/sbin/telinit");
+ myarg = rc_xstrdup (lvl);
+ execl (mycmd, mycmd, myarg, (char *) NULL);
+ eerrorx ("%s: unable to exec `/sbin/telinit': %s",
+ applet, strerror (errno));
+ }
+ }
#endif
- }
+ }
}
/* Check we're in the runlevel requested, ie from
@@ -750,63 +750,63 @@ int main (int argc, char **argv)
if (newlevel)
{
if (myarg)
- {
- free (myarg);
- myarg = NULL;
- }
+ {
+ free (myarg);
+ myarg = NULL;
+ }
if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0)
- {
- if (! RUNLEVEL ||
- (strcmp (RUNLEVEL, "S") != 0 &&
- strcmp (RUNLEVEL, "1") != 0))
- {
- /* Remember the current runlevel for when we come back */
- set_ksoftlevel (runlevel);
+ {
+ if (! RUNLEVEL ||
+ (strcmp (RUNLEVEL, "S") != 0 &&
+ strcmp (RUNLEVEL, "1") != 0))
+ {
+ /* Remember the current runlevel for when we come back */
+ set_ksoftlevel (runlevel);
#ifdef __linux__
- mycmd = rc_xstrdup ("/sbin/telinit");
- myarg = rc_xstrdup ("S");
- execl (mycmd, mycmd, myarg, (char *) NULL);
- eerrorx ("%s: unable to exec `/%s': %s",
- mycmd, applet, strerror (errno));
+ mycmd = rc_xstrdup ("/sbin/telinit");
+ myarg = rc_xstrdup ("S");
+ execl (mycmd, mycmd, myarg, (char *) NULL);
+ eerrorx ("%s: unable to exec `/%s': %s",
+ mycmd, applet, strerror (errno));
#else
- if (kill (1, SIGTERM) != 0)
- eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s",
- applet, strerror (errno));
- exit (EXIT_SUCCESS);
+ if (kill (1, SIGTERM) != 0)
+ eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s",
+ applet, strerror (errno));
+ exit (EXIT_SUCCESS);
#endif
- }
- }
+ }
+ }
else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0)
- {
- if (! RUNLEVEL ||
- strcmp (RUNLEVEL, "6") != 0)
- {
- mycmd = rc_xstrdup ("/sbin/shutdown");
- myarg = rc_xstrdup ("-r");
- tmp = rc_xstrdup ("now");
- execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
- eerrorx ("%s: unable to exec `%s': %s",
- mycmd, applet, strerror (errno));
- }
- }
+ {
+ if (! RUNLEVEL ||
+ strcmp (RUNLEVEL, "6") != 0)
+ {
+ mycmd = rc_xstrdup ("/sbin/shutdown");
+ myarg = rc_xstrdup ("-r");
+ tmp = rc_xstrdup ("now");
+ execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
+ eerrorx ("%s: unable to exec `%s': %s",
+ mycmd, applet, strerror (errno));
+ }
+ }
else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0)
- {
- if (! RUNLEVEL ||
- strcmp (RUNLEVEL, "0") != 0)
- {
- mycmd = rc_xstrdup ("/sbin/shutdown");
+ {
+ if (! RUNLEVEL ||
+ strcmp (RUNLEVEL, "0") != 0)
+ {
+ mycmd = rc_xstrdup ("/sbin/shutdown");
#ifdef __linux__
- myarg = rc_xstrdup ("-h");
+ myarg = rc_xstrdup ("-h");
#else
- myarg = rc_xstrdup ("-p");
+ myarg = rc_xstrdup ("-p");
#endif
- tmp = rc_xstrdup ("now");
- execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
- eerrorx ("%s: unable to exec `%s': %s",
- mycmd, applet, strerror (errno));
- }
- }
+ tmp = rc_xstrdup ("now");
+ execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
+ eerrorx ("%s: unable to exec `%s': %s",
+ mycmd, applet, strerror (errno));
+ }
+ }
}
/* Export our current softlevel */
@@ -819,31 +819,31 @@ int main (int argc, char **argv)
strcmp (newlevel, RC_LEVEL_DEFAULT) == 0)
{
/* We should only use ksoftlevel if we were in single user mode
- If not, we need to erase ksoftlevel now. */
+ If not, we need to erase ksoftlevel now. */
if (PREVLEVEL &&
- (strcmp (PREVLEVEL, "1") == 0 ||
- strcmp (PREVLEVEL, "S") == 0 ||
- strcmp (PREVLEVEL, "N") == 0))
- {
- FILE *fp;
-
- if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
- eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
- strerror (errno));
- else
- {
- if (fgets (ksoftbuffer, sizeof (ksoftbuffer), fp))
- {
- i = strlen (ksoftbuffer) - 1;
- if (ksoftbuffer[i] == '\n')
- ksoftbuffer[i] = 0;
- newlevel = ksoftbuffer;
- }
- fclose (fp);
- }
- }
+ (strcmp (PREVLEVEL, "1") == 0 ||
+ strcmp (PREVLEVEL, "S") == 0 ||
+ strcmp (PREVLEVEL, "N") == 0))
+ {
+ FILE *fp;
+
+ if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
+ eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
+ strerror (errno));
+ else
+ {
+ if (fgets (ksoftbuffer, sizeof (ksoftbuffer), fp))
+ {
+ i = strlen (ksoftbuffer) - 1;
+ if (ksoftbuffer[i] == '\n')
+ ksoftbuffer[i] = 0;
+ newlevel = ksoftbuffer;
+ }
+ fclose (fp);
+ }
+ }
else
- set_ksoftlevel (NULL);
+ set_ksoftlevel (NULL);
}
if (newlevel &&
@@ -866,7 +866,7 @@ int main (int argc, char **argv)
{
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL);
if (! rc_is_dir (tmp))
- eerrorx ("%s: is not a valid runlevel", newlevel);
+ eerrorx ("%s: is not a valid runlevel", newlevel);
CHAR_FREE (tmp);
}
@@ -892,10 +892,10 @@ 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. */
+ This may seem redunant, but only Linux needs this and saves on
+ code bloat. */
rc_strlist_free (start_services);
start_services = NULL;
}
@@ -912,36 +912,36 @@ int main (int argc, char **argv)
/* The net interfaces are easy - they're all in net /dev/net :) */
start_services = rc_ls_dir (NULL, "/dev/net", 0);
STRLIST_FOREACH (start_services, service, i)
- {
- j = (strlen ("net.") + strlen (service) + 1);
- tmp = rc_xmalloc (sizeof (char *) * j);
- snprintf (tmp, j, "net.%s", service);
+ {
+ j = (strlen ("net.") + strlen (service) + 1);
+ tmp = rc_xmalloc (sizeof (char *) * j);
+ snprintf (tmp, j, "net.%s", service);
if (rc_service_exists (tmp) && rc_allow_plug (tmp))
rc_mark_service (tmp, rc_service_coldplugged);
- CHAR_FREE (tmp);
- }
+ CHAR_FREE (tmp);
+ }
rc_strlist_free (start_services);
/* The mice are a little more tricky.
If we coldplug anything else, we'll probably do it here. */
start_services = rc_ls_dir (NULL, "/dev", 0);
STRLIST_FOREACH (start_services, service, i)
- {
- if (strncmp (service, "psm", 3) == 0 ||
- strncmp (service, "ums", 3) == 0)
- {
- char *p = service + 3;
- if (p && isdigit (*p))
- {
- j = (strlen ("moused.") + strlen (service) + 1);
- tmp = rc_xmalloc (sizeof (char *) * j);
- snprintf (tmp, j, "moused.%s", service);
- if (rc_service_exists (tmp) && rc_allow_plug (tmp))
- rc_mark_service (tmp, rc_service_coldplugged);
- CHAR_FREE (tmp);
- }
- }
- }
+ {
+ if (strncmp (service, "psm", 3) == 0 ||
+ strncmp (service, "ums", 3) == 0)
+ {
+ char *p = service + 3;
+ if (p && isdigit (*p))
+ {
+ j = (strlen ("moused.") + strlen (service) + 1);
+ tmp = rc_xmalloc (sizeof (char *) * j);
+ snprintf (tmp, j, "moused.%s", service);
+ if (rc_service_exists (tmp) && rc_allow_plug (tmp))
+ rc_mark_service (tmp, rc_service_coldplugged);
+ CHAR_FREE (tmp);
+ }
+ }
+ }
rc_strlist_free (start_services);
start_services = NULL;
}
@@ -957,7 +957,7 @@ int main (int argc, char **argv)
types = rc_strlist_add (types, "iuse");
types = rc_strlist_add (types, "iafter");
deporder = rc_get_depends (deptree, types, stop_services,
- runlevel, depoptions);
+ runlevel, depoptions);
rc_strlist_free (stop_services);
rc_strlist_free (types);
stop_services = deporder;
@@ -967,24 +967,24 @@ int main (int argc, char **argv)
/* Load our list of coldplugged services */
coldplugged_services = rc_ls_dir (coldplugged_services,
- RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
+ RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
/* Load our start services now.
We have different rules dependent on runlevel. */
if (newlevel && strcmp (newlevel, RC_LEVEL_BOOT) == 0)
{
if (coldplugged_services)
- {
- einfon ("Device initiated services:");
- STRLIST_FOREACH (coldplugged_services, service, i)
- {
- printf (" %s", service);
- start_services = rc_strlist_add (start_services, service);
- }
- printf ("\n");
- }
+ {
+ einfon ("Device initiated services:");
+ STRLIST_FOREACH (coldplugged_services, service, i)
+ {
+ printf (" %s", service);
+ start_services = rc_strlist_add (start_services, service);
+ }
+ printf ("\n");
+ }
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
- (char *) NULL);
+ (char *) NULL);
start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
CHAR_FREE (tmp);
}
@@ -992,22 +992,22 @@ int main (int argc, char **argv)
{
/* Store our list of coldplugged services */
coldplugged_services = rc_ls_dir (coldplugged_services, RC_SVCDIR_COLDPLUGGED,
- RC_LS_INITD);
+ RC_LS_INITD);
if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
- strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
- strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
- {
- /* We need to include the boot runlevel services if we're not in it */
- start_services = rc_ls_dir (start_services, RC_RUNLEVELDIR RC_LEVEL_BOOT,
- RC_LS_INITD);
- STRLIST_FOREACH (coldplugged_services, service, i)
- start_services = rc_strlist_add (start_services, service);
-
- tmp = rc_strcatpaths (RC_RUNLEVELDIR,
- newlevel ? newlevel : runlevel, (char *) NULL);
- start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
- CHAR_FREE (tmp);
- }
+ strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
+ strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
+ {
+ /* We need to include the boot runlevel services if we're not in it */
+ start_services = rc_ls_dir (start_services, RC_RUNLEVELDIR RC_LEVEL_BOOT,
+ RC_LS_INITD);
+ STRLIST_FOREACH (coldplugged_services, service, i)
+ start_services = rc_strlist_add (start_services, service);
+
+ tmp = rc_strcatpaths (RC_RUNLEVELDIR,
+ newlevel ? newlevel : runlevel, (char *) NULL);
+ start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
+ CHAR_FREE (tmp);
+ }
}
/* Save out softlevel now */
@@ -1027,82 +1027,82 @@ int main (int argc, char **argv)
int k;
if (rc_service_state (service, rc_service_stopped))
- continue;
+ continue;
/* We always stop the service when in these runlevels */
if (going_down)
- {
- rc_stop_service (service);
- continue;
- }
+ {
+ rc_stop_service (service);
+ continue;
+ }
/* If we're in the start list then don't bother stopping us */
STRLIST_FOREACH (start_services, svc1, j)
if (strcmp (svc1, service) == 0)
- {
- found = true;
- break;
- }
+ {
+ found = true;
+ break;
+ }
/* Unless we would use a different config file */
if (found)
- {
- int len;
- if (! newlevel)
- continue;
-
- len = strlen (service) + strlen (runlevel) + 2;
- tmp = rc_xmalloc (sizeof (char *) * len);
- snprintf (tmp, len, "%s.%s", service, runlevel);
- conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
- found = rc_exists (conf);
- CHAR_FREE (conf);
- CHAR_FREE (tmp);
- if (! found)
- {
- len = strlen (service) + strlen (newlevel) + 2;
- tmp = rc_xmalloc (sizeof (char *) * len);
- snprintf (tmp, len, "%s.%s", service, newlevel);
- conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
- found = rc_exists (conf);
- CHAR_FREE (conf);
- CHAR_FREE (tmp);
- if (!found)
- continue;
- }
- }
+ {
+ int len;
+ if (! newlevel)
+ continue;
+
+ len = strlen (service) + strlen (runlevel) + 2;
+ tmp = rc_xmalloc (sizeof (char *) * len);
+ snprintf (tmp, len, "%s.%s", service, runlevel);
+ conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
+ found = rc_exists (conf);
+ CHAR_FREE (conf);
+ CHAR_FREE (tmp);
+ if (! found)
+ {
+ len = strlen (service) + strlen (newlevel) + 2;
+ tmp = rc_xmalloc (sizeof (char *) * len);
+ snprintf (tmp, len, "%s.%s", service, newlevel);
+ conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
+ found = rc_exists (conf);
+ CHAR_FREE (conf);
+ CHAR_FREE (tmp);
+ if (!found)
+ continue;
+ }
+ }
else
- /* Allow coldplugged services not to be in the runlevels list */
- {
- if (rc_service_state (service, rc_service_coldplugged))
- continue;
- }
+ /* Allow coldplugged services not to be in the runlevels list */
+ {
+ if (rc_service_state (service, rc_service_coldplugged))
+ continue;
+ }
/* We got this far! Or last check is to see if any any service that
- going to be started depends on us */
+ going to be started depends on us */
stopdeps = rc_strlist_add (stopdeps, service);
deporder = rc_get_depends (deptree, types, stopdeps,
- runlevel, RC_DEP_STRICT);
+ runlevel, RC_DEP_STRICT);
rc_strlist_free (stopdeps);
stopdeps = NULL;
found = false;
STRLIST_FOREACH (deporder, svc1, j)
- {
- STRLIST_FOREACH (start_services, svc2, k)
- if (strcmp (svc1, svc2) == 0)
- {
- found = true;
- break;
- }
- if (found)
- break;
- }
+ {
+ STRLIST_FOREACH (start_services, svc2, k)
+ if (strcmp (svc1, svc2) == 0)
+ {
+ found = true;
+ break;
+ }
+ if (found)
+ break;
+ }
rc_strlist_free (deporder);
deporder = NULL;
/* After all that we can finally stop the blighter! */
if (! found)
- rc_stop_service (service);
+ rc_stop_service (service);
}
rc_strlist_free (types);
types = NULL;
@@ -1132,14 +1132,14 @@ int main (int argc, char **argv)
myarg = rc_xstrdup (runlevel);
execl (mycmd, mycmd, myarg, (char *) NULL);
eerrorx ("%s: unable to exec `%s': %s",
- applet, HALTSH, strerror (errno));
+ applet, HALTSH, strerror (errno));
}
/* Single user is done now */
if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0)
{
if (rc_exists (INTERACTIVE))
- unlink (INTERACTIVE);
+ unlink (INTERACTIVE);
sulogin (false);
}
@@ -1155,7 +1155,7 @@ int main (int argc, char **argv)
types = rc_strlist_add (types, "iuse");
types = rc_strlist_add (types, "iafter");
deporder = rc_get_depends (deptree, types, start_services,
- runlevel, depoptions);
+ runlevel, depoptions);
rc_strlist_free (types);
types = NULL;
rc_strlist_free (start_services);
@@ -1165,31 +1165,31 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i)
{
if (rc_service_state (service, rc_service_stopped))
- {
- if (! interactive)
- interactive = want_interactive ();
+ {
+ if (! interactive)
+ interactive = want_interactive ();
- if (interactive)
- {
+ if (interactive)
+ {
interactive_retry:
- printf ("\n");
- einfo ("About to start the service %s", service);
- eindent ();
- einfo ("1) Start the service\t\t2) Skip the service");
- einfo ("3) Continue boot process\t\t4) Exit to shell");
- eoutdent ();
+ printf ("\n");
+ einfo ("About to start the service %s", service);
+ eindent ();
+ einfo ("1) Start the service\t\t2) Skip the service");
+ einfo ("3) Continue boot process\t\t4) Exit to shell");
+ eoutdent ();
interactive_option:
- switch (read_key (true))
- {
- case '1': break;
- case '2': continue;
- case '3': interactive = false; break;
- case '4': sulogin (true); goto interactive_retry;
- default: goto interactive_option;
- }
- }
- rc_start_service (service);
- }
+ switch (read_key (true))
+ {
+ case '1': break;
+ case '2': continue;
+ case '3': interactive = false; break;
+ case '4': sulogin (true); goto interactive_retry;
+ default: goto interactive_option;
+ }
+ }
+ rc_start_service (service);
+ }
}
/* Wait for our services to finish */
@@ -1204,7 +1204,7 @@ interactive_option:
else
{
if (rc_exists (INTERACTIVE))
- unlink (INTERACTIVE);
+ unlink (INTERACTIVE);
}
return (EXIT_SUCCESS);
diff --git a/src/rc.h b/src/rc.h
index 69999114..cfc518b2 100644
--- a/src/rc.h
+++ b/src/rc.h
@@ -45,19 +45,19 @@ bool rc_mark_service (const char *service, rc_service_state_t state);
pid_t rc_stop_service (const char *service);
pid_t rc_start_service (const char *service);
void rc_schedule_start_service (const char *service,
- const char *service_to_start);
+ const char *service_to_start);
char **rc_services_scheduled_by (const char *service);
void rc_schedule_clear (const char *service);
bool rc_wait_service (const char *service);
bool rc_get_service_option (const char *service, const char *option,
- char *value);
+ char *value);
bool rc_set_service_option (const char *service, const char *option,
- const char *value);
+ const char *value);
void rc_set_service_daemon (const char *service, const char *exec,
- const char *name, const char *pidfile,
- bool started);
+ const char *name, const char *pidfile,
+ bool started);
bool rc_service_started_daemon (const char *service, const char *exec,
- int indx);
+ int indx);
bool rc_allow_plug (char *service);
@@ -75,7 +75,7 @@ char **rc_services_scheduled (const char *service);
/* Find pids based on criteria - free the pointer returned after use */
pid_t *rc_find_pids (const char *exec, const char *cmd,
- uid_t uid, pid_t pid);
+ uid_t uid, pid_t pid);
/* Checks that all daemons started with start-stop-daemon by the service
are still running. If so, return false otherwise true.
You should check that the service has been started before calling this. */
@@ -110,14 +110,14 @@ rc_depinfo_t *rc_load_deptree (void);
rc_depinfo_t *rc_get_depinfo (rc_depinfo_t *deptree, const char *service);
rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
char **rc_get_depends (rc_depinfo_t *deptree, char **types,
- char **services, const char *runlevel, int options);
+ char **services, const char *runlevel, int options);
/* List all the services that should be started, in order, the the
given runlevel, including sysinit and boot services where
approriate.
If reboot, shutdown or single are given then we list all the services
we that we need to shutdown in order. */
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
- int options);
+ int options);
void rc_free_deptree (rc_depinfo_t *deptree);
diff --git a/src/runscript.c b/src/runscript.c
index 0b440e29..70db2cdf 100644
--- a/src/runscript.c
+++ b/src/runscript.c
@@ -71,20 +71,20 @@ void setup_selinux (int argc, char **argv)
if (lib_handle)
{
/* FIXME: the below code generates the warning
- ISO C forbids assignment between function pointer and 'void *'
- which sucks ass
- http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html */
+ ISO C forbids assignment between function pointer and 'void *'
+ which sucks ass
+http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html */
selinux_run_init_old = dlsym (lib_handle, "selinux_runscript");
selinux_run_init_new = dlsym (lib_handle, "selinux_runscript2");
/* Use new run_init if it rc_exists, else fall back to old */
if (selinux_run_init_new)
- selinux_run_init_new (argc, argv);
+ selinux_run_init_new (argc, argv);
else if (selinux_run_init_old)
- selinux_run_init_old ();
+ selinux_run_init_old ();
else
- /* This shouldnt happen... probably corrupt lib */
- eerrorx ("run_init is missing from runscript_selinux.so!");
+ /* This shouldnt happen... probably corrupt lib */
+ eerrorx ("run_init is missing from runscript_selinux.so!");
}
}
#endif
@@ -104,26 +104,26 @@ static void handle_signal (int sig)
case SIGCHLD:
do
- {
- pid = waitpid (-1, &status, WNOHANG);
- if (pid < 0)
- {
- if (errno != ECHILD)
- eerror ("waitpid: %s", strerror (errno));
- return;
- }
- } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
+ {
+ pid = waitpid (-1, &status, WNOHANG);
+ if (pid < 0)
+ {
+ if (errno != ECHILD)
+ eerror ("waitpid: %s", strerror (errno));
+ return;
+ }
+ } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
break;
-
+
case SIGINT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGINT");
+ snprintf (signame, sizeof (signame), "SIGINT");
case SIGTERM:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGTERM");
+ snprintf (signame, sizeof (signame), "SIGTERM");
case SIGQUIT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGQUIT");
+ snprintf (signame, sizeof (signame), "SIGQUIT");
eerrorx ("%s: caught %s, aborting", applet, signame);
default:
@@ -174,14 +174,14 @@ static bool in_control ()
{
path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL);
if (rc_exists (path))
- {
- int m = get_mtime (path, false);
- if (mtime < m && m != 0)
- {
- free (path);
- return (false);
- }
- }
+ {
+ int m = get_mtime (path, false);
+ if (mtime < m && m != 0)
+ {
+ free (path);
+ return (false);
+ }
+ }
free (path);
i++;
}
@@ -192,7 +192,7 @@ static bool in_control ()
static void uncoldplug (char *service)
{
char *cold = rc_strcatpaths (RC_SVCDIR "coldplugged", basename (service),
- (char *) NULL);
+ (char *) NULL);
if (rc_exists (cold) && unlink (cold) != 0)
eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno));
free (cold);
@@ -235,27 +235,27 @@ static void cleanup (void)
if (in_control ())
{
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);
- else
- rc_mark_service (applet, rc_service_started);
- }
+ {
+ /* 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);
+ else
+ rc_mark_service (applet, rc_service_started);
+ }
else if (rc_service_state (applet, rc_service_starting))
- {
- if (rc_service_state (applet, rc_service_wasinactive))
- rc_mark_service (applet, rc_service_inactive);
- else
- rc_mark_service (applet, rc_service_stopped);
- }
+ {
+ if (rc_service_state (applet, rc_service_wasinactive))
+ rc_mark_service (applet, rc_service_inactive);
+ else
+ rc_mark_service (applet, rc_service_stopped);
+ }
if (exclusive && rc_exists (exclusive))
- unlink (exclusive);
+ unlink (exclusive);
}
if (env)
@@ -281,7 +281,7 @@ static bool svc_exec (const char *service, const char *arg1, const char *arg2)
/* We need to disable our child signal handler now so we block
until our script returns. */
signal (SIGCHLD, NULL);
-
+
pid = fork();
if (pid == -1)
@@ -291,32 +291,32 @@ static bool svc_exec (const char *service, const char *arg1, const char *arg2)
mycmd = rc_xstrdup (service);
myarg1 = rc_xstrdup (arg1);
if (arg2)
- myarg2 = rc_xstrdup (arg2);
+ myarg2 = rc_xstrdup (arg2);
if (rc_exists (RC_SVCDIR "runscript.sh"))
- {
- execl (RC_SVCDIR "runscript.sh", mycmd, mycmd, myarg1, myarg2,
- (char *) NULL);
- eerrorx ("%s: exec `" RC_SVCDIR "runscript.sh': %s",
- service, strerror (errno));
- }
+ {
+ execl (RC_SVCDIR "runscript.sh", mycmd, mycmd, myarg1, myarg2,
+ (char *) NULL);
+ eerrorx ("%s: exec `" RC_SVCDIR "runscript.sh': %s",
+ service, strerror (errno));
+ }
else
- {
- execl (RC_LIBDIR "sh/runscript.sh", mycmd, mycmd, myarg1, myarg2,
- (char *) NULL);
- eerrorx ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s",
- service, strerror (errno));
- }
+ {
+ execl (RC_LIBDIR "sh/runscript.sh", mycmd, mycmd, myarg1, myarg2,
+ (char *) NULL);
+ eerrorx ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s",
+ service, strerror (errno));
+ }
}
do
{
if (waitpid (pid, &status, 0) < 0)
- {
- if (errno != ECHILD)
- eerror ("waitpid: %s", strerror (errno));
- break;
- }
+ {
+ if (errno != ECHILD)
+ eerror ("waitpid: %s", strerror (errno));
+ break;
+ }
} while (! WIFEXITED (status) && ! WIFSIGNALED (status));
/* Done, so restore the signal handler */
@@ -383,7 +383,7 @@ static void make_exclusive (const char *service)
if (mkfifo (exclusive, 0600) != 0 && errno != EEXIST &&
(errno != EACCES || geteuid () == 0))
eerrorx ("%s: unable to create fifo `%s': %s",
- applet, exclusive, strerror (errno));
+ applet, exclusive, strerror (errno));
path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
i = strlen (path) + 16;
@@ -394,7 +394,7 @@ static void make_exclusive (const char *service)
if (rc_exists (mtime_test) && unlink (mtime_test) != 0)
{
eerror ("%s: unlink `%s': %s",
- applet, mtime_test, strerror (errno));
+ applet, mtime_test, strerror (errno));
free (mtime_test);
mtime_test = NULL;
return;
@@ -403,7 +403,7 @@ static void make_exclusive (const char *service)
if (symlink (service, mtime_test) != 0)
{
eerror ("%s: symlink `%s' to `%s': %s",
- applet, service, mtime_test, strerror (errno));
+ applet, service, mtime_test, strerror (errno));
free (mtime_test);
mtime_test = NULL;
}
@@ -451,7 +451,7 @@ static void svc_start (const char *service, bool deps)
if (rc_is_env ("IN_HOTPLUG", "1") || in_background)
{
if (! rc_service_state (service, rc_service_inactive))
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
background = true;
}
@@ -472,7 +472,7 @@ static void svc_start (const char *service, bool deps)
if (deps)
{
if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
- eerrorx ("failed to load deptree");
+ eerrorx ("failed to load deptree");
rc_strlist_free (types);
types = rc_strlist_add (NULL, "broken");
@@ -481,16 +481,16 @@ static void svc_start (const char *service, bool deps)
rc_strlist_free (services);
services = rc_get_depends (deptree, types, svclist, softlevel, 0);
if (services)
- {
- eerrorn ("ERROR: `%s' needs ", applet);
- STRLIST_FOREACH (services, svc, i)
- {
- if (i > 0)
- fprintf (stderr, ", ");
- fprintf (stderr, "%s", svc);
- }
- exit (EXIT_FAILURE);
- }
+ {
+ eerrorn ("ERROR: `%s' needs ", applet);
+ STRLIST_FOREACH (services, svc, i)
+ {
+ if (i > 0)
+ fprintf (stderr, ", ");
+ fprintf (stderr, "%s", svc);
+ }
+ exit (EXIT_FAILURE);
+ }
rc_strlist_free (services);
services = NULL;
@@ -498,95 +498,95 @@ static void svc_start (const char *service, bool deps)
types = rc_strlist_add (NULL, "ineed");
rc_strlist_free (need_services);
need_services = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
+ softlevel, depoptions);
types = rc_strlist_add (types, "iuse");
if (! rc_runlevel_starting ())
- {
- services = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
- STRLIST_FOREACH (services, svc, i)
- if (rc_service_state (svc, rc_service_stopped))
- rc_start_service (svc);
+ {
+ services = rc_get_depends (deptree, types, svclist,
+ softlevel, depoptions);
+ STRLIST_FOREACH (services, svc, i)
+ if (rc_service_state (svc, rc_service_stopped))
+ rc_start_service (svc);
- rc_strlist_free (services);
- }
+ rc_strlist_free (services);
+ }
/* Now wait for them to start */
types = rc_strlist_add (types, "iafter");
services = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
+ softlevel, depoptions);
/* We use tmplist to hold our scheduled by list */
rc_strlist_free (tmplist);
tmplist = NULL;
STRLIST_FOREACH (services, svc, i)
- {
- if (rc_service_state (svc, rc_service_started))
- continue;
- if (! rc_wait_service (svc))
- eerror ("%s: timed out waiting for %s", applet, svc);
- 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))
- tmplist = rc_strlist_add (tmplist, svc);
- else
- eerrorx ("ERROR: cannot start %s as %s would not start",
- applet, svc);
- }
- }
+ {
+ if (rc_service_state (svc, rc_service_started))
+ continue;
+ if (! rc_wait_service (svc))
+ eerror ("%s: timed out waiting for %s", applet, svc);
+ 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))
+ tmplist = rc_strlist_add (tmplist, svc);
+ else
+ eerrorx ("ERROR: cannot start %s as %s would not start",
+ applet, svc);
+ }
+ }
if (tmplist)
- {
- int n = 0;
- int len = 0;
- char *p;
-
- /* Set the state now, then unlink our exclusive so that
- our scheduled list is preserved */
- rc_mark_service (service, rc_service_stopped);
- unlink_mtime_test ();
-
- rc_strlist_free (types);
- types = rc_strlist_add (NULL, "iprovide");
- STRLIST_FOREACH (tmplist, svc, i)
- {
- rc_schedule_start_service (svc, service);
-
- rc_strlist_free (svclist);
- svclist = rc_strlist_add (NULL, svc);
- rc_strlist_free (providelist);
- providelist = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
- STRLIST_FOREACH (providelist, svc2, j)
- rc_schedule_start_service (svc2, service);
-
- len += strlen (svc) + 2;
- n++;
- }
-
- len += 5;
- tmp = rc_xmalloc (sizeof (char *) * len);
- p = tmp;
- STRLIST_FOREACH (tmplist, svc, i)
- {
- if (i > 1)
- {
- if (i == n - 1)
- p += snprintf (p, len, " or ");
- else
- p += snprintf (p, len, ", ");
- }
- p += snprintf (p, len, "%s", svc);
- }
- ewarnx ("WARNING: %s is scheduled to start when %s has started",
- applet, tmp);
- }
+ {
+ int n = 0;
+ int len = 0;
+ char *p;
+
+ /* Set the state now, then unlink our exclusive so that
+ our scheduled list is preserved */
+ rc_mark_service (service, rc_service_stopped);
+ unlink_mtime_test ();
+
+ rc_strlist_free (types);
+ types = rc_strlist_add (NULL, "iprovide");
+ STRLIST_FOREACH (tmplist, svc, i)
+ {
+ rc_schedule_start_service (svc, service);
+
+ rc_strlist_free (svclist);
+ svclist = rc_strlist_add (NULL, svc);
+ rc_strlist_free (providelist);
+ providelist = rc_get_depends (deptree, types, svclist,
+ softlevel, depoptions);
+ STRLIST_FOREACH (providelist, svc2, j)
+ rc_schedule_start_service (svc2, service);
+
+ len += strlen (svc) + 2;
+ n++;
+ }
+
+ len += 5;
+ tmp = rc_xmalloc (sizeof (char *) * len);
+ p = tmp;
+ STRLIST_FOREACH (tmplist, svc, i)
+ {
+ if (i > 1)
+ {
+ if (i == n - 1)
+ p += snprintf (p, len, " or ");
+ else
+ p += snprintf (p, len, ", ");
+ }
+ p += snprintf (p, len, "%s", svc);
+ }
+ ewarnx ("WARNING: %s is scheduled to start when %s has started",
+ applet, tmp);
+ }
rc_strlist_free (services);
services = NULL;
@@ -607,17 +607,17 @@ static void svc_start (const char *service, bool deps)
if (in_control ())
{
if (! started)
- {
- if (rc_service_state (service, rc_service_wasinactive))
- rc_mark_service (service, rc_service_inactive);
- else
- {
- rc_mark_service (service, rc_service_stopped);
- if (rc_runlevel_starting ())
- rc_mark_service (service, rc_service_failed);
- }
- eerrorx ("ERROR: %s failed to start", applet);
- }
+ {
+ if (rc_service_state (service, rc_service_wasinactive))
+ rc_mark_service (service, rc_service_inactive);
+ else
+ {
+ rc_mark_service (service, rc_service_stopped);
+ if (rc_runlevel_starting ())
+ rc_mark_service (service, rc_service_failed);
+ }
+ eerrorx ("ERROR: %s failed to start", applet);
+ }
rc_mark_service (service, rc_service_started);
unlink_mtime_test ();
@@ -628,9 +628,9 @@ static void svc_start (const char *service, bool deps)
else
{
if (rc_service_state (service, rc_service_inactive))
- ewarn ("WARNING: %s has started, but is inactive", applet);
+ ewarn ("WARNING: %s has started, but is inactive", applet);
else
- ewarn ("WARNING: %s not under our control, aborting", applet);
+ ewarn ("WARNING: %s not under our control, aborting", applet);
}
/* Now start any scheduled services */
@@ -656,7 +656,7 @@ static void svc_start (const char *service, bool deps)
services = rc_services_scheduled (svc2);
STRLIST_FOREACH (services, svc, i)
if (rc_service_state (svc, rc_service_stopped))
- rc_start_service (svc);
+ rc_start_service (svc);
}
}
@@ -683,20 +683,20 @@ static void svc_stop (const char *service, bool deps)
make_exclusive (service);
if (! rc_runlevel_stopping () &&
- rc_service_in_runlevel (service, RC_LEVEL_BOOT))
- ewarn ("WARNING: you are stopping a boot service");
+ 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))
{
int depoptions = RC_DEP_TRACE;
char *svc;
int i;
-
+
if (rc_is_env ("RC_STRICT_DEPEND", "yes"))
- depoptions |= RC_DEP_STRICT;
+ depoptions |= RC_DEP_STRICT;
if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
- eerrorx ("failed to load deptree");
+ eerrorx ("failed to load deptree");
rc_strlist_free (types);
types = rc_strlist_add (NULL, "needsme");
@@ -706,55 +706,55 @@ static void svc_stop (const char *service, bool deps)
tmplist = NULL;
rc_strlist_free (services);
services = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
+ 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))
- {
- rc_wait_service (svc);
- if (rc_service_state (svc, rc_service_started) ||
- rc_service_state (svc, rc_service_inactive))
- {
- rc_stop_service (svc);
- tmplist = rc_strlist_add (tmplist, svc);
- }
- }
- }
+ {
+ 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))
+ {
+ rc_stop_service (svc);
+ tmplist = rc_strlist_add (tmplist, svc);
+ }
+ }
+ }
rc_strlist_free (services);
services = NULL;
STRLIST_FOREACH (tmplist, svc, i)
- {
- 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_runlevel_stopping ())
- rc_mark_service (svc, rc_service_failed);
- eerrorx ("ERROR: cannot stop %s as %s is still up",
- applet, svc);
- }
- }
+ {
+ 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_runlevel_stopping ())
+ rc_mark_service (svc, rc_service_failed);
+ eerrorx ("ERROR: cannot stop %s as %s is still up",
+ applet, svc);
+ }
+ }
rc_strlist_free (tmplist);
tmplist = NULL;
/* We now wait for other services that may use us and are stopping
- This is important when a runlevel stops */
+ This is important when a runlevel stops */
types = rc_strlist_add (types, "usesme");
types = rc_strlist_add (types, "ibefore");
services = rc_get_depends (deptree, types, svclist,
- softlevel, depoptions);
+ softlevel, depoptions);
STRLIST_FOREACH (services, svc, i)
- {
- if (rc_service_state (svc, rc_service_stopped))
- continue;
- rc_wait_service (svc);
- }
+ {
+ if (rc_service_state (svc, rc_service_stopped))
+ continue;
+ rc_wait_service (svc);
+ }
rc_strlist_free (services);
services = NULL;
@@ -776,9 +776,9 @@ static void svc_stop (const char *service, bool deps)
if (! stopped)
{
if (rc_service_state (service, rc_service_wasinactive))
- rc_mark_service (service, rc_service_inactive);
+ rc_mark_service (service, rc_service_inactive);
else
- rc_mark_service (service, rc_service_started);
+ rc_mark_service (service, rc_service_started);
eerrorx ("ERROR: %s failed to stop", applet);
}
@@ -797,7 +797,7 @@ static void svc_restart (const char *service, bool deps)
char *svc;
int i;
bool inactive = false;
-
+
/* This is hairly and a better way needs to be found I think!
The issue is this - openvpn need net and dns. net can restart
dns via resolvconf, so you could have openvpn trying to restart dnsmasq
@@ -809,10 +809,10 @@ static void svc_restart (const char *service, bool deps)
if (! deps)
{
if (rc_service_state (service, rc_service_started) ||
- rc_service_state (service, rc_service_inactive))
- svc_exec (service, "stop", "start");
+ rc_service_state (service, rc_service_inactive))
+ svc_exec (service, "stop", "start");
else
- svc_exec (service, "start", NULL);
+ svc_exec (service, "start", NULL);
return;
}
@@ -830,25 +830,25 @@ static void svc_restart (const char *service, bool deps)
inactive = rc_service_state (service, rc_service_inactive);
if (! inactive)
inactive = rc_service_state (service, rc_service_wasinactive);
-
+
if (inactive ||
rc_service_state (service, rc_service_starting) ||
rc_service_state (service, rc_service_started))
{
STRLIST_FOREACH (restart_services, svc, i)
- {
- if (rc_service_state (svc, rc_service_stopped))
- {
- if (inactive)
- {
- rc_schedule_start_service (service, svc);
- ewarn ("WARNING: %s is scheduled to started when %s has started",
- svc, basename (service));
- }
- else
- rc_start_service (svc);
- }
- }
+ {
+ if (rc_service_state (svc, rc_service_stopped))
+ {
+ if (inactive)
+ {
+ rc_schedule_start_service (service, svc);
+ ewarn ("WARNING: %s is scheduled to started when %s has started",
+ svc, basename (service));
+ }
+ else
+ rc_start_service (svc);
+ }
+ }
}
}
@@ -870,7 +870,7 @@ int main (int argc, char **argv)
{
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
- applet, strerror (errno));
+ applet, strerror (errno));
}
#ifdef __linux__
@@ -880,7 +880,7 @@ int main (int argc, char **argv)
{
eerror ("%s: cannot run until sysvinit completes", applet);
if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST)
- eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno));
+ eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno));
tmp = rc_strcatpaths ("/dev/.rcboot", applet, (char *) NULL);
symlink (service, tmp);
exit (EXIT_FAILURE);
@@ -890,40 +890,40 @@ int main (int argc, char **argv)
if ((softlevel = getenv ("RC_SOFTLEVEL")) == NULL)
{
/* Ensure our environment is pure
- Also, add our configuration to it */
+ Also, add our configuration to it */
env = rc_filter_env ();
env = rc_config_env (env);
if (env)
- {
- char *p;
+ {
+ char *p;
#ifdef __linux__
- /* clearenv isn't portable, but there's no harm in using it
- if we have it */
- clearenv ();
+ /* clearenv isn't portable, but there's no harm in using it
+ if we have it */
+ clearenv ();
#else
- char *var;
- /* No clearenv present here then.
- We could manipulate environ directly ourselves, but it seems that
- some kernels bitch about this according to the environ man pages
- so we walk though environ and call unsetenv for each value. */
- while (environ[0])
- {
- tmp = rc_xstrdup (environ[0]);
- p = tmp;
- var = strsep (&p, "=");
- unsetenv (var);
- free (tmp);
- }
- tmp = NULL;
+ char *var;
+ /* No clearenv present here then.
+ We could manipulate environ directly ourselves, but it seems that
+ some kernels bitch about this according to the environ man pages
+ so we walk though environ and call unsetenv for each value. */
+ while (environ[0])
+ {
+ tmp = rc_xstrdup (environ[0]);
+ p = tmp;
+ var = strsep (&p, "=");
+ unsetenv (var);
+ free (tmp);
+ }
+ tmp = NULL;
#endif
- STRLIST_FOREACH (env, p, i)
- putenv (p);
+ STRLIST_FOREACH (env, p, i)
+ putenv (p);
- /* We don't free our list as that would be null in environ */
- }
+ /* We don't free our list as that would be null in environ */
+ }
softlevel = rc_get_runlevel ();
@@ -969,44 +969,44 @@ int main (int argc, char **argv)
for (i = 2; i < argc; i++)
{
if (strlen (argv[i]) < 2 || argv[i][0] != '-' || argv[i][1] != '-')
- continue;
+ continue;
if (strcmp (argv[i], "--debug") == 0)
- setenv ("RC_DEBUG", "yes", 1);
+ setenv ("RC_DEBUG", "yes", 1);
else if (strcmp (argv[i], "--help") == 0)
- {
- execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
- eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
- applet, strerror (errno));
- }
+ {
+ execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
+ eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
+ applet, strerror (errno));
+ }
else if (strcmp (argv[i],"--ifstarted") == 0)
- ifstarted = true;
+ ifstarted = true;
else if (strcmp (argv[i], "--nocolour") == 0 ||
- strcmp (argv[i], "--nocolor") == 0)
- setenv ("RC_NOCOLOR", "yes", 1);
+ strcmp (argv[i], "--nocolor") == 0)
+ setenv ("RC_NOCOLOR", "yes", 1);
else if (strcmp (argv[i], "--nodeps") == 0)
- deps = false;
+ deps = false;
else if (strcmp (argv[i], "--quiet") == 0)
- setenv ("RC_QUIET", "yes", 1);
+ setenv ("RC_QUIET", "yes", 1);
else if (strcmp (argv[i], "--verbose") == 0)
- setenv ("RC_VERBOSE", "yes", 1);
+ setenv ("RC_VERBOSE", "yes", 1);
else if (strcmp (argv[i], "--version") == 0)
- printf ("version me\n");
+ printf ("version me\n");
else
- eerror ("%s: unknown option `%s'", applet, argv[i]);
+ eerror ("%s: unknown option `%s'", applet, argv[i]);
}
if (ifstarted && ! rc_service_state (applet, rc_service_started))
{
if (! rc_is_env("RC_QUIET", "yes"))
- eerror ("ERROR: %s is not started", applet);
+ eerror ("ERROR: %s is not started", applet);
exit (EXIT_FAILURE);
}
if (rc_is_env ("IN_HOTPLUG", "1"))
{
if (! rc_is_env ("RC_HOTPLUG", "yes") || ! rc_allow_plug (applet))
- eerrorx ("%s: not allowed to be hotplugged", applet);
+ eerrorx ("%s: not allowed to be hotplugged", applet);
}
/* Setup a signal handler */
@@ -1025,71 +1025,71 @@ int main (int argc, char **argv)
{
/* Abort on a sighup here */
if (sighup)
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
if (strlen (argv[i]) < 2 ||
- (argv[i][0] == '-' && argv[i][1] == '-'))
- continue;
+ (argv[i][0] == '-' && argv[i][1] == '-'))
+ continue;
/* Export the command we're running.
- This is important as we stamp on the restart function now but
- some start/stop routines still need to behave differently if
- restarting. */
+ This is important as we stamp on the restart function now but
+ some start/stop routines still need to behave differently if
+ restarting. */
unsetenv ("RC_CMD");
setenv ("RC_CMD", argv[i], 1);
-
+
doneone = true;
if (strcmp (argv[i], "conditionalrestart") == 0 ||
- strcmp (argv[i], "condrestart") == 0)
- {
- if (rc_service_state (service, rc_service_started))
- svc_restart (service, deps);
- }
+ strcmp (argv[i], "condrestart") == 0)
+ {
+ if (rc_service_state (service, rc_service_started))
+ svc_restart (service, deps);
+ }
else if (strcmp (argv[i], "restart") == 0)
- svc_restart (service, deps);
+ svc_restart (service, deps);
else if (strcmp (argv[i], "start") == 0)
- svc_start (service, deps);
+ svc_start (service, deps);
else if (strcmp (argv[i], "status") == 0)
- {
- rc_service_state_t r = svc_status (service);
- retval = (int) r;
- }
+ {
+ rc_service_state_t r = svc_status (service);
+ retval = (int) r;
+ }
else if (strcmp (argv[i], "stop") == 0)
- {
- if (in_background)
- get_started_services ();
-
- svc_stop (service, deps);
-
- if (! in_background &&
- ! rc_runlevel_stopping () &&
- rc_service_state (service, rc_service_stopped))
- uncoldplug (applet);
-
- if (in_background &&
- rc_service_state (service, rc_service_inactive))
- {
- char *svc;
- int j;
- STRLIST_FOREACH (restart_services, svc, j)
- if (rc_service_state (svc, rc_service_stopped))
- rc_schedule_start_service (service, svc);
- }
- }
+ {
+ if (in_background)
+ get_started_services ();
+
+ svc_stop (service, deps);
+
+ if (! in_background &&
+ ! rc_runlevel_stopping () &&
+ rc_service_state (service, rc_service_stopped))
+ uncoldplug (applet);
+
+ if (in_background &&
+ rc_service_state (service, rc_service_inactive))
+ {
+ char *svc;
+ int j;
+ STRLIST_FOREACH (restart_services, svc, j)
+ if (rc_service_state (svc, rc_service_stopped))
+ rc_schedule_start_service (service, svc);
+ }
+ }
else if (strcmp (argv[i], "zap") == 0)
- {
- einfo ("Manually resetting %s to stopped state", applet);
- rc_mark_service (applet, rc_service_stopped);
- uncoldplug (applet);
- }
+ {
+ einfo ("Manually resetting %s to stopped state", applet);
+ rc_mark_service (applet, rc_service_stopped);
+ uncoldplug (applet);
+ }
else if (strcmp (argv[i], "help") == 0)
- {
- execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL);
- eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
- applet, strerror (errno));
- }
+ {
+ execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL);
+ eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
+ applet, strerror (errno));
+ }
else
- svc_exec (service, argv[i], NULL);
+ svc_exec (service, argv[i], NULL);
/* Flush our buffered output if any */
eflush ();
@@ -1103,7 +1103,7 @@ int main (int argc, char **argv)
{
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
- applet, strerror (errno));
+ applet, strerror (errno));
}
return (retval);
diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c
index b48b7966..499543b9 100644
--- a/src/start-stop-daemon.c
+++ b/src/start-stop-daemon.c
@@ -130,7 +130,7 @@ static int parse_signal (const char *sig)
if (sscanf (sig, "%u", &i) == 1)
{
if (i > 0 && i < sizeof (signallist) / sizeof (signallist[0]))
- return (i);
+ return (i);
eerrorx ("%s: `%s' is not a valid signal", progname, sig);
}
@@ -141,7 +141,7 @@ static int parse_signal (const char *sig)
for (i = 0; i < sizeof (signallist) / sizeof (signallist[0]); i++)
if (strcmp (sig, signallist[i].name) == 0 ||
- (s && strcmp (s, signallist[i].name) == 0))
+ (s && strcmp (s, signallist[i].name) == 0))
return (signallist[i].signal);
eerrorx ("%s: `%s' is not a valid signal", progname, sig);
@@ -159,11 +159,11 @@ static void parse_schedule_item (schedulelist_t *item, const char *string)
item->type = schedule_timeout;
errno = 0;
if (sscanf (string, "%d", &item->value) != 1)
- eerrorx ("%s: invalid timeout value in schedule `%s'", progname,
- string);
+ eerrorx ("%s: invalid timeout value in schedule `%s'", progname,
+ string);
}
else if ((after_hyph = string + (string[0] == '-')) &&
- ((sig = parse_signal (after_hyph)) != -1))
+ ((sig = parse_signal (after_hyph)) != -1))
{
item->type = schedule_signal;
item->value = (int) sig;
@@ -184,7 +184,7 @@ static void parse_schedule (const char *string, int default_signal)
if (string)
for (slash = string; *slash; slash++)
if (*slash == '/')
- count++;
+ count++;
if (schedule)
free_schedulelist (&schedule);
@@ -201,12 +201,12 @@ static void parse_schedule (const char *string, int default_signal)
next->type = schedule_timeout;
next->gotolist = NULL;
if (string)
- {
- if (sscanf (string, "%d", &next->value) != 1)
- eerrorx ("%s: invalid timeout value in schedule", progname);
- }
+ {
+ if (sscanf (string, "%d", &next->value) != 1)
+ eerrorx ("%s: invalid timeout value in schedule", progname);
+ }
else
- next->value = 5;
+ next->value = 5;
next->next = NULL;
return;
@@ -216,12 +216,12 @@ static void parse_schedule (const char *string, int default_signal)
while (string != NULL)
{
if ((slash = strchr (string, '/')))
- len = slash - string;
+ len = slash - string;
else
- len = strlen (string);
+ len = strlen (string);
if (len >= (ptrdiff_t) sizeof (buffer))
- eerrorx ("%s: invalid schedule item, far too long", progname);
+ eerrorx ("%s: invalid schedule item, far too long", progname);
memcpy (buffer, string, len);
buffer[len] = 0;
@@ -229,21 +229,21 @@ static void parse_schedule (const char *string, int default_signal)
parse_schedule_item (next, buffer);
if (next->type == schedule_forever)
- {
- if (repeatat)
- eerrorx ("%s: invalid schedule, `forever' appears more than once",
- progname);
+ {
+ if (repeatat)
+ eerrorx ("%s: invalid schedule, `forever' appears more than once",
+ progname);
- repeatat = next;
- continue;
- }
+ repeatat = next;
+ continue;
+ }
if (string)
- {
- next->next = rc_xmalloc (sizeof (schedulelist_t));
- next = next->next;
- next->gotolist = NULL;
- }
+ {
+ next->next = rc_xmalloc (sizeof (schedulelist_t));
+ next = next->next;
+ next->gotolist = NULL;
+ }
}
if (repeatat)
@@ -270,14 +270,14 @@ static pid_t get_pid (const char *pidfile, bool quiet)
if ((fp = fopen (pidfile, "r")) == NULL)
{
if (! quiet)
- eerror ("%s: fopen `%s': %s", progname, pidfile, strerror (errno));
+ eerror ("%s: fopen `%s': %s", progname, pidfile, strerror (errno));
return (-1);
}
if (fscanf (fp, "%d", &pid) != 1)
{
if (! quiet)
- eerror ("%s: no pid found in `%s'", progname, pidfile);
+ eerror ("%s: no pid found in `%s'", progname, pidfile);
fclose (fp);
return (-1);
}
@@ -288,8 +288,8 @@ static pid_t get_pid (const char *pidfile, bool quiet)
/* return number of processed killed, -1 on error */
static int do_stop (const char *exec, const char *cmd,
- const char *pidfile, uid_t uid,int sig,
- bool quiet, bool verbose, bool test)
+ const char *pidfile, uid_t uid,int sig,
+ bool quiet, bool verbose, bool test)
{
pid_t *pids;
bool killed;
@@ -307,33 +307,33 @@ static int do_stop (const char *exec, const char *cmd,
for (i = 0; pids[i]; i++)
{
if (test)
- {
- if (! quiet)
- einfo ("Would send signal %d to PID %d", sig, pids[i]);
- nkilled++;
- continue;
- }
+ {
+ if (! quiet)
+ einfo ("Would send signal %d to PID %d", sig, pids[i]);
+ nkilled++;
+ continue;
+ }
if (verbose)
- ebegin ("Sending signal %d to PID %d", sig, pids[i]);
+ ebegin ("Sending signal %d to PID %d", sig, pids[i]);
errno = 0;
killed = (kill (pids[i], sig) == 0 || errno == ESRCH ? true : false);
if (! killed)
- {
- if (! quiet)
- eerror ("%s: failed to send signal %d to PID %d: %s",
- progname, sig, pids[i], strerror (errno));
- if (verbose)
- eend (1, NULL);
- nkilled = -1;
- }
+ {
+ if (! quiet)
+ eerror ("%s: failed to send signal %d to PID %d: %s",
+ progname, sig, pids[i], strerror (errno));
+ if (verbose)
+ eend (1, NULL);
+ nkilled = -1;
+ }
else
- {
- if (verbose)
- eend (0, NULL);
- if (nkilled != -1)
- nkilled++;
- }
+ {
+ if (verbose)
+ eend (0, NULL);
+ if (nkilled != -1)
+ nkilled++;
+ }
}
free (pids);
@@ -341,8 +341,8 @@ static int do_stop (const char *exec, const char *cmd,
}
static int run_stop_schedule (const char *exec, const char *cmd,
- const char *pidfile, uid_t uid,
- bool quiet, bool verbose, bool test)
+ const char *pidfile, uid_t uid,
+ bool quiet, bool verbose, bool test)
{
schedulelist_t *item = schedule;
int nkilled = 0;
@@ -355,89 +355,89 @@ static int run_stop_schedule (const char *exec, const char *cmd,
if (verbose)
{
if (pidfile)
- einfo ("Will stop PID in pidfile `%s'", pidfile);
+ einfo ("Will stop PID in pidfile `%s'", pidfile);
if (uid)
- einfo ("Will stop processes owned by UID %d", uid);
+ einfo ("Will stop processes owned by UID %d", uid);
if (exec)
- einfo ("Will stop processes of `%s'", exec);
+ einfo ("Will stop processes of `%s'", exec);
if (cmd)
- einfo ("Will stop processes called `%s'", cmd);
+ einfo ("Will stop processes called `%s'", cmd);
}
while (item)
{
switch (item->type)
- {
- case schedule_goto:
- item = item->gotolist;
- continue;
-
- case schedule_signal:
- nrunning = 0;
- nkilled = do_stop (exec, cmd, pidfile, uid, item->value,
- quiet, verbose, test);
- if (nkilled == 0)
- {
- if (tkilled == 0)
- {
- if (! quiet)
- eerror ("%s: no matching processes found", progname);
- }
- return (tkilled);
- }
- else if (nkilled == -1)
- return (0);
-
- tkilled += nkilled;
- break;
- case schedule_timeout:
- if (item->value < 1)
- {
- item = NULL;
- break;
- }
-
- if (gettimeofday (&stopat, NULL) != 0)
- {
- eerror ("%s: gettimeofday: %s", progname, strerror (errno));
- return (0);
- }
-
- stopat.tv_sec += item->value;
- while (1)
- {
- if ((nrunning = do_stop (exec, cmd, pidfile,
- uid, 0, true, false, true)) == 0)
- return (true);
-
- tv.tv_sec = 0;
- tv.tv_usec = POLL_INTERVAL;
- if (select (0, 0, 0, 0, &tv) < 0)
- {
- if (errno == EINTR)
- eerror ("%s: caught an interupt", progname);
- else
- eerror ("%s: select: %s", progname, strerror (errno));
- return (0);
- }
-
- if (gettimeofday (&now, NULL) != 0)
- {
- eerror ("%s: gettimeofday: %s", progname, strerror (errno));
- return (0);
- }
- if (timercmp (&now, &stopat, >))
- break;
- }
- break;
-
- default:
- eerror ("%s: invalid schedule item `%d'", progname, item->type);
- return (0);
- }
+ {
+ case schedule_goto:
+ item = item->gotolist;
+ continue;
+
+ case schedule_signal:
+ nrunning = 0;
+ nkilled = do_stop (exec, cmd, pidfile, uid, item->value,
+ quiet, verbose, test);
+ if (nkilled == 0)
+ {
+ if (tkilled == 0)
+ {
+ if (! quiet)
+ eerror ("%s: no matching processes found", progname);
+ }
+ return (tkilled);
+ }
+ else if (nkilled == -1)
+ return (0);
+
+ tkilled += nkilled;
+ break;
+ case schedule_timeout:
+ if (item->value < 1)
+ {
+ item = NULL;
+ break;
+ }
+
+ if (gettimeofday (&stopat, NULL) != 0)
+ {
+ eerror ("%s: gettimeofday: %s", progname, strerror (errno));
+ return (0);
+ }
+
+ stopat.tv_sec += item->value;
+ while (1)
+ {
+ if ((nrunning = do_stop (exec, cmd, pidfile,
+ uid, 0, true, false, true)) == 0)
+ return (true);
+
+ tv.tv_sec = 0;
+ tv.tv_usec = POLL_INTERVAL;
+ if (select (0, 0, 0, 0, &tv) < 0)
+ {
+ if (errno == EINTR)
+ eerror ("%s: caught an interupt", progname);
+ else
+ eerror ("%s: select: %s", progname, strerror (errno));
+ return (0);
+ }
+
+ if (gettimeofday (&now, NULL) != 0)
+ {
+ eerror ("%s: gettimeofday: %s", progname, strerror (errno));
+ return (0);
+ }
+ if (timercmp (&now, &stopat, >))
+ break;
+ }
+ break;
+
+ default:
+ eerror ("%s: invalid schedule item `%d'", progname, item->type);
+ return (0);
+ }
if (item)
- item = item->next;
+ item = item->next;
}
if (test || (tkilled > 0 && nrunning == 0))
@@ -446,9 +446,9 @@ static int run_stop_schedule (const char *exec, const char *cmd,
if (! quiet)
{
if (nrunning == 1)
- eerror ("%s: %d process refused to stop", progname, nrunning);
+ eerror ("%s: %d process refused to stop", progname, nrunning);
else
- eerror ("%s: %d process(es) refused to stop", progname, nrunning);
+ eerror ("%s: %d process(es) refused to stop", progname, nrunning);
}
return (-nrunning);
@@ -465,27 +465,27 @@ static void handle_signal (int sig)
{
case SIGINT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGINT");
+ snprintf (signame, sizeof (signame), "SIGINT");
case SIGTERM:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGTERM");
+ snprintf (signame, sizeof (signame), "SIGTERM");
case SIGQUIT:
if (! signame[0])
- snprintf (signame, sizeof (signame), "SIGQUIT");
+ snprintf (signame, sizeof (signame), "SIGQUIT");
eerrorx ("%s: caught %s, aborting", progname, signame);
case SIGCHLD:
while (1)
- {
- if ((pid = waitpid (-1, &status, WNOHANG)) < 0)
- {
- if (errno != ECHILD)
- eerror ("%s: waitpid: %s", progname, strerror (errno));
- break;
- }
- }
+ {
+ if ((pid = waitpid (-1, &status, WNOHANG)) < 0)
+ {
+ if (errno != ECHILD)
+ eerror ("%s: waitpid: %s", progname, strerror (errno));
+ break;
+ }
+ }
break;
-
+
default:
eerror ("%s: caught unknown signal %d", progname, sig);
}
@@ -568,141 +568,141 @@ int main (int argc, char **argv)
signal (SIGTERM, handle_signal);
while ((c = getopt_long (argc, argv,
- "KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:",
- longopts, (int *) 0)) != -1)
+ "KN:R:Sbc:d:g:mn:op:qs:tu:r:vx:1:2:",
+ longopts, (int *) 0)) != -1)
switch (c)
{
case 'K': /* --stop */
- stop = true;
- break;
+ stop = true;
+ break;
case 'N': /* --nice */
- if (sscanf (optarg, "%d", &nicelevel) != 1)
- eerrorx ("%s: invalid nice level `%s'", progname, optarg);
- break;
+ if (sscanf (optarg, "%d", &nicelevel) != 1)
+ eerrorx ("%s: invalid nice level `%s'", progname, optarg);
+ break;
case 'R': /* --retry <schedule>|<timeout> */
- parse_schedule (optarg, sig);
- break;
+ parse_schedule (optarg, sig);
+ break;
case 'S': /* --start */
- start = true;
- break;
+ start = true;
+ break;
case 'b': /* --background */
- background = true;
- break;
+ background = true;
+ break;
case 'c': /* --chuid <username>|<uid> */
- /* we copy the string just in case we need the
- * argument later. */
- {
- char *p = optarg;
- char *cu = strsep (&p, ":");
- changeuser = strdup (cu);
- if (sscanf (cu, "%d", &tid) != 1)
- {
- struct passwd *pw = getpwnam (cu);
- if (! pw)
- eerrorx ("%s: user `%s' not found", progname, cu);
- ch_uid = pw->pw_uid;
- }
- else
- ch_uid = tid;
- if (p)
- {
- char *cg = strsep (&p, ":");
- if (sscanf (cg, "%d", &tid) != 1)
- {
- struct group *gr = getgrnam (cg);
- if (! gr)
- eerrorx ("%s: group `%s' not found", progname, cg);
- ch_gid = gr->gr_gid;
- }
- else
- ch_gid = tid;
- }
- }
- break;
+ /* we copy the string just in case we need the
+ * argument later. */
+ {
+ char *p = optarg;
+ char *cu = strsep (&p, ":");
+ changeuser = strdup (cu);
+ if (sscanf (cu, "%d", &tid) != 1)
+ {
+ struct passwd *pw = getpwnam (cu);
+ if (! pw)
+ eerrorx ("%s: user `%s' not found", progname, cu);
+ ch_uid = pw->pw_uid;
+ }
+ else
+ ch_uid = tid;
+ if (p)
+ {
+ char *cg = strsep (&p, ":");
+ if (sscanf (cg, "%d", &tid) != 1)
+ {
+ struct group *gr = getgrnam (cg);
+ if (! gr)
+ eerrorx ("%s: group `%s' not found", progname, cg);
+ ch_gid = gr->gr_gid;
+ }
+ else
+ ch_gid = tid;
+ }
+ }
+ break;
case 'd': /* --chdir /new/dir */
- ch_dir = optarg;
- break;
+ ch_dir = optarg;
+ break;
case 'g': /* --group <group>|<gid> */
- if (sscanf (optarg, "%d", &tid) != 1)
- {
- struct group *gr = getgrnam (optarg);
- if (! gr)
- eerrorx ("%s: group `%s' not found", progname, optarg);
- ch_gid = gr->gr_gid;
- }
- else
- ch_gid = tid;
- break;
+ if (sscanf (optarg, "%d", &tid) != 1)
+ {
+ struct group *gr = getgrnam (optarg);
+ if (! gr)
+ eerrorx ("%s: group `%s' not found", progname, optarg);
+ ch_gid = gr->gr_gid;
+ }
+ else
+ ch_gid = tid;
+ break;
case 'm': /* --make-pidfile */
- makepidfile = true;
- break;
+ makepidfile = true;
+ break;
case 'n': /* --name <process-name> */
- cmd = optarg;
- break;
+ cmd = optarg;
+ break;
case 'o': /* --oknodo */
- oknodo = true;
- break;
+ oknodo = true;
+ break;
case 'p': /* --pidfile <pid-file> */
- pidfile = optarg;
- break;
+ pidfile = optarg;
+ break;
case 'q': /* --quiet */
- quiet = true;
- break;
+ quiet = true;
+ break;
case 's': /* --signal <signal> */
- sig = parse_signal (optarg);
- break;
+ sig = parse_signal (optarg);
+ break;
case 't': /* --test */
- test = true;
- break;
+ test = true;
+ break;
case 'u': /* --user <username>|<uid> */
- if (sscanf (optarg, "%d", &tid) != 1)
- {
- struct passwd *pw = getpwnam (optarg);
- if (! pw)
- eerrorx ("%s: user `%s' not found", progname, optarg);
- uid = pw->pw_uid;
- }
- else
- uid = tid;
- break;
+ if (sscanf (optarg, "%d", &tid) != 1)
+ {
+ struct passwd *pw = getpwnam (optarg);
+ if (! pw)
+ eerrorx ("%s: user `%s' not found", progname, optarg);
+ uid = pw->pw_uid;
+ }
+ else
+ uid = tid;
+ break;
case 'r': /* --chroot /new/root */
- ch_root = optarg;
- break;
+ ch_root = optarg;
+ break;
case 'v': /* --verbose */
- verbose = true;
- break;
+ verbose = true;
+ break;
case 'x': /* --exec <executable> */
- exec = optarg;
- break;
+ exec = optarg;
+ break;
case '1': /* --stdout /path/to/stdout.lgfile */
- redirect_stdout = optarg;
- break;
+ redirect_stdout = optarg;
+ break;
case '2': /* --stderr /path/to/stderr.logfile */
- redirect_stderr = optarg;
- break;
+ redirect_stderr = optarg;
+ break;
default:
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
}
/* Respect RC as well as how we are called */
@@ -726,7 +726,7 @@ int main (int argc, char **argv)
if ((redirect_stdout || redirect_stderr) && ! background)
eerrorx ("%s: --stdout and --stderr are only relevant with --background",
- progname);
+ progname);
argc -= optind;
argv += optind;
@@ -736,18 +736,18 @@ int main (int argc, char **argv)
{
char *tmp;
if (ch_root)
- tmp = rc_strcatpaths (ch_root, exec, (char *) NULL);
+ tmp = rc_strcatpaths (ch_root, exec, (char *) NULL);
else
- tmp = exec;
+ tmp = exec;
if (! rc_is_file (tmp))
- {
- eerror ("%s: %s does not exist", progname, tmp);
- if (ch_root)
- free (tmp);
- exit (EXIT_FAILURE);
- }
+ {
+ eerror ("%s: %s does not exist", progname, tmp);
+ if (ch_root)
+ free (tmp);
+ exit (EXIT_FAILURE);
+ }
if (ch_root)
- free (tmp);
+ free (tmp);
}
if (stop)
@@ -755,24 +755,24 @@ int main (int argc, char **argv)
int result;
if (! schedule)
- {
- if (test || oknodo)
- parse_schedule ("0", sig);
- else
- parse_schedule (NULL, sig);
- }
+ {
+ if (test || oknodo)
+ parse_schedule ("0", sig);
+ else
+ parse_schedule (NULL, sig);
+ }
result = run_stop_schedule (exec, cmd, pidfile, uid, quiet, verbose, test);
if (test || oknodo)
- return (result > 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ return (result > 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (result < 1)
- exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ exit (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
if (pidfile && rc_is_file (pidfile))
- unlink (pidfile);
+ unlink (pidfile);
if (svcname)
- rc_set_service_daemon (svcname, exec, cmd, pidfile, false);
+ rc_set_service_daemon (svcname, exec, cmd, pidfile, false);
exit (EXIT_SUCCESS);
}
@@ -783,23 +783,23 @@ int main (int argc, char **argv)
if (test)
{
if (quiet)
- exit (EXIT_SUCCESS);
+ exit (EXIT_SUCCESS);
einfon ("Would start %s", exec);
while (argc-- > 0)
- printf("%s ", *argv++);
+ printf("%s ", *argv++);
printf ("\n");
eindent ();
if (ch_uid != 0)
- einfo ("as user %d", ch_uid);
+ einfo ("as user %d", ch_uid);
if (ch_gid != 0)
- einfo ("as group %d", ch_gid);
+ einfo ("as group %d", ch_gid);
if (ch_root)
- einfo ("in root `%s'", ch_root);
+ einfo ("in root `%s'", ch_root);
if (ch_dir)
- einfo ("in dir `%s'", ch_dir);
+ einfo ("in dir `%s'", ch_dir);
if (nicelevel != 0)
- einfo ("with a priority of %d", nicelevel);
+ einfo ("with a priority of %d", nicelevel);
eoutdent ();
exit (EXIT_SUCCESS);
}
@@ -833,64 +833,64 @@ int main (int argc, char **argv)
devnull_fd = open("/dev/null", O_RDWR);
if (nicelevel)
- {
- if (setpriority (PRIO_PROCESS, mypid, nicelevel) == -1)
- eerrorx ("%s: setpritory %d: %s", progname, nicelevel,
- strerror(errno));
- }
+ {
+ if (setpriority (PRIO_PROCESS, mypid, nicelevel) == -1)
+ eerrorx ("%s: setpritory %d: %s", progname, nicelevel,
+ strerror(errno));
+ }
if (ch_root && chroot (ch_root) < 0)
- eerrorx ("%s: chroot `%s': %s", progname, ch_root, strerror (errno));
+ eerrorx ("%s: chroot `%s': %s", progname, ch_root, strerror (errno));
if (ch_dir && chdir (ch_dir) < 0)
- eerrorx ("%s: chdir `%s': %s", progname, ch_dir, strerror (errno));
+ eerrorx ("%s: chdir `%s': %s", progname, ch_dir, strerror (errno));
if (makepidfile && pidfile)
- {
- FILE *fp = fopen (pidfile, "w");
- if (! fp)
- eerrorx ("%s: fopen `%s': %s", progname, pidfile, strerror
- (errno));
- fprintf (fp, "%d\n", mypid);
- fclose (fp);
- }
+ {
+ FILE *fp = fopen (pidfile, "w");
+ if (! fp)
+ eerrorx ("%s: fopen `%s': %s", progname, pidfile, strerror
+ (errno));
+ fprintf (fp, "%d\n", mypid);
+ fclose (fp);
+ }
#ifdef HAVE_PAM
if (changeuser != NULL)
- pamr = pam_start ("start-stop-daemon", changeuser, &conv, &pamh);
+ pamr = pam_start ("start-stop-daemon", changeuser, &conv, &pamh);
else
- pamr = pam_start ("start-stop-daemon", "nobody", &conv, &pamh);
+ pamr = pam_start ("start-stop-daemon", "nobody", &conv, &pamh);
if (pamr == PAM_SUCCESS)
- pamr = pam_authenticate (pamh, PAM_SILENT);
+ pamr = pam_authenticate (pamh, PAM_SILENT);
if (pamr == PAM_SUCCESS)
- pamr = pam_acct_mgmt (pamh, PAM_SILENT);
+ pamr = pam_acct_mgmt (pamh, PAM_SILENT);
if (pamr == PAM_SUCCESS)
- pamr = pam_open_session (pamh, PAM_SILENT);
+ pamr = pam_open_session (pamh, PAM_SILENT);
if (pamr != PAM_SUCCESS)
- eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr));
+ eerrorx ("%s: pam error: %s", progname, pam_strerror(pamh, pamr));
#endif
if ((ch_gid) && setgid(ch_gid))
- eerrorx ("%s: unable to set groupid to %d", progname, ch_gid);
+ eerrorx ("%s: unable to set groupid to %d", progname, ch_gid);
if (changeuser && ch_gid)
- if (initgroups (changeuser, ch_gid))
- eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
+ if (initgroups (changeuser, ch_gid))
+ eerrorx ("%s: initgroups (%s, %d)", progname, changeuser, ch_gid);
if (ch_uid && setuid (ch_uid))
- eerrorx ("%s: unable to set userid to %d", progname, ch_uid);
+ eerrorx ("%s: unable to set userid to %d", progname, ch_uid);
else
- {
- struct passwd *passwd = getpwuid (ch_uid);
- if (passwd)
- {
- unsetenv ("HOME");
- if (passwd->pw_dir)
- setenv ("HOME", passwd->pw_dir, 1);
- unsetenv ("USER");
- if (passwd->pw_name)
- setenv ("USER", passwd->pw_name, 1);
- }
- }
+ {
+ struct passwd *passwd = getpwuid (ch_uid);
+ if (passwd)
+ {
+ unsetenv ("HOME");
+ if (passwd->pw_dir)
+ setenv ("HOME", passwd->pw_dir, 1);
+ unsetenv ("USER");
+ if (passwd->pw_name)
+ setenv ("USER", passwd->pw_name, 1);
+ }
+ }
/* Close any fd's to the passwd database */
endpwent ();
@@ -903,60 +903,60 @@ int main (int argc, char **argv)
/* Clean the environment of any RC_ variables */
STRLIST_FOREACH (environ, env, i)
if (env && strncmp (env, "RC_", 3) != 0)
- {
- /* For the path character, remove the rcscript bin dir from it */
- if (strncmp (env, "PATH=" RC_LIBDIR "bin:",
- strlen ("PATH=" RC_LIBDIR "bin:")) == 0)
- {
- char *path = env;
- char *newpath;
- int len;
- path += strlen ("PATH=" RC_LIBDIR "bin:");
- len = sizeof (char *) * strlen (path) + 6;
- newpath = rc_xmalloc (len);
- snprintf (newpath, len, "PATH=%s", path);
- newenv = rc_strlist_add (newenv, newpath);
- free (newpath);
- }
- else
- newenv = rc_strlist_add (newenv, env);
- }
+ {
+ /* For the path character, remove the rcscript bin dir from it */
+ if (strncmp (env, "PATH=" RC_LIBDIR "bin:",
+ strlen ("PATH=" RC_LIBDIR "bin:")) == 0)
+ {
+ char *path = env;
+ char *newpath;
+ int len;
+ path += strlen ("PATH=" RC_LIBDIR "bin:");
+ len = sizeof (char *) * strlen (path) + 6;
+ newpath = rc_xmalloc (len);
+ snprintf (newpath, len, "PATH=%s", path);
+ newenv = rc_strlist_add (newenv, newpath);
+ free (newpath);
+ }
+ else
+ newenv = rc_strlist_add (newenv, env);
+ }
umask (022);
stdout_fd = devnull_fd;
stderr_fd = devnull_fd;
if (redirect_stdout)
- {
- if ((stdout_fd = open (redirect_stdout, O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR)) == -1)
- eerrorx ("%s: unable to open the logfile for stdout `%s': %s",
- progname, redirect_stdout, strerror (errno));
- }
+ {
+ if ((stdout_fd = open (redirect_stdout, O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR)) == -1)
+ eerrorx ("%s: unable to open the logfile for stdout `%s': %s",
+ progname, redirect_stdout, strerror (errno));
+ }
if (redirect_stderr)
- {
- if ((stderr_fd = open (redirect_stderr, O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR)) == -1)
- eerrorx ("%s: unable to open the logfile for stderr `%s': %s",
- progname, redirect_stderr, strerror (errno));
- }
+ {
+ if ((stderr_fd = open (redirect_stderr, O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR)) == -1)
+ eerrorx ("%s: unable to open the logfile for stderr `%s': %s",
+ progname, redirect_stderr, strerror (errno));
+ }
dup2 (devnull_fd, STDIN_FILENO);
if (background)
- {
- dup2 (stdout_fd, STDOUT_FILENO);
- dup2 (stderr_fd, STDERR_FILENO);
- }
+ {
+ dup2 (stdout_fd, STDOUT_FILENO);
+ dup2 (stderr_fd, STDERR_FILENO);
+ }
for (i = getdtablesize () - 1; i >= 3; --i)
- close(i);
+ close(i);
setsid ();
execve (exec, argv, newenv);
#ifdef HAVE_PAM
if (pamr == PAM_SUCCESS)
- pam_close_session (pamh, PAM_SILENT);
+ pam_close_session (pamh, PAM_SILENT);
#endif
eerrorx ("%s: failed to exec `%s': %s", progname, exec, strerror (errno));
}
@@ -970,21 +970,21 @@ int main (int argc, char **argv)
errno = 0;
do
- {
- pid = waitpid (savepid, &status, 0);
- if (pid < 1)
- {
- eerror ("waitpid %d: %s", savepid, strerror (errno));
- return (-1);
- }
- } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
+ {
+ pid = waitpid (savepid, &status, 0);
+ if (pid < 1)
+ {
+ eerror ("waitpid %d: %s", savepid, strerror (errno));
+ return (-1);
+ }
+ } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
if (! WIFEXITED (status) || WEXITSTATUS (status) != 0)
- {
- if (! quiet)
- eerrorx ("%s: failed to started `%s'", progname, exec);
- exit (EXIT_FAILURE);
- }
+ {
+ if (! quiet)
+ eerrorx ("%s: failed to started `%s'", progname, exec);
+ exit (EXIT_FAILURE);
+ }
pid = savepid;
}
@@ -997,56 +997,56 @@ int main (int argc, char **argv)
struct timeval now;
if (gettimeofday (&stopat, NULL) != 0)
- eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
+ eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
stopat.tv_usec += START_WAIT;
while (1)
- {
- bool alive = false;
-
- tv.tv_sec = 0;
- tv.tv_usec = POLL_INTERVAL;
- if (select (0, 0, 0, 0, &tv) < 0)
- {
- /* Let our signal handler handle the interupt */
- if (errno != EINTR)
- eerrorx ("%s: select: %s", progname, strerror (errno));
- }
-
- if (gettimeofday (&now, NULL) != 0)
- eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
-
- /* This is knarly.
- If we backgrounded then we know the exact pid.
- Otherwise if we have a pidfile then it *may* know the exact pid.
- Failing that, we'll have to query processes.
- We sleep first as some programs like ntp like to fork, and write
- their pidfile a LONG time later. */
- if (background)
- {
- if (kill (pid, 0) == 0)
- alive = true;
- }
- else
- {
- if (pidfile && rc_exists (pidfile))
- {
- if (do_stop (NULL, NULL, pidfile, uid, 0, true, false, true) > 0)
- alive = true;
- }
- else
- {
- if (do_stop (exec, cmd, NULL, uid, 0, true, false, true) > 0)
- alive = true;
- }
- }
-
- if (! alive)
- eerrorx ("%s: %s died", progname, exec);
-
- if (timercmp (&now, &stopat, >))
- break;
- }
+ {
+ bool alive = false;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = POLL_INTERVAL;
+ if (select (0, 0, 0, 0, &tv) < 0)
+ {
+ /* Let our signal handler handle the interupt */
+ if (errno != EINTR)
+ eerrorx ("%s: select: %s", progname, strerror (errno));
+ }
+
+ if (gettimeofday (&now, NULL) != 0)
+ eerrorx ("%s: gettimeofday: %s", progname, strerror (errno));
+
+ /* This is knarly.
+ If we backgrounded then we know the exact pid.
+ Otherwise if we have a pidfile then it *may* know the exact pid.
+ Failing that, we'll have to query processes.
+ We sleep first as some programs like ntp like to fork, and write
+ their pidfile a LONG time later. */
+ if (background)
+ {
+ if (kill (pid, 0) == 0)
+ alive = true;
+ }
+ else
+ {
+ if (pidfile && rc_exists (pidfile))
+ {
+ if (do_stop (NULL, NULL, pidfile, uid, 0, true, false, true) > 0)
+ alive = true;
+ }
+ else
+ {
+ if (do_stop (exec, cmd, NULL, uid, 0, true, false, true) > 0)
+ alive = true;
+ }
+ }
+
+ if (! alive)
+ eerrorx ("%s: %s died", progname, exec);
+
+ if (timercmp (&now, &stopat, >))
+ break;
+ }
}
if (svcname)