Fix indentation

This commit is contained in:
Roy Marples
2007-04-10 11:24:58 +00:00
parent 662e308d86
commit d3db9e9910
17 changed files with 2325 additions and 2325 deletions

View File

@@ -25,12 +25,12 @@
#define CSH_ENV "/etc/csh.env" #define CSH_ENV "/etc/csh.env"
#define LDSOCONF "/etc/ld.so.conf" #define LDSOCONF "/etc/ld.so.conf"
#define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \ #define NOTICE "# THIS FILE IS AUTOMATICALLY GENERATED BY env-update.\n" \
"# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \ "# DO NOT EDIT THIS FILE. CHANGES TO STARTUP PROFILES\n" \
"# GO INTO %s NOT %s\n\n" "# GO INTO %s NOT %s\n\n"
#define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \ #define LDNOTICE "# ld.so.conf autogenerated by env-update; make all\n" \
"# changes to contents of /etc/env.d directory\n" "# changes to contents of /etc/env.d directory\n"
static const char *specials[] = static const char *specials[] =
{ {
@@ -85,78 +85,78 @@ int main (int argc, char **argv)
int j; int j;
if (! rc_is_dir (path)) if (! rc_is_dir (path))
entries = rc_get_config (NULL, path); entries = rc_get_config (NULL, path);
free (path); free (path);
STRLIST_FOREACH (entries, entry, j) STRLIST_FOREACH (entries, entry, j)
{ {
char *tmpent = rc_xstrdup (entry); char *tmpent = rc_xstrdup (entry);
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
int k; int k;
bool isspecial = false; bool isspecial = false;
bool isspecial_spaced = false; bool isspecial_spaced = false;
bool replaced = false; bool replaced = false;
for (k = 0; special_spaces[k]; k++) for (k = 0; special_spaces[k]; k++)
if (strcmp (special_spaces[k], var) == 0) if (strcmp (special_spaces[k], var) == 0)
{ {
isspecial = true; isspecial = true;
isspecial_spaced = true; isspecial_spaced = true;
break; break;
} }
if (! isspecial) if (! isspecial)
{ {
for (k = 0; specials[k]; k++) for (k = 0; specials[k]; k++)
if (strcmp (specials[k], var) == 0) if (strcmp (specials[k], var) == 0)
{ {
isspecial = true; isspecial = true;
break; break;
} }
} }
/* Skip blank vars */ /* Skip blank vars */
if (isspecial && if (isspecial &&
(! value || strlen (value)) == 0) (! value || strlen (value)) == 0)
{ {
free (tmpent); free (tmpent);
continue; continue;
} }
STRLIST_FOREACH (envs, env, k) STRLIST_FOREACH (envs, env, k)
{ {
char *tmpenv = rc_xstrdup (env); char *tmpenv = rc_xstrdup (env);
char *tmpvalue = tmpenv; char *tmpvalue = tmpenv;
char *tmpentry = strsep (&tmpvalue, "="); char *tmpentry = strsep (&tmpvalue, "=");
if (strcmp (tmpentry, var) == 0) if (strcmp (tmpentry, var) == 0)
{ {
if (isspecial) if (isspecial)
{ {
int len = strlen (envs[k - 1]) + strlen (entry) + 1; int len = strlen (envs[k - 1]) + strlen (entry) + 1;
envs[k - 1] = rc_xrealloc (envs[k - 1], len); envs[k - 1] = rc_xrealloc (envs[k - 1], len);
snprintf (envs[k - 1] + strlen (envs[k - 1]), len, snprintf (envs[k - 1] + strlen (envs[k - 1]), len,
"%s%s", isspecial_spaced ? " " : ":", value); "%s%s", isspecial_spaced ? " " : ":", value);
} }
else else
{ {
free (envs[k - 1]); free (envs[k - 1]);
envs[k - 1] = strdup (entry); envs[k - 1] = strdup (entry);
} }
replaced = true; replaced = true;
} }
free (tmpenv); free (tmpenv);
if (replaced) if (replaced)
break; break;
} }
if (! replaced) if (! replaced)
envs = rc_strlist_addsort (envs, entry); envs = rc_strlist_addsort (envs, entry);
free (tmpent); free (tmpent);
} }
} }
if ((fp = fopen (PROFILE_ENV, "w")) == NULL) if ((fp = fopen (PROFILE_ENV, "w")) == NULL)
@@ -168,7 +168,7 @@ int main (int argc, char **argv)
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0) if (strcmp (var, "LDPATH") != 0)
fprintf (fp, "export %s='%s'\n", var, value); fprintf (fp, "export %s='%s'\n", var, value);
free (tmpent); free (tmpent);
} }
fclose (fp); fclose (fp);
@@ -182,24 +182,24 @@ int main (int argc, char **argv)
char *value = tmpent; char *value = tmpent;
char *var = strsep (&value, "="); char *var = strsep (&value, "=");
if (strcmp (var, "LDPATH") != 0) if (strcmp (var, "LDPATH") != 0)
fprintf (fp, "setenv %s '%s'\n", var, value); fprintf (fp, "setenv %s '%s'\n", var, value);
free (tmpent); free (tmpent);
} }
fclose (fp); fclose (fp);
ldent = rc_get_config_entry (envs, "LDPATH"); ldent = rc_get_config_entry (envs, "LDPATH");
if (! ldent || if (! ldent ||
(argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0)) (argc > 1 && argv[1] && strcmp (argv[1], "--no-ldconfig") == 0))
{ {
free (envs); free (envs);
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
} }
while ((file = strsep (&ldent, ":"))) while ((file = strsep (&ldent, ":")))
{ {
if (strlen (file) == 0) if (strlen (file) == 0)
continue; continue;
ldents = rc_strlist_add (ldents, file); ldents = rc_strlist_add (ldents, file);
nents++; nents++;
@@ -213,12 +213,12 @@ int main (int argc, char **argv)
ld = false; ld = false;
STRLIST_FOREACH (lines, line, i) STRLIST_FOREACH (lines, line, i)
if (i > nents || strcmp (line, ldents[i - 1]) != 0) if (i > nents || strcmp (line, ldents[i - 1]) != 0)
{ {
ld = true; ld = true;
break; break;
} }
if (i - 1 != nents) if (i - 1 != nents)
ld = true; ld = true;
} }
if (ld) if (ld)
@@ -226,7 +226,7 @@ int main (int argc, char **argv)
int retval = 0; int retval = 0;
if ((fp = fopen (LDSOCONF, "w")) == NULL) 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); fprintf (fp, LDNOTICE);
STRLIST_FOREACH (ldents, ldent, i) STRLIST_FOREACH (ldents, ldent, i)
fprintf (fp, "%s\n", ldent); fprintf (fp, "%s\n", ldent);

View File

@@ -46,8 +46,8 @@ static struct mntent *getmntfile (FILE *fp, const char *file)
struct mntent *ent; struct mntent *ent;
while ((ent = getmntent (fp))) while ((ent = getmntent (fp)))
if (strcmp (file, ent->mnt_dir) == 0) if (strcmp (file, ent->mnt_dir) == 0)
return (ent); return (ent);
return (NULL); return (NULL);
} }
@@ -74,70 +74,70 @@ int main (int argc, char **argv)
#endif #endif
if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc) if (strcmp (argv[i], "--fstype") == 0 && i + 1 < argc)
{ {
i++; i++;
p = argv[i]; p = argv[i];
while ((token = strsep (&p, ","))) while ((token = strsep (&p, ",")))
while ((ent = GET_ENT)) while ((ent = GET_ENT))
if (strcmp (token, ENT_TYPE (ent)) == 0) if (strcmp (token, ENT_TYPE (ent)) == 0)
printf ("%s\n", ENT_FILE (ent)); printf ("%s\n", ENT_FILE (ent));
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }
if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc) if (strcmp (argv[i], "--mount-cmd") == 0 && i + 1 < argc)
{ {
i++; i++;
if ((ent = GET_ENT_FILE (argv[i])) == NULL) if ((ent = GET_ENT_FILE (argv[i])) == NULL)
continue; continue;
printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent), printf ("-o %s -t %s %s %s\n", ENT_OPTS (ent), ENT_TYPE (ent),
ENT_DEVICE (ent), ENT_FILE (ent)); ENT_DEVICE (ent), ENT_FILE (ent));
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }
if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc) if (strcmp (argv[i], "--opts") == 0 && i + 1 < argc)
{ {
i++; i++;
if ((ent = GET_ENT_FILE (argv[i])) == NULL) if ((ent = GET_ENT_FILE (argv[i])) == NULL)
continue; continue;
printf ("%s\n", ENT_OPTS (ent)); printf ("%s\n", ENT_OPTS (ent));
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }
if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc) if (strcmp (argv[i], "--passno") == 0 && i + 1 < argc)
{ {
i++; i++;
switch (argv[i][0]) switch (argv[i][0])
{ {
case '=': case '=':
case '<': case '<':
case '>': case '>':
if (sscanf (argv[i] + 1, "%d", &n) != 1) if (sscanf (argv[i] + 1, "%d", &n) != 1)
eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1); eerrorx ("%s: invalid passno %s", argv[0], argv[i] + 1);
while ((ent = GET_ENT)) while ((ent = GET_ENT))
{ {
if (((argv[i][0] == '=' && n == ENT_PASS (ent)) || if (((argv[i][0] == '=' && n == ENT_PASS (ent)) ||
(argv[i][0] == '<' && n > ENT_PASS (ent)) || (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) strcmp (ENT_FILE (ent), "none") != 0)
printf ("%s\n", ENT_FILE (ent)); printf ("%s\n", ENT_FILE (ent));
} }
default: default:
if ((ent = GET_ENT_FILE (argv[i])) == NULL) if ((ent = GET_ENT_FILE (argv[i])) == NULL)
continue; continue;
printf ("%d\n", ENT_PASS (ent)); printf ("%d\n", ENT_PASS (ent));
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }
} }
END_ENT; END_ENT;
if (result != EXIT_SUCCESS) if (result != EXIT_SUCCESS)
{ {
eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]); eerror ("%s: unknown option `%s'", basename (argv[0]), argv[i]);
break; break;
} }
} }

View File

@@ -116,10 +116,10 @@ bool colour_terminal (void)
while (colour_terms[i]) while (colour_terms[i])
{ {
if (strcmp (colour_terms[i], term) == 0) if (strcmp (colour_terms[i], term) == 0)
{ {
in_colour = 1; in_colour = 1;
return (true); return (true);
} }
i++; i++;
} }
@@ -235,12 +235,12 @@ void eflush (void)
{ {
snprintf (newfile, sizeof (newfile), "%s.%d", file, i); snprintf (newfile, sizeof (newfile), "%s.%d", file, i);
if (stat (newfile, &buf) != 0) if (stat (newfile, &buf) != 0)
{ {
if (rename (file, newfile)) if (rename (file, newfile))
fprintf (stderr, "rename `%s' `%s': %s\n", file, newfile, fprintf (stderr, "rename `%s' `%s': %s\n", file, newfile,
strerror (errno)); strerror (errno));
break; break;
} }
i++; i++;
} }
@@ -263,10 +263,10 @@ void eflush (void)
select (0, NULL, NULL, NULL, &tv); select (0, NULL, NULL, NULL, &tv);
errno = 0; errno = 0;
if (link (newfile, EBUFFER_LOCK) == 0) if (link (newfile, EBUFFER_LOCK) == 0)
break; break;
if (errno != EEXIST) if (errno != EEXIST)
fprintf (stderr, "link `%s' `%s': %s\n", newfile, EBUFFER_LOCK, fprintf (stderr, "link `%s' `%s': %s\n", newfile, EBUFFER_LOCK,
strerror (errno)); strerror (errno));
} }
if (! (fp = fopen (newfile, "r"))) if (! (fp = fopen (newfile, "r")))
@@ -282,56 +282,56 @@ void eflush (void)
{ {
i = strlen (buffer) - 1; i = strlen (buffer) - 1;
if (i < 1) if (i < 1)
continue; continue;
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
p = buffer; p = buffer;
cmd = strsep (&p, " "); cmd = strsep (&p, " ");
token = strsep (&p, " "); token = strsep (&p, " ");
if (sscanf (token, "%d", &retval) != 1) if (sscanf (token, "%d", &retval) != 1)
{ {
fprintf (stderr, "eflush `%s': not a number", token); fprintf (stderr, "eflush `%s': not a number", token);
continue; continue;
} }
token = strsep (&p, " "); token = strsep (&p, " ");
if (sscanf (token, "%d", &length) != 1) if (sscanf (token, "%d", &length) != 1)
{ {
fprintf (stderr, "eflush `%s': not a number", token); fprintf (stderr, "eflush `%s': not a number", token);
continue; continue;
} }
i = 0; i = 0;
while (funcmap[i].name) while (funcmap[i].name)
{ {
if (strcmp (funcmap[i].name, cmd) == 0) if (strcmp (funcmap[i].name, cmd) == 0)
{ {
if (funcmap[i].efunc) if (funcmap[i].efunc)
{ {
if (p) if (p)
funcmap[i].efunc ("%s", p); funcmap[i].efunc ("%s", p);
else else
funcmap[i].efunc (NULL, NULL); funcmap[i].efunc (NULL, NULL);
} }
else if (funcmap[i].eefunc) else if (funcmap[i].eefunc)
{ {
if (p) if (p)
funcmap[i].eefunc (retval, "%s", p); funcmap[i].eefunc (retval, "%s", p);
else else
funcmap[i].eefunc (retval, NULL, NULL); funcmap[i].eefunc (retval, NULL, NULL);
} }
else if (funcmap[i].eind) else if (funcmap[i].eind)
funcmap[i].eind (); funcmap[i].eind ();
else else
fprintf (stderr, "eflush `%s': no function defined\n", cmd); fprintf (stderr, "eflush `%s': no function defined\n", cmd);
break; break;
} }
i++; i++;
} }
if (! funcmap[i].name) if (! funcmap[i].name)
fprintf (stderr, "eflush `%s': invalid function\n", cmd); fprintf (stderr, "eflush `%s': invalid function\n", cmd);
} }
fclose (fp); fclose (fp);
@@ -348,7 +348,7 @@ void eflush (void)
{ \ { \
int _i = ebuffer (_cmd, _retval, _fmt, _ap); \ int _i = ebuffer (_cmd, _retval, _fmt, _ap); \
if (_i) \ if (_i) \
return (_i); \ return (_i); \
} }
static void elog (int level, const char *fmt, va_list ap) static void elog (int level, const char *fmt, va_list ap)
@@ -377,12 +377,12 @@ static int _eindent (FILE *stream)
errno = 0; errno = 0;
amount = strtol (env, NULL, 0); amount = strtol (env, NULL, 0);
if (errno != 0 || amount < 0) if (errno != 0 || amount < 0)
amount = 0; amount = 0;
else if (amount > INDENT_MAX) else if (amount > INDENT_MAX)
amount = INDENT_MAX; amount = INDENT_MAX;
if (amount > 0) if (amount > 0)
memset (indent, ' ', amount); memset (indent, ' ', amount);
} }
/* Terminate it */ /* Terminate it */
@@ -392,19 +392,19 @@ static int _eindent (FILE *stream)
} }
#define VEINFON(_file, _colour) \ #define VEINFON(_file, _colour) \
if (colour_terminal ()) \ if (colour_terminal ()) \
fprintf (_file, " " _colour "*" EINFO_NORMAL " "); \ fprintf (_file, " " _colour "*" EINFO_NORMAL " "); \
else \ else \
fprintf (_file, " * "); \ fprintf (_file, " * "); \
retval += _eindent (_file); \ retval += _eindent (_file); \
{ \ { \
va_list _ap; \ va_list _ap; \
va_copy (_ap, ap); \ va_copy (_ap, ap); \
retval += vfprintf (_file, fmt, _ap) + 3; \ retval += vfprintf (_file, fmt, _ap) + 3; \
va_end (_ap); \ va_end (_ap); \
} \ } \
if (colour_terminal ()) \ if (colour_terminal ()) \
fprintf (_file, "\033[K"); fprintf (_file, "\033[K");
static int _veinfon (const char *fmt, va_list ap) static int _veinfon (const char *fmt, va_list ap)
{ {
@@ -604,32 +604,32 @@ static void _eend (int col, einfo_color_t color, const char *msg)
{ {
fprintf (fp, "\033[A\033[%dC %s[ ", cols, EINFO_BRACKET); fprintf (fp, "\033[A\033[%dC %s[ ", cols, EINFO_BRACKET);
switch (color) switch (color)
{ {
case einfo_good: case einfo_good:
fprintf (fp, EINFO_GOOD); fprintf (fp, EINFO_GOOD);
break; break;
case einfo_warn: case einfo_warn:
fprintf (fp, EINFO_WARN); fprintf (fp, EINFO_WARN);
break; break;
case einfo_bad: case einfo_bad:
fprintf (fp, EINFO_BAD); fprintf (fp, EINFO_BAD);
break; break;
case einfo_hilite: case einfo_hilite:
fprintf (fp, EINFO_HILITE); fprintf (fp, EINFO_HILITE);
break; break;
case einfo_bracket: case einfo_bracket:
fprintf (fp, EINFO_BRACKET); fprintf (fp, EINFO_BRACKET);
break; break;
case einfo_normal: case einfo_normal:
fprintf (fp, EINFO_NORMAL); fprintf (fp, EINFO_NORMAL);
break; break;
} }
fprintf (fp, "%s%s ]%s\n", msg, EINFO_BRACKET, EINFO_NORMAL); fprintf (fp, "%s%s ]%s\n", msg, EINFO_BRACKET, EINFO_NORMAL);
} }
else else
{ {
for (i = -1; i < cols - col; i++) for (i = -1; i < cols - col; i++)
fprintf (fp, " "); fprintf (fp, " ");
fprintf (fp, "[ %s ]\n", msg); 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); eb = ebuffer (cmd, retval, fmt, apc);
va_end (apc); va_end (apc);
if (eb) if (eb)
return (retval); return (retval);
} }
if (fmt && retval != 0) if (fmt && retval != 0)
{ {
va_copy (apc, ap); va_copy (apc, ap);
if (strcmp (cmd, "ewend") == 0) if (strcmp (cmd, "ewend") == 0)
{ {
col = _vewarnn (fmt, apc); col = _vewarnn (fmt, apc);
fp = stdout; fp = stdout;
} }
else else
{ {
col = _veerrorn (fmt, apc); col = _veerrorn (fmt, apc);
fp = stderr; fp = stderr;
} }
va_end (apc); va_end (apc);
if (colour_terminal ()) if (colour_terminal ())
fprintf (fp, "\n"); fprintf (fp, "\n");
} }
_eend (col, retval == 0 ? einfo_good : einfo_bad, retval == 0 ? OK : NOT_OK); _eend (col, retval == 0 ? einfo_good : einfo_bad, retval == 0 ? OK : NOT_OK);
@@ -719,7 +719,7 @@ void eindent (void)
errno = 0; errno = 0;
amount = strtol (env, NULL, 0); amount = strtol (env, NULL, 0);
if (errno != 0) if (errno != 0)
amount = 0; amount = 0;
} }
amount += INDENT_WIDTH; amount += INDENT_WIDTH;
@@ -810,7 +810,7 @@ int veinfo (const char *fmt, ...)
retval = _veinfon (fmt, ap); retval = _veinfon (fmt, ap);
retval += printf ("\n"); retval += printf ("\n");
} }
va_end (ap); va_end (ap);
return (retval); return (retval);
} }
@@ -831,7 +831,7 @@ int vewarn (const char *fmt, ...)
retval = _vewarnn (fmt, ap); retval = _vewarnn (fmt, ap);
retval += printf ("\n"); retval += printf ("\n");
} }
va_end (ap); va_end (ap);
retval += printf ("\n"); retval += printf ("\n");
return (retval); return (retval);
@@ -853,7 +853,7 @@ int vebegin (const char *fmt, ...)
retval = _veinfon (fmt, ap); retval = _veinfon (fmt, ap);
retval += printf (" ..."); retval += printf (" ...");
if (colour_terminal ()) if (colour_terminal ())
retval += printf ("\n"); retval += printf ("\n");
} }
va_end (ap); va_end (ap);

View File

