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

View File

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

View File

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

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

View File

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

View File

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

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,
int (*sortfunc) (const char *s1,
const char *s2))
int (*sortfunc) (const char *s1,
const char *s2))
{
char **newlist;
int i = 0;
@ -90,12 +90,12 @@ char **rc_strlist_delete (char **list, const char *item)
while (list[i])
if (! strcmp (list[i], item))
{
free (list[i]);
do
{
list[i] = list[i + 1];
i++;
} while (list[i]);
free (list[i]);
do
{
list[i] = list[i + 1];
i++;
} while (list[i]);
}
return (list);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

744
src/rc.c

File diff suppressed because it is too large Load Diff

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

View File

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

File diff suppressed because it is too large Load Diff