@@ -75,19 +75,19 @@ static bool pid_is_exec (pid_t pid, const char *exec)
if (readlink (cmdline, buffer, sizeof (buffer)) != -1) if (readlink (cmdline, buffer, sizeof (buffer)) != -1)
{ {
if (strcmp (exec, buffer) == 0) if (strcmp (exec, buffer) == 0)
return (true); return (true);
/* We should cater for deleted binaries too */ /* We should cater for deleted binaries too */
if (strlen (buffer) > 10) if (strlen (buffer) > 10)
{ {
p = buffer + (strlen (buffer) - 10); p = buffer + (strlen (buffer) - 10);
if (strcmp (p, " (deleted)") == 0) if (strcmp (p, " (deleted)") == 0)
{ {
*p = 0; *p = 0;
if (strcmp (buffer, exec) == 0) if (strcmp (buffer, exec) == 0)
return (true); return (true);
} }
} }
} }
snprintf (cmdline, sizeof (cmdline), "/proc/%u/cmdline", pid); 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, 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; DIR *procdir;
struct dirent *entry; struct dirent *entry;
@@ -130,42 +130,42 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
catching /etc/init.d/ntpd stop catching /etc/init.d/ntpd stop
nasty nasty
*/ */
if ((pp = getenv ("RC_RUNSCRIPT_PID"))) if ((pp = getenv ("RC_RUNSCRIPT_PID")))
{ {
if (sscanf (pp, "%d", &runscript_pid) != 1) if (sscanf (pp, "%d", &runscript_pid) != 1)
runscript_pid = 0; runscript_pid = 0;
} }
while ((entry = readdir (procdir)) != NULL) while ((entry = readdir (procdir)) != NULL)
{ {
if (sscanf (entry->d_name, "%d", &p) != 1) if (sscanf (entry->d_name, "%d", &p) != 1)
continue; continue;
foundany = true; foundany = true;
if (runscript_pid != 0 && runscript_pid == p) if (runscript_pid != 0 && runscript_pid == p)
continue; continue;
if (pid != 0 && pid != p) if (pid != 0 && pid != p)
continue; continue;
if (uid) if (uid)
{ {
snprintf (buffer, sizeof (buffer), "/proc/%d", pid); snprintf (buffer, sizeof (buffer), "/proc/%d", pid);
if (stat (buffer, &sb) != 0 || sb.st_uid != uid) if (stat (buffer, &sb) != 0 || sb.st_uid != uid)
continue; continue;
} }
if (cmd && ! pid_is_cmd (p, cmd)) if (cmd && ! pid_is_cmd (p, cmd))
continue; continue;
if (exec && ! cmd && ! pid_is_exec (p, exec)) if (exec && ! cmd && ! pid_is_exec (p, exec))
continue; continue;
pids = realloc (pids, sizeof (pid_t) * (npids + 2)); pids = realloc (pids, sizeof (pid_t) * (npids + 2));
if (! pids) if (! pids)
eerrorx ("memory exhausted"); eerrorx ("memory exhausted");
pids[npids] = p; pids[npids] = p;
pids[npids + 1] = 0; pids[npids + 1] = 0;
@@ -200,7 +200,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
# endif # endif
pid_t *rc_find_pids (const char *exec, const char *cmd, 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; static kvm_t *kd = NULL;
char errbuf[_POSIX2_LINE_MAX]; 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); kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
#else #else
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
&processes); &processes);
#endif #endif
for (i = 0; i < processes; i++) for (i = 0; i < processes; i++)
{ {
pid_t p = _GET_KINFO_PID (kp[i]); pid_t p = _GET_KINFO_PID (kp[i]);
if (pid != 0 && pid != p) if (pid != 0 && pid != p)
continue; continue;
if (uid != 0 && uid != _GET_KINFO_UID (kp[i])) if (uid != 0 && uid != _GET_KINFO_UID (kp[i]))
continue; continue;
if (cmd) if (cmd)
{ {
if (! _GET_KINFO_COMM (kp[i]) || if (! _GET_KINFO_COMM (kp[i]) ||
strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0) strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
continue; continue;
} }
if (exec && ! cmd) if (exec && ! cmd)
{ {
if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv) if ((argv = _KVM_GETARGV (kd, &kp[i], argc)) == NULL || ! *argv)
continue; continue;
if (strcmp (*argv, exec) != 0) if (strcmp (*argv, exec) != 0)
continue; continue;
} }
pids = realloc (pids, sizeof (pid_t) * (npids + 2)); pids = realloc (pids, sizeof (pid_t) * (npids + 2));
if (! pids) if (! pids)
eerrorx ("memory exhausted"); eerrorx ("memory exhausted");
pids[npids] = p; pids[npids] = p;
pids[npids + 1] = 0; pids[npids + 1] = 0;
@@ -264,8 +264,8 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
#endif #endif
static bool _match_daemon (const char *path, const char *file, static bool _match_daemon (const char *path, const char *file,
const char *mexec, const char *mname, const char *mexec, const char *mname,
const char *mpidfile) const char *mpidfile)
{ {
char buffer[RC_LINEBUFFER]; char buffer[RC_LINEBUFFER];
char *ffile = rc_strcatpaths (path, file, (char *) NULL); char *ffile = rc_strcatpaths (path, file, (char *) NULL);
@@ -296,21 +296,21 @@ static bool _match_daemon (const char *path, const char *file,
{ {
int lb = strlen (buffer) - 1; int lb = strlen (buffer) - 1;
if (buffer[lb] == '\n') if (buffer[lb] == '\n')
buffer[lb] = 0; buffer[lb] = 0;
if (strcmp (buffer, mexec) == 0) if (strcmp (buffer, mexec) == 0)
m += 1; m += 1;
else if (mname && strcmp (buffer, mname) == 0) else if (mname && strcmp (buffer, mname) == 0)
m += 10; m += 10;
else if (mpidfile && strcmp (buffer, mpidfile) == 0) else if (mpidfile && strcmp (buffer, mpidfile) == 0)
m += 100; m += 100;
if (m == 111) if (m == 111)
break; break;
lc++; lc++;
if (lc > 5) if (lc > 5)
break; break;
} }
fclose (fp); fclose (fp);
free (ffile); 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, void rc_set_service_daemon (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started) bool started)
{ {
char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service), char *dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
(char *) NULL); (char *) NULL);
char **files = NULL; char **files = NULL;
char *file; char *file;
char *ffile = NULL; char *ffile = NULL;
@@ -369,28 +369,28 @@ void rc_set_service_daemon (const char *service, const char *exec,
char *oldfile = NULL; char *oldfile = NULL;
files = rc_ls_dir (NULL, dirpath, 0); files = rc_ls_dir (NULL, dirpath, 0);
STRLIST_FOREACH (files, file, i) STRLIST_FOREACH (files, file, i)
{ {
ffile = rc_strcatpaths (dirpath, file, (char *) NULL); ffile = rc_strcatpaths (dirpath, file, (char *) NULL);
nfiles++; nfiles++;
if (! oldfile) if (! oldfile)
{ {
if (_match_daemon (dirpath, file, mexec, mname, mpidfile)) if (_match_daemon (dirpath, file, mexec, mname, mpidfile))
{ {
unlink (ffile); unlink (ffile);
oldfile = ffile; oldfile = ffile;
nfiles--; nfiles--;
} }
} }
else else
{ {
rename (ffile, oldfile); rename (ffile, oldfile);
free (oldfile); free (oldfile);
oldfile = ffile; oldfile = ffile;
} }
} }
if (ffile) if (ffile)
free (ffile); free (ffile);
free (files); free (files);
} }
@@ -401,18 +401,18 @@ void rc_set_service_daemon (const char *service, const char *exec,
FILE *fp; FILE *fp;
if (! rc_is_dir (dirpath)) if (! rc_is_dir (dirpath))
if (mkdir (dirpath, 0755) != 0) if (mkdir (dirpath, 0755) != 0)
eerror ("mkdir `%s': %s", dirpath, strerror (errno)); eerror ("mkdir `%s': %s", dirpath, strerror (errno));
snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1); snprintf (buffer, sizeof (buffer), "%03d", nfiles + 1);
file = rc_strcatpaths (dirpath, buffer, (char *) NULL); file = rc_strcatpaths (dirpath, buffer, (char *) NULL);
if ((fp = fopen (file, "w")) == NULL) if ((fp = fopen (file, "w")) == NULL)
eerror ("fopen `%s': %s", file, strerror (errno)); eerror ("fopen `%s': %s", file, strerror (errno));
else else
{ {
fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile); fprintf (fp, "%s\n%s\n%s\n", mexec, mname, mpidfile);
fclose (fp); fclose (fp);
} }
free (file); 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, bool rc_service_started_daemon (const char *service, const char *exec,
int indx) int indx)
{ {
char *dirpath; char *dirpath;
char *file; char *file;
@@ -435,7 +435,7 @@ bool rc_service_started_daemon (const char *service, const char *exec,
return (false); return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
(char *) NULL); (char *) NULL);
if (! rc_is_dir (dirpath)) if (! rc_is_dir (dirpath))
{ {
free (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); char **files = rc_ls_dir (NULL, dirpath, 0);
STRLIST_FOREACH (files, file, i) STRLIST_FOREACH (files, file, i)
{ {
retval = _match_daemon (dirpath, file, mexec, NULL, NULL); retval = _match_daemon (dirpath, file, mexec, NULL, NULL);
if (retval) if (retval)
break; break;
} }
free (files); free (files);
} }
@@ -492,7 +492,7 @@ bool rc_service_daemons_crashed (const char *service)
return (false); return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename (service),
(char *) NULL); (char *) NULL);
if (! rc_is_dir (dirpath)) if (! rc_is_dir (dirpath))
{ {
free (dirpath); free (dirpath);
@@ -507,91 +507,91 @@ bool rc_service_daemons_crashed (const char *service)
fp = fopen (path, "r"); fp = fopen (path, "r");
free (path); free (path);
if (! fp) if (! fp)
{ {
eerror ("fopen `%s': %s", file, strerror (errno)); eerror ("fopen `%s': %s", file, strerror (errno));
continue; continue;
} }
while ((fgets (buffer, RC_LINEBUFFER, fp))) while ((fgets (buffer, RC_LINEBUFFER, fp)))
{ {
int lb = strlen (buffer) - 1; int lb = strlen (buffer) - 1;
if (buffer[lb] == '\n') if (buffer[lb] == '\n')
buffer[lb] = 0; buffer[lb] = 0;
p = buffer; p = buffer;
if ((token = strsep (&p, "=")) == NULL || ! p) if ((token = strsep (&p, "=")) == NULL || ! p)
continue; continue;
if (strlen (p) == 0) if (strlen (p) == 0)
continue; continue;
if (strcmp (token, "exec") == 0) if (strcmp (token, "exec") == 0)
{ {
if (exec) if (exec)
free (exec); free (exec);
exec = strdup (p); exec = strdup (p);
} }
else if (strcmp (token, "name") == 0) else if (strcmp (token, "name") == 0)
{ {
if (name) if (name)
free (name); free (name);
name = strdup (p); name = strdup (p);
} }
else if (strcmp (token, "pidfile") == 0) else if (strcmp (token, "pidfile") == 0)
{ {
if (pidfile) if (pidfile)
free (pidfile); free (pidfile);
pidfile = strdup (p); pidfile = strdup (p);
} }
} }
fclose (fp); fclose (fp);
pid = 0; pid = 0;
if (pidfile) if (pidfile)
{ {
if (! rc_exists (pidfile)) if (! rc_exists (pidfile))
{ {
retval = true; retval = true;
break; break;
} }
if ((fp = fopen (pidfile, "r")) == NULL) if ((fp = fopen (pidfile, "r")) == NULL)
{ {
eerror ("fopen `%s': %s", pidfile, strerror (errno)); eerror ("fopen `%s': %s", pidfile, strerror (errno));
retval = true; retval = true;
break; break;
} }
if (fscanf (fp, "%d", &pid) != 1) if (fscanf (fp, "%d", &pid) != 1)
{ {
eerror ("no pid found in `%s'", pidfile); eerror ("no pid found in `%s'", pidfile);
fclose (fp); fclose (fp);
retval = true; retval = true;
break; break;
} }
fclose (fp); fclose (fp);
free (pidfile); free (pidfile);
pidfile = NULL; pidfile = NULL;
} }
if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL) if ((pids = rc_find_pids (exec, name, 0, pid)) == NULL)
{ {
retval = true; retval = true;
break; break;
} }
free (pids); free (pids);
if (exec) if (exec)
{ {
free (exec); free (exec);
exec = NULL; exec = NULL;
} }
if (name) if (name)
{ {
free (name); free (name);
name = NULL; name = NULL;
} }
} }
if (exec) if (exec)

View File

@@ -59,13 +59,13 @@ void rc_free_deptree (rc_depinfo_t *deptree)
rc_deptype_t *dt = di->depends; rc_deptype_t *dt = di->depends;
free (di->service); free (di->service);
while (dt) while (dt)
{ {
rc_deptype_t *dtp = dt->next; rc_deptype_t *dtp = dt->next;
free (dt->type); free (dt->type);
rc_strlist_free (dt->services); rc_strlist_free (dt->services);
free (dt); free (dt);
dt = dtp; dt = dtp;
} }
free (di); free (di);
di = dip; di = dip;
} }
@@ -94,63 +94,63 @@ rc_depinfo_t *rc_load_deptree (void)
p = buffer; p = buffer;
e = strsep (&p, "_"); e = strsep (&p, "_");
if (! e || strcmp (e, "depinfo") != 0) if (! e || strcmp (e, "depinfo") != 0)
continue; continue;
e = strsep (&p, "_"); e = strsep (&p, "_");
if (! e || sscanf (e, "%d", &i) != 1) if (! e || sscanf (e, "%d", &i) != 1)
continue; continue;
if (! (type = strsep (&p, "_="))) if (! (type = strsep (&p, "_=")))
continue; continue;
if (strcmp (type, "service") == 0) if (strcmp (type, "service") == 0)
{ {
/* Sanity */ /* Sanity */
e = get_shell_value (p); e = get_shell_value (p);
if (! e || strlen (e) == 0) if (! e || strlen (e) == 0)
continue; continue;
if (! deptree) if (! deptree)
{ {
deptree = rc_xmalloc (sizeof (rc_depinfo_t)); deptree = rc_xmalloc (sizeof (rc_depinfo_t));
depinfo = deptree; depinfo = deptree;
} }
else else
{ {
depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
depinfo = depinfo->next; depinfo = depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t)); memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = strdup (e); depinfo->service = strdup (e);
deptype = NULL; deptype = NULL;
continue; continue;
} }
e = strsep (&p, "="); e = strsep (&p, "=");
if (! e || sscanf (e, "%d", &i) != 1) if (! e || sscanf (e, "%d", &i) != 1)
continue; continue;
/* Sanity */ /* Sanity */
e = get_shell_value (p); e = get_shell_value (p);
if (! e || strlen (e) == 0) if (! e || strlen (e) == 0)
continue; continue;
if (! deptype) if (! deptype)
{ {
depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
memset (deptype, 0, sizeof (rc_deptype_t)); memset (deptype, 0, sizeof (rc_deptype_t));
} }
else else
if (strcmp (deptype->type, type) != 0) if (strcmp (deptype->type, type) != 0)
{ {
deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
deptype = deptype->next; deptype = deptype->next;
memset (deptype, 0, sizeof (rc_deptype_t)); memset (deptype, 0, sizeof (rc_deptype_t));
} }
if (! deptype->type) if (! deptype->type)
deptype->type = strdup (type); deptype->type = strdup (type);
deptype->services = rc_strlist_addsort (deptype->services, e); 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) static bool valid_service (const char *runlevel, const char *service)
{ {
return ((strcmp (runlevel, RC_LEVEL_BOOT) != 0 && return ((strcmp (runlevel, RC_LEVEL_BOOT) != 0 &&
rc_service_in_runlevel (service, RC_LEVEL_BOOT)) || rc_service_in_runlevel (service, RC_LEVEL_BOOT)) ||
rc_service_in_runlevel (service, runlevel) || rc_service_in_runlevel (service, runlevel) ||
rc_service_state (service, rc_service_coldplugged) || rc_service_state (service, rc_service_coldplugged) ||
rc_service_state (service, rc_service_started)); rc_service_state (service, rc_service_started));
} }
static bool get_provided1 (const char *runlevel, struct lhead *providers, static bool get_provided1 (const char *runlevel, struct lhead *providers,
rc_deptype_t *deptype, rc_deptype_t *deptype,
const char *level, bool coldplugged, const char *level, bool coldplugged,
bool started, bool inactive) bool started, bool inactive)
{ {
char *service; char *service;
int i; int i;
@@ -209,24 +209,24 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
{ {
bool ok = true; bool ok = true;
if (level) if (level)
ok = rc_service_in_runlevel (service, level); ok = rc_service_in_runlevel (service, level);
else if (coldplugged) else if (coldplugged)
ok = (rc_service_state (service, rc_service_coldplugged) && ok = (rc_service_state (service, rc_service_coldplugged) &&
! rc_service_in_runlevel (service, runlevel) && ! rc_service_in_runlevel (service, runlevel) &&
! rc_service_in_runlevel (service, RC_LEVEL_BOOT)); ! rc_service_in_runlevel (service, RC_LEVEL_BOOT));
if (! ok) if (! ok)
continue; continue;
if (started) if (started)
ok = (rc_service_state (service, rc_service_starting) || ok = (rc_service_state (service, rc_service_starting) ||
rc_service_state (service, rc_service_started) || rc_service_state (service, rc_service_started) ||
rc_service_state (service, rc_service_stopping)); rc_service_state (service, rc_service_stopping));
else if (inactive) else if (inactive)
ok = rc_service_state (service, rc_service_inactive); ok = rc_service_state (service, rc_service_inactive);
if (! ok) if (! ok)
continue; continue;
retval = true; retval = true;
providers->list = rc_strlist_add (providers->list, service); 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. provided dependancy can change depending on runlevel state.
*/ */
static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo, 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; rc_deptype_t *dt;
struct lhead providers; struct lhead providers;
@@ -268,7 +268,7 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (options & RC_DEP_STOP) if (options & RC_DEP_STOP)
{ {
STRLIST_FOREACH (dt->services, service, i) 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); return (providers.list);
} }
@@ -277,11 +277,11 @@ static char **get_provided (rc_depinfo_t *deptree, rc_depinfo_t *depinfo,
if (options & RC_DEP_STRICT) if (options & RC_DEP_STRICT)
{ {
STRLIST_FOREACH (dt->services, service, i) STRLIST_FOREACH (dt->services, service, i)
if (rc_service_in_runlevel (service, runlevel)) if (rc_service_in_runlevel (service, runlevel))
providers.list = rc_strlist_add (providers.list, service); providers.list = rc_strlist_add (providers.list, service);
if (providers.list) if (providers.list)
return (providers.list); return (providers.list);
} }
/* OK, we're not strict or there were no services in our runlevel. /* 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); \ return (NULL); \
} \ } \
else if (providers.list) \ else if (providers.list) \
return providers.list; \ return providers.list; \
/* Anything in the runlevel has to come first */ /* Anything in the runlevel has to come first */
if (get_provided1 (runlevel, &providers, dt, runlevel, false, true, false)) 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 (strcmp (runlevel, RC_LEVEL_BOOT) != 0)
{ {
if (get_provided1 (runlevel, &providers, dt, RC_LEVEL_BOOT, false, true, false)) 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)) if (get_provided1 (runlevel, &providers, dt, RC_LEVEL_BOOT, false, false, true))
{ DO } { DO }
} }
/* Check coldplugged inactive services */ /* 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 */ /* Still nothing? OK, list all services */
STRLIST_FOREACH (dt->services, service, i) 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); return (providers.list);
} }
static void visit_service (rc_depinfo_t *deptree, char **types, static void visit_service (rc_depinfo_t *deptree, char **types,
struct lhead *sorted, struct lhead *visited, struct lhead *sorted, struct lhead *visited,
rc_depinfo_t *depinfo, rc_depinfo_t *depinfo,
const char *runlevel, int options) const char *runlevel, int options)
{ {
int i, j, k; int i, j, k;
char *lp, *item; char *lp, *item;
@@ -372,55 +372,55 @@ static void visit_service (rc_depinfo_t *deptree, char **types,
STRLIST_FOREACH (types, item, i) STRLIST_FOREACH (types, item, i)
{ {
if ((dt = rc_get_deptype (depinfo, item))) if ((dt = rc_get_deptype (depinfo, item)))
{ {
STRLIST_FOREACH (dt->services, service, j) STRLIST_FOREACH (dt->services, service, j)
{ {
if (! options & RC_DEP_TRACE || strcmp (item, "iprovide") == 0) if (! options & RC_DEP_TRACE || strcmp (item, "iprovide") == 0)
{ {
sorted->list = rc_strlist_add (sorted->list, service); sorted->list = rc_strlist_add (sorted->list, service);
continue; continue;
} }
di = rc_get_depinfo (deptree, service); di = rc_get_depinfo (deptree, service);
if ((provides = get_provided (deptree, di, runlevel, options))) if ((provides = get_provided (deptree, di, runlevel, options)))
{ {
STRLIST_FOREACH (provides, lp, k) STRLIST_FOREACH (provides, lp, k)
{ {
di = rc_get_depinfo (deptree, lp); di = rc_get_depinfo (deptree, lp);
if (di && (strcmp (item, "ineed") == 0 || if (di && (strcmp (item, "ineed") == 0 ||
valid_service (runlevel, di->service))) valid_service (runlevel, di->service)))
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
} }
rc_strlist_free (provides); rc_strlist_free (provides);
} }
else else
if (di && (strcmp (item, "ineed") == 0 || if (di && (strcmp (item, "ineed") == 0 ||
valid_service (runlevel, service))) valid_service (runlevel, service)))
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
} }
} }
} }
/* Now visit the stuff we provide for */ /* Now visit the stuff we provide for */
if (options & RC_DEP_TRACE && (dt = rc_get_deptype (depinfo, "iprovide"))) if (options & RC_DEP_TRACE && (dt = rc_get_deptype (depinfo, "iprovide")))
{ {
STRLIST_FOREACH (dt->services, service, i) STRLIST_FOREACH (dt->services, service, i)
{ {
if ((di = rc_get_depinfo (deptree, service))) if ((di = rc_get_depinfo (deptree, service)))
if ((provides = get_provided (deptree, di, runlevel, options))) if ((provides = get_provided (deptree, di, runlevel, options)))
{ {
STRLIST_FOREACH (provides, lp, j) STRLIST_FOREACH (provides, lp, j)
if (strcmp (lp, depinfo->service) == 0) if (strcmp (lp, depinfo->service) == 0)
{ {
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
break; break;
} }
rc_strlist_free (provides); rc_strlist_free (provides);
} }
} }
} }
/* We've visited everything we need, so add ourselves unless we /* 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 **rc_get_depends (rc_depinfo_t *deptree,
char **types, char **services, char **types, char **services,
const char *runlevel, int options) const char *runlevel, int options)
{ {
struct lhead sorted; struct lhead sorted;
struct lhead visited; 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, char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
int options) int options)
{ {
char **list = NULL; char **list = NULL;
char **types = 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 we're not the boot runlevel then add that too */
if (strcmp (runlevel, RC_LEVEL_BOOT) != 0) if (strcmp (runlevel, RC_LEVEL_BOOT) != 0)
{ {
char *path = rc_strcatpaths (RC_RUNLEVELDIR, RC_LEVEL_BOOT, char *path = rc_strcatpaths (RC_RUNLEVELDIR, RC_LEVEL_BOOT,
(char *) NULL); (char *) NULL);
list = rc_ls_dir (list, path, RC_LS_INITD); list = rc_ls_dir (list, path, RC_LS_INITD);
free (path); free (path);
} }
} }
/* Now we have our lists, we need to pull in any dependencies /* 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, "iuse");
types = rc_strlist_add (types, "iafter"); types = rc_strlist_add (types, "iafter");
services = rc_get_depends (deptree, types, list, runlevel, 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 (list);
rc_strlist_free (types); rc_strlist_free (types);
@@ -533,13 +533,13 @@ static bool is_newer_than (const char *file, const char *target)
int i; int i;
bool newer = true; bool newer = true;
STRLIST_FOREACH (targets, t, i) STRLIST_FOREACH (targets, t, i)
{ {
char *path = rc_strcatpaths (target, t, (char *) NULL); char *path = rc_strcatpaths (target, t, (char *) NULL);
newer = is_newer_than (file, path); newer = is_newer_than (file, path);
free (path); free (path);
if (! newer) if (! newer)
break; break;
} }
rc_strlist_free (targets); rc_strlist_free (targets);
return (newer); return (newer);
} }
@@ -613,13 +613,13 @@ int rc_update_deptree (bool force)
for (i = 0; depdirs[i]; i++) for (i = 0; depdirs[i]; i++)
if (! rc_is_dir (depdirs[i])) if (! rc_is_dir (depdirs[i]))
if (mkdir (depdirs[i], 0755) != 0) if (mkdir (depdirs[i], 0755) != 0)
eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno)); eerrorx ("mkdir `%s': %s", depdirs[i], strerror (errno));
if (! force) if (! force)
if (is_newer_than (RC_DEPTREE, RC_INITDIR) && if (is_newer_than (RC_DEPTREE, RC_INITDIR) &&
is_newer_than (RC_DEPTREE, RC_CONFDIR) && is_newer_than (RC_DEPTREE, RC_CONFDIR) &&
is_newer_than (RC_DEPTREE, "/etc/rc.conf")) is_newer_than (RC_DEPTREE, "/etc/rc.conf"))
return 0; return 0;
ebegin ("Caching service dependencies"); ebegin ("Caching service dependencies");
@@ -641,79 +641,79 @@ int rc_update_deptree (bool force)
{ {
/* Trim the newline */ /* Trim the newline */
if (buffer[strlen (buffer) - 1] == '\n') if (buffer[strlen (buffer) - 1] == '\n')
buffer[strlen(buffer) -1] = 0; buffer[strlen(buffer) -1] = 0;
depends = buffer; depends = buffer;
service = strsep (&depends, " "); service = strsep (&depends, " ");
if (! service) if (! service)
continue; continue;
type = strsep (&depends, " "); type = strsep (&depends, " ");
for (depinfo = deptree; depinfo; depinfo = depinfo->next) for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{ {
last_depinfo = depinfo; last_depinfo = depinfo;
if (depinfo->service && strcmp (depinfo->service, service) == 0) if (depinfo->service && strcmp (depinfo->service, service) == 0)
break; break;
} }
if (! depinfo) if (! depinfo)
{ {
if (! last_depinfo->service) if (! last_depinfo->service)
depinfo = last_depinfo; depinfo = last_depinfo;
else else
{ {
last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
depinfo = last_depinfo->next; depinfo = last_depinfo->next;
} }
memset (depinfo, 0, sizeof (rc_depinfo_t)); memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = strdup (service); depinfo->service = strdup (service);
} }
/* We may not have any depends */ /* We may not have any depends */
if (! type || ! depends) if (! type || ! depends)
continue; continue;
last_deptype = NULL; last_deptype = NULL;
for (deptype = depinfo->depends; deptype; deptype = deptype->next) for (deptype = depinfo->depends; deptype; deptype = deptype->next)
{ {
last_deptype = deptype; last_deptype = deptype;
if (strcmp (deptype->type, type) == 0) if (strcmp (deptype->type, type) == 0)
break; break;
} }
if (! deptype) if (! deptype)
{ {
if (! last_deptype) if (! last_deptype)
{ {
depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t)); depinfo->depends = rc_xmalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends; deptype = depinfo->depends;
} }
else else
{ {
last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
deptype = last_deptype->next; deptype = last_deptype->next;
} }
memset (deptype, 0, sizeof (rc_deptype_t)); memset (deptype, 0, sizeof (rc_deptype_t));
deptype->type = strdup (type); deptype->type = strdup (type);
} }
/* Now add each depend to our 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, " "))) while ((depend = strsep (&depends, " ")))
{ {
if (depend[0] == 0) if (depend[0] == 0)
continue; continue;
/* .sh files are not init scripts */ /* .sh files are not init scripts */
len = strlen (depend); len = strlen (depend);
if (len > 2 && if (len > 2 &&
depend[len - 3] == '.' && depend[len - 3] == '.' &&
depend[len - 2] == 's' && depend[len - 2] == 's' &&
depend[len - 1] == 'h') depend[len - 1] == 'h')
continue; continue;
deptype->services = rc_strlist_addsort (deptype->services, depend); deptype->services = rc_strlist_addsort (deptype->services, depend);
} }
} }
pclose (fp); pclose (fp);
@@ -722,84 +722,84 @@ int rc_update_deptree (bool force)
for (depinfo = deptree; depinfo; depinfo = depinfo->next) for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{ {
if ((deptype = rc_get_deptype (depinfo, "iprovide"))) if ((deptype = rc_get_deptype (depinfo, "iprovide")))
STRLIST_FOREACH (deptype->services, service, i) STRLIST_FOREACH (deptype->services, service, i)
{ {
for (di = deptree; di; di = di->next) for (di = deptree; di; di = di->next)
{ {
last_depinfo = di; last_depinfo = di;
if (strcmp (di->service, service) == 0) if (strcmp (di->service, service) == 0)
break; break;
} }
if (! di) if (! di)
{ {
last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t)); last_depinfo->next = rc_xmalloc (sizeof (rc_depinfo_t));
di = last_depinfo->next; di = last_depinfo->next;
memset (di, 0, sizeof (rc_depinfo_t)); memset (di, 0, sizeof (rc_depinfo_t));
di->service = strdup (service); di->service = strdup (service);
} }
} }
} }
/* Phase 4 - backreference our depends */ /* Phase 4 - backreference our depends */
for (depinfo = deptree; depinfo; depinfo = depinfo->next) for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{ {
for (i = 0; deppairs[i].depend; i++) for (i = 0; deppairs[i].depend; i++)
{ {
deptype = rc_get_deptype (depinfo, deppairs[i].depend); deptype = rc_get_deptype (depinfo, deppairs[i].depend);
if (! deptype) if (! deptype)
continue; continue;
STRLIST_FOREACH (deptype->services, service, j) STRLIST_FOREACH (deptype->services, service, j)
{ {
di = rc_get_depinfo (deptree, service); di = rc_get_depinfo (deptree, service);
if (! di) if (! di)
{ {
if (strcmp (deptype->type, "ineed") == 0) if (strcmp (deptype->type, "ineed") == 0)
{ {
eerror ("Service `%s' needs non existant service `%s'", eerror ("Service `%s' needs non existant service `%s'",
depinfo->service, service); depinfo->service, service);
retval = -1; retval = -1;
} }
continue; continue;
} }
/* Add our deptype now */ /* Add our deptype now */
last_deptype = NULL; last_deptype = NULL;
for (dt = di->depends; dt; dt = dt->next) for (dt = di->depends; dt; dt = dt->next)
{ {
last_deptype = dt; last_deptype = dt;
if (strcmp (dt->type, deppairs[i].addto) == 0) if (strcmp (dt->type, deppairs[i].addto) == 0)
break; break;
} }
if (! dt) if (! dt)
{ {
if (! last_deptype) if (! last_deptype)
{ {
di->depends = rc_xmalloc (sizeof (rc_deptype_t)); di->depends = rc_xmalloc (sizeof (rc_deptype_t));
dt = di->depends; dt = di->depends;
} }
else else
{ {
last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t)); last_deptype->next = rc_xmalloc (sizeof (rc_deptype_t));
dt = last_deptype->next; dt = last_deptype->next;
} }
memset (dt, 0, sizeof (rc_deptype_t)); memset (dt, 0, sizeof (rc_deptype_t));
dt->type = strdup (deppairs[i].addto); dt->type = strdup (deppairs[i].addto);
} }
already_added = false; already_added = false;
STRLIST_FOREACH (dt->services, service, k) STRLIST_FOREACH (dt->services, service, k)
if (strcmp (service, depinfo->service) == 0) if (strcmp (service, depinfo->service) == 0)
{ {
already_added = true; already_added = true;
break; break;
} }
if (! already_added) if (! already_added)
dt->services = rc_strlist_addsort (dt->services, dt->services = rc_strlist_addsort (dt->services,
depinfo->service); depinfo->service);
} }
} }
} }
/* Phase 5 - save to disk /* Phase 5 - save to disk
@@ -814,20 +814,20 @@ int rc_update_deptree (bool force)
{ {
i = 0; i = 0;
for (depinfo = deptree; depinfo; depinfo = depinfo->next) for (depinfo = deptree; depinfo; depinfo = depinfo->next)
{ {
fprintf (fp, "depinfo_%d_service='%s'\n", i, depinfo->service); fprintf (fp, "depinfo_%d_service='%s'\n", i, depinfo->service);
for (deptype = depinfo->depends; deptype; deptype = deptype->next) for (deptype = depinfo->depends; deptype; deptype = deptype->next)
{ {
k = 0; k = 0;
STRLIST_FOREACH (deptype->services, service, j) STRLIST_FOREACH (deptype->services, service, j)
{ {
fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type, fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type,
k, service); k, service);
k++; k++;
} }
} }
i++; i++;
} }
fclose (fp); fclose (fp);
} }

View File

@@ -133,7 +133,7 @@ char *rc_strcatpaths (const char *path1, const char *paths, ...)
while ((p = va_arg (ap, char *)) != NULL) while ((p = va_arg (ap, char *)) != NULL)
{ {
if (*pathp != '/') if (*pathp != '/')
*pathp++ = '/'; *pathp++ = '/';
i = strlen (p); i = strlen (p);
memcpy (pathp, p, i); memcpy (pathp, p, i);
pathp += i; pathp += i;
@@ -233,25 +233,25 @@ char **rc_ls_dir (char **list, const char *dir, int options)
while (((d = readdir (dp)) != NULL) && errno == 0) while (((d = readdir (dp)) != NULL) && errno == 0)
{ {
if (d->d_name[0] != '.') if (d->d_name[0] != '.')
{ {
if (options & RC_LS_INITD) if (options & RC_LS_INITD)
{ {
int l = strlen (d->d_name); int l = strlen (d->d_name);
char *init = rc_strcatpaths (RC_INITDIR, d->d_name, char *init = rc_strcatpaths (RC_INITDIR, d->d_name,
(char *) NULL); (char *) NULL);
bool ok = rc_exists (init); bool ok = rc_exists (init);
free (init); free (init);
if (! ok) if (! ok)
continue; continue;
/* .sh files are not init scripts */ /* .sh files are not init scripts */
if (l > 2 && d->d_name[l - 3] == '.' && if (l > 2 && d->d_name[l - 3] == '.' &&
d->d_name[l - 2] == 's' && d->d_name[l - 2] == 's' &&
d->d_name[l - 1] == 'h') d->d_name[l - 1] == 'h')
continue; continue;
} }
list = rc_strlist_addsort (list, d->d_name); list = rc_strlist_addsort (list, d->d_name);
} }
} }
closedir (dp); closedir (dp);
@@ -283,29 +283,29 @@ bool rc_rm_dir (const char *pathname, bool top)
while (((d = readdir (dp)) != NULL) && errno == 0) while (((d = readdir (dp)) != NULL) && errno == 0)
{ {
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0) if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
{ {
char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL); char *tmp = rc_strcatpaths (pathname, d->d_name, (char *) NULL);
if (d->d_type == DT_DIR) if (d->d_type == DT_DIR)
{ {
if (! rc_rm_dir (tmp, true)) if (! rc_rm_dir (tmp, true))
{ {
free (tmp); free (tmp);
closedir (dp); closedir (dp);
return (false); return (false);
} }
} }
else else
{ {
if (unlink (tmp)) if (unlink (tmp))
{ {
eerror ("failed to unlink `%s': %s", tmp, strerror (errno)); eerror ("failed to unlink `%s': %s", tmp, strerror (errno));
free (tmp); free (tmp);
closedir (dp); closedir (dp);
return (false); return (false);
} }
} }
free (tmp); free (tmp);
} }
} }
if (errno != 0) if (errno != 0)
eerror ("failed to readdir `%s': %s", pathname, strerror (errno)); 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 */ /* Strip leading spaces/tabs */
while ((*p == ' ') || (*p == '\t')) while ((*p == ' ') || (*p == '\t'))
p++; p++;
if (! p || strlen (p) < 3 || p[0] == '#') if (! p || strlen (p) < 3 || p[0] == '#')
continue; continue;
/* Get entry */ /* Get entry */
token = strsep (&p, "="); token = strsep (&p, "=");
if (! token) if (! token)
continue; continue;
entry = rc_xstrdup (token); entry = rc_xstrdup (token);
do do
{ {
/* Bash variables are usually quoted */ /* Bash variables are usually quoted */
token = strsep (&p, "\"\'"); token = strsep (&p, "\"\'");
} }
while ((token) && (strlen (token) == 0)); while ((token) && (strlen (token) == 0));
/* Drop a newline if that's all we have */ /* Drop a newline if that's all we have */
i = strlen (token) - 1; i = strlen (token) - 1;
if (token[i] == 10) if (token[i] == 10)
token[i] = 0; token[i] = 0;
i = strlen (entry) + strlen (token) + 2; i = strlen (entry) + strlen (token) + 2;
newline = rc_xmalloc (i); newline = rc_xmalloc (i);
@@ -376,29 +376,29 @@ char **rc_get_config (char **list, const char *file)
replaced = false; replaced = false;
/* In shells the last item takes precedence, so we need to remove /* 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) STRLIST_FOREACH (list, line, i)
{ {
char *tmp = rc_xstrdup (line); char *tmp = rc_xstrdup (line);
linep = tmp; linep = tmp;
linetok = strsep (&linep, "="); linetok = strsep (&linep, "=");
if (strcmp (linetok, entry) == 0) if (strcmp (linetok, entry) == 0)
{ {
/* We have a match now - to save time we directly replace it */ /* We have a match now - to save time we directly replace it */
free (list[i - 1]); free (list[i - 1]);
list[i - 1] = newline; list[i - 1] = newline;
replaced = true; replaced = true;
free (tmp); free (tmp);
break; break;
} }
free (tmp); free (tmp);
} }
if (! replaced) if (! replaced)
{ {
list = rc_strlist_addsort (list, newline); list = rc_strlist_addsort (list, newline);
free (newline); free (newline);
} }
free (entry); free (entry);
} }
fclose (fp); fclose (fp);
@@ -416,7 +416,7 @@ char *rc_get_config_entry (char **list, const char *entry)
{ {
p = strchr (line, '='); p = strchr (line, '=');
if (p && strncmp (entry, line, p - line) == 0) if (p && strncmp (entry, line, p - line) == 0)
return (p += 1); return (p += 1);
} }
return (NULL); return (NULL);
@@ -441,18 +441,18 @@ char **rc_get_list (char **list, const char *file)
/* Strip leading spaces/tabs */ /* Strip leading spaces/tabs */
while ((*p == ' ') || (*p == '\t')) while ((*p == ' ') || (*p == '\t'))
p++; p++;
/* Get entry - we do not want comments */ /* Get entry - we do not want comments */
token = strsep (&p, "#"); token = strsep (&p, "#");
if (token && (strlen (token) > 1)) if (token && (strlen (token) > 1))
{ {
/* Stip the newline if present */ /* Stip the newline if present */
if (token[strlen (token) - 1] == '\n') if (token[strlen (token) - 1] == '\n')
token[strlen (token) - 1] = 0; token[strlen (token) - 1] = 0;
list = rc_strlist_add (list, token); list = rc_strlist_add (list, token);
} }
} }
fclose (fp); fclose (fp);
@@ -491,54 +491,54 @@ char **rc_filter_env (void)
{ {
char *space = strchr (env_name, ' '); char *space = strchr (env_name, ' ');
if (space) if (space)
*space = 0; *space = 0;
env_var = getenv (env_name); env_var = getenv (env_name);
if (! env_var && profile) if (! env_var && profile)
{ {
env_len = strlen (env_name) + strlen ("export ") + 1; env_len = strlen (env_name) + strlen ("export ") + 1;
p = rc_xmalloc (sizeof (char *) * env_len); p = rc_xmalloc (sizeof (char *) * env_len);
snprintf (p, env_len, "export %s", env_name); snprintf (p, env_len, "export %s", env_name);
env_var = rc_get_config_entry (profile, p); env_var = rc_get_config_entry (profile, p);
free (p); free (p);
} }
if (! env_var) if (! env_var)
continue; continue;
/* Ensure our PATH is prefixed with the system locations first /* Ensure our PATH is prefixed with the system locations first
for a little extra security */ for a little extra security */
if (strcmp (env_name, "PATH") == 0 && if (strcmp (env_name, "PATH") == 0 &&
strncmp (PATH_PREFIX, env_var, pplen) != 0) strncmp (PATH_PREFIX, env_var, pplen) != 0)
{ {
got_path = true; got_path = true;
env_len = strlen (env_name) + strlen (env_var) + pplen + 2; env_len = strlen (env_name) + strlen (env_var) + pplen + 2;
e = p = rc_xmalloc (sizeof (char *) * env_len); e = p = rc_xmalloc (sizeof (char *) * env_len);
p += snprintf (e, env_len, "%s=%s", env_name, PATH_PREFIX); 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 */ /* Now go through the env var and only add bits not in our PREFIX */
sep = env_var; sep = env_var;
while ((token = strsep (&sep, ":"))) while ((token = strsep (&sep, ":")))
{ {
char *np = strdup (PATH_PREFIX); char *np = strdup (PATH_PREFIX);
char *npp = np; char *npp = np;
char *tok = NULL; char *tok = NULL;
while ((tok = strsep (&npp, ":"))) while ((tok = strsep (&npp, ":")))
if (strcmp (tok, token) == 0) if (strcmp (tok, token) == 0)
break; break;
if (! tok) if (! tok)
p += snprintf (p, env_len - (p - e), ":%s", token); p += snprintf (p, env_len - (p - e), ":%s", token);
free (np); free (np);
} }
*p++ = 0; *p++ = 0;
} }
else else
{ {
env_len = strlen (env_name) + strlen (env_var) + 2; env_len = strlen (env_name) + strlen (env_var) + 2;
e = rc_xmalloc (sizeof (char *) * env_len); e = rc_xmalloc (sizeof (char *) * env_len);
snprintf (e, env_len, "%s=%s", env_name, env_var); snprintf (e, env_len, "%s=%s", env_name, env_var);
} }
env = rc_strlist_add (env, e); env = rc_strlist_add (env, e);
free (e); free (e);
@@ -591,10 +591,10 @@ static bool file_regex (const char *file, const char *regex)
while (fgets (buffer, RC_LINEBUFFER, fp)) while (fgets (buffer, RC_LINEBUFFER, fp))
{ {
if (regexec (&re, buffer, 0, NULL, 0) == 0) if (regexec (&re, buffer, 0, NULL, 0) == 0)
{ {
retval = true; retval = true;
break; break;
} }
} }
fclose (fp); fclose (fp);
regfree (&re); regfree (&re);
@@ -620,23 +620,23 @@ char **rc_config_env (char **env)
{ {
p = strchr (line, '='); p = strchr (line, '=');
if (! p) if (! p)
continue; continue;
*p = 0; *p = 0;
e = getenv (line); e = getenv (line);
if (! e) if (! e)
{ {
*p = '='; *p = '=';
env = rc_strlist_add (env, line); env = rc_strlist_add (env, line);
} }
else else
{ {
int len = strlen (line) + strlen (e) + 2; int len = strlen (line) + strlen (e) + 2;
char *new = rc_xmalloc (sizeof (char *) * len); char *new = rc_xmalloc (sizeof (char *) * len);
snprintf (new, len, "%s=%s", line, e); snprintf (new, len, "%s=%s", line, e);
env = rc_strlist_add (env, new); env = rc_strlist_add (env, new);
free (new); free (new);
} }
} }
rc_strlist_free (config); rc_strlist_free (config);
@@ -666,59 +666,59 @@ char **rc_config_env (char **env)
if (rc_exists (RC_SVCDIR "ksoftlevel")) if (rc_exists (RC_SVCDIR "ksoftlevel"))
{ {
if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r"))) if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel", eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
strerror (errno)); strerror (errno));
else else
{ {
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
if (fgets (buffer, sizeof (buffer), fp)) if (fgets (buffer, sizeof (buffer), fp))
{ {
i = strlen (buffer) - 1; i = strlen (buffer) - 1;
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
i += strlen ("RC_DEFAULTLEVEL=") + 2; i += strlen ("RC_DEFAULTLEVEL=") + 2;
line = rc_xmalloc (sizeof (char *) * i); line = rc_xmalloc (sizeof (char *) * i);
snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer); snprintf (line, i, "RC_DEFAULTLEVEL=%s", buffer);
env = rc_strlist_add (env, line); env = rc_strlist_add (env, line);
free (line); free (line);
} }
fclose (fp); fclose (fp);
} }
} }
else else
env = rc_strlist_add (env, "RC_DEFAULTLEVEL=" RC_LEVEL_DEFAULT); env = rc_strlist_add (env, "RC_DEFAULTLEVEL=" RC_LEVEL_DEFAULT);
memset (sys, 0, sizeof (sys)); memset (sys, 0, sizeof (sys));
/* Linux can run some funky stuff like Xen, VServer, UML, etc /* Linux can run some funky stuff like Xen, VServer, UML, etc
We store this special system in RC_SYS so our scripts run fast */ We store this special system in RC_SYS so our scripts run fast */
#ifdef __linux__ #ifdef __linux__
if (rc_is_dir ("/proc/xen")) if (rc_is_dir ("/proc/xen"))
{ {
fp = fopen ("/proc/xen/capabilities", "r"); fp = fopen ("/proc/xen/capabilities", "r");
if (fp) if (fp)
{ {
fclose (fp); fclose (fp);
if (file_regex ("/proc/xen/capabilities", "control_d")) if (file_regex ("/proc/xen/capabilities", "control_d"))
snprintf (sys, sizeof (sys), "XENU"); snprintf (sys, sizeof (sys), "XENU");
} }
if (! sys) if (! sys)
snprintf (sys, sizeof (sys), "XEN0"); snprintf (sys, sizeof (sys), "XEN0");
} }
else if (file_regex ("/proc/cpuinfo", "UML")) else if (file_regex ("/proc/cpuinfo", "UML"))
snprintf (sys, sizeof (sys), "UML"); snprintf (sys, sizeof (sys), "UML");
else if (file_regex ("/proc/self/status", else if (file_regex ("/proc/self/status",
"(s_context|VxID|envID):[[:space:]]*[1-9]")) "(s_context|VxID|envID):[[:space:]]*[1-9]"))
snprintf (sys, sizeof (sys), "VPS"); snprintf (sys, sizeof (sys), "VPS");
#endif #endif
/* Only add a NET_FS list if not defined */ /* Only add a NET_FS list if not defined */
STRLIST_FOREACH (env, line, i) STRLIST_FOREACH (env, line, i)
if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0) if (strncmp (line, "RC_NET_FS_LIST=", strlen ("RC_NET_FS_LIST=")) == 0)
{ {
has_net_fs_list = true; has_net_fs_list = true;
break; break;
} }
if (! has_net_fs_list) if (! has_net_fs_list)
{ {
i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1; i = strlen ("RC_NET_FS_LIST=") + strlen (RC_NET_FS_LIST_DEFAULT) + 1;

View File

@@ -33,8 +33,8 @@ char **rc_strlist_add (char **list, const char *item)
} }
static char **_rc_strlist_addsort (char **list, const char *item, static char **_rc_strlist_addsort (char **list, const char *item,
int (*sortfunc) (const char *s1, int (*sortfunc) (const char *s1,
const char *s2)) const char *s2))
{ {
char **newlist; char **newlist;
int i = 0; int i = 0;
@@ -90,12 +90,12 @@ char **rc_strlist_delete (char **list, const char *item)
while (list[i]) while (list[i])
if (! strcmp (list[i], item)) if (! strcmp (list[i], item))
{ {
free (list[i]); free (list[i]);
do do
{ {
list[i] = list[i + 1]; list[i] = list[i + 1];
i++; i++;
} while (list[i]); } while (list[i]);
} }
return (list); return (list);

View File

@@ -71,7 +71,7 @@ char **rc_get_runlevels (void)
{ {
char *path = rc_strcatpaths (RC_RUNLEVELDIR, dir, (char *) NULL); char *path = rc_strcatpaths (RC_RUNLEVELDIR, dir, (char *) NULL);
if (rc_is_dir (path)) if (rc_is_dir (path))
runlevels = rc_strlist_addsort (runlevels, dir); runlevels = rc_strlist_addsort (runlevels, dir);
free (path); free (path);
} }
rc_strlist_free (dirs); rc_strlist_free (dirs);
@@ -94,7 +94,7 @@ char *rc_get_runlevel (void)
{ {
int i = strlen (buffer) - 1; int i = strlen (buffer) - 1;
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
fclose (fp); fclose (fp);
return (buffer); return (buffer);
} }
@@ -146,10 +146,10 @@ char *rc_resolve_service (const char *service)
free (file); free (file);
file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "inactive", service, (char *) NULL);
if (! rc_is_link (file)) if (! rc_is_link (file))
{ {
free (file); free (file);
file = NULL; file = NULL;
} }
} }
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
@@ -158,7 +158,7 @@ char *rc_resolve_service (const char *service)
r = readlink (file, buffer, sizeof (buffer)); r = readlink (file, buffer, sizeof (buffer));
free (file); free (file);
if (r > 0) if (r > 0)
return strdup (buffer); return strdup (buffer);
} }
snprintf (buffer, sizeof (buffer), RC_INITDIR "%s", service); 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); return (false);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
(char *) NULL); (char *) NULL);
retval = rc_exists (file); retval = rc_exists (file);
free (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 (state != rc_service_stopped)
{ {
if (! rc_is_file(init)) if (! rc_is_file(init))
{ {
free (init); free (init);
return (false); return (false);
} }
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base, file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
unlink (file); unlink (file);
i = symlink (init, file); i = symlink (init, file);
if (i != 0) if (i != 0)
{ {
free (file); free (file);
free (init); free (init);
einfo ("%d %s %s", state, rc_service_state_names[state], base); einfo ("%d %s %s", state, rc_service_state_names[state], base);
eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno)); eerror ("symlink `%s' to `%s': %s", init, file, strerror (errno));
return (false); return (false);
} }
free (file); free (file);
skip_state = state; 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]) while (rc_service_state_names[i])
{ {
if ((i != skip_state && if ((i != skip_state &&
i != rc_service_stopped && i != rc_service_stopped &&
i != rc_service_coldplugged && i != rc_service_coldplugged &&
i != rc_service_crashed) && i != rc_service_crashed) &&
(! skip_wasinactive || i != rc_service_wasinactive)) (! skip_wasinactive || i != rc_service_wasinactive))
{ {
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base, file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i], base,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
{ {
if ((state == rc_service_starting || if ((state == rc_service_starting ||
state == rc_service_stopping) && state == rc_service_stopping) &&
i == rc_service_inactive) i == rc_service_inactive)
{ {
char *wasfile = rc_strcatpaths (RC_SVCDIR, char *wasfile = rc_strcatpaths (RC_SVCDIR,
rc_service_state_names[rc_service_wasinactive], rc_service_state_names[rc_service_wasinactive],
base, (char *) NULL); base, (char *) NULL);
if (symlink (init, wasfile) != 0) if (symlink (init, wasfile) != 0)
eerror ("symlink `%s' to `%s': %s", init, wasfile, eerror ("symlink `%s' to `%s': %s", init, wasfile,
strerror (errno)); strerror (errno));
skip_wasinactive = true; skip_wasinactive = true;
free (wasfile); free (wasfile);
} }
errno = 0; errno = 0;
if (unlink (file) != 0 && errno != ENOENT) if (unlink (file) != 0 && errno != ENOENT)
eerror ("failed to delete `%s': %s", file, eerror ("failed to delete `%s': %s", file,
strerror (errno)); strerror (errno));
} }
free (file); free (file);
} }
i++; 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); file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
if (unlink (file) != 0) if (unlink (file) != 0)
eerror ("unlink `%s': %s", file, strerror (errno)); eerror ("unlink `%s': %s", file, strerror (errno));
free (file); free (file);
} }
@@ -312,12 +312,12 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL); char *dir = rc_strcatpaths (RC_SVCDIR, "options", base, (char *) NULL);
if (rc_is_dir (dir)) if (rc_is_dir (dir))
rc_rm_dir (dir, true); rc_rm_dir (dir, true);
free (dir); free (dir);
dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL); dir = rc_strcatpaths (RC_SVCDIR, "daemons", base, (char *) NULL);
if (rc_is_dir (dir)) if (rc_is_dir (dir))
rc_rm_dir (dir, true); rc_rm_dir (dir, true);
free (dir); free (dir);
rc_schedule_clear (service); rc_schedule_clear (service);
@@ -332,20 +332,20 @@ bool rc_mark_service (const char *service, const rc_service_state_t state)
int serrno; int serrno;
STRLIST_FOREACH (dirs, dir, i) STRLIST_FOREACH (dirs, dir, i)
{ {
char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL); char *bdir = rc_strcatpaths (sdir, dir, (char *) NULL);
file = rc_strcatpaths (bdir, base, (char *) NULL); file = rc_strcatpaths (bdir, base, (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
if (unlink (file) != 0) if (unlink (file) != 0)
eerror ("unlink `%s': %s", file, strerror (errno)); eerror ("unlink `%s': %s", file, strerror (errno));
free (file); free (file);
/* Try and remove the dir - we don't care about errors */ /* Try and remove the dir - we don't care about errors */
serrno = errno; serrno = errno;
rmdir (bdir); rmdir (bdir);
errno = serrno; errno = serrno;
free (bdir); free (bdir);
} }
rc_strlist_free (dirs); rc_strlist_free (dirs);
free (sdir); 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 */ /* We check stopped state by not being in any of the others */
if (state == rc_service_stopped) if (state == rc_service_stopped)
return ( ! (rc_service_state (service, rc_service_started) || return ( ! (rc_service_state (service, rc_service_started) ||
rc_service_state (service, rc_service_starting) || rc_service_state (service, rc_service_starting) ||
rc_service_state (service, rc_service_stopping) || rc_service_state (service, rc_service_stopping) ||
rc_service_state (service, rc_service_inactive))); rc_service_state (service, rc_service_inactive)));
/* The crashed state and scheduled states are virtual */ /* The crashed state and scheduled states are virtual */
if (state == rc_service_crashed) if (state == rc_service_crashed)
@@ -378,43 +378,43 @@ bool rc_service_state (const char *service, const rc_service_state_t state)
char **services = rc_services_scheduled_by (service); char **services = rc_services_scheduled_by (service);
retval = (services); retval = (services);
if (services) if (services)
free (services); free (services);
return (retval); return (retval);
} }
/* Now we just check if a file by the service name rc_exists /* Now we just check if a file by the service name rc_exists
in the state dir */ in the state dir */
file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state],
basename (service), (char*) NULL); basename (service), (char*) NULL);
retval = rc_exists (file); retval = rc_exists (file);
free (file); free (file);
return (retval); return (retval);
} }
bool rc_get_service_option (const char *service, const char *option, bool rc_get_service_option (const char *service, const char *option,
char *value) char *value)
{ {
FILE *fp; FILE *fp;
char buffer[RC_LINEBUFFER]; char buffer[RC_LINEBUFFER];
char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option, char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option,
(char *) NULL); (char *) NULL);
bool retval = false; bool retval = false;
if (rc_exists (file)) if (rc_exists (file))
{ {
if ((fp = fopen (file, "r")) == NULL) if ((fp = fopen (file, "r")) == NULL)
eerror ("fopen `%s': %s", file, strerror (errno)); eerror ("fopen `%s': %s", file, strerror (errno));
else else
{ {
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
while (fgets (buffer, RC_LINEBUFFER, fp)) while (fgets (buffer, RC_LINEBUFFER, fp))
{ {
memcpy (value, buffer, strlen (buffer)); memcpy (value, buffer, strlen (buffer));
value += strlen (buffer); value += strlen (buffer);
} }
fclose (fp); fclose (fp);
retval = true; retval = true;
} }
} }
free (file); 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, bool rc_set_service_option (const char *service, const char *option,
const char *value) const char *value)
{ {
FILE *fp; FILE *fp;
char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL); char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL);
@@ -432,12 +432,12 @@ bool rc_set_service_option (const char *service, const char *option,
if (! rc_is_dir (path)) if (! rc_is_dir (path))
{ {
if (mkdir (path, 0755) != 0) if (mkdir (path, 0755) != 0)
{ {
eerror ("mkdir `%s': %s", path, strerror (errno)); eerror ("mkdir `%s': %s", path, strerror (errno));
free (path); free (path);
free (file); free (file);
return (false); return (false);
} }
} }
if ((fp = fopen (file, "w")) == NULL) if ((fp = fopen (file, "w")) == NULL)
@@ -445,7 +445,7 @@ bool rc_set_service_option (const char *service, const char *option,
else else
{ {
if (value) if (value)
fprintf (fp, "%s", value); fprintf (fp, "%s", value);
fclose (fp); fclose (fp);
retval = true; 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 */ /* We create a fifo so that other services can wait until we complete */
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service), fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service),
(char *) NULL); (char *) NULL);
if (mkfifo (fifo, 0600) != 0 && errno != EEXIST) 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); pid = waitpid (savedpid, &status, 0);
if (pid < 0) if (pid < 0)
{ {
if (errno != ECHILD) if (errno != ECHILD)
eerror ("waitpid %d: %s", savedpid, strerror (errno)); eerror ("waitpid %d: %s", savedpid, strerror (errno));
return (-1); return (-1);
} }
} while (! WIFEXITED (status) && ! WIFSIGNALED (status)); } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
return (0); return (0);
@@ -541,7 +541,7 @@ pid_t rc_start_service (const char *service)
} }
void rc_schedule_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 *dir;
char *init; char *init;
@@ -551,13 +551,13 @@ void rc_schedule_start_service (const char *service,
return; return;
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service), dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
(char *) NULL); (char *) NULL);
if (! rc_is_dir (dir)) if (! rc_is_dir (dir))
if (mkdir (dir, 0755) != 0) if (mkdir (dir, 0755) != 0)
{ {
eerror ("mkdir `%s': %s", dir, strerror (errno)); eerror ("mkdir `%s': %s", dir, strerror (errno));
free (dir); free (dir);
return; return;
} }
init = rc_resolve_service (service_to_start); 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) void rc_schedule_clear (const char *service)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service), char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
(char *) NULL); (char *) NULL);
if (rc_is_dir (dir)) if (rc_is_dir (dir))
rc_rm_dir (dir, true); rc_rm_dir (dir, true);
@@ -583,7 +583,7 @@ void rc_schedule_clear (const char *service)
bool rc_wait_service (const char *service) bool rc_wait_service (const char *service)
{ {
char *fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service), char *fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename (service),
(char *) NULL); (char *) NULL);
struct timeval tv; struct timeval tv;
struct timeval stopat; struct timeval stopat;
struct timeval now; struct timeval now;
@@ -599,28 +599,28 @@ bool rc_wait_service (const char *service)
while (true) while (true)
{ {
if (! rc_exists (fifo)) if (! rc_exists (fifo))
{ {
retval = true; retval = true;
break; break;
} }
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = WAIT_INTERVAL; tv.tv_usec = WAIT_INTERVAL;
if (select (0, 0, 0, 0, &tv) < 0) if (select (0, 0, 0, 0, &tv) < 0)
{ {
if (errno != EINTR) if (errno != EINTR)
eerror ("select: %s",strerror (errno)); eerror ("select: %s",strerror (errno));
break; break;
} }
/* Don't hang around forever */ /* Don't hang around forever */
if (gettimeofday (&now, NULL) != 0) if (gettimeofday (&now, NULL) != 0)
{ {
eerror ("gettimeofday: %s", strerror (errno)); eerror ("gettimeofday: %s", strerror (errno));
break; break;
} }
if (timercmp (&now, &stopat, >)) if (timercmp (&now, &stopat, >))
break; break;
} }
free (fifo); free (fifo);
@@ -642,7 +642,7 @@ char **rc_services_in_runlevel (const char *runlevel)
dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL);
if (! rc_is_dir (dir)) if (! rc_is_dir (dir))
eerror ("runlevel `%s' does not exist", runlevel); eerror ("runlevel `%s' does not exist", runlevel);
else else
list = rc_ls_dir (list, dir, RC_LS_INITD); 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 **rc_services_in_state (rc_service_state_t state)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state], char *dir = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[state],
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
if (rc_is_dir (dir)) if (rc_is_dir (dir))
@@ -683,7 +683,7 @@ bool rc_service_add (const char *runlevel, const char *service)
init = rc_resolve_service (service); init = rc_resolve_service (service);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
(char *) NULL); (char *) NULL);
retval = (symlink (init, file) == 0); retval = (symlink (init, file) == 0);
free (init); free (init);
free (file); free (file);
@@ -699,7 +699,7 @@ bool rc_service_delete (const char *runlevel, const char *service)
return (false); return (false);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename (service),
(char *) NULL); (char *) NULL);
if (unlink (file) == 0) if (unlink (file) == 0)
retval = true; retval = true;
@@ -717,9 +717,9 @@ char **rc_services_scheduled_by (const char *service)
STRLIST_FOREACH (dirs, dir, i) STRLIST_FOREACH (dirs, dir, i)
{ {
char *file = rc_strcatpaths (RC_SVCDIR "scheduled", dir, service, char *file = rc_strcatpaths (RC_SVCDIR "scheduled", dir, service,
(char *) NULL); (char *) NULL);
if (rc_exists (file)) if (rc_exists (file))
list = rc_strlist_add (list, file); list = rc_strlist_add (list, file);
free (file); free (file);
} }
rc_strlist_free (dirs); rc_strlist_free (dirs);
@@ -730,7 +730,7 @@ char **rc_services_scheduled_by (const char *service)
char **rc_services_scheduled (const char *service) char **rc_services_scheduled (const char *service)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service), char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename (service),
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
if (rc_is_dir (dir)) if (rc_is_dir (dir))
@@ -757,28 +757,28 @@ bool rc_allow_plug (char *service)
{ {
bool truefalse = true; bool truefalse = true;
if (token[0] == '!') if (token[0] == '!')
{ {
truefalse = false; truefalse = false;
token++; token++;
} }
star = strchr (token, '*'); star = strchr (token, '*');
if (star) if (star)
{ {
if (strncmp (service, token, star - token) == 0) if (strncmp (service, token, star - token) == 0)
{ {
allow = truefalse; allow = truefalse;
break; break;
} }
} }
else else
{ {
if (strcmp (service, token) == 0) if (strcmp (service, token) == 0)
{ {
allow = truefalse; allow = truefalse;
break; break;
} }
} }
} }
free (list); free (list);

View File

@@ -28,7 +28,7 @@
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__)
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, 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; struct statfs *mnts;
int nmnts; int nmnts;
@@ -36,36 +36,36 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
char **list = NULL; char **list = NULL;
if ((nmnts = getmntinfo (&mnts, MNT_NOWAIT)) == 0) if ((nmnts = getmntinfo (&mnts, MNT_NOWAIT)) == 0)
eerrorx ("getmntinfo: %s", strerror (errno)); eerrorx ("getmntinfo: %s", strerror (errno));
for (i = 0; i < nmnts; i++) for (i = 0; i < nmnts; i++)
{ {
if (node_regex && if (node_regex &&
regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0) regexec (node_regex, mnts[i].f_mntfromname, 0, NULL, 0) != 0)
continue; continue;
if (fstype_regex && if (fstype_regex &&
regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0) regexec (fstype_regex, mnts[i].f_fstypename, 0, NULL, 0) != 0)
continue; continue;
if (mounts) if (mounts)
{ {
bool found = false; bool found = false;
int j; int j;
char *mnt; char *mnt;
STRLIST_FOREACH (mounts, mnt, j) STRLIST_FOREACH (mounts, mnt, j)
if (strcmp (mnt, mnts[i].f_mntonname) == 0) if (strcmp (mnt, mnts[i].f_mntonname) == 0)
{ {
found = true; found = true;
break; break;
} }
if (! found) if (! found)
continue; continue;
} }
list = rc_strlist_addsortc (list, list_nodes ? list = rc_strlist_addsortc (list, list_nodes ?
mnts[i].f_mntfromname : mnts[i].f_mntfromname :
list_fstype ? mnts[i].f_fstypename : list_fstype ? mnts[i].f_fstypename :
mnts[i].f_mntonname); mnts[i].f_mntonname);
} }
return (list); return (list);
@@ -73,7 +73,7 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
#elif defined (__linux__) #elif defined (__linux__)
static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, 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; FILE *fp;
char buffer[PATH_MAX * 3]; char buffer[PATH_MAX * 3];
@@ -84,44 +84,44 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex,
char **list = NULL; char **list = NULL;
if ((fp = fopen ("/proc/mounts", "r")) == NULL) if ((fp = fopen ("/proc/mounts", "r")) == NULL)
eerrorx ("getmntinfo: %s", strerror (errno)); eerrorx ("getmntinfo: %s", strerror (errno));
while (fgets (buffer, sizeof (buffer), fp)) while (fgets (buffer, sizeof (buffer), fp))
{ {
p = buffer; p = buffer;
from = strsep (&p, " "); from = strsep (&p, " ");
if (node_regex && if (node_regex &&
regexec (node_regex, from, 0, NULL, 0) != 0) regexec (node_regex, from, 0, NULL, 0) != 0)
continue; continue;
to = strsep (&p, " "); to = strsep (&p, " ");
fstype = strsep (&p, " "); fstype = strsep (&p, " ");
/* Skip the really silly rootfs */ /* Skip the really silly rootfs */
if (strcmp (fstype, "rootfs") == 0) if (strcmp (fstype, "rootfs") == 0)
continue; continue;
if (fstype_regex && if (fstype_regex &&
regexec (fstype_regex, fstype, 0, NULL, 0) != 0) regexec (fstype_regex, fstype, 0, NULL, 0) != 0)
continue; continue;
if (mounts) if (mounts)
{ {
bool found = false; bool found = false;
int j; int j;
char *mnt; char *mnt;
STRLIST_FOREACH (mounts, mnt, j) STRLIST_FOREACH (mounts, mnt, j)
if (strcmp (mnt, to) == 0) if (strcmp (mnt, to) == 0)
{ {
found = true; found = true;
break; break;
} }
if (! found) if (! found)
continue; continue;
} }
list = rc_strlist_addsortc (list, list = rc_strlist_addsortc (list,
list_nodes ? list_nodes ?
list_fstype ? fstype : list_fstype ? fstype :
from : to); from : to);
} }
fclose (fp); fclose (fp);
@@ -150,75 +150,75 @@ int main (int argc, char **argv)
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (strcmp (argv[i], "--fstype-regex") == 0 && (i + 1 < argc)) if (strcmp (argv[i], "--fstype-regex") == 0 && (i + 1 < argc))
{ {
i++; i++;
if (fstype_regex) if (fstype_regex)
free (fstype_regex); free (fstype_regex);
fstype_regex = rc_xmalloc (sizeof (regex_t)); fstype_regex = rc_xmalloc (sizeof (regex_t));
if ((result = regcomp (fstype_regex, argv[i], if ((result = regcomp (fstype_regex, argv[i],
REG_EXTENDED | REG_NOSUB)) != 0) REG_EXTENDED | REG_NOSUB)) != 0)
{ {
regerror (result, fstype_regex, buffer, sizeof (buffer)); regerror (result, fstype_regex, buffer, sizeof (buffer));
eerrorx ("%s: invalid regex `%s'", argv[0], buffer); eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
} }
continue; continue;
} }
if (strcmp (argv[i], "--node-regex") == 0 && (i + 1 < argc)) if (strcmp (argv[i], "--node-regex") == 0 && (i + 1 < argc))
{ {
i++; i++;
if (node_regex) if (node_regex)
free (node_regex); free (node_regex);
node_regex = rc_xmalloc (sizeof (regex_t)); node_regex = rc_xmalloc (sizeof (regex_t));
if ((result = regcomp (node_regex, argv[i], if ((result = regcomp (node_regex, argv[i],
REG_EXTENDED | REG_NOSUB)) != 0) REG_EXTENDED | REG_NOSUB)) != 0)
{ {
regerror (result, node_regex, buffer, sizeof (buffer)); regerror (result, node_regex, buffer, sizeof (buffer));
eerrorx ("%s: invalid regex `%s'", argv[0], buffer); eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
} }
continue; continue;
} }
if (strcmp (argv[i], "--skip-regex") == 0 && (i + 1 < argc)) if (strcmp (argv[i], "--skip-regex") == 0 && (i + 1 < argc))
{ {
i++; i++;
if (skip_regex) if (skip_regex)
free (skip_regex); free (skip_regex);
skip_regex = rc_xmalloc (sizeof (regex_t)); skip_regex = rc_xmalloc (sizeof (regex_t));
if ((result = regcomp (skip_regex, argv[i], if ((result = regcomp (skip_regex, argv[i],
REG_EXTENDED | REG_NOSUB)) != 0) REG_EXTENDED | REG_NOSUB)) != 0)
{ {
regerror (result, skip_regex, buffer, sizeof (buffer)); regerror (result, skip_regex, buffer, sizeof (buffer));
eerrorx ("%s: invalid regex `%s'", argv[0], buffer); eerrorx ("%s: invalid regex `%s'", argv[0], buffer);
} }
continue; continue;
} }
if (strcmp (argv[i], "--fstype") == 0) if (strcmp (argv[i], "--fstype") == 0)
{ {
list_fstype = true; list_fstype = true;
continue; continue;
} }
if (strcmp (argv[i], "--node") == 0) if (strcmp (argv[i], "--node") == 0)
{ {
list_nodes = true; list_nodes = true;
continue; continue;
} }
if (strcmp (argv[i], "--reverse") == 0) if (strcmp (argv[i], "--reverse") == 0)
{ {
reverse = true; reverse = true;
continue; continue;
} }
if (argv[i][0] != '/') 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]); mounts = rc_strlist_add (mounts, argv[i]);
} }
nodes = find_mounts (node_regex, fstype_regex, mounts, nodes = find_mounts (node_regex, fstype_regex, mounts,
list_nodes, list_fstype); list_nodes, list_fstype);
if (node_regex) if (node_regex)
regfree (node_regex); regfree (node_regex);
@@ -232,7 +232,7 @@ int main (int argc, char **argv)
STRLIST_FOREACH (nodes, node, i) STRLIST_FOREACH (nodes, node, i)
{ {
if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0) if (skip_regex && regexec (skip_regex, node, 0, NULL, 0) == 0)
continue; continue;
printf ("%s\n", node); printf ("%s\n", node);
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
} }

View File

@@ -38,43 +38,43 @@ int main (int argc, char **argv)
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (strcmp (argv[i], "--update") == 0) if (strcmp (argv[i], "--update") == 0)
{ {
if (! update) if (! update)
{ {
rc_update_deptree (true); rc_update_deptree (true);
update = true; update = true;
} }
continue; continue;
} }
if (strcmp (argv[i], "--strict") == 0) if (strcmp (argv[i], "--strict") == 0)
{ {
options |= RC_DEP_STRICT; options |= RC_DEP_STRICT;
continue; continue;
} }
if (strcmp (argv[i], "--notrace") == 0) if (strcmp (argv[i], "--notrace") == 0)
{ {
options &= RC_DEP_TRACE; options &= RC_DEP_TRACE;
continue; continue;
} }
if (argv[i][0] == '-') if (argv[i][0] == '-')
{ {
argv[i]++; argv[i]++;
types = rc_strlist_add (types, argv[i]); types = rc_strlist_add (types, argv[i]);
} }
else else
{ {
if ((deptree = rc_load_deptree ()) == NULL) if ((deptree = rc_load_deptree ()) == NULL)
eerrorx ("failed to load deptree"); eerrorx ("failed to load deptree");
di = rc_get_depinfo (deptree, argv[i]); di = rc_get_depinfo (deptree, argv[i]);
if (! di) if (! di)
eerror ("no dependency info for service `%s'", argv[i]); eerror ("no dependency info for service `%s'", argv[i]);
else else
services = rc_strlist_add (services, argv[i]); services = rc_strlist_add (services, argv[i]);
} }
} }
if (! services) if (! services)
@@ -82,7 +82,7 @@ int main (int argc, char **argv)
rc_strlist_free (types); rc_strlist_free (types);
rc_free_deptree (deptree); rc_free_deptree (deptree);
if (update) if (update)
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
eerrorx ("no services specified"); eerrorx ("no services specified");
} }
@@ -98,16 +98,16 @@ int main (int argc, char **argv)
if (depends) if (depends)
{ {
STRLIST_FOREACH (depends, service, i) STRLIST_FOREACH (depends, service, i)
{ {
if (first) if (first)
first = false; first = false;
else else
printf (" "); printf (" ");
if (service) if (service)
printf ("%s", service); printf ("%s", service);
} }
printf ("\n"); printf ("\n");
} }

View File

@@ -50,11 +50,11 @@ void rc_plugin_load (void)
int len; int len;
if (! h) if (! h)
{ {
eerror ("dlopen `%s': %s", p, dlerror ()); eerror ("dlopen `%s': %s", p, dlerror ());
free (p); free (p);
continue; continue;
} }
func = file; func = file;
file = strsep (&func, "."); file = strsep (&func, ".");
@@ -64,25 +64,25 @@ void rc_plugin_load (void)
f = dlsym (h, func); f = dlsym (h, func);
if (! f) if (! f)
{ {
eerror ("`%s' does not expose the symbol `%s'", p, func); eerror ("`%s' does not expose the symbol `%s'", p, func);
dlclose (h); dlclose (h);
} }
else else
{ {
if (plugin) if (plugin)
{ {
plugin->next = rc_xmalloc (sizeof (plugin_t)); plugin->next = rc_xmalloc (sizeof (plugin_t));
plugin = plugin->next; plugin = plugin->next;
} }
else else
plugin = plugins = rc_xmalloc (sizeof (plugin_t)); plugin = plugins = rc_xmalloc (sizeof (plugin_t));
memset (plugin, 0, sizeof (plugin_t)); memset (plugin, 0, sizeof (plugin_t));
plugin->name = strdup (file); plugin->name = strdup (file);
plugin->handle = h; plugin->handle = h;
plugin->hook = f; plugin->hook = f;
} }
free (func); free (func);
free (p); free (p);
@@ -98,7 +98,7 @@ void rc_plugin_run (rc_hook_t hook, const char *value)
while (plugin) while (plugin)
{ {
if (plugin->hook) if (plugin->hook)
plugin->hook (hook, value); plugin->hook (hook, value);
plugin = plugin->next; plugin = plugin->next;
} }

View File

@@ -72,53 +72,53 @@ int main (int argc, char **argv)
const struct option longopts[] = const struct option longopts[] =
{ {
{"all", no_argument, NULL, 'a'}, {"all", no_argument, NULL, 'a'},
{"list", no_argument, NULL, 'l'}, {"list", no_argument, NULL, 'l'},
{"servicelist", no_argument, NULL, 's'}, {"servicelist", no_argument, NULL, 's'},
{"unused", no_argument, NULL, 'u'}, {"unused", no_argument, NULL, 'u'},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
while ((c = getopt_long(argc, argv, "alsu", longopts, &option_index)) != -1) while ((c = getopt_long(argc, argv, "alsu", longopts, &option_index)) != -1)
switch (c) switch (c)
{ {
case 'a': case 'a':
levels = rc_get_runlevels (); levels = rc_get_runlevels ();
break; break;
case 'l': case 'l':
levels = rc_get_runlevels (); levels = rc_get_runlevels ();
STRLIST_FOREACH (levels, level, i) STRLIST_FOREACH (levels, level, i)
printf ("%s\n", level); printf ("%s\n", level);
rc_strlist_free (levels); rc_strlist_free (levels);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
case 's': case 's':
services = rc_services_in_runlevel (NULL); services = rc_services_in_runlevel (NULL);
STRLIST_FOREACH (services, service, i) STRLIST_FOREACH (services, service, i)
print_service (service); print_service (service);
rc_strlist_free (services); rc_strlist_free (services);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
case 'u': case 'u':
services = rc_services_in_runlevel (NULL); services = rc_services_in_runlevel (NULL);
levels = rc_get_runlevels (); levels = rc_get_runlevels ();
STRLIST_FOREACH (services, service, i) STRLIST_FOREACH (services, service, i)
{ {
bool found = false; bool found = false;
STRLIST_FOREACH (levels, level, j) STRLIST_FOREACH (levels, level, j)
if (rc_service_in_runlevel (service, level)) if (rc_service_in_runlevel (service, level))
{ {
found = true; found = true;
break; break;
} }
if (! found) if (! found)
print_service (service); print_service (service);
} }
rc_strlist_free (levels); rc_strlist_free (levels);
rc_strlist_free (services); rc_strlist_free (services);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
case '?': case '?':
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
default: default:
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
while (optind < argc) while (optind < argc)

View File

@@ -32,16 +32,16 @@ static bool add (const char *runlevel, const char *service)
if (rc_service_in_runlevel (service, runlevel)) if (rc_service_in_runlevel (service, runlevel))
{ {
ewarn ("%s already installed in runlevel `%s'; skipping", ewarn ("%s already installed in runlevel `%s'; skipping",
service, runlevel); service, runlevel);
return (false); return (false);
} }
if (rc_service_add (runlevel, service)) if (rc_service_add (runlevel, service))
einfo ("%s added to runlevel %s", service, runlevel); einfo ("%s added to runlevel %s", service, runlevel);
else else
{ {
eerror ("%s: failed to add service `%s' to runlevel `%s': %s", eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
applet, service, runlevel, strerror (errno)); applet, service, runlevel, strerror (errno));
retval = false; retval = false;
} }
@@ -65,53 +65,53 @@ int main (int argc, char **argv)
char **services = rc_services_in_runlevel (NULL); char **services = rc_services_in_runlevel (NULL);
for (i = 2; i < argc; i++) for (i = 2; i < argc; i++)
{ {
if (strcmp (argv[i], "--verbose") == 0 || if (strcmp (argv[i], "--verbose") == 0 ||
strcmp (argv[i], "-v") == 0) strcmp (argv[i], "-v") == 0)
verbose = true; verbose = true;
else else
runlevels = rc_strlist_add (runlevels, argv[i]); runlevels = rc_strlist_add (runlevels, argv[i]);
} }
if (! runlevels) if (! runlevels)
runlevels = rc_get_runlevels (); runlevels = rc_get_runlevels ();
STRLIST_FOREACH (services, service, i) STRLIST_FOREACH (services, service, i)
{ {
char **in = NULL; char **in = NULL;
bool inone = false; bool inone = false;
STRLIST_FOREACH (runlevels, runlevel, j) STRLIST_FOREACH (runlevels, runlevel, j)
{ {
if (rc_service_in_runlevel (service, runlevel)) if (rc_service_in_runlevel (service, runlevel))
{ {
in = rc_strlist_add (in, runlevel); in = rc_strlist_add (in, runlevel);
inone = true; inone = true;
} }
else else
{ {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
memset (buffer, ' ', strlen (runlevel)); memset (buffer, ' ', strlen (runlevel));
buffer[strlen (runlevel)] = 0; buffer[strlen (runlevel)] = 0;
in = rc_strlist_add (in, buffer); in = rc_strlist_add (in, buffer);
} }
} }
if (! inone && ! verbose) if (! inone && ! verbose)
continue; continue;
printf (" %20s |", service); printf (" %20s |", service);
STRLIST_FOREACH (in, runlevel, j) STRLIST_FOREACH (in, runlevel, j)
printf (" %s", runlevel); printf (" %s", runlevel);
printf ("\n"); printf ("\n");
} }
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
} }
if (geteuid () != 0) if (geteuid () != 0)
eerrorx ("%s: must be root to add or delete services from runlevels", eerrorx ("%s: must be root to add or delete services from runlevels",
applet); applet);
if (! (service = argv[2])) if (! (service = argv[2]))
eerrorx ("%s: no service specified", applet); eerrorx ("%s: no service specified", applet);
@@ -120,15 +120,15 @@ int main (int argc, char **argv)
strcmp (argv[1], "-a") == 0) strcmp (argv[1], "-a") == 0)
{ {
if (! service) if (! service)
eerrorx ("%s: no service specified", applet); eerrorx ("%s: no service specified", applet);
if (! rc_service_exists (service)) 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) if (argc < 4)
add (rc_get_runlevel (), service); add (rc_get_runlevel (), service);
for (i = 3; i < argc; i++) for (i = 3; i < argc; i++)
add (argv[i], service); add (argv[i], service);
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
} }
@@ -138,22 +138,22 @@ int main (int argc, char **argv)
strcmp (argv[1], "-d") == 0) strcmp (argv[1], "-d") == 0)
{ {
for (i = 3; i < argc; i++) for (i = 3; i < argc; i++)
runlevels = rc_strlist_add (runlevels, argv[i]); runlevels = rc_strlist_add (runlevels, argv[i]);
if (! runlevels) if (! runlevels)
runlevels = rc_strlist_add (runlevels, rc_get_runlevel ()); runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
STRLIST_FOREACH (runlevels, runlevel, i) STRLIST_FOREACH (runlevels, runlevel, i)
{ {
if (rc_service_in_runlevel (service, runlevel)) if (rc_service_in_runlevel (service, runlevel))
{ {
if (rc_service_delete (runlevel, service)) if (rc_service_delete (runlevel, service))
einfo ("%s removed from runlevel %s", service, runlevel); einfo ("%s removed from runlevel %s", service, runlevel);
else else
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s", eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
applet, service, runlevel, strerror (errno)); applet, service, runlevel, strerror (errno));
} }
} }
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
} }

736
src/rc.c
View File

@@ -123,36 +123,36 @@ static int do_e (int argc, char **argv)
strcmp (applet, "vweend") == 0) strcmp (applet, "vweend") == 0)
{ {
if (argc > 0) if (argc > 0)
{ {
errno = 0; errno = 0;
retval = strtol (argv[0], NULL, 0); retval = strtol (argv[0], NULL, 0);
if (errno != 0) if (errno != 0)
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
else else
{ {
argc--; argc--;
argv++; argv++;
} }
} }
else else
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} }
if (argc > 0) if (argc > 0)
{ {
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
l += strlen (argv[i]) + 1; l += strlen (argv[i]) + 1;
message = rc_xmalloc (l); message = rc_xmalloc (l);
p = message; p = message;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
if (i > 0) if (i > 0)
*p++ = ' '; *p++ = ' ';
memcpy (p, argv[i], strlen (argv[i])); memcpy (p, argv[i], strlen (argv[i]));
p += strlen (argv[i]); p += strlen (argv[i]);
} }
*p = 0; *p = 0;
} }
@@ -245,9 +245,9 @@ static int do_service (int argc, char **argv)
{ {
int idx = 0; int idx = 0;
if (argc > 2) if (argc > 2)
sscanf (argv[2], "%d", &idx); sscanf (argv[2], "%d", &idx);
exit (rc_service_started_daemon (argv[0], argv[1], idx) exit (rc_service_started_daemon (argv[0], argv[1], idx)
? 0 : 1); ? 0 : 1);
} }
else else
eerrorx ("%s: unknown applet", applet); eerrorx ("%s: unknown applet", applet);
@@ -288,21 +288,21 @@ static int do_mark_service (int argc, char **argv)
int l; int l;
if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1) if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1)
if (kill (pid, SIGHUP) != 0) if (kill (pid, SIGHUP) != 0)
eerror ("%s: failed to signal parent %d: %s", eerror ("%s: failed to signal parent %d: %s",
applet, pid, strerror (errno)); applet, pid, strerror (errno));
/* Remove the exclsive time test. This ensures that it's not /* Remove the exclsive time test. This ensures that it's not
in control as well */ in control as well */
l = strlen (RC_SVCDIR "exclusive") + l = strlen (RC_SVCDIR "exclusive") +
strlen (svcname) + strlen (svcname) +
strlen (runscript_pid) + strlen (runscript_pid) +
4; 4;
mtime = rc_xmalloc (l); mtime = rc_xmalloc (l);
snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
svcname, runscript_pid); svcname, runscript_pid);
if (rc_exists (mtime) && unlink (mtime) != 0) if (rc_exists (mtime) && unlink (mtime) != 0)
eerror ("%s: unlink: %s", applet, strerror (errno)); eerror ("%s: unlink: %s", applet, strerror (errno));
free (mtime); free (mtime);
} }
@@ -326,7 +326,7 @@ static int do_options (int argc, char **argv)
memset (buffer, 0, 1024); memset (buffer, 0, 1024);
ok = rc_get_service_option (service, argv[0], buffer); ok = rc_get_service_option (service, argv[0], buffer);
if (ok) if (ok)
printf ("%s", buffer); printf ("%s", buffer);
} }
else if (strcmp (applet, "save_options") == 0) else if (strcmp (applet, "save_options") == 0)
ok = rc_set_service_option (service, argv[0], argv[1]); ok = rc_set_service_option (service, argv[0], argv[1]);
@@ -392,15 +392,15 @@ static void sulogin (bool cont)
pid_t pid = fork(); pid_t pid = fork();
if (pid == -1) if (pid == -1)
eerrorx ("%s: fork: %s", applet, strerror (errno)); eerrorx ("%s: fork: %s", applet, strerror (errno));
if (pid == 0) if (pid == 0)
{ {
newenv = rc_filter_env (); newenv = rc_filter_env ();
mycmd = rc_xstrdup ("/sbin/sulogin"); mycmd = rc_xstrdup ("/sbin/sulogin");
myarg = rc_xstrdup (getenv ("CONSOLE")); myarg = rc_xstrdup (getenv ("CONSOLE"));
execle (mycmd, mycmd, myarg, (char *) NULL, newenv); execle (mycmd, mycmd, myarg, (char *) NULL, newenv);
eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno)); eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno));
} }
waitpid (pid, &status, 0); waitpid (pid, &status, 0);
} }
else else
@@ -429,8 +429,8 @@ static void set_ksoftlevel (const char *runlevel)
strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) strcmp (runlevel, RC_LEVEL_SYSINIT) == 0)
{ {
if (rc_exists (RC_SVCDIR "ksoftlevel") && if (rc_exists (RC_SVCDIR "ksoftlevel") &&
unlink (RC_SVCDIR "ksoftlevel") != 0) unlink (RC_SVCDIR "ksoftlevel") != 0)
eerror ("unlink `%s': %s", RC_SVCDIR "ksoftlevel", strerror (errno)); eerror ("unlink `%s': %s", RC_SVCDIR "ksoftlevel", strerror (errno));
return; return;
} }
@@ -465,13 +465,13 @@ static void handle_signal (int sig)
{ {
case SIGINT: case SIGINT:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGINT"); snprintf (signame, sizeof (signame), "SIGINT");
case SIGTERM: case SIGTERM:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGTERM"); snprintf (signame, sizeof (signame), "SIGTERM");
case SIGQUIT: case SIGQUIT:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGQUIT"); snprintf (signame, sizeof (signame), "SIGQUIT");
eerrorx ("%s: caught %s, aborting", applet, signame); eerrorx ("%s: caught %s, aborting", applet, signame);
default: default:
@@ -554,28 +554,28 @@ int main (int argc, char **argv)
#ifdef __linux__ #ifdef __linux__
/* clearenv isn't portable, but there's no harm in using it /* clearenv isn't portable, but there's no harm in using it
if we have it */ if we have it */
clearenv (); clearenv ();
#else #else
char *var; char *var;
/* No clearenv present here then. /* No clearenv present here then.
We could manipulate environ directly ourselves, but it seems that We could manipulate environ directly ourselves, but it seems that
some kernels bitch about this according to the environ man pages some kernels bitch about this according to the environ man pages
so we walk though environ and call unsetenv for each value. */ so we walk though environ and call unsetenv for each value. */
while (environ[0]) while (environ[0])
{ {
tmp = rc_xstrdup (environ[0]); tmp = rc_xstrdup (environ[0]);
p = tmp; p = tmp;
var = strsep (&p, "="); var = strsep (&p, "=");
unsetenv (var); unsetenv (var);
free (tmp); free (tmp);
} }
tmp = NULL; tmp = NULL;
#endif #endif
STRLIST_FOREACH (env, p, i) STRLIST_FOREACH (env, p, i)
if (strcmp (p, "RC_SOFTLEVEL") != 0 && strcmp (p, "SOFTLEVEL") != 0) 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 */ /* 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 (RUNLEVEL && newlevel)
{ {
if (strcmp (RUNLEVEL, "S") == 0 || strcmp (RUNLEVEL, "1") == 0) if (strcmp (RUNLEVEL, "S") == 0 || strcmp (RUNLEVEL, "1") == 0)
{ {
/* OK, we're either in runlevel 1 or single user mode */ /* OK, we're either in runlevel 1 or single user mode */
if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0) if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0)
{ {
struct utsname uts; struct utsname uts;
pid_t pid; pid_t pid;
pid_t wpid; pid_t wpid;
int status = 0; int status = 0;
#ifdef __linux__ #ifdef __linux__
FILE *fp; FILE *fp;
#endif #endif
uname (&uts); uname (&uts);
printf ("\n"); printf ("\n");
PEINFO_GOOD; PEINFO_GOOD;
printf (" Gentoo/%s; ", uts.sysname); printf (" Gentoo/%s; ", uts.sysname);
PEINFO_BRACKET; PEINFO_BRACKET;
printf ("http://www.gentoo.org/"); printf ("http://www.gentoo.org/");
PEINFO_NORMAL; PEINFO_NORMAL;
printf ("\n Copyright 1999-2007 Gentoo Foundation; " printf ("\n Copyright 1999-2007 Gentoo Foundation; "
"Distributed under the GPLv2\n\n"); "Distributed under the GPLv2\n\n");
printf ("Press "); printf ("Press ");
PEINFO_GOOD; PEINFO_GOOD;
printf ("I"); printf ("I");
PEINFO_NORMAL; PEINFO_NORMAL;
printf (" to enter interactive boot mode\n\n"); printf (" to enter interactive boot mode\n\n");
setenv ("RC_SOFTLEVEL", newlevel, 1); setenv ("RC_SOFTLEVEL", newlevel, 1);
rc_plugin_run (rc_hook_runlevel_start_in, newlevel); rc_plugin_run (rc_hook_runlevel_start_in, newlevel);
if ((pid = fork ()) == -1) if ((pid = fork ()) == -1)
eerrorx ("%s: fork: %s", applet, strerror (errno)); eerrorx ("%s: fork: %s", applet, strerror (errno));
if (pid == 0) if (pid == 0)
{ {
mycmd = rc_xstrdup (INITSH); mycmd = rc_xstrdup (INITSH);
execl (mycmd, mycmd, (char *) NULL); execl (mycmd, mycmd, (char *) NULL);
eerrorx ("%s: unable to exec `" INITSH "': %s", eerrorx ("%s: unable to exec `" INITSH "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
do do
{ {
wpid = waitpid (pid, &status, 0); wpid = waitpid (pid, &status, 0);
if (wpid < 1) if (wpid < 1)
eerror ("waitpid: %s", strerror (errno)); eerror ("waitpid: %s", strerror (errno));
} while (! WIFEXITED (status) && ! WIFSIGNALED (status)); } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0) if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
/* If we requested a softlevel, save it now */ /* If we requested a softlevel, save it now */
#ifdef __linux__ #ifdef __linux__
set_ksoftlevel (NULL); set_ksoftlevel (NULL);
if ((fp = fopen ("/proc/cmdline", "r"))) if ((fp = fopen ("/proc/cmdline", "r")))
{ {
char buffer[RC_LINEBUFFER]; char buffer[RC_LINEBUFFER];
char *soft; char *soft;
memset (buffer, 0, sizeof (buffer)); memset (buffer, 0, sizeof (buffer));
if (fgets (buffer, RC_LINEBUFFER, fp) && if (fgets (buffer, RC_LINEBUFFER, fp) &&
(soft = strstr (buffer, "softlevel="))) (soft = strstr (buffer, "softlevel=")))
{ {
i = soft - buffer; i = soft - buffer;
if (i == 0 || buffer[i - 1] == ' ') if (i == 0 || buffer[i - 1] == ' ')
{ {
char *level; char *level;
/* Trim the trailing carriage return if present */ /* Trim the trailing carriage return if present */
i = strlen (buffer) - 1; i = strlen (buffer) - 1;
if (buffer[i] == '\n') if (buffer[i] == '\n')
buffer[i] = 0; buffer[i] = 0;
soft += strlen ("softlevel="); soft += strlen ("softlevel=");
level = strsep (&soft, " "); level = strsep (&soft, " ");
set_ksoftlevel (level); set_ksoftlevel (level);
} }
} }
fclose (fp); fclose (fp);
} }
#endif #endif
rc_plugin_run (rc_hook_runlevel_start_out, newlevel); rc_plugin_run (rc_hook_runlevel_start_out, newlevel);
if (want_interactive ()) if (want_interactive ())
mark_interactive (); mark_interactive ();
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
#ifdef __linux__ #ifdef __linux__
/* Parse the inittab file so we can work out the level to telinit */ /* Parse the inittab file so we can work out the level to telinit */
if (strcmp (newlevel, RC_LEVEL_BOOT) != 0 && if (strcmp (newlevel, RC_LEVEL_BOOT) != 0 &&
strcmp (newlevel, RC_LEVEL_SINGLE) != 0) strcmp (newlevel, RC_LEVEL_SINGLE) != 0)
{ {
char **inittab = rc_get_list (NULL, "/etc/inittab"); char **inittab = rc_get_list (NULL, "/etc/inittab");
char *line; char *line;
char *p; char *p;
char *token; char *token;
char lvl[2] = {0, 0}; char lvl[2] = {0, 0};
STRLIST_FOREACH (inittab, line, i) STRLIST_FOREACH (inittab, line, i)
{ {
p = line; p = line;
token = strsep (&p, ":"); token = strsep (&p, ":");
if (! token || token[0] != 'l') if (! token || token[0] != 'l')
continue; continue;
if ((token = strsep (&p, ":")) == NULL) if ((token = strsep (&p, ":")) == NULL)
continue; continue;
/* Snag the level */ /* Snag the level */
lvl[0] = token[0]; lvl[0] = token[0];
/* The name is spaced after this */ /* The name is spaced after this */
if ((token = strsep (&p, " ")) == NULL) if ((token = strsep (&p, " ")) == NULL)
continue; continue;
if ((token = strsep (&p, " ")) == NULL) if ((token = strsep (&p, " ")) == NULL)
continue; continue;
if (strcmp (token, newlevel) == 0) if (strcmp (token, newlevel) == 0)
break; break;
} }
rc_strlist_free (inittab); rc_strlist_free (inittab);
/* We have a level, so telinit into it */ /* We have a level, so telinit into it */
if (lvl[0] == 0) if (lvl[0] == 0)
{ {
eerrorx ("%s: couldn't find a runlevel called `%s'", eerrorx ("%s: couldn't find a runlevel called `%s'",
applet, newlevel); applet, newlevel);
} }
else else
{ {
mycmd = rc_xstrdup ("/sbin/telinit"); mycmd = rc_xstrdup ("/sbin/telinit");
myarg = rc_xstrdup (lvl); myarg = rc_xstrdup (lvl);
execl (mycmd, mycmd, myarg, (char *) NULL); execl (mycmd, mycmd, myarg, (char *) NULL);
eerrorx ("%s: unable to exec `/sbin/telinit': %s", eerrorx ("%s: unable to exec `/sbin/telinit': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
} }
#endif #endif
} }
} }
/* Check we're in the runlevel requested, ie from /* Check we're in the runlevel requested, ie from
@@ -750,63 +750,63 @@ int main (int argc, char **argv)
if (newlevel) if (newlevel)
{ {
if (myarg) if (myarg)
{ {
free (myarg); free (myarg);
myarg = NULL; myarg = NULL;
} }
if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0)
{ {
if (! RUNLEVEL || if (! RUNLEVEL ||
(strcmp (RUNLEVEL, "S") != 0 && (strcmp (RUNLEVEL, "S") != 0 &&
strcmp (RUNLEVEL, "1") != 0)) strcmp (RUNLEVEL, "1") != 0))
{ {
/* Remember the current runlevel for when we come back */ /* Remember the current runlevel for when we come back */
set_ksoftlevel (runlevel); set_ksoftlevel (runlevel);
#ifdef __linux__ #ifdef __linux__
mycmd = rc_xstrdup ("/sbin/telinit"); mycmd = rc_xstrdup ("/sbin/telinit");
myarg = rc_xstrdup ("S"); myarg = rc_xstrdup ("S");
execl (mycmd, mycmd, myarg, (char *) NULL); execl (mycmd, mycmd, myarg, (char *) NULL);
eerrorx ("%s: unable to exec `/%s': %s", eerrorx ("%s: unable to exec `/%s': %s",
mycmd, applet, strerror (errno)); mycmd, applet, strerror (errno));
#else #else
if (kill (1, SIGTERM) != 0) if (kill (1, SIGTERM) != 0)
eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s", eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s",
applet, strerror (errno)); applet, strerror (errno));
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
#endif #endif
} }
} }
else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0) else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0)
{ {
if (! RUNLEVEL || if (! RUNLEVEL ||
strcmp (RUNLEVEL, "6") != 0) strcmp (RUNLEVEL, "6") != 0)
{ {
mycmd = rc_xstrdup ("/sbin/shutdown"); mycmd = rc_xstrdup ("/sbin/shutdown");
myarg = rc_xstrdup ("-r"); myarg = rc_xstrdup ("-r");
tmp = rc_xstrdup ("now"); tmp = rc_xstrdup ("now");
execl (mycmd, mycmd, myarg, tmp, (char *) NULL); execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
eerrorx ("%s: unable to exec `%s': %s", eerrorx ("%s: unable to exec `%s': %s",
mycmd, applet, strerror (errno)); mycmd, applet, strerror (errno));
} }
} }
else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0) else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0)
{ {
if (! RUNLEVEL || if (! RUNLEVEL ||
strcmp (RUNLEVEL, "0") != 0) strcmp (RUNLEVEL, "0") != 0)
{ {
mycmd = rc_xstrdup ("/sbin/shutdown"); mycmd = rc_xstrdup ("/sbin/shutdown");
#ifdef __linux__ #ifdef __linux__
myarg = rc_xstrdup ("-h"); myarg = rc_xstrdup ("-h");
#else #else
myarg = rc_xstrdup ("-p"); myarg = rc_xstrdup ("-p");
#endif #endif
tmp = rc_xstrdup ("now"); tmp = rc_xstrdup ("now");
execl (mycmd, mycmd, myarg, tmp, (char *) NULL); execl (mycmd, mycmd, myarg, tmp, (char *) NULL);
eerrorx ("%s: unable to exec `%s': %s", eerrorx ("%s: unable to exec `%s': %s",
mycmd, applet, strerror (errno)); mycmd, applet, strerror (errno));
} }
} }
} }
/* Export our current softlevel */ /* Export our current softlevel */
@@ -819,31 +819,31 @@ int main (int argc, char **argv)
strcmp (newlevel, RC_LEVEL_DEFAULT) == 0) strcmp (newlevel, RC_LEVEL_DEFAULT) == 0)
{ {
/* We should only use ksoftlevel if we were in single user mode /* 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 && if (PREVLEVEL &&
(strcmp (PREVLEVEL, "1") == 0 || (strcmp (PREVLEVEL, "1") == 0 ||
strcmp (PREVLEVEL, "S") == 0 || strcmp (PREVLEVEL, "S") == 0 ||
strcmp (PREVLEVEL, "N") == 0)) strcmp (PREVLEVEL, "N") == 0))
{ {
FILE *fp; FILE *fp;
if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r"))) if (! (fp = fopen (RC_SVCDIR "ksoftlevel", "r")))
eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel", eerror ("fopen `%s': %s", RC_SVCDIR "ksoftlevel",
strerror (errno)); strerror (errno));
else else
{ {
if (fgets (ksoftbuffer, sizeof (ksoftbuffer), fp)) if (fgets (ksoftbuffer, sizeof (ksoftbuffer), fp))
{ {
i = strlen (ksoftbuffer) - 1; i = strlen (ksoftbuffer) - 1;
if (ksoftbuffer[i] == '\n') if (ksoftbuffer[i] == '\n')
ksoftbuffer[i] = 0; ksoftbuffer[i] = 0;
newlevel = ksoftbuffer; newlevel = ksoftbuffer;
} }
fclose (fp); fclose (fp);
} }
} }
else else
set_ksoftlevel (NULL); set_ksoftlevel (NULL);
} }
if (newlevel && if (newlevel &&
@@ -866,7 +866,7 @@ int main (int argc, char **argv)
{ {
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL); tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL);
if (! rc_is_dir (tmp)) if (! rc_is_dir (tmp))
eerrorx ("%s: is not a valid runlevel", newlevel); eerrorx ("%s: is not a valid runlevel", newlevel);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@@ -892,10 +892,10 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
if (rc_allow_plug (service)) if (rc_allow_plug (service))
rc_mark_service (service, rc_service_coldplugged); rc_mark_service (service, rc_service_coldplugged);
/* We need to dump this list now. /* We need to dump this list now.
This may seem redunant, but only Linux needs this and saves on This may seem redunant, but only Linux needs this and saves on
code bloat. */ code bloat. */
rc_strlist_free (start_services); rc_strlist_free (start_services);
start_services = NULL; 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 :) */ /* The net interfaces are easy - they're all in net /dev/net :) */
start_services = rc_ls_dir (NULL, "/dev/net", 0); start_services = rc_ls_dir (NULL, "/dev/net", 0);
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
{ {
j = (strlen ("net.") + strlen (service) + 1); j = (strlen ("net.") + strlen (service) + 1);
tmp = rc_xmalloc (sizeof (char *) * j); tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "net.%s", service); snprintf (tmp, j, "net.%s", service);
if (rc_service_exists (tmp) && rc_allow_plug (tmp)) if (rc_service_exists (tmp) && rc_allow_plug (tmp))
rc_mark_service (tmp, rc_service_coldplugged); rc_mark_service (tmp, rc_service_coldplugged);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
rc_strlist_free (start_services); rc_strlist_free (start_services);
/* The mice are a little more tricky. /* The mice are a little more tricky.
If we coldplug anything else, we'll probably do it here. */ If we coldplug anything else, we'll probably do it here. */
start_services = rc_ls_dir (NULL, "/dev", 0); start_services = rc_ls_dir (NULL, "/dev", 0);
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
{ {
if (strncmp (service, "psm", 3) == 0 || if (strncmp (service, "psm", 3) == 0 ||
strncmp (service, "ums", 3) == 0) strncmp (service, "ums", 3) == 0)
{ {
char *p = service + 3; char *p = service + 3;
if (p && isdigit (*p)) if (p && isdigit (*p))
{ {
j = (strlen ("moused.") + strlen (service) + 1); j = (strlen ("moused.") + strlen (service) + 1);
tmp = rc_xmalloc (sizeof (char *) * j); tmp = rc_xmalloc (sizeof (char *) * j);
snprintf (tmp, j, "moused.%s", service); snprintf (tmp, j, "moused.%s", service);
if (rc_service_exists (tmp) && rc_allow_plug (tmp)) if (rc_service_exists (tmp) && rc_allow_plug (tmp))
rc_mark_service (tmp, rc_service_coldplugged); rc_mark_service (tmp, rc_service_coldplugged);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
} }
} }
rc_strlist_free (start_services); rc_strlist_free (start_services);
start_services = NULL; start_services = NULL;
} }
@@ -957,7 +957,7 @@ int main (int argc, char **argv)
types = rc_strlist_add (types, "iuse"); types = rc_strlist_add (types, "iuse");
types = rc_strlist_add (types, "iafter"); types = rc_strlist_add (types, "iafter");
deporder = rc_get_depends (deptree, types, stop_services, deporder = rc_get_depends (deptree, types, stop_services,
runlevel, depoptions); runlevel, depoptions);
rc_strlist_free (stop_services); rc_strlist_free (stop_services);
rc_strlist_free (types); rc_strlist_free (types);
stop_services = deporder; stop_services = deporder;
@@ -967,24 +967,24 @@ int main (int argc, char **argv)
/* Load our list of coldplugged services */ /* Load our list of coldplugged services */
coldplugged_services = rc_ls_dir (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. /* Load our start services now.
We have different rules dependent on runlevel. */ We have different rules dependent on runlevel. */
if (newlevel && strcmp (newlevel, RC_LEVEL_BOOT) == 0) if (newlevel && strcmp (newlevel, RC_LEVEL_BOOT) == 0)
{ {
if (coldplugged_services) if (coldplugged_services)
{ {
einfon ("Device initiated services:"); einfon ("Device initiated services:");
STRLIST_FOREACH (coldplugged_services, service, i) STRLIST_FOREACH (coldplugged_services, service, i)
{ {
printf (" %s", service); printf (" %s", service);
start_services = rc_strlist_add (start_services, service); start_services = rc_strlist_add (start_services, service);
} }
printf ("\n"); printf ("\n");
} }
tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel, tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
(char *) NULL); (char *) NULL);
start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD); start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@@ -992,22 +992,22 @@ int main (int argc, char **argv)
{ {
/* Store our list of coldplugged services */ /* Store our list of coldplugged services */
coldplugged_services = rc_ls_dir (coldplugged_services, RC_SVCDIR_COLDPLUGGED, 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 && if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 && strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0) strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
{ {
/* We need to include the boot runlevel services if we're not in it */ /* 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, start_services = rc_ls_dir (start_services, RC_RUNLEVELDIR RC_LEVEL_BOOT,
RC_LS_INITD); RC_LS_INITD);
STRLIST_FOREACH (coldplugged_services, service, i) STRLIST_FOREACH (coldplugged_services, service, i)
start_services = rc_strlist_add (start_services, service); start_services = rc_strlist_add (start_services, service);
tmp = rc_strcatpaths (RC_RUNLEVELDIR, tmp = rc_strcatpaths (RC_RUNLEVELDIR,
newlevel ? newlevel : runlevel, (char *) NULL); newlevel ? newlevel : runlevel, (char *) NULL);
start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD); start_services = rc_ls_dir (start_services, tmp, RC_LS_INITD);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
} }
/* Save out softlevel now */ /* Save out softlevel now */
@@ -1027,82 +1027,82 @@ int main (int argc, char **argv)
int k; int k;
if (rc_service_state (service, rc_service_stopped)) if (rc_service_state (service, rc_service_stopped))
continue; continue;
/* We always stop the service when in these runlevels */ /* We always stop the service when in these runlevels */
if (going_down) if (going_down)
{ {
rc_stop_service (service); rc_stop_service (service);
continue; continue;
} }
/* If we're in the start list then don't bother stopping us */ /* If we're in the start list then don't bother stopping us */
STRLIST_FOREACH (start_services, svc1, j) STRLIST_FOREACH (start_services, svc1, j)
if (strcmp (svc1, service) == 0) if (strcmp (svc1, service) == 0)
{ {
found = true; found = true;
break; break;
} }
/* Unless we would use a different config file */ /* Unless we would use a different config file */
if (found) if (found)
{ {
int len; int len;
if (! newlevel) if (! newlevel)
continue; continue;
len = strlen (service) + strlen (runlevel) + 2; len = strlen (service) + strlen (runlevel) + 2;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = rc_xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, runlevel); snprintf (tmp, len, "%s.%s", service, runlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = rc_exists (conf);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (! found) if (! found)
{ {
len = strlen (service) + strlen (newlevel) + 2; len = strlen (service) + strlen (newlevel) + 2;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = rc_xmalloc (sizeof (char *) * len);
snprintf (tmp, len, "%s.%s", service, newlevel); snprintf (tmp, len, "%s.%s", service, newlevel);
conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
found = rc_exists (conf); found = rc_exists (conf);
CHAR_FREE (conf); CHAR_FREE (conf);
CHAR_FREE (tmp); CHAR_FREE (tmp);
if (!found) if (!found)
continue; continue;
} }
} }
else else
/* Allow coldplugged services not to be in the runlevels list */ /* Allow coldplugged services not to be in the runlevels list */
{ {
if (rc_service_state (service, rc_service_coldplugged)) if (rc_service_state (service, rc_service_coldplugged))
continue; continue;
} }
/* We got this far! Or last check is to see if any any service that /* 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); stopdeps = rc_strlist_add (stopdeps, service);
deporder = rc_get_depends (deptree, types, stopdeps, deporder = rc_get_depends (deptree, types, stopdeps,
runlevel, RC_DEP_STRICT); runlevel, RC_DEP_STRICT);
rc_strlist_free (stopdeps); rc_strlist_free (stopdeps);
stopdeps = NULL; stopdeps = NULL;
found = false; found = false;
STRLIST_FOREACH (deporder, svc1, j) STRLIST_FOREACH (deporder, svc1, j)
{ {
STRLIST_FOREACH (start_services, svc2, k) STRLIST_FOREACH (start_services, svc2, k)
if (strcmp (svc1, svc2) == 0) if (strcmp (svc1, svc2) == 0)
{ {
found = true; found = true;
break; break;
} }
if (found) if (found)
break; break;
} }
rc_strlist_free (deporder); rc_strlist_free (deporder);
deporder = NULL; deporder = NULL;
/* After all that we can finally stop the blighter! */ /* After all that we can finally stop the blighter! */
if (! found) if (! found)
rc_stop_service (service); rc_stop_service (service);
} }
rc_strlist_free (types); rc_strlist_free (types);
types = NULL; types = NULL;
@@ -1132,14 +1132,14 @@ int main (int argc, char **argv)
myarg = rc_xstrdup (runlevel); myarg = rc_xstrdup (runlevel);
execl (mycmd, mycmd, myarg, (char *) NULL); execl (mycmd, mycmd, myarg, (char *) NULL);
eerrorx ("%s: unable to exec `%s': %s", eerrorx ("%s: unable to exec `%s': %s",
applet, HALTSH, strerror (errno)); applet, HALTSH, strerror (errno));
} }
/* Single user is done now */ /* Single user is done now */
if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0)
{ {
if (rc_exists (INTERACTIVE)) if (rc_exists (INTERACTIVE))
unlink (INTERACTIVE); unlink (INTERACTIVE);
sulogin (false); sulogin (false);
} }
@@ -1155,7 +1155,7 @@ int main (int argc, char **argv)
types = rc_strlist_add (types, "iuse"); types = rc_strlist_add (types, "iuse");
types = rc_strlist_add (types, "iafter"); types = rc_strlist_add (types, "iafter");
deporder = rc_get_depends (deptree, types, start_services, deporder = rc_get_depends (deptree, types, start_services,
runlevel, depoptions); runlevel, depoptions);
rc_strlist_free (types); rc_strlist_free (types);
types = NULL; types = NULL;
rc_strlist_free (start_services); rc_strlist_free (start_services);
@@ -1165,31 +1165,31 @@ int main (int argc, char **argv)
STRLIST_FOREACH (start_services, service, i) STRLIST_FOREACH (start_services, service, i)
{ {
if (rc_service_state (service, rc_service_stopped)) if (rc_service_state (service, rc_service_stopped))
{ {
if (! interactive) if (! interactive)
interactive = want_interactive (); interactive = want_interactive ();
if (interactive) if (interactive)
{ {
interactive_retry: interactive_retry:
printf ("\n"); printf ("\n");
einfo ("About to start the service %s", service); einfo ("About to start the service %s", service);
eindent (); eindent ();
einfo ("1) Start the service\t\t2) Skip the service"); einfo ("1) Start the service\t\t2) Skip the service");
einfo ("3) Continue boot process\t\t4) Exit to shell"); einfo ("3) Continue boot process\t\t4) Exit to shell");
eoutdent (); eoutdent ();
interactive_option: interactive_option:
switch (read_key (true)) switch (read_key (true))
{ {
case '1': break; case '1': break;
case '2': continue; case '2': continue;
case '3': interactive = false; break; case '3': interactive = false; break;
case '4': sulogin (true); goto interactive_retry; case '4': sulogin (true); goto interactive_retry;
default: goto interactive_option; default: goto interactive_option;
} }
} }
rc_start_service (service); rc_start_service (service);
} }
} }
/* Wait for our services to finish */ /* Wait for our services to finish */
@@ -1204,7 +1204,7 @@ interactive_option:
else else
{ {
if (rc_exists (INTERACTIVE)) if (rc_exists (INTERACTIVE))
unlink (INTERACTIVE); unlink (INTERACTIVE);
} }
return (EXIT_SUCCESS); return (EXIT_SUCCESS);

View File

@@ -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_stop_service (const char *service);
pid_t rc_start_service (const char *service); pid_t rc_start_service (const char *service);
void rc_schedule_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); char **rc_services_scheduled_by (const char *service);
void rc_schedule_clear (const char *service); void rc_schedule_clear (const char *service);
bool rc_wait_service (const char *service); bool rc_wait_service (const char *service);
bool rc_get_service_option (const char *service, const char *option, 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, 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, void rc_set_service_daemon (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started); bool started);
bool rc_service_started_daemon (const char *service, const char *exec, bool rc_service_started_daemon (const char *service, const char *exec,
int indx); int indx);
bool rc_allow_plug (char *service); 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 */ /* Find pids based on criteria - free the pointer returned after use */
pid_t *rc_find_pids (const char *exec, const char *cmd, 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 /* Checks that all daemons started with start-stop-daemon by the service
are still running. If so, return false otherwise true. are still running. If so, return false otherwise true.
You should check that the service has been started before calling this. */ 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_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); rc_deptype_t *rc_get_deptype (rc_depinfo_t *depinfo, const char *type);
char **rc_get_depends (rc_depinfo_t *deptree, char **types, 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 /* List all the services that should be started, in order, the the
given runlevel, including sysinit and boot services where given runlevel, including sysinit and boot services where
approriate. approriate.
If reboot, shutdown or single are given then we list all the services If reboot, shutdown or single are given then we list all the services
we that we need to shutdown in order. */ we that we need to shutdown in order. */
char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel, char **rc_order_services (rc_depinfo_t *deptree, const char *runlevel,
int options); int options);
void rc_free_deptree (rc_depinfo_t *deptree); void rc_free_deptree (rc_depinfo_t *deptree);

View File

@@ -71,20 +71,20 @@ void setup_selinux (int argc, char **argv)
if (lib_handle) if (lib_handle)
{ {
/* FIXME: the below code generates the warning /* FIXME: the below code generates the warning
ISO C forbids assignment between function pointer and 'void *' ISO C forbids assignment between function pointer and 'void *'
which sucks ass which sucks ass
http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html */ http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html */
selinux_run_init_old = dlsym (lib_handle, "selinux_runscript"); selinux_run_init_old = dlsym (lib_handle, "selinux_runscript");
selinux_run_init_new = dlsym (lib_handle, "selinux_runscript2"); selinux_run_init_new = dlsym (lib_handle, "selinux_runscript2");
/* Use new run_init if it rc_exists, else fall back to old */ /* Use new run_init if it rc_exists, else fall back to old */
if (selinux_run_init_new) if (selinux_run_init_new)
selinux_run_init_new (argc, argv); selinux_run_init_new (argc, argv);
else if (selinux_run_init_old) else if (selinux_run_init_old)
selinux_run_init_old (); selinux_run_init_old ();
else else
/* This shouldnt happen... probably corrupt lib */ /* This shouldnt happen... probably corrupt lib */
eerrorx ("run_init is missing from runscript_selinux.so!"); eerrorx ("run_init is missing from runscript_selinux.so!");
} }
} }
#endif #endif
@@ -104,26 +104,26 @@ static void handle_signal (int sig)
case SIGCHLD: case SIGCHLD:
do do
{ {
pid = waitpid (-1, &status, WNOHANG); pid = waitpid (-1, &status, WNOHANG);
if (pid < 0) if (pid < 0)
{ {
if (errno != ECHILD) if (errno != ECHILD)
eerror ("waitpid: %s", strerror (errno)); eerror ("waitpid: %s", strerror (errno));
return; return;
} }
} while (! WIFEXITED (status) && ! WIFSIGNALED (status)); } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
break; break;
case SIGINT: case SIGINT:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGINT"); snprintf (signame, sizeof (signame), "SIGINT");
case SIGTERM: case SIGTERM:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGTERM"); snprintf (signame, sizeof (signame), "SIGTERM");
case SIGQUIT: case SIGQUIT:
if (! signame[0]) if (! signame[0])
snprintf (signame, sizeof (signame), "SIGQUIT"); snprintf (signame, sizeof (signame), "SIGQUIT");
eerrorx ("%s: caught %s, aborting", applet, signame); eerrorx ("%s: caught %s, aborting", applet, signame);
default: default:
@@ -174,14 +174,14 @@ static bool in_control ()
{ {
path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL); path = rc_strcatpaths (RC_SVCDIR, tests[i], applet, (char *) NULL);
if (rc_exists (path)) if (rc_exists (path))
{ {
int m = get_mtime (path, false); int m = get_mtime (path, false);
if (mtime < m && m != 0) if (mtime < m && m != 0)
{ {
free (path); free (path);
return (false); return (false);
} }
} }
free (path); free (path);
i++; i++;
} }
@@ -192,7 +192,7 @@ static bool in_control ()
static void uncoldplug (char *service) static void uncoldplug (char *service)
{ {
char *cold = rc_strcatpaths (RC_SVCDIR "coldplugged", basename (service), char *cold = rc_strcatpaths (RC_SVCDIR "coldplugged", basename (service),
(char *) NULL); (char *) NULL);
if (rc_exists (cold) && unlink (cold) != 0) if (rc_exists (cold) && unlink (cold) != 0)
eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno)); eerror ("%s: unlink `%s': %s", applet, cold, strerror (errno));
free (cold); free (cold);
@@ -235,27 +235,27 @@ static void cleanup (void)
if (in_control ()) if (in_control ())
{ {
if (rc_service_state (applet, rc_service_stopping)) if (rc_service_state (applet, rc_service_stopping))
{ {
/* If the we're shutting down, do it cleanly */ /* If the we're shutting down, do it cleanly */
if ((softlevel && if ((softlevel &&
rc_runlevel_stopping () && rc_runlevel_stopping () &&
(strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 || (strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (softlevel, RC_LEVEL_REBOOT) == 0))) strcmp (softlevel, RC_LEVEL_REBOOT) == 0)))
rc_mark_service (applet, rc_service_stopped); rc_mark_service (applet, rc_service_stopped);
else if (rc_service_state (applet, rc_service_wasinactive)) else if (rc_service_state (applet, rc_service_wasinactive))
rc_mark_service (applet, rc_service_inactive); rc_mark_service (applet, rc_service_inactive);
else else
rc_mark_service (applet, rc_service_started); rc_mark_service (applet, rc_service_started);
} }
else if (rc_service_state (applet, rc_service_starting)) else if (rc_service_state (applet, rc_service_starting))
{ {
if (rc_service_state (applet, rc_service_wasinactive)) if (rc_service_state (applet, rc_service_wasinactive))
rc_mark_service (applet, rc_service_inactive); rc_mark_service (applet, rc_service_inactive);
else else
rc_mark_service (applet, rc_service_stopped); rc_mark_service (applet, rc_service_stopped);
} }
if (exclusive && rc_exists (exclusive)) if (exclusive && rc_exists (exclusive))
unlink (exclusive); unlink (exclusive);
} }
if (env) if (env)
@@ -291,32 +291,32 @@ static bool svc_exec (const char *service, const char *arg1, const char *arg2)
mycmd = rc_xstrdup (service); mycmd = rc_xstrdup (service);
myarg1 = rc_xstrdup (arg1); myarg1 = rc_xstrdup (arg1);
if (arg2) if (arg2)
myarg2 = rc_xstrdup (arg2); myarg2 = rc_xstrdup (arg2);
if (rc_exists (RC_SVCDIR "runscript.sh")) if (rc_exists (RC_SVCDIR "runscript.sh"))
{ {
execl (RC_SVCDIR "runscript.sh", mycmd, mycmd, myarg1, myarg2, execl (RC_SVCDIR "runscript.sh", mycmd, mycmd, myarg1, myarg2,
(char *) NULL); (char *) NULL);
eerrorx ("%s: exec `" RC_SVCDIR "runscript.sh': %s", eerrorx ("%s: exec `" RC_SVCDIR "runscript.sh': %s",
service, strerror (errno)); service, strerror (errno));
} }
else else
{ {
execl (RC_LIBDIR "sh/runscript.sh", mycmd, mycmd, myarg1, myarg2, execl (RC_LIBDIR "sh/runscript.sh", mycmd, mycmd, myarg1, myarg2,
(char *) NULL); (char *) NULL);
eerrorx ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s", eerrorx ("%s: exec `" RC_LIBDIR "sh/runscript.sh': %s",
service, strerror (errno)); service, strerror (errno));
} }
} }
do do
{ {
if (waitpid (pid, &status, 0) < 0) if (waitpid (pid, &status, 0) < 0)
{ {
if (errno != ECHILD) if (errno != ECHILD)
eerror ("waitpid: %s", strerror (errno)); eerror ("waitpid: %s", strerror (errno));
break; break;
} }
} while (! WIFEXITED (status) && ! WIFSIGNALED (status)); } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
/* Done, so restore the signal handler */ /* Done, so restore the signal handler */
@@ -383,7 +383,7 @@ static void make_exclusive (const char *service)
if (mkfifo (exclusive, 0600) != 0 && errno != EEXIST && if (mkfifo (exclusive, 0600) != 0 && errno != EEXIST &&
(errno != EACCES || geteuid () == 0)) (errno != EACCES || geteuid () == 0))
eerrorx ("%s: unable to create fifo `%s': %s", 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); path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
i = strlen (path) + 16; i = strlen (path) + 16;
@@ -394,7 +394,7 @@ static void make_exclusive (const char *service)
if (rc_exists (mtime_test) && unlink (mtime_test) != 0) if (rc_exists (mtime_test) && unlink (mtime_test) != 0)
{ {
eerror ("%s: unlink `%s': %s", eerror ("%s: unlink `%s': %s",
applet, mtime_test, strerror (errno)); applet, mtime_test, strerror (errno));
free (mtime_test); free (mtime_test);
mtime_test = NULL; mtime_test = NULL;
return; return;
@@ -403,7 +403,7 @@ static void make_exclusive (const char *service)
if (symlink (service, mtime_test) != 0) if (symlink (service, mtime_test) != 0)
{ {
eerror ("%s: symlink `%s' to `%s': %s", eerror ("%s: symlink `%s' to `%s': %s",
applet, service, mtime_test, strerror (errno)); applet, service, mtime_test, strerror (errno));
free (mtime_test); free (mtime_test);
mtime_test = NULL; 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_is_env ("IN_HOTPLUG", "1") || in_background)
{ {
if (! rc_service_state (service, rc_service_inactive)) if (! rc_service_state (service, rc_service_inactive))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
background = true; background = true;
} }
@@ -472,7 +472,7 @@ static void svc_start (const char *service, bool deps)
if (deps) if (deps)
{ {
if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
eerrorx ("failed to load deptree"); eerrorx ("failed to load deptree");
rc_strlist_free (types); rc_strlist_free (types);
types = rc_strlist_add (NULL, "broken"); types = rc_strlist_add (NULL, "broken");
@@ -481,16 +481,16 @@ static void svc_start (const char *service, bool deps)
rc_strlist_free (services); rc_strlist_free (services);
services = rc_get_depends (deptree, types, svclist, softlevel, 0); services = rc_get_depends (deptree, types, svclist, softlevel, 0);
if (services) if (services)
{ {
eerrorn ("ERROR: `%s' needs ", applet); eerrorn ("ERROR: `%s' needs ", applet);
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
{ {
if (i > 0) if (i > 0)
fprintf (stderr, ", "); fprintf (stderr, ", ");
fprintf (stderr, "%s", svc); fprintf (stderr, "%s", svc);
} }
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
rc_strlist_free (services); rc_strlist_free (services);
services = NULL; services = NULL;
@@ -498,95 +498,95 @@ static void svc_start (const char *service, bool deps)
types = rc_strlist_add (NULL, "ineed"); types = rc_strlist_add (NULL, "ineed");
rc_strlist_free (need_services); rc_strlist_free (need_services);
need_services = rc_get_depends (deptree, types, svclist, need_services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
types = rc_strlist_add (types, "iuse"); types = rc_strlist_add (types, "iuse");
if (! rc_runlevel_starting ()) if (! rc_runlevel_starting ())
{ {
services = rc_get_depends (deptree, types, svclist, services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
rc_start_service (svc); rc_start_service (svc);
rc_strlist_free (services); rc_strlist_free (services);
} }
/* Now wait for them to start */ /* Now wait for them to start */
types = rc_strlist_add (types, "iafter"); types = rc_strlist_add (types, "iafter");
services = rc_get_depends (deptree, types, svclist, services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
/* We use tmplist to hold our scheduled by list */ /* We use tmplist to hold our scheduled by list */
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
tmplist = NULL; tmplist = NULL;
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
{ {
if (rc_service_state (svc, rc_service_started)) if (rc_service_state (svc, rc_service_started))
continue; continue;
if (! rc_wait_service (svc)) if (! rc_wait_service (svc))
eerror ("%s: timed out waiting for %s", applet, svc); eerror ("%s: timed out waiting for %s", applet, svc);
if (rc_service_state (svc, rc_service_started)) if (rc_service_state (svc, rc_service_started))
continue; continue;
STRLIST_FOREACH (need_services, svc2, j) STRLIST_FOREACH (need_services, svc2, j)
if (strcmp (svc, svc2) == 0) if (strcmp (svc, svc2) == 0)
{ {
if (rc_service_state (svc, rc_service_inactive) || if (rc_service_state (svc, rc_service_inactive) ||
rc_service_state (svc, rc_service_wasinactive)) rc_service_state (svc, rc_service_wasinactive))
tmplist = rc_strlist_add (tmplist, svc); tmplist = rc_strlist_add (tmplist, svc);
else else
eerrorx ("ERROR: cannot start %s as %s would not start", eerrorx ("ERROR: cannot start %s as %s would not start",
applet, svc); applet, svc);
} }
} }
if (tmplist) if (tmplist)
{ {
int n = 0; int n = 0;
int len = 0; int len = 0;
char *p; char *p;
/* Set the state now, then unlink our exclusive so that /* Set the state now, then unlink our exclusive so that
our scheduled list is preserved */ our scheduled list is preserved */
rc_mark_service (service, rc_service_stopped); rc_mark_service (service, rc_service_stopped);
unlink_mtime_test (); unlink_mtime_test ();
rc_strlist_free (types); rc_strlist_free (types);
types = rc_strlist_add (NULL, "iprovide"); types = rc_strlist_add (NULL, "iprovide");
STRLIST_FOREACH (tmplist, svc, i) STRLIST_FOREACH (tmplist, svc, i)
{ {
rc_schedule_start_service (svc, service); rc_schedule_start_service (svc, service);
rc_strlist_free (svclist); rc_strlist_free (svclist);
svclist = rc_strlist_add (NULL, svc); svclist = rc_strlist_add (NULL, svc);
rc_strlist_free (providelist); rc_strlist_free (providelist);
providelist = rc_get_depends (deptree, types, svclist, providelist = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
STRLIST_FOREACH (providelist, svc2, j) STRLIST_FOREACH (providelist, svc2, j)
rc_schedule_start_service (svc2, service); rc_schedule_start_service (svc2, service);
len += strlen (svc) + 2; len += strlen (svc) + 2;
n++; n++;
} }
len += 5; len += 5;
tmp = rc_xmalloc (sizeof (char *) * len); tmp = rc_xmalloc (sizeof (char *) * len);
p = tmp; p = tmp;
STRLIST_FOREACH (tmplist, svc, i) STRLIST_FOREACH (tmplist, svc, i)
{ {
if (i > 1) if (i > 1)
{ {
if (i == n - 1) if (i == n - 1)
p += snprintf (p, len, " or "); p += snprintf (p, len, " or ");
else else
p += snprintf (p, len, ", "); p += snprintf (p, len, ", ");
} }
p += snprintf (p, len, "%s", svc); p += snprintf (p, len, "%s", svc);
} }
ewarnx ("WARNING: %s is scheduled to start when %s has started", ewarnx ("WARNING: %s is scheduled to start when %s has started",
applet, tmp); applet, tmp);
} }
rc_strlist_free (services); rc_strlist_free (services);
services = NULL; services = NULL;
@@ -607,17 +607,17 @@ static void svc_start (const char *service, bool deps)
if (in_control ()) if (in_control ())
{ {
if (! started) if (! started)
{ {
if (rc_service_state (service, rc_service_wasinactive)) if (rc_service_state (service, rc_service_wasinactive))
rc_mark_service (service, rc_service_inactive); rc_mark_service (service, rc_service_inactive);
else else
{ {
rc_mark_service (service, rc_service_stopped); rc_mark_service (service, rc_service_stopped);
if (rc_runlevel_starting ()) if (rc_runlevel_starting ())
rc_mark_service (service, rc_service_failed); rc_mark_service (service, rc_service_failed);
} }
eerrorx ("ERROR: %s failed to start", applet); eerrorx ("ERROR: %s failed to start", applet);
} }
rc_mark_service (service, rc_service_started); rc_mark_service (service, rc_service_started);
unlink_mtime_test (); unlink_mtime_test ();
@@ -628,9 +628,9 @@ static void svc_start (const char *service, bool deps)
else else
{ {
if (rc_service_state (service, rc_service_inactive)) 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 else
ewarn ("WARNING: %s not under our control, aborting", applet); ewarn ("WARNING: %s not under our control, aborting", applet);
} }
/* Now start any scheduled services */ /* Now start any scheduled services */
@@ -656,7 +656,7 @@ static void svc_start (const char *service, bool deps)
services = rc_services_scheduled (svc2); services = rc_services_scheduled (svc2);
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
rc_start_service (svc); rc_start_service (svc);
} }
} }
@@ -683,8 +683,8 @@ static void svc_stop (const char *service, bool deps)
make_exclusive (service); make_exclusive (service);
if (! rc_runlevel_stopping () && if (! rc_runlevel_stopping () &&
rc_service_in_runlevel (service, RC_LEVEL_BOOT)) rc_service_in_runlevel (service, RC_LEVEL_BOOT))
ewarn ("WARNING: you are stopping a boot service"); ewarn ("WARNING: you are stopping a boot service");
if (deps || ! rc_service_state (service, rc_service_wasinactive)) if (deps || ! rc_service_state (service, rc_service_wasinactive))
{ {
@@ -693,10 +693,10 @@ static void svc_stop (const char *service, bool deps)
int i; int i;
if (rc_is_env ("RC_STRICT_DEPEND", "yes")) if (rc_is_env ("RC_STRICT_DEPEND", "yes"))
depoptions |= RC_DEP_STRICT; depoptions |= RC_DEP_STRICT;
if (! deptree && ((deptree = rc_load_deptree ()) == NULL)) if (! deptree && ((deptree = rc_load_deptree ()) == NULL))
eerrorx ("failed to load deptree"); eerrorx ("failed to load deptree");
rc_strlist_free (types); rc_strlist_free (types);
types = rc_strlist_add (NULL, "needsme"); types = rc_strlist_add (NULL, "needsme");
@@ -706,55 +706,55 @@ static void svc_stop (const char *service, bool deps)
tmplist = NULL; tmplist = NULL;
rc_strlist_free (services); rc_strlist_free (services);
services = rc_get_depends (deptree, types, svclist, services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
rc_strlist_reverse (services); rc_strlist_reverse (services);
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
{ {
if (rc_service_state (svc, rc_service_started) || if (rc_service_state (svc, rc_service_started) ||
rc_service_state (svc, rc_service_inactive)) rc_service_state (svc, rc_service_inactive))
{ {
rc_wait_service (svc); rc_wait_service (svc);
if (rc_service_state (svc, rc_service_started) || if (rc_service_state (svc, rc_service_started) ||
rc_service_state (svc, rc_service_inactive)) rc_service_state (svc, rc_service_inactive))
{ {
rc_stop_service (svc); rc_stop_service (svc);
tmplist = rc_strlist_add (tmplist, svc); tmplist = rc_strlist_add (tmplist, svc);
} }
} }
} }
rc_strlist_free (services); rc_strlist_free (services);
services = NULL; services = NULL;
STRLIST_FOREACH (tmplist, svc, i) STRLIST_FOREACH (tmplist, svc, i)
{ {
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
continue; continue;
/* We used to loop 3 times here - maybe re-do this if needed */ /* We used to loop 3 times here - maybe re-do this if needed */
rc_wait_service (svc); rc_wait_service (svc);
if (! rc_service_state (svc, rc_service_stopped)) if (! rc_service_state (svc, rc_service_stopped))
{ {
if (rc_runlevel_stopping ()) if (rc_runlevel_stopping ())
rc_mark_service (svc, rc_service_failed); rc_mark_service (svc, rc_service_failed);
eerrorx ("ERROR: cannot stop %s as %s is still up", eerrorx ("ERROR: cannot stop %s as %s is still up",
applet, svc); applet, svc);
} }
} }
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
tmplist = NULL; tmplist = NULL;
/* We now wait for other services that may use us and are stopping /* 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, "usesme");
types = rc_strlist_add (types, "ibefore"); types = rc_strlist_add (types, "ibefore");
services = rc_get_depends (deptree, types, svclist, services = rc_get_depends (deptree, types, svclist,
softlevel, depoptions); softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) STRLIST_FOREACH (services, svc, i)
{ {
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
continue; continue;
rc_wait_service (svc); rc_wait_service (svc);
} }
rc_strlist_free (services); rc_strlist_free (services);
services = NULL; services = NULL;
@@ -776,9 +776,9 @@ static void svc_stop (const char *service, bool deps)
if (! stopped) if (! stopped)
{ {
if (rc_service_state (service, rc_service_wasinactive)) if (rc_service_state (service, rc_service_wasinactive))
rc_mark_service (service, rc_service_inactive); rc_mark_service (service, rc_service_inactive);
else else
rc_mark_service (service, rc_service_started); rc_mark_service (service, rc_service_started);
eerrorx ("ERROR: %s failed to stop", applet); eerrorx ("ERROR: %s failed to stop", applet);
} }
@@ -809,10 +809,10 @@ static void svc_restart (const char *service, bool deps)
if (! deps) if (! deps)
{ {
if (rc_service_state (service, rc_service_started) || if (rc_service_state (service, rc_service_started) ||
rc_service_state (service, rc_service_inactive)) rc_service_state (service, rc_service_inactive))
svc_exec (service, "stop", "start"); svc_exec (service, "stop", "start");
else else
svc_exec (service, "start", NULL); svc_exec (service, "start", NULL);
return; return;
} }
@@ -836,19 +836,19 @@ static void svc_restart (const char *service, bool deps)
rc_service_state (service, rc_service_started)) rc_service_state (service, rc_service_started))
{ {
STRLIST_FOREACH (restart_services, svc, i) STRLIST_FOREACH (restart_services, svc, i)
{ {
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
{ {
if (inactive) if (inactive)
{ {
rc_schedule_start_service (service, svc); rc_schedule_start_service (service, svc);
ewarn ("WARNING: %s is scheduled to started when %s has started", ewarn ("WARNING: %s is scheduled to started when %s has started",
svc, basename (service)); svc, basename (service));
} }
else else
rc_start_service (svc); rc_start_service (svc);
} }
} }
} }
} }
@@ -870,7 +870,7 @@ int main (int argc, char **argv)
{ {
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
#ifdef __linux__ #ifdef __linux__
@@ -880,7 +880,7 @@ int main (int argc, char **argv)
{ {
eerror ("%s: cannot run until sysvinit completes", applet); eerror ("%s: cannot run until sysvinit completes", applet);
if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST) if (mkdir ("/dev/.rcboot", 0755) != 0 && errno != EEXIST)
eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno)); eerrorx ("%s: mkdir `/dev/.rcboot': %s", applet, strerror (errno));
tmp = rc_strcatpaths ("/dev/.rcboot", applet, (char *) NULL); tmp = rc_strcatpaths ("/dev/.rcboot", applet, (char *) NULL);
symlink (service, tmp); symlink (service, tmp);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@@ -890,40 +890,40 @@ int main (int argc, char **argv)
if ((softlevel = getenv ("RC_SOFTLEVEL")) == NULL) if ((softlevel = getenv ("RC_SOFTLEVEL")) == NULL)
{ {
/* Ensure our environment is pure /* Ensure our environment is pure
Also, add our configuration to it */ Also, add our configuration to it */
env = rc_filter_env (); env = rc_filter_env ();
env = rc_config_env (env); env = rc_config_env (env);
if (env) if (env)
{ {
char *p; char *p;
#ifdef __linux__ #ifdef __linux__
/* clearenv isn't portable, but there's no harm in using it /* clearenv isn't portable, but there's no harm in using it
if we have it */ if we have it */
clearenv (); clearenv ();
#else #else
char *var; char *var;
/* No clearenv present here then. /* No clearenv present here then.
We could manipulate environ directly ourselves, but it seems that We could manipulate environ directly ourselves, but it seems that
some kernels bitch about this according to the environ man pages some kernels bitch about this according to the environ man pages
so we walk though environ and call unsetenv for each value. */ so we walk though environ and call unsetenv for each value. */
while (environ[0]) while (environ[0])
{ {
tmp = rc_xstrdup (environ[0]); tmp = rc_xstrdup (environ[0]);
p = tmp; p = tmp;
var = strsep (&p, "="); var = strsep (&p, "=");
unsetenv (var); unsetenv (var);
free (tmp); free (tmp);
} }
tmp = NULL; tmp = NULL;
#endif #endif
STRLIST_FOREACH (env, p, i) STRLIST_FOREACH (env, p, i)
putenv (p); 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 (); softlevel = rc_get_runlevel ();
@@ -969,44 +969,44 @@ int main (int argc, char **argv)
for (i = 2; i < argc; i++) for (i = 2; i < argc; i++)
{ {
if (strlen (argv[i]) < 2 || argv[i][0] != '-' || argv[i][1] != '-') if (strlen (argv[i]) < 2 || argv[i][0] != '-' || argv[i][1] != '-')
continue; continue;
if (strcmp (argv[i], "--debug") == 0) if (strcmp (argv[i], "--debug") == 0)
setenv ("RC_DEBUG", "yes", 1); setenv ("RC_DEBUG", "yes", 1);
else if (strcmp (argv[i], "--help") == 0) else if (strcmp (argv[i], "--help") == 0)
{ {
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
else if (strcmp (argv[i],"--ifstarted") == 0) else if (strcmp (argv[i],"--ifstarted") == 0)
ifstarted = true; ifstarted = true;
else if (strcmp (argv[i], "--nocolour") == 0 || else if (strcmp (argv[i], "--nocolour") == 0 ||
strcmp (argv[i], "--nocolor") == 0) strcmp (argv[i], "--nocolor") == 0)
setenv ("RC_NOCOLOR", "yes", 1); setenv ("RC_NOCOLOR", "yes", 1);
else if (strcmp (argv[i], "--nodeps") == 0) else if (strcmp (argv[i], "--nodeps") == 0)
deps = false; deps = false;
else if (strcmp (argv[i], "--quiet") == 0) else if (strcmp (argv[i], "--quiet") == 0)
setenv ("RC_QUIET", "yes", 1); setenv ("RC_QUIET", "yes", 1);
else if (strcmp (argv[i], "--verbose") == 0) else if (strcmp (argv[i], "--verbose") == 0)
setenv ("RC_VERBOSE", "yes", 1); setenv ("RC_VERBOSE", "yes", 1);
else if (strcmp (argv[i], "--version") == 0) else if (strcmp (argv[i], "--version") == 0)
printf ("version me\n"); printf ("version me\n");
else 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 (ifstarted && ! rc_service_state (applet, rc_service_started))
{ {
if (! rc_is_env("RC_QUIET", "yes")) if (! rc_is_env("RC_QUIET", "yes"))
eerror ("ERROR: %s is not started", applet); eerror ("ERROR: %s is not started", applet);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
if (rc_is_env ("IN_HOTPLUG", "1")) if (rc_is_env ("IN_HOTPLUG", "1"))
{ {
if (! rc_is_env ("RC_HOTPLUG", "yes") || ! rc_allow_plug (applet)) 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 */ /* Setup a signal handler */
@@ -1025,71 +1025,71 @@ int main (int argc, char **argv)
{ {
/* Abort on a sighup here */ /* Abort on a sighup here */
if (sighup) if (sighup)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (strlen (argv[i]) < 2 || if (strlen (argv[i]) < 2 ||
(argv[i][0] == '-' && argv[i][1] == '-')) (argv[i][0] == '-' && argv[i][1] == '-'))
continue; continue;
/* Export the command we're running. /* Export the command we're running.
This is important as we stamp on the restart function now but This is important as we stamp on the restart function now but
some start/stop routines still need to behave differently if some start/stop routines still need to behave differently if
restarting. */ restarting. */
unsetenv ("RC_CMD"); unsetenv ("RC_CMD");
setenv ("RC_CMD", argv[i], 1); setenv ("RC_CMD", argv[i], 1);
doneone = true; doneone = true;
if (strcmp (argv[i], "conditionalrestart") == 0 || if (strcmp (argv[i], "conditionalrestart") == 0 ||
strcmp (argv[i], "condrestart") == 0) strcmp (argv[i], "condrestart") == 0)
{ {
if (rc_service_state (service, rc_service_started)) if (rc_service_state (service, rc_service_started))
svc_restart (service, deps); svc_restart (service, deps);
} }
else if (strcmp (argv[i], "restart") == 0) else if (strcmp (argv[i], "restart") == 0)
svc_restart (service, deps); svc_restart (service, deps);
else if (strcmp (argv[i], "start") == 0) else if (strcmp (argv[i], "start") == 0)
svc_start (service, deps); svc_start (service, deps);
else if (strcmp (argv[i], "status") == 0) else if (strcmp (argv[i], "status") == 0)
{ {
rc_service_state_t r = svc_status (service); rc_service_state_t r = svc_status (service);
retval = (int) r; retval = (int) r;
} }
else if (strcmp (argv[i], "stop") == 0) else if (strcmp (argv[i], "stop") == 0)
{ {
if (in_background) if (in_background)
get_started_services (); get_started_services ();
svc_stop (service, deps); svc_stop (service, deps);
if (! in_background && if (! in_background &&
! rc_runlevel_stopping () && ! rc_runlevel_stopping () &&
rc_service_state (service, rc_service_stopped)) rc_service_state (service, rc_service_stopped))
uncoldplug (applet); uncoldplug (applet);
if (in_background && if (in_background &&
rc_service_state (service, rc_service_inactive)) rc_service_state (service, rc_service_inactive))
{ {
char *svc; char *svc;
int j; int j;
STRLIST_FOREACH (restart_services, svc, j) STRLIST_FOREACH (restart_services, svc, j)
if (rc_service_state (svc, rc_service_stopped)) if (rc_service_state (svc, rc_service_stopped))
rc_schedule_start_service (service, svc); rc_schedule_start_service (service, svc);
} }
} }
else if (strcmp (argv[i], "zap") == 0) else if (strcmp (argv[i], "zap") == 0)
{ {
einfo ("Manually resetting %s to stopped state", applet); einfo ("Manually resetting %s to stopped state", applet);
rc_mark_service (applet, rc_service_stopped); rc_mark_service (applet, rc_service_stopped);
uncoldplug (applet); uncoldplug (applet);
} }
else if (strcmp (argv[i], "help") == 0) else if (strcmp (argv[i], "help") == 0)
{ {
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL); execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
else else
svc_exec (service, argv[i], NULL); svc_exec (service, argv[i], NULL);
/* Flush our buffered output if any */ /* Flush our buffered output if any */
eflush (); eflush ();
@@ -1103,7 +1103,7 @@ int main (int argc, char **argv)
{ {
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
return (retval); return (retval);

File diff suppressed because it is too large Load Diff