Re-indent to a standard tw of 8.

This commit is contained in:
Roy Marples 2008-01-11 15:51:40 +00:00
parent fec312d448
commit abde759d5b
19 changed files with 392 additions and 389 deletions

View File

@ -45,7 +45,7 @@ const char libeinfo_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#include <strings.h> #include <strings.h>
#include <syslog.h> #include <syslog.h>
#ifdef HAVE_TERMCAP #ifdef HAVE_TERMCAP
#include <termcap.h> # include <termcap.h>
#endif #endif
#include <unistd.h> #include <unistd.h>
@ -78,24 +78,24 @@ hidden_proto(ewarnx)
hidden_proto(ewend) hidden_proto(ewend)
hidden_proto(ewendv) hidden_proto(ewendv)
/* Incase we cannot work out how many columns from ioctl, supply a default */ /* Incase we cannot work out how many columns from ioctl, supply a default */
#define DEFAULT_COLS 80 #define DEFAULT_COLS 80
#define OK "ok" #define OK "ok"
#define NOT_OK "!!" #define NOT_OK "!!"
/* Number of spaces for an indent */ /* Number of spaces for an indent */
#define INDENT_WIDTH 2 #define INDENT_WIDTH 2
/* How wide can the indent go? */ /* How wide can the indent go? */
#define INDENT_MAX 40 #define INDENT_MAX 40
/* Default colours */ /* Default colours */
#define GOOD 2 #define GOOD 2
#define WARN 3 #define WARN 3
#define BAD 1 #define BAD 1
#define HILITE 6 #define HILITE 6
#define BRACKET 4 #define BRACKET 4
/* We fallback to these escape codes if termcap isn't available /* We fallback to these escape codes if termcap isn't available
* like say /usr isn't mounted */ * like say /usr isn't mounted */
@ -106,6 +106,12 @@ hidden_proto(ewendv)
#define ME "\033[m" #define ME "\033[m"
#define UP "\033[A" #define UP "\033[A"
#define _GET_CAP(_d, _c) strlcpy (_d, tgoto (_c, 0, 0), sizeof (_d));
#define _ASSIGN_CAP(_v) { \
_v = p; \
p += strlcpy (p, tmp, sizeof (ebuffer) - (p - ebuffer)) + 1; \
}
/* A pointer to a string to prefix to einfo/ewarn/eerror messages */ /* A pointer to a string to prefix to einfo/ewarn/eerror messages */
static const char *_eprefix = NULL; static const char *_eprefix = NULL;
@ -246,17 +252,17 @@ static bool yesno (const char *value)
} }
if (strcasecmp (value, "yes") == 0 || if (strcasecmp (value, "yes") == 0 ||
strcasecmp (value, "y") == 0 || strcasecmp (value, "y") == 0 ||
strcasecmp (value, "true") == 0 || strcasecmp (value, "true") == 0 ||
strcasecmp (value, "on") == 0 || strcasecmp (value, "on") == 0 ||
strcasecmp (value, "1") == 0) strcasecmp (value, "1") == 0)
return (true); return (true);
if (strcasecmp (value, "no") != 0 && if (strcasecmp (value, "no") != 0 &&
strcasecmp (value, "n") != 0 && strcasecmp (value, "n") != 0 &&
strcasecmp (value, "false") != 0 && strcasecmp (value, "false") != 0 &&
strcasecmp (value, "off") != 0 && strcasecmp (value, "off") != 0 &&
strcasecmp (value, "0") != 0) strcasecmp (value, "0") != 0)
errno = EINVAL; errno = EINVAL;
return (false); return (false);
@ -388,12 +394,6 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f)
} }
#endif #endif
#define _GET_CAP(_d, _c) strlcpy (_d, tgoto (_c, 0, 0), sizeof (_d));
#define _ASSIGN_CAP(_v) { \
_v = p; \
p += strlcpy (p, tmp, sizeof (ebuffer) - (p - ebuffer)) + 1; \
}
/* Now setup our colours */ /* Now setup our colours */
p = ebuffer; p = ebuffer;
for (i = 0; i < sizeof (ecolors) / sizeof (ecolors[0]); i++) { for (i = 0; i < sizeof (ecolors) / sizeof (ecolors[0]); i++) {
@ -402,7 +402,7 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f)
if (ecolors[i].name) { if (ecolors[i].name) {
const char *bold = _md; const char *bold = _md;
c = ecolors[i].def; c = ecolors[i].def;
/* See if the user wants to override the colour /* See if the user wants to override the colour
* We use a :col;bold: format like 2;1: for bold green * We use a :col;bold: format like 2;1: for bold green
* and 1;0: for a normal red */ * and 1;0: for a normal red */
@ -441,8 +441,8 @@ static bool colour_terminal (FILE * __EINFO_RESTRICT f)
} }
_GET_CAP (tmp, _ce) _GET_CAP (tmp, _ce)
_ASSIGN_CAP (flush) _ASSIGN_CAP (flush)
_GET_CAP (tmp, _up); _GET_CAP (tmp, _up);
_ASSIGN_CAP (up); _ASSIGN_CAP (up);
strlcpy (tmp, _ch, sizeof (tmp)); strlcpy (tmp, _ch, sizeof (tmp));
_ASSIGN_CAP (goto_column); _ASSIGN_CAP (goto_column);
@ -557,26 +557,27 @@ const char *ecolor (einfo_color_t color)
return (_ecolor (f, color)); return (_ecolor (f, color));
} }
#define LASTCMD(_cmd) \ #define LASTCMD(_cmd) { \
unsetenv ("EINFO_LASTCMD"); \ unsetenv ("EINFO_LASTCMD"); \
setenv ("EINFO_LASTCMD", _cmd, 1); setenv ("EINFO_LASTCMD", _cmd, 1); \
}
#define EINFOVN(_file, _color) \ #define EINFOVN(_file, _color) \
{ \ { \
char *_e = getenv ("EINFO_LASTCMD"); \ char *_e = getenv ("EINFO_LASTCMD"); \
if (_e && ! colour_terminal (_file) && strcmp (_e, "ewarn") != 0 && \ if (_e && ! colour_terminal (_file) && strcmp (_e, "ewarn") != 0 && \
_e[strlen (_e) - 1] == 'n') \ _e[strlen (_e) - 1] == 'n') \
fprintf (_file, "\n"); \ fprintf (_file, "\n"); \
if (_eprefix) \ if (_eprefix) \
fprintf (_file, "%s%s%s|", _ecolor (_file, _color), _eprefix, _ecolor (_file, ECOLOR_NORMAL)); \ fprintf (_file, "%s%s%s|", _ecolor (_file, _color), _eprefix, _ecolor (_file, ECOLOR_NORMAL)); \
fprintf (_file, " %s*%s ", _ecolor (_file, _color), _ecolor (_file, ECOLOR_NORMAL)); \ fprintf (_file, " %s*%s ", _ecolor (_file, _color), _ecolor (_file, ECOLOR_NORMAL)); \
retval += _eindent (_file); \ retval += _eindent (_file); \
{ \ { \
va_list _ap; \ va_list _ap; \
va_copy (_ap, ap); \ va_copy (_ap, ap); \
retval += vfprintf (_file, fmt, _ap) + 3; \ retval += vfprintf (_file, fmt, _ap) + 3; \
va_end (_ap); \ va_end (_ap); \
} \ } \
if (colour_terminal (_file)) \ if (colour_terminal (_file)) \
fprintf (_file, "%s", flush); \ fprintf (_file, "%s", flush); \
} }
@ -769,7 +770,7 @@ int ebegin (const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ebegin) hidden_def(ebegin)
static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color, static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color,
const char *msg) const char *msg)
{ {
int i; int i;
int cols; int cols;
@ -793,8 +794,8 @@ static void _eend (FILE * __EINFO_RESTRICT fp, int col, einfo_color_t color,
if (cols > 0 && colour_terminal (fp)) { if (cols > 0 && colour_terminal (fp)) {
fprintf (fp, "%s%s %s[%s%s%s]%s\n", up, tgoto (goto_column, 0, cols), fprintf (fp, "%s%s %s[%s%s%s]%s\n", up, tgoto (goto_column, 0, cols),
ecolor (ECOLOR_BRACKET), ecolor (color), msg, ecolor (ECOLOR_BRACKET), ecolor (color), msg,
ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL)); ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL));
} else { } else {
if (col > 0) if (col > 0)
for (i = 0; i < cols - col; i++) for (i = 0; i < cols - col; i++)
@ -823,8 +824,8 @@ static int _do_eend (const char *cmd, int retval, const char *__EINFO_RESTRICT f
} }
_eend (fp, col, _eend (fp, col,
retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD, retval == 0 ? ECOLOR_GOOD : ECOLOR_BAD,
retval == 0 ? OK : NOT_OK); retval == 0 ? OK : NOT_OK);
return (retval); return (retval);
} }
@ -1013,7 +1014,7 @@ hidden_def(ebeginv)
int eendv (int retval, const char *__EINFO_RESTRICT fmt, ...) int eendv (int retval, const char *__EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
if (! is_verbose ()) if (! is_verbose ())
return (0); return (0);

View File

@ -98,7 +98,7 @@ static bool pid_is_exec (pid_t pid, const char *exec)
} }
pid_t *rc_find_pids (const char *exec, const char *cmd, pid_t *rc_find_pids (const char *exec, const char *cmd,
uid_t uid, pid_t pid) uid_t uid, pid_t pid)
{ {
DIR *procdir; DIR *procdir;
struct dirent *entry; struct dirent *entry;
@ -192,7 +192,7 @@ librc_hidden_def(rc_find_pids)
# endif # endif
pid_t *rc_find_pids (const char *exec, const char *cmd, pid_t *rc_find_pids (const char *exec, const char *cmd,
uid_t uid, pid_t pid) uid_t uid, pid_t pid)
{ {
static kvm_t *kd = NULL; static kvm_t *kd = NULL;
char errbuf[_POSIX2_LINE_MAX]; char errbuf[_POSIX2_LINE_MAX];
@ -212,7 +212,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
#ifdef _KVM_GETPROC2 #ifdef _KVM_GETPROC2
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
&processes); &processes);
#else #else
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes); kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
#endif #endif
@ -226,7 +226,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
if (cmd) { if (cmd) {
if (! _GET_KINFO_COMM (kp[i]) || if (! _GET_KINFO_COMM (kp[i]) ||
strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0) strcmp (cmd, _GET_KINFO_COMM (kp[i])) != 0)
continue; continue;
} }
@ -262,8 +262,8 @@ librc_hidden_def(rc_find_pids)
#endif #endif
static bool _match_daemon (const char *path, const char *file, static bool _match_daemon (const char *path, const char *file,
const char *mexec, const char *mname, const char *mexec, const char *mname,
const char *mpidfile) const char *mpidfile)
{ {
char *line; char *line;
char *ffile = rc_strcatpaths (path, file, (char *) NULL); char *ffile = rc_strcatpaths (path, file, (char *) NULL);
@ -304,8 +304,8 @@ static bool _match_daemon (const char *path, const char *file,
} }
bool rc_service_daemon_set (const char *service, const char *exec, bool rc_service_daemon_set (const char *service, const char *exec,
const char *name, const char *pidfile, const char *name, const char *pidfile,
bool started) bool started)
{ {
char *dirpath; char *dirpath;
char *file = NULL; char *file = NULL;
@ -325,7 +325,7 @@ bool rc_service_daemon_set (const char *service, const char *exec,
} }
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", dirpath = rc_strcatpaths (RC_SVCDIR, "daemons",
basename_c (service), (char *) NULL); basename_c (service), (char *) NULL);
if (exec) { if (exec) {
i = strlen (exec) + 6; i = strlen (exec) + 6;
@ -358,7 +358,7 @@ bool rc_service_daemon_set (const char *service, const char *exec,
if (! oldfile) { if (! oldfile) {
if (_match_daemon (dirpath, d->d_name, if (_match_daemon (dirpath, d->d_name,
mexec, mname, mpidfile)) mexec, mname, mpidfile))
{ {
unlink (file); unlink (file);
oldfile = file; oldfile = file;
@ -402,7 +402,7 @@ bool rc_service_daemon_set (const char *service, const char *exec,
librc_hidden_def(rc_service_daemon_set) librc_hidden_def(rc_service_daemon_set)
bool rc_service_started_daemon (const char *service, const char *exec, bool rc_service_started_daemon (const char *service, const char *exec,
int indx) int indx)
{ {
char *dirpath; char *dirpath;
char *file; char *file;
@ -416,8 +416,8 @@ bool rc_service_started_daemon (const char *service, const char *exec,
return (false); return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename_c (service), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename_c (service),
(char *) NULL); (char *) NULL);
i = strlen (exec) + 6; i = strlen (exec) + 6;
mexec = xmalloc (sizeof (char) * i); mexec = xmalloc (sizeof (char) * i);
snprintf (mexec, i, "exec=%s", exec); snprintf (mexec, i, "exec=%s", exec);
@ -468,7 +468,7 @@ bool rc_service_daemons_crashed (const char *service)
return (false); return (false);
dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename_c (service), dirpath = rc_strcatpaths (RC_SVCDIR, "daemons", basename_c (service),
(char *) NULL); (char *) NULL);
if (! (dp = opendir (dirpath))) { if (! (dp = opendir (dirpath))) {
free (dirpath); free (dirpath);

View File

@ -89,7 +89,7 @@ void rc_deptree_free (rc_depinfo_t *deptree)
librc_hidden_def(rc_deptree_free) librc_hidden_def(rc_deptree_free)
static rc_depinfo_t *get_depinfo (const rc_depinfo_t *deptree, static rc_depinfo_t *get_depinfo (const rc_depinfo_t *deptree,
const char *service) const char *service)
{ {
const rc_depinfo_t *di; const rc_depinfo_t *di;
@ -104,7 +104,7 @@ static rc_depinfo_t *get_depinfo (const rc_depinfo_t *deptree,
} }
static rc_deptype_t *get_deptype (const rc_depinfo_t *depinfo, static rc_deptype_t *get_deptype (const rc_depinfo_t *depinfo,
const char *type) const char *type)
{ {
rc_deptype_t *dt; rc_deptype_t *dt;
@ -212,16 +212,16 @@ static bool valid_service (const char *runlevel, const char *service)
rc_service_state_t state = rc_service_state (service); rc_service_state_t state = rc_service_state (service);
return ((strcmp (runlevel, bootlevel) != 0 && return ((strcmp (runlevel, bootlevel) != 0 &&
rc_service_in_runlevel (service, bootlevel)) || rc_service_in_runlevel (service, bootlevel)) ||
rc_service_in_runlevel (service, runlevel) || rc_service_in_runlevel (service, runlevel) ||
state & RC_SERVICE_COLDPLUGGED || state & RC_SERVICE_COLDPLUGGED ||
state & RC_SERVICE_STARTED); state & RC_SERVICE_STARTED);
} }
static bool get_provided1 (const char *runlevel, struct lhead *providers, static bool get_provided1 (const char *runlevel, struct lhead *providers,
rc_deptype_t *deptype, rc_deptype_t *deptype,
const char *level, bool coldplugged, const char *level, bool coldplugged,
rc_service_state_t state) rc_service_state_t state)
{ {
char *service; char *service;
int i; int i;
@ -235,8 +235,8 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
ok = rc_service_in_runlevel (service, level); ok = rc_service_in_runlevel (service, level);
else if (coldplugged) else if (coldplugged)
ok = (s & RC_SERVICE_COLDPLUGGED && ok = (s & RC_SERVICE_COLDPLUGGED &&
! rc_service_in_runlevel (service, runlevel) && ! rc_service_in_runlevel (service, runlevel) &&
! rc_service_in_runlevel (service, bootlevel)); ! rc_service_in_runlevel (service, bootlevel));
if (! ok) if (! ok)
continue; continue;
@ -249,8 +249,8 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
case RC_SERVICE_STARTING: case RC_SERVICE_STARTING:
case RC_SERVICE_STOPPING: case RC_SERVICE_STOPPING:
ok = (s & RC_SERVICE_STARTING || ok = (s & RC_SERVICE_STARTING ||
s & RC_SERVICE_STOPPING || s & RC_SERVICE_STOPPING ||
s & RC_SERVICE_INACTIVE); s & RC_SERVICE_INACTIVE);
break; break;
default: default:
break; break;
@ -276,8 +276,8 @@ static bool get_provided1 (const char *runlevel, struct lhead *providers,
provided dependancy can change depending on runlevel state. provided dependancy can change depending on runlevel state.
*/ */
static char **get_provided (const rc_depinfo_t *deptree, static char **get_provided (const rc_depinfo_t *deptree,
const rc_depinfo_t *depinfo, const rc_depinfo_t *depinfo,
const char *runlevel, int options) const char *runlevel, int options)
{ {
rc_deptype_t *dt; rc_deptype_t *dt;
struct lhead providers; struct lhead providers;
@ -286,7 +286,7 @@ static char **get_provided (const rc_depinfo_t *deptree,
if (! deptree || ! depinfo) if (! deptree || ! depinfo)
return (NULL); return (NULL);
if (rc_service_exists (depinfo->service)) if (rc_service_exists (depinfo->service))
return (NULL); return (NULL);
@ -312,7 +312,7 @@ static char **get_provided (const rc_depinfo_t *deptree,
{ {
STRLIST_FOREACH (dt->services, service, i) STRLIST_FOREACH (dt->services, service, i)
if (rc_service_in_runlevel (service, runlevel) || if (rc_service_in_runlevel (service, runlevel) ||
rc_service_in_runlevel (service, bootlevel)) rc_service_in_runlevel (service, bootlevel))
rc_strlist_add (&providers.list, service); rc_strlist_add (&providers.list, service);
if (providers.list) if (providers.list)
@ -373,7 +373,7 @@ static char **get_provided (const rc_depinfo_t *deptree,
return (providers.list); return (providers.list);
if (bootlevel && (strcmp (runlevel, bootlevel) != 0) if (bootlevel && (strcmp (runlevel, bootlevel) != 0)
&& (get_provided1 (runlevel, &providers, dt, bootlevel, false, RC_SERVICE_STOPPED))) && (get_provided1 (runlevel, &providers, dt, bootlevel, false, RC_SERVICE_STOPPED)))
return (providers.list); return (providers.list);
/* Still nothing? OK, list all services */ /* Still nothing? OK, list all services */
@ -384,10 +384,10 @@ static char **get_provided (const rc_depinfo_t *deptree,
} }
static void visit_service (const rc_depinfo_t *deptree, static void visit_service (const rc_depinfo_t *deptree,
const char * const *types, const char * const *types,
struct lhead *sorted, struct lhead *visited, struct lhead *sorted, struct lhead *visited,
const rc_depinfo_t *depinfo, const rc_depinfo_t *depinfo,
const char *runlevel, int options) const char *runlevel, int options)
{ {
int i, j, k; int i, j, k;
char *lp; char *lp;
@ -428,26 +428,26 @@ static void visit_service (const rc_depinfo_t *deptree,
{ {
di = get_depinfo (deptree, lp); di = get_depinfo (deptree, lp);
if (di && (strcmp (item, "ineed") == 0 || if (di && (strcmp (item, "ineed") == 0 ||
strcmp (item, "needsme") == 0 || strcmp (item, "needsme") == 0 ||
valid_service (runlevel, di->service))) valid_service (runlevel, di->service)))
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
} }
rc_strlist_free (provides); rc_strlist_free (provides);
} }
else else
if (di && (strcmp (item, "ineed") == 0 || if (di && (strcmp (item, "ineed") == 0 ||
strcmp (item, "needsme") == 0 || strcmp (item, "needsme") == 0 ||
valid_service (runlevel, service))) valid_service (runlevel, service)))
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
} }
} }
} }
/* Now visit the stuff we provide for */ /* Now visit the stuff we provide for */
if (options & RC_DEP_TRACE && if (options & RC_DEP_TRACE &&
(dt = get_deptype (depinfo, "iprovide"))) (dt = get_deptype (depinfo, "iprovide")))
{ {
STRLIST_FOREACH (dt->services, service, i) STRLIST_FOREACH (dt->services, service, i)
{ {
@ -458,7 +458,7 @@ static void visit_service (const rc_depinfo_t *deptree,
if (strcmp (lp, depinfo->service) == 0) if (strcmp (lp, depinfo->service) == 0)
{ {
visit_service (deptree, types, sorted, visited, di, visit_service (deptree, types, sorted, visited, di,
runlevel, options | RC_DEP_TRACE); runlevel, options | RC_DEP_TRACE);
break; break;
} }
rc_strlist_free (provides); rc_strlist_free (provides);
@ -475,7 +475,7 @@ static void visit_service (const rc_depinfo_t *deptree,
} }
char **rc_deptree_depend (const rc_depinfo_t *deptree, char **rc_deptree_depend (const rc_depinfo_t *deptree,
const char *service, const char *type) const char *service, const char *type)
{ {
rc_depinfo_t *di; rc_depinfo_t *di;
rc_deptype_t *dt; rc_deptype_t *dt;
@ -484,7 +484,7 @@ char **rc_deptree_depend (const rc_depinfo_t *deptree,
char *svc; char *svc;
if (! (di = get_depinfo (deptree, service)) || if (! (di = get_depinfo (deptree, service)) ||
! (dt = get_deptype (di, type))) ! (dt = get_deptype (di, type)))
{ {
errno = ENOENT; errno = ENOENT;
return (NULL); return (NULL);
@ -499,9 +499,9 @@ char **rc_deptree_depend (const rc_depinfo_t *deptree,
librc_hidden_def(rc_deptree_depend) librc_hidden_def(rc_deptree_depend)
char **rc_deptree_depends (const rc_depinfo_t *deptree, char **rc_deptree_depends (const rc_depinfo_t *deptree,
const char *const *types, const char *const *types,
const char *const *services, const char *const *services,
const char *runlevel, int options) const char *runlevel, int options)
{ {
struct lhead sorted; struct lhead sorted;
struct lhead visited; struct lhead visited;
@ -527,7 +527,7 @@ char **rc_deptree_depends (const rc_depinfo_t *deptree,
} }
if (types) if (types)
visit_service (deptree, types, &sorted, &visited, visit_service (deptree, types, &sorted, &visited,
di, runlevel, options); di, runlevel, options);
} }
rc_strlist_free (visited.list); rc_strlist_free (visited.list);
@ -535,9 +535,9 @@ char **rc_deptree_depends (const rc_depinfo_t *deptree,
} }
librc_hidden_def(rc_deptree_depends) librc_hidden_def(rc_deptree_depends)
static const char * const order_types[] = { "ineed", "iuse", "iafter", NULL }; static const char * const order_types[] = { "ineed", "iuse", "iafter", NULL };
char **rc_deptree_order (const rc_depinfo_t *deptree, const char *runlevel, char **rc_deptree_order (const rc_depinfo_t *deptree, const char *runlevel,
int options) int options)
{ {
char **list = NULL; char **list = NULL;
char **services = NULL; char **services = NULL;
@ -553,8 +553,8 @@ char **rc_deptree_order (const rc_depinfo_t *deptree, const char *runlevel,
/* When shutting down, list all running services */ /* When shutting down, list all running services */
if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 ||
strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 || strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (runlevel, RC_LEVEL_REBOOT) == 0) strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
{ {
list = rc_services_in_state (RC_SERVICE_STARTED); list = rc_services_in_state (RC_SERVICE_STARTED);
@ -585,8 +585,8 @@ char **rc_deptree_order (const rc_depinfo_t *deptree, const char *runlevel,
/* Now we have our lists, we need to pull in any dependencies /* Now we have our lists, we need to pull in any dependencies
and order them */ and order them */
services = rc_deptree_depends (deptree, order_types, (const char **) list, services = rc_deptree_depends (deptree, order_types, (const char **) list,
runlevel, runlevel,
RC_DEP_STRICT | RC_DEP_TRACE | options); RC_DEP_STRICT | RC_DEP_TRACE | options);
rc_strlist_free (list); rc_strlist_free (list);
if (reverse) if (reverse)
@ -680,10 +680,10 @@ bool rc_deptree_update_needed (void)
/* Quick test to see if anything we use has changed */ /* Quick test to see if anything we use has changed */
if (! is_newer_than (RC_DEPTREE, RC_INITDIR) || if (! is_newer_than (RC_DEPTREE, RC_INITDIR) ||
! is_newer_than (RC_DEPTREE, RC_CONFDIR) || ! is_newer_than (RC_DEPTREE, RC_CONFDIR) ||
! is_newer_than (RC_DEPTREE, RC_INITDIR_LOCAL) || ! is_newer_than (RC_DEPTREE, RC_INITDIR_LOCAL) ||
! is_newer_than (RC_DEPTREE, RC_CONFDIR_LOCAL) || ! is_newer_than (RC_DEPTREE, RC_CONFDIR_LOCAL) ||
! is_newer_than (RC_DEPTREE, "/etc/rc.conf")) ! is_newer_than (RC_DEPTREE, "/etc/rc.conf"))
return (true); return (true);
/* Some init scripts dependencies change depending on config files /* Some init scripts dependencies change depending on config files
@ -701,14 +701,14 @@ bool rc_deptree_update_needed (void)
} }
librc_hidden_def(rc_deptree_update_needed) librc_hidden_def(rc_deptree_update_needed)
/* This is a 5 phase operation /* This is a 5 phase operation
Phase 1 is a shell script which loads each init script and config in turn Phase 1 is a shell script which loads each init script and config in turn
and echos their dependency info to stdout and echos their dependency info to stdout
Phase 2 takes that and populates a depinfo object with that data Phase 2 takes that and populates a depinfo object with that data
Phase 3 adds any provided services to the depinfo object Phase 3 adds any provided services to the depinfo object
Phase 4 scans that depinfo object and puts in backlinks Phase 4 scans that depinfo object and puts in backlinks
Phase 5 saves the depinfo object to disk Phase 5 saves the depinfo object to disk
*/ */
bool rc_deptree_update (void) bool rc_deptree_update (void)
{ {
char *depends; char *depends;
@ -819,9 +819,9 @@ bool rc_deptree_update (void)
/* .sh files are not init scripts */ /* .sh files are not init scripts */
len = strlen (depend); len = strlen (depend);
if (len > 2 && if (len > 2 &&
depend[len - 3] == '.' && depend[len - 3] == '.' &&
depend[len - 2] == 's' && depend[len - 2] == 's' &&
depend[len - 1] == 'h') depend[len - 1] == 'h')
continue; continue;
rc_strlist_addsort (&deptype->services, depend); rc_strlist_addsort (&deptype->services, depend);
@ -835,8 +835,8 @@ bool rc_deptree_update (void)
} }
/* If we're after something, remove us from the before list */ /* If we're after something, remove us from the before list */
if (strcmp (type, "iafter") == 0 || if (strcmp (type, "iafter") == 0 ||
strcmp (type, "ineed") == 0 || strcmp (type, "ineed") == 0 ||
strcmp (type, "iuse") == 0) { strcmp (type, "iuse") == 0) {
if ((dt = get_deptype (depinfo, "ibefore"))) if ((dt = get_deptype (depinfo, "ibefore")))
rc_strlist_delete (&dt->services, depend); rc_strlist_delete (&dt->services, depend);
} }
@ -886,8 +886,8 @@ next:
if (strcmp (deptype->type, "ineed") == 0) if (strcmp (deptype->type, "ineed") == 0)
{ {
fprintf (stderr, fprintf (stderr,
"Service `%s' needs non existant service `%s'\n", "Service `%s' needs non existant service `%s'\n",
depinfo->service, service); depinfo->service, service);
} }
continue; continue;
} }
@ -947,7 +947,7 @@ next:
STRLIST_FOREACH (deptype->services, service, j) STRLIST_FOREACH (deptype->services, service, j)
{ {
fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type, fprintf (fp, "depinfo_%d_%s_%d='%s'\n", i, deptype->type,
k, service); k, service);
k++; k++;
} }
} }

View File

@ -39,15 +39,15 @@ bool rc_yesno (const char *value)
} }
if (strcasecmp (value, "yes") == 0 || if (strcasecmp (value, "yes") == 0 ||
strcasecmp (value, "y") == 0 || strcasecmp (value, "y") == 0 ||
strcasecmp (value, "true") == 0 || strcasecmp (value, "true") == 0 ||
strcasecmp (value, "1") == 0) strcasecmp (value, "1") == 0)
return (true); return (true);
if (strcasecmp (value, "no") != 0 && if (strcasecmp (value, "no") != 0 &&
strcasecmp (value, "n") != 0 && strcasecmp (value, "n") != 0 &&
strcasecmp (value, "false") != 0 && strcasecmp (value, "false") != 0 &&
strcasecmp (value, "0") != 0) strcasecmp (value, "0") != 0)
errno = EINVAL; errno = EINVAL;
return (false); return (false);

View File

@ -71,9 +71,9 @@ char *rc_strlist_addu (char ***list, const char *item)
librc_hidden_def(rc_strlist_addu) librc_hidden_def(rc_strlist_addu)
static char *_rc_strlist_addsort (char ***list, const char *item, static char *_rc_strlist_addsort (char ***list, const char *item,
int (*sortfunc) (const char *s1, int (*sortfunc) (const char *s1,
const char *s2), const char *s2),
bool uniq) bool uniq)
{ {
char **newlist; char **newlist;
char **lst = *list; char **lst = *list;

View File

@ -90,8 +90,8 @@ static char **ls_dir (const char *dir, int options)
/* .sh files are not init scripts */ /* .sh files are not init scripts */
if (l > 2 && d->d_name[l - 3] == '.' && if (l > 2 && d->d_name[l - 3] == '.' &&
d->d_name[l - 2] == 's' && d->d_name[l - 2] == 's' &&
d->d_name[l - 1] == 'h') d->d_name[l - 1] == 'h')
continue; continue;
} }
if (options & LS_DIR) { if (options & LS_DIR) {
@ -227,7 +227,7 @@ bool rc_runlevel_exists (const char *runlevel)
} }
librc_hidden_def(rc_runlevel_exists) librc_hidden_def(rc_runlevel_exists)
/* Resolve a service name to it's full path */ /* Resolve a service name to it's full path */
char *rc_service_resolve (const char *service) char *rc_service_resolve (const char *service)
{ {
char buffer[PATH_MAX]; char buffer[PATH_MAX];
@ -285,8 +285,8 @@ bool rc_service_exists (const char *service)
/* .sh files are not init scripts */ /* .sh files are not init scripts */
if (len > 2 && service[len - 3] == '.' && if (len > 2 && service[len - 3] == '.' &&
service[len - 2] == 's' && service[len - 2] == 's' &&
service[len - 1] == 'h') service[len - 1] == 'h')
return (false); return (false);
if (! (file = rc_service_resolve (service))) if (! (file = rc_service_resolve (service)))
@ -367,7 +367,7 @@ bool rc_service_in_runlevel (const char *service, const char *runlevel)
return (false); return (false);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service),
(char *) NULL); (char *) NULL);
retval = exists (file); retval = exists (file);
free (file); free (file);
@ -396,7 +396,7 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
} }
file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), base, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), base,
(char *) NULL); (char *) NULL);
if (exists (file)) if (exists (file))
unlink (file); unlink (file);
i = symlink (init, file); i = symlink (init, file);
@ -420,21 +420,21 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
int s = rc_service_state_names[i].state; int s = rc_service_state_names[i].state;
if ((s != skip_state && if ((s != skip_state &&
s != RC_SERVICE_STOPPED && s != RC_SERVICE_STOPPED &&
s != RC_SERVICE_COLDPLUGGED && s != RC_SERVICE_COLDPLUGGED &&
s != RC_SERVICE_SCHEDULED) && s != RC_SERVICE_SCHEDULED) &&
(! skip_wasinactive || s != RC_SERVICE_WASINACTIVE)) (! skip_wasinactive || s != RC_SERVICE_WASINACTIVE))
{ {
file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (s), base, file = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (s), base,
(char *) NULL); (char *) NULL);
if (exists (file)) { if (exists (file)) {
if ((state == RC_SERVICE_STARTING || if ((state == RC_SERVICE_STARTING ||
state == RC_SERVICE_STOPPING) && state == RC_SERVICE_STOPPING) &&
s == RC_SERVICE_INACTIVE) s == RC_SERVICE_INACTIVE)
{ {
char *wasfile = rc_strcatpaths (RC_SVCDIR, char *wasfile = rc_strcatpaths (RC_SVCDIR,
rc_parse_service_state (RC_SERVICE_WASINACTIVE), rc_parse_service_state (RC_SERVICE_WASINACTIVE),
base, (char *) NULL); base, (char *) NULL);
symlink (init, wasfile); symlink (init, wasfile);
skip_wasinactive = true; skip_wasinactive = true;
@ -448,8 +448,8 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
/* Remove the exclusive state if we're inactive */ /* Remove the exclusive state if we're inactive */
if (state == RC_SERVICE_STARTED || if (state == RC_SERVICE_STARTED ||
state == RC_SERVICE_STOPPED || state == RC_SERVICE_STOPPED ||
state == RC_SERVICE_INACTIVE) state == RC_SERVICE_INACTIVE)
{ {
file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL); file = rc_strcatpaths (RC_SVCDIR, "exclusive", base, (char *) NULL);
unlink (file); unlink (file);
@ -504,7 +504,7 @@ rc_service_state_t rc_service_state (const char *service)
for (i = 0; rc_service_state_names[i].name; i++) { for (i = 0; rc_service_state_names[i].name; i++) {
char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name, char *file = rc_strcatpaths (RC_SVCDIR, rc_service_state_names[i].name,
basename_c (service), (char*) NULL); basename_c (service), (char*) NULL);
if (exists (file)) { if (exists (file)) {
if (rc_service_state_names[i].state <= 0x10) if (rc_service_state_names[i].state <= 0x10)
state = rc_service_state_names[i].state; state = rc_service_state_names[i].state;
@ -531,7 +531,7 @@ char *rc_service_value_get (const char *service, const char *option)
FILE *fp; FILE *fp;
char *line = NULL; char *line = NULL;
char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option, char *file = rc_strcatpaths (RC_SVCDIR, "options", service, option,
(char *) NULL); (char *) NULL);
if ((fp = fopen (file, "r"))) { if ((fp = fopen (file, "r"))) {
line = rc_getline (fp); line = rc_getline (fp);
@ -544,7 +544,7 @@ char *rc_service_value_get (const char *service, const char *option)
librc_hidden_def(rc_service_value_get) librc_hidden_def(rc_service_value_get)
bool rc_service_value_set (const char *service, const char *option, bool rc_service_value_set (const char *service, const char *option,
const char *value) const char *value)
{ {
FILE *fp; FILE *fp;
char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL); char *path = rc_strcatpaths (RC_SVCDIR, "options", service, (char *) NULL);
@ -585,7 +585,7 @@ static pid_t _exec_service (const char *service, const char *arg)
/* We create a fifo so that other services can wait until we complete */ /* We create a fifo so that other services can wait until we complete */
fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename_c (service), fifo = rc_strcatpaths (RC_SVCDIR, "exclusive", basename_c (service),
(char *) NULL); (char *) NULL);
if (mkfifo (fifo, 0600) != 0 && errno != EEXIST) { if (mkfifo (fifo, 0600) != 0 && errno != EEXIST) {
free (fifo); free (fifo);
@ -638,7 +638,7 @@ pid_t rc_service_start (const char *service)
librc_hidden_def(rc_service_start) librc_hidden_def(rc_service_start)
bool rc_service_schedule_start (const char *service, bool rc_service_schedule_start (const char *service,
const char *service_to_start) const char *service_to_start)
{ {
char *dir; char *dir;
char *init; char *init;
@ -650,7 +650,7 @@ bool rc_service_schedule_start (const char *service,
return (false); return (false);
dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service), dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service),
(char *) NULL); (char *) NULL);
if (mkdir (dir, 0755) != 0 && errno != EEXIST) { if (mkdir (dir, 0755) != 0 && errno != EEXIST) {
free (dir); free (dir);
return (false); return (false);
@ -670,7 +670,7 @@ librc_hidden_def(rc_service_schedule_start)
bool rc_service_schedule_clear (const char *service) bool rc_service_schedule_clear (const char *service)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service), char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service),
(char *) NULL); (char *) NULL);
bool retval; bool retval;
if (! (retval = rm_dir (dir, true)) && errno == ENOENT) if (! (retval = rm_dir (dir, true)) && errno == ENOENT)
@ -699,7 +699,7 @@ char **rc_services_in_runlevel (const char *runlevel)
/* These special levels never contain any services */ /* These special levels never contain any services */
if (strcmp (runlevel, RC_LEVEL_SYSINIT) == 0 || if (strcmp (runlevel, RC_LEVEL_SYSINIT) == 0 ||
strcmp (runlevel, RC_LEVEL_SINGLE) == 0) strcmp (runlevel, RC_LEVEL_SINGLE) == 0)
return (NULL); return (NULL);
dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL); dir = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, (char *) NULL);
@ -712,7 +712,7 @@ librc_hidden_def(rc_services_in_runlevel)
char **rc_services_in_state (rc_service_state_t state) char **rc_services_in_state (rc_service_state_t state)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state), char *dir = rc_strcatpaths (RC_SVCDIR, rc_parse_service_state (state),
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
if (state == RC_SERVICE_SCHEDULED) { if (state == RC_SERVICE_SCHEDULED) {
@ -776,7 +776,7 @@ bool rc_service_add (const char *runlevel, const char *service)
} }
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service),
(char *) NULL); (char *) NULL);
retval = (symlink (init, file) == 0); retval = (symlink (init, file) == 0);
free (init); free (init);
free (file); free (file);
@ -793,7 +793,7 @@ bool rc_service_delete (const char *runlevel, const char *service)
return (false); return (false);
file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service), file = rc_strcatpaths (RC_RUNLEVELDIR, runlevel, basename_c (service),
(char *) NULL); (char *) NULL);
if (unlink (file) == 0) if (unlink (file) == 0)
retval = true; retval = true;
@ -811,7 +811,7 @@ char **rc_services_scheduled_by (const char *service)
STRLIST_FOREACH (dirs, dir, i) { STRLIST_FOREACH (dirs, dir, i) {
char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service, char *file = rc_strcatpaths (RC_SVCDIR, "scheduled", dir, service,
(char *) NULL); (char *) NULL);
if (exists (file)) if (exists (file))
rc_strlist_add (&list, file); rc_strlist_add (&list, file);
free (file); free (file);
@ -825,7 +825,7 @@ librc_hidden_def(rc_services_scheduled_by)
char **rc_services_scheduled (const char *service) char **rc_services_scheduled (const char *service)
{ {
char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service), char *dir = rc_strcatpaths (RC_SVCDIR, "scheduled", basename_c (service),
(char *) NULL); (char *) NULL);
char **list = NULL; char **list = NULL;
list = ls_dir (dir, LS_INITD); list = ls_dir (dir, LS_INITD);

View File

@ -37,7 +37,7 @@ static void usage (int exit_status)
printf ("\n\nOptions: [" getoptstring "]\n"); printf ("\n\nOptions: [" getoptstring "]\n");
for (i = 0; longopts[i].name; ++i) { for (i = 0; longopts[i].name; ++i) {
int len = printf (" -%c, --%s %s", longopts[i].val, longopts[i].name, int len = printf (" -%c, --%s %s", longopts[i].val, longopts[i].name,
has_arg[longopts[i].has_arg]); has_arg[longopts[i].has_arg]);
char *lo = xstrdup (longopts_help[i]); char *lo = xstrdup (longopts_help[i]);
char *p = lo; char *p = lo;

View File

@ -75,7 +75,7 @@ static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, int file)
} }
} else { } else {
if ((file && S_ISDIR (st.st_mode)) || if ((file && S_ISDIR (st.st_mode)) ||
(! file && ! S_ISDIR (st.st_mode))) (! file && ! S_ISDIR (st.st_mode)))
{ {
if (file) if (file)
eerror ("%s: is a directory", path); eerror ("%s: is a directory", path);
@ -84,7 +84,7 @@ static int do_check (char *path, uid_t uid, gid_t gid, mode_t mode, int file)
return (-1); return (-1);
} }
} }
if (mode && (st.st_mode & 0777) != mode) { if (mode && (st.st_mode & 0777) != mode) {
einfo ("%s: correcting mode", applet); einfo ("%s: correcting mode", applet);
if (chmod (path, mode)) { if (chmod (path, mode)) {
@ -126,7 +126,7 @@ static int parse_mode (mode_t *mode, char *text)
} }
static int parse_owner (struct passwd **user, struct group **group, static int parse_owner (struct passwd **user, struct group **group,
const char *owner) const char *owner)
{ {
char *u = xstrdup (owner); char *u = xstrdup (owner);
char *g = strchr (u, ':'); char *g = strchr (u, ':');
@ -164,7 +164,7 @@ static int parse_owner (struct passwd **user, struct group **group,
static struct option longopts[] = { static struct option longopts[] = {
{ "directory", 0, NULL, 'd'}, { "directory", 0, NULL, 'd'},
{ "file", 0, NULL, 'f'}, { "file", 0, NULL, 'f'},
{ "mode", 1, NULL, 'm'}, { "mode", 1, NULL, 'm'},
{ "owner", 1, NULL, 'o'}, { "owner", 1, NULL, 'o'},
longopts_COMMON longopts_COMMON
}; };
@ -191,7 +191,7 @@ int checkpath (int argc, char **argv)
applet = basename_c (argv[0]); applet = basename_c (argv[0]);
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 'd': case 'd':
@ -202,11 +202,13 @@ int checkpath (int argc, char **argv)
break; break;
case 'm': case 'm':
if (parse_mode (&mode, optarg) != 0) if (parse_mode (&mode, optarg) != 0)
eerrorx ("%s: invalid mode `%s'", applet, optarg); eerrorx ("%s: invalid mode `%s'",
applet, optarg);
break; break;
case 'o': case 'o':
if (parse_owner (&pw, &gr, optarg) != 0) if (parse_owner (&pw, &gr, optarg) != 0)
eerrorx ("%s: owner `%s' not found", applet, optarg); eerrorx ("%s: owner `%s' not found",
applet, optarg);
break; break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT

View File

@ -81,7 +81,7 @@ static struct mntent *getmntfile (const char *file)
if (strcmp (file, ent->mnt_dir) == 0) if (strcmp (file, ent->mnt_dir) == 0)
break; break;
END_ENT; END_ENT;
return (ent); return (ent);
} }
#endif #endif
@ -134,7 +134,7 @@ int fstabinfo (int argc, char **argv)
unsetenv ("EINFO_QUIET"); unsetenv ("EINFO_QUIET");
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 'b': case 'b':
@ -156,9 +156,9 @@ int fstabinfo (int argc, char **argv)
START_ENT; START_ENT;
while ((ent = GET_ENT)) { while ((ent = GET_ENT)) {
if (((optarg[0] == '=' && i == ENT_PASS (ent)) || if (((optarg[0] == '=' && i == ENT_PASS (ent)) ||
(optarg[0] == '<' && i > ENT_PASS (ent)) || (optarg[0] == '<' && i > ENT_PASS (ent)) ||
(optarg[0] == '>' && i < ENT_PASS (ent))) && (optarg[0] == '>' && i < ENT_PASS (ent))) &&
strcmp (ENT_FILE (ent), "none") != 0) strcmp (ENT_FILE (ent), "none") != 0)
rc_strlist_add (&files, ENT_FILE (ent)); rc_strlist_add (&files, ENT_FILE (ent));
} }
END_ENT; END_ENT;
@ -182,7 +182,7 @@ int fstabinfo (int argc, char **argv)
} }
break; break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
} }

View File

@ -86,8 +86,8 @@ struct args {
}; };
static int process_mount (char ***list, struct args *args, static int process_mount (char ***list, struct args *args,
char *from, char *to, char *fstype, char *options, char *from, char *to, char *fstype, char *options,
int netdev) int netdev)
{ {
char *p; char *p;
@ -107,24 +107,24 @@ static int process_mount (char ***list, struct args *args,
return (1); return (1);
} else { } else {
if (args->node_regex && if (args->node_regex &&
regexec (args->node_regex, from, 0, NULL, 0) != 0) regexec (args->node_regex, from, 0, NULL, 0) != 0)
return (1); return (1);
if (args->skip_node_regex && if (args->skip_node_regex &&
regexec (args->skip_node_regex, from, 0, NULL, 0) == 0) regexec (args->skip_node_regex, from, 0, NULL, 0) == 0)
return (1); return (1);
if (args->fstype_regex && if (args->fstype_regex &&
regexec (args->fstype_regex, fstype, 0, NULL, 0) != 0) regexec (args->fstype_regex, fstype, 0, NULL, 0) != 0)
return (-1); return (-1);
if (args->skip_fstype_regex && if (args->skip_fstype_regex &&
regexec (args->skip_fstype_regex, fstype, 0, NULL, 0) == 0) regexec (args->skip_fstype_regex, fstype, 0, NULL, 0) == 0)
return (-1); return (-1);
if (args->options_regex && if (args->options_regex &&
regexec (args->options_regex, options, 0, NULL, 0) != 0) regexec (args->options_regex, options, 0, NULL, 0) != 0)
return (-1); return (-1);
if (args->skip_options_regex && if (args->skip_options_regex &&
regexec (args->skip_options_regex, options, 0, NULL, 0) == 0) regexec (args->skip_options_regex, options, 0, NULL, 0) == 0)
return (-1); return (-1);
} }
@ -247,11 +247,11 @@ static char **find_mounts (struct args *args)
} }
process_mount (&list, args, process_mount (&list, args,
mnts[i].f_mntfromname, mnts[i].f_mntfromname,
mnts[i].f_mntonname, mnts[i].f_mntonname,
mnts[i].f_fstypename, mnts[i].f_fstypename,
options, options,
netdev); netdev);
free (options); free (options);
options = NULL; options = NULL;
@ -271,7 +271,7 @@ static struct mntent *getmntfile (const char *file)
if (strcmp (file, ent->mnt_dir) == 0) if (strcmp (file, ent->mnt_dir) == 0)
break; break;
endmntent (fp); endmntent (fp);
return (ent); return (ent);
} }
@ -395,7 +395,7 @@ int mountinfo (int argc, char **argv)
args.netdev = net_ignore; args.netdev = net_ignore;
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 'e': case 'e':
@ -456,7 +456,7 @@ int mountinfo (int argc, char **argv)
REG_FREE (args.skip_node_regex); REG_FREE (args.skip_node_regex);
REG_FREE (args.options_regex); REG_FREE (args.options_regex);
REG_FREE (args.skip_options_regex); REG_FREE (args.skip_options_regex);
rc_strlist_reverse (nodes); rc_strlist_reverse (nodes);
result = EXIT_FAILURE; result = EXIT_FAILURE;

View File

@ -99,7 +99,7 @@ int rc_depend (int argc, char **argv)
applet = basename_c (argv[0]); applet = basename_c (argv[0]);
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 's': case 's':
@ -116,7 +116,7 @@ int rc_depend (int argc, char **argv)
options &= RC_DEP_TRACE; options &= RC_DEP_TRACE;
break; break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
} }
@ -140,7 +140,7 @@ int rc_depend (int argc, char **argv)
rc_strlist_add (&list, argv[optind]); rc_strlist_add (&list, argv[optind]);
errno = 0; errno = 0;
depends = rc_deptree_depends (deptree, NULL, (const char **) list, depends = rc_deptree_depends (deptree, NULL, (const char **) list,
runlevel, 0); runlevel, 0);
if (! depends && errno == ENOENT) if (! depends && errno == ENOENT)
eerror ("no dependency info for service `%s'", argv[optind]); eerror ("no dependency info for service `%s'", argv[optind]);
else else
@ -167,7 +167,7 @@ int rc_depend (int argc, char **argv)
} }
depends = rc_deptree_depends (deptree, (const char **) types, depends = rc_deptree_depends (deptree, (const char **) types,
(const char **) services, runlevel, options); (const char **) services, runlevel, options);
if (depends) { if (depends) {
STRLIST_FOREACH (depends, service, i) { STRLIST_FOREACH (depends, service, i) {

View File

@ -96,7 +96,7 @@ static void write_log (int logfd, const char *buffer, size_t bytes)
in_term = true; in_term = true;
break; break;
} }
if (! in_escape) { if (! in_escape) {
write (logfd, p++, 1); write (logfd, p++, 1);
continue; continue;
@ -159,7 +159,7 @@ void rc_logger_open (const char *level)
eerrorx ("pipe: %s", strerror (errno)); eerrorx ("pipe: %s", strerror (errno));
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if ((s = fcntl (signal_pipe[i], F_GETFD, 0) == -1 || if ((s = fcntl (signal_pipe[i], F_GETFD, 0) == -1 ||
fcntl (signal_pipe[i], F_SETFD, s | FD_CLOEXEC) == -1)) fcntl (signal_pipe[i], F_SETFD, s | FD_CLOEXEC) == -1))
eerrorx ("fcntl: %s", strerror (errno)); eerrorx ("fcntl: %s", strerror (errno));
tcgetattr (STDOUT_FILENO, &tt); tcgetattr (STDOUT_FILENO, &tt);
@ -213,7 +213,7 @@ void rc_logger_open (const char *level)
if (logbuf_size - logbuf_len < bytes) { if (logbuf_size - logbuf_len < bytes) {
logbuf_size += BUFSIZ * 10; logbuf_size += BUFSIZ * 10;
logbuf = xrealloc (logbuf, sizeof (char ) * logbuf = xrealloc (logbuf, sizeof (char ) *
logbuf_size); logbuf_size);
} }
memcpy (logbuf + logbuf_len, buffer, bytes); memcpy (logbuf + logbuf_len, buffer, bytes);
@ -242,7 +242,7 @@ void rc_logger_open (const char *level)
/* Try and cat our new logfile to a more permament location and then /* Try and cat our new logfile to a more permament location and then
* punt it */ * punt it */
system (MOVELOG); system (MOVELOG);
exit (0); exit (0);
default: default:
setpgid (rc_logger_pid, 0); setpgid (rc_logger_pid, 0);
@ -251,8 +251,8 @@ void rc_logger_open (const char *level)
dup2 (slave_tty, STDOUT_FILENO); dup2 (slave_tty, STDOUT_FILENO);
dup2 (slave_tty, STDERR_FILENO); dup2 (slave_tty, STDERR_FILENO);
if (slave_tty != STDIN_FILENO && if (slave_tty != STDIN_FILENO &&
slave_tty != STDOUT_FILENO && slave_tty != STDOUT_FILENO &&
slave_tty != STDERR_FILENO) slave_tty != STDERR_FILENO)
close (slave_tty); close (slave_tty);
close (signal_pipe[0]); close (signal_pipe[0]);
signal_pipe[0] = -1; signal_pipe[0] = -1;

View File

@ -186,7 +186,7 @@ char **env_filter (void)
/* Ensure our PATH is prefixed with the system locations first /* Ensure our PATH is prefixed with the system locations first
for a little extra security */ for a little extra security */
if (strcmp (env_name, "PATH") == 0 && if (strcmp (env_name, "PATH") == 0 &&
strncmp (PATH_PREFIX, env_var, pplen) != 0) strncmp (PATH_PREFIX, env_var, pplen) != 0)
{ {
got_path = true; got_path = true;
env_len = strlen (env_name) + strlen (env_var) + pplen + 2; env_len = strlen (env_name) + strlen (env_var) + pplen + 2;
@ -233,7 +233,7 @@ char **env_filter (void)
return (env); return (env);
} }
/* Other systems may need this at some point, but for now it's Linux only */ /* Other systems may need this at some point, but for now it's Linux only */
#ifdef __linux__ #ifdef __linux__
static bool file_regex (const char *file, const char *regex) static bool file_regex (const char *file, const char *regex)
{ {
@ -338,7 +338,7 @@ char **env_config (void)
} else if (file_regex ("/proc/cpuinfo", "UML")) { } else if (file_regex ("/proc/cpuinfo", "UML")) {
snprintf (sys, sizeof (sys), "UML"); snprintf (sys, sizeof (sys), "UML");
} else if (file_regex ("/proc/self/status", } else if (file_regex ("/proc/self/status",
"(s_context|VxID|envID):[[:space:]]*[1-9]")) "(s_context|VxID|envID):[[:space:]]*[1-9]"))
{ {
snprintf (sys, sizeof (sys), "VPS"); snprintf (sys, sizeof (sys), "VPS");
} }
@ -381,7 +381,7 @@ char **env_config (void)
errno = 0; errno = 0;
if ((! rc_conf_yesno ("rc_color") && errno == 0) || if ((! rc_conf_yesno ("rc_color") && errno == 0) ||
rc_conf_yesno ("rc_nocolor")) rc_conf_yesno ("rc_nocolor"))
rc_strlist_add (&env, "EINFO_COLOR=no"); rc_strlist_add (&env, "EINFO_COLOR=no");
free (runlevel); free (runlevel);

View File

@ -167,7 +167,7 @@ void rc_plugin_run (rc_hook_t hook, const char *value)
* plugin will probably hang when running in silent mode. */ * plugin will probably hang when running in silent mode. */
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if ((flags = fcntl (pfd[i], F_GETFD, 0)) < 0 || if ((flags = fcntl (pfd[i], F_GETFD, 0)) < 0 ||
fcntl (pfd[i], F_SETFD, flags | FD_CLOEXEC) < 0) fcntl (pfd[i], F_SETFD, flags | FD_CLOEXEC) < 0)
eerror ("fcntl: %s", strerror (errno)); eerror ("fcntl: %s", strerror (errno));
/* We run the plugin in a new process so we never crash /* We run the plugin in a new process so we never crash
@ -214,7 +214,7 @@ void rc_plugin_run (rc_hook_t hook, const char *value)
} }
} }
} }
free (buffer); free (buffer);
close (pfd[0]); close (pfd[0]);

View File

@ -48,9 +48,9 @@ static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL };
static void print_level (char *level) static void print_level (char *level)
{ {
printf ("Runlevel: %s%s%s\n", printf ("Runlevel: %s%s%s\n",
ecolor (ECOLOR_HILITE), ecolor (ECOLOR_HILITE),
level, level,
ecolor (ECOLOR_NORMAL)); ecolor (ECOLOR_NORMAL));
} }
static void print_service (char *service) static void print_service (char *service)
@ -121,7 +121,7 @@ int rc_status (int argc, char **argv)
int depopts = RC_DEP_STRICT | RC_DEP_START | RC_DEP_TRACE; int depopts = RC_DEP_STRICT | RC_DEP_START | RC_DEP_TRACE;
while ((opt = getopt_long (argc, argv, getoptstring, longopts, while ((opt = getopt_long (argc, argv, getoptstring, longopts,
(int *) 0)) != -1) (int *) 0)) != -1)
switch (opt) { switch (opt) {
case 'a': case 'a':
levels = rc_runlevel_list (); levels = rc_runlevel_list ();
@ -155,7 +155,7 @@ int rc_status (int argc, char **argv)
rc_strlist_free (services); rc_strlist_free (services);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
while (optind < argc) while (optind < argc)
@ -178,8 +178,8 @@ int rc_status (int argc, char **argv)
services = rc_services_in_runlevel (level); services = rc_services_in_runlevel (level);
if (deptree) { if (deptree) {
ordered = rc_deptree_depends (deptree, types_nua, ordered = rc_deptree_depends (deptree, types_nua,
(const char **) services, (const char **) services,
level, depopts); level, depopts);
rc_strlist_free (services); rc_strlist_free (services);
services = ordered; services = ordered;
ordered = NULL; ordered = NULL;

View File

@ -59,14 +59,14 @@ static int add (const char *runlevel, const char *service)
eerror ("%s: service `%s' does not exist", applet, service); eerror ("%s: service `%s' does not exist", applet, service);
else if (rc_service_in_runlevel (service, runlevel)) { else if (rc_service_in_runlevel (service, runlevel)) {
ewarn ("%s: %s already installed in runlevel `%s'; skipping", ewarn ("%s: %s already installed in runlevel `%s'; skipping",
applet, service, runlevel); applet, service, runlevel);
retval = 0; retval = 0;
} else if (rc_service_add (runlevel, service)) { } else if (rc_service_add (runlevel, service)) {
einfo ("%s added to runlevel %s", service, runlevel); einfo ("%s added to runlevel %s", service, runlevel);
retval = 1; retval = 1;
} else } else
eerror ("%s: failed to add service `%s' to runlevel `%s': %s", eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
applet, service, runlevel, strerror (errno)); applet, service, runlevel, strerror (errno));
return (retval); return (retval);
} }
@ -83,10 +83,10 @@ static int delete (const char *runlevel, const char *service)
if (errno == ENOENT) if (errno == ENOENT)
eerror ("%s: service `%s' is not in the runlevel `%s'", eerror ("%s: service `%s' is not in the runlevel `%s'",
applet, service, runlevel); applet, service, runlevel);
else else
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s", eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
applet, service, runlevel, strerror (errno)); applet, service, runlevel, strerror (errno));
return (retval); return (retval);
} }
@ -162,7 +162,7 @@ int rc_update (int argc, char **argv)
applet = basename_c (argv[0]); applet = basename_c (argv[0]);
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 'a': case 'a':
@ -175,15 +175,15 @@ int rc_update (int argc, char **argv)
action |= DOSHOW; action |= DOSHOW;
break; break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
} }
verbose = rc_yesno (getenv ("EINFO_VERBOSE")); verbose = rc_yesno (getenv ("EINFO_VERBOSE"));
if ((action & DOSHOW && action != DOSHOW) || if ((action & DOSHOW && action != DOSHOW) ||
(action & DOADD && action != DOADD) || (action & DOADD && action != DOADD) ||
(action & DODELETE && action != DODELETE)) (action & DODELETE && action != DODELETE))
eerrorx ("%s: cannot mix commands", applet); eerrorx ("%s: cannot mix commands", applet);
/* We need to be backwards compatible */ /* We need to be backwards compatible */
@ -192,7 +192,7 @@ int rc_update (int argc, char **argv)
if (strcmp (argv[optind], "add") == 0) if (strcmp (argv[optind], "add") == 0)
action = DOADD; action = DOADD;
else if (strcmp (argv[optind], "delete") == 0 || else if (strcmp (argv[optind], "delete") == 0 ||
strcmp (argv[optind], "del") == 0) strcmp (argv[optind], "del") == 0)
action = DODELETE; action = DODELETE;
else if (strcmp (argv[optind], "show") == 0) else if (strcmp (argv[optind], "show") == 0)
action = DOSHOW; action = DOSHOW;

View File

@ -123,8 +123,8 @@ static void clean_failed (void)
if ((dp = opendir (RC_SVCDIR "/failed"))) { if ((dp = opendir (RC_SVCDIR "/failed"))) {
while ((d = readdir (dp))) { while ((d = readdir (dp))) {
if (d->d_name[0] == '.' && if (d->d_name[0] == '.' &&
(d->d_name[1] == '\0' || (d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0'))) (d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue; continue;
i = strlen (RC_SVCDIR "/failed/") + strlen (d->d_name) + 1; i = strlen (RC_SVCDIR "/failed/") + strlen (d->d_name) + 1;
@ -133,7 +133,7 @@ static void clean_failed (void)
if (path) { if (path) {
if (unlink (path)) if (unlink (path))
eerror ("%s: unlink `%s': %s", applet, path, eerror ("%s: unlink `%s': %s", applet, path,
strerror (errno)); strerror (errno));
free (path); free (path);
} }
} }
@ -147,7 +147,7 @@ static void cleanup (void)
pidlist_t *pl = service_pids; pidlist_t *pl = service_pids;
rc_plugin_unload (); rc_plugin_unload ();
if (! rc_in_plugin && termios_orig) { if (! rc_in_plugin && termios_orig) {
tcsetattr (fileno (stdin), TCSANOW, termios_orig); tcsetattr (fileno (stdin), TCSANOW, termios_orig);
free (termios_orig); free (termios_orig);
@ -204,21 +204,21 @@ static int do_e (int argc, char **argv)
if (strcmp (applet, "eval_ecolors") == 0) { if (strcmp (applet, "eval_ecolors") == 0) {
printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n", printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
ecolor (ECOLOR_GOOD), ecolor (ECOLOR_GOOD),
ecolor (ECOLOR_WARN), ecolor (ECOLOR_WARN),
ecolor (ECOLOR_BAD), ecolor (ECOLOR_BAD),
ecolor (ECOLOR_HILITE), ecolor (ECOLOR_HILITE),
ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_BRACKET),
ecolor (ECOLOR_NORMAL)); ecolor (ECOLOR_NORMAL));
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
if (argc > 0) { if (argc > 0) {
if (strcmp (applet, "eend") == 0 || if (strcmp (applet, "eend") == 0 ||
strcmp (applet, "ewend") == 0 || strcmp (applet, "ewend") == 0 ||
strcmp (applet, "veend") == 0 || strcmp (applet, "veend") == 0 ||
strcmp (applet, "vweend") == 0) strcmp (applet, "vweend") == 0)
{ {
errno = 0; errno = 0;
retval = strtol (argv[0], NULL, 0); retval = strtol (argv[0], NULL, 0);
@ -229,7 +229,7 @@ static int do_e (int argc, char **argv)
argv++; argv++;
} }
} else if (strcmp (applet, "esyslog") == 0 || } else if (strcmp (applet, "esyslog") == 0 ||
strcmp (applet, "elog") == 0) { strcmp (applet, "elog") == 0) {
char *dot = strchr (argv[0], '.'); char *dot = strchr (argv[0], '.');
if ((level = syslog_decode (dot + 1, prioritynames)) == -1) if ((level = syslog_decode (dot + 1, prioritynames)) == -1)
eerrorx ("%s: invalid log level `%s'", applet, argv[0]); eerrorx ("%s: invalid log level `%s'", applet, argv[0]);
@ -405,7 +405,7 @@ static int do_mark_service (int argc, char **argv)
if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1) if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1)
if (kill (pid, SIGHUP) != 0) if (kill (pid, SIGHUP) != 0)
eerror ("%s: failed to signal parent %d: %s", eerror ("%s: failed to signal parent %d: %s",
applet, pid, strerror (errno)); applet, pid, strerror (errno));
/* Remove the exclusive time test. This ensures that it's not /* Remove the exclusive time test. This ensures that it's not
in control as well */ in control as well */
@ -415,7 +415,7 @@ static int do_mark_service (int argc, char **argv)
4; 4;
mtime = xmalloc (l); mtime = xmalloc (l);
snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
svcname, runscript_pid); svcname, runscript_pid);
if (exists (mtime) && unlink (mtime) != 0) if (exists (mtime) && unlink (mtime) != 0)
eerror ("%s: unlink: %s", applet, strerror (errno)); eerror ("%s: unlink: %s", applet, strerror (errno));
free (mtime); free (mtime);
@ -436,7 +436,7 @@ static int do_value (int argc, char **argv)
eerrorx ("%s: no option specified", applet); eerrorx ("%s: no option specified", applet);
if (strcmp (applet, "service_get_value") == 0 || if (strcmp (applet, "service_get_value") == 0 ||
strcmp (applet, "get_options") == 0) strcmp (applet, "get_options") == 0)
{ {
char *option = rc_service_value_get (service, argv[0]); char *option = rc_service_value_get (service, argv[0]);
if (option) { if (option) {
@ -445,7 +445,7 @@ static int do_value (int argc, char **argv)
ok = true; ok = true;
} }
} else if (strcmp (applet, "service_set_value") == 0 || } else if (strcmp (applet, "service_set_value") == 0 ||
strcmp (applet, "save_options") == 0) strcmp (applet, "save_options") == 0)
ok = rc_service_value_set (service, argv[0], argv[1]); ok = rc_service_value_set (service, argv[0], argv[1]);
else else
eerrorx ("%s: unknown applet", applet); eerrorx ("%s: unknown applet", applet);
@ -493,7 +493,7 @@ static char *proc_getent (const char *ent)
} }
if ((proc = rc_getline (fp)) && if ((proc = rc_getline (fp)) &&
(p = strstr (proc, ent))) (p = strstr (proc, ent)))
{ {
i = p - proc; i = p - proc;
if (i == '\0' || proc[i - 1] == ' ') { if (i == '\0' || proc[i - 1] == ' ') {
@ -554,9 +554,9 @@ static bool want_interactive (void)
return (false); return (false);
if (PREVLEVEL && if (PREVLEVEL &&
strcmp (PREVLEVEL, "N") != 0 && strcmp (PREVLEVEL, "N") != 0 &&
strcmp (PREVLEVEL, "S") != 0 && strcmp (PREVLEVEL, "S") != 0 &&
strcmp (PREVLEVEL, "1") != 0) strcmp (PREVLEVEL, "1") != 0)
return (false); return (false);
if (! gotinteractive) { if (! gotinteractive) {
@ -609,11 +609,11 @@ static void sulogin (bool cont)
execle (SULOGIN, SULOGIN, (char *) NULL, newenv); execle (SULOGIN, SULOGIN, (char *) NULL, newenv);
eerror ("%s: unable to exec `%s': %s", applet, SULOGIN, eerror ("%s: unable to exec `%s': %s", applet, SULOGIN,
strerror (errno)); strerror (errno));
#else #else
execle ("/bin/sh", "/bin/sh", (char *) NULL, newenv); execle ("/bin/sh", "/bin/sh", (char *) NULL, newenv);
eerror ("%s: unable to exec `/bin/sh': %s", applet, eerror ("%s: unable to exec `/bin/sh': %s", applet,
strerror (errno)); strerror (errno));
#endif #endif
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
} }
@ -637,11 +637,11 @@ static void single_user (void)
#ifdef __linux__ #ifdef __linux__
execl ("/sbin/telinit", "/sbin/telinit", "S", (char *) NULL); execl ("/sbin/telinit", "/sbin/telinit", "S", (char *) NULL);
eerrorx ("%s: unable to exec `/sbin/telinit': %s", eerrorx ("%s: unable to exec `/sbin/telinit': %s",
applet, strerror (errno)); applet, strerror (errno));
#else #else
if (kill (1, SIGTERM) != 0) if (kill (1, SIGTERM) != 0)
eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s", eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s",
applet, strerror (errno)); applet, strerror (errno));
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
#endif #endif
} }
@ -651,12 +651,12 @@ static bool set_ksoftlevel (const char *level)
FILE *fp; FILE *fp;
if (! level || if (! level ||
strcmp (level, getenv ("RC_BOOTLEVEL")) == 0 || strcmp (level, getenv ("RC_BOOTLEVEL")) == 0 ||
strcmp (level, RC_LEVEL_SINGLE) == 0 || strcmp (level, RC_LEVEL_SINGLE) == 0 ||
strcmp (level, RC_LEVEL_SYSINIT) == 0) strcmp (level, RC_LEVEL_SYSINIT) == 0)
{ {
if (exists (RC_KSOFTLEVEL) && if (exists (RC_KSOFTLEVEL) &&
unlink (RC_KSOFTLEVEL) != 0) unlink (RC_KSOFTLEVEL) != 0)
eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
return (false); return (false);
} }
@ -786,11 +786,11 @@ static void handle_signal (int sig)
/* Only drop into single user mode if we're booting */ /* Only drop into single user mode if we're booting */
if ((PREVLEVEL && if ((PREVLEVEL &&
(strcmp (PREVLEVEL, "S") == 0 || (strcmp (PREVLEVEL, "S") == 0 ||
strcmp (PREVLEVEL, "1") == 0)) || strcmp (PREVLEVEL, "1") == 0)) ||
(RUNLEVEL && (RUNLEVEL &&
(strcmp (RUNLEVEL, "S") == 0 || (strcmp (RUNLEVEL, "S") == 0 ||
strcmp (RUNLEVEL, "1") == 0))) strcmp (RUNLEVEL, "1") == 0)))
single_user (); single_user ();
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -814,7 +814,7 @@ static void run_script (const char *script)
else if (pid == 0) { else if (pid == 0) {
execl (script, script, (char *) NULL); execl (script, script, (char *) NULL);
eerror ("%s: unable to exec `%s': %s", eerror ("%s: unable to exec `%s': %s",
script, applet, strerror (errno)); script, applet, strerror (errno));
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
} }
@ -868,9 +868,9 @@ int main (int argc, char **argv)
if (argc > 1 && (strcmp (argv[1], "--version") == 0)) { if (argc > 1 && (strcmp (argv[1], "--version") == 0)) {
printf ("%s (OpenRC" printf ("%s (OpenRC"
#ifdef BRANDING #ifdef BRANDING
" " BRANDING " " BRANDING
#endif #endif
") version " VERSION "\n", applet); ") version " VERSION "\n", applet);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
@ -885,7 +885,7 @@ int main (int argc, char **argv)
else if (strcmp (applet, "rc-status") == 0) else if (strcmp (applet, "rc-status") == 0)
exit (rc_status (argc, argv)); exit (rc_status (argc, argv));
else if (strcmp (applet, "rc-update") == 0 || else if (strcmp (applet, "rc-update") == 0 ||
strcmp (applet, "update-rc") == 0) strcmp (applet, "update-rc") == 0)
exit (rc_update (argc, argv)); exit (rc_update (argc, argv));
else if (strcmp (applet, "runscript") == 0) else if (strcmp (applet, "runscript") == 0)
exit (runscript (argc, argv)); exit (runscript (argc, argv));
@ -902,9 +902,9 @@ int main (int argc, char **argv)
exit (do_e (argc, argv)); exit (do_e (argc, argv));
if (strcmp (applet, "service_get_value") == 0 || if (strcmp (applet, "service_get_value") == 0 ||
strcmp (applet, "service_set_value") == 0 || strcmp (applet, "service_set_value") == 0 ||
strcmp (applet, "get_options") == 0 || strcmp (applet, "get_options") == 0 ||
strcmp (applet, "save_options") == 0) strcmp (applet, "save_options") == 0)
exit (do_value (argc, argv)); exit (do_value (argc, argv));
if (strncmp (applet, "service_", strlen ("service_")) == 0) if (strncmp (applet, "service_", strlen ("service_")) == 0)
@ -928,7 +928,7 @@ int main (int argc, char **argv)
if (p && sscanf (p, "%d", &pid) == 1) { if (p && sscanf (p, "%d", &pid) == 1) {
if (kill (pid, SIGUSR1) != 0) if (kill (pid, SIGUSR1) != 0)
eerrorx ("rc-abort: failed to signal parent %d: %s", eerrorx ("rc-abort: failed to signal parent %d: %s",
pid, strerror (errno)); pid, strerror (errno));
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
@ -986,14 +986,14 @@ int main (int argc, char **argv)
argc++; argc++;
argv--; argv--;
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
{ {
switch (opt) { switch (opt) {
case 'o': case 'o':
if (strlen (optarg) == 0) if (strlen (optarg) == 0)
optarg = NULL; optarg = NULL;
exit (set_ksoftlevel (optarg) ? EXIT_SUCCESS : EXIT_FAILURE); exit (set_ksoftlevel (optarg) ? EXIT_SUCCESS : EXIT_FAILURE);
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
} }
@ -1035,9 +1035,9 @@ int main (int argc, char **argv)
*/ */
if (newlevel) { if (newlevel) {
if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0 && if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0 &&
RUNLEVEL && RUNLEVEL &&
(strcmp (RUNLEVEL, "S") == 0 || (strcmp (RUNLEVEL, "S") == 0 ||
strcmp (RUNLEVEL, "1") == 0)) strcmp (RUNLEVEL, "1") == 0))
{ {
/* OK, we're either in runlevel 1 or single user mode */ /* OK, we're either in runlevel 1 or single user mode */
struct utsname uts; struct utsname uts;
@ -1053,19 +1053,19 @@ int main (int argc, char **argv)
uname (&uts); uname (&uts);
printf ("\n %sOpenRC %s" VERSION "%s is starting up %s%s%s\n\n", printf ("\n %sOpenRC %s" VERSION "%s is starting up %s%s%s\n\n",
ecolor (ECOLOR_GOOD), ecolor (ECOLOR_HILITE), ecolor (ECOLOR_GOOD), ecolor (ECOLOR_HILITE),
ecolor (ECOLOR_NORMAL), ecolor (ECOLOR_BRACKET), ecolor (ECOLOR_NORMAL), ecolor (ECOLOR_BRACKET),
#ifdef BRANDING #ifdef BRANDING
BRANDING BRANDING
#else #else
"" ""
#endif #endif
, ecolor (ECOLOR_NORMAL)); , ecolor (ECOLOR_NORMAL));
if (! rc_yesno (getenv ("EINFO_QUIET")) && if (! rc_yesno (getenv ("EINFO_QUIET")) &&
rc_conf_yesno ("rc_interactive")) rc_conf_yesno ("rc_interactive"))
printf ("Press %sI%s to enter interactive boot mode\n\n", printf ("Press %sI%s to enter interactive boot mode\n\n",
ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL)); ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL));
setenv ("RC_SOFTLEVEL", newlevel, 1); setenv ("RC_SOFTLEVEL", newlevel, 1);
rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, newlevel); rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, newlevel);
@ -1088,8 +1088,8 @@ int main (int argc, char **argv)
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} else if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) { } else if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) {
if (! RUNLEVEL || if (! RUNLEVEL ||
(strcmp (RUNLEVEL, "S") != 0 && (strcmp (RUNLEVEL, "S") != 0 &&
strcmp (RUNLEVEL, "1") != 0)) strcmp (RUNLEVEL, "1") != 0))
{ {
/* Remember the current runlevel for when we come back */ /* Remember the current runlevel for when we come back */
set_ksoftlevel (runlevel); set_ksoftlevel (runlevel);
@ -1097,27 +1097,27 @@ int main (int argc, char **argv)
} }
} else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0) { } else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0) {
if (! RUNLEVEL || if (! RUNLEVEL ||
strcmp (RUNLEVEL, "6") != 0) strcmp (RUNLEVEL, "6") != 0)
{ {
rc_logger_close (); rc_logger_close ();
execl (SHUTDOWN, SHUTDOWN, "-r", "now", (char *) NULL); execl (SHUTDOWN, SHUTDOWN, "-r", "now", (char *) NULL);
eerrorx ("%s: unable to exec `" SHUTDOWN "': %s", eerrorx ("%s: unable to exec `" SHUTDOWN "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
} else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0) { } else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0) {
if (! RUNLEVEL || if (! RUNLEVEL ||
strcmp (RUNLEVEL, "0") != 0) strcmp (RUNLEVEL, "0") != 0)
{ {
rc_logger_close (); rc_logger_close ();
execl (SHUTDOWN, SHUTDOWN, execl (SHUTDOWN, SHUTDOWN,
#ifdef __linux__ #ifdef __linux__
"-h", "-h",
#else #else
"-p", "-p",
#endif #endif
"now", (char *) NULL); "now", (char *) NULL);
eerrorx ("%s: unable to exec `" SHUTDOWN "': %s", eerrorx ("%s: unable to exec `" SHUTDOWN "': %s",
applet, strerror (errno)); applet, strerror (errno));
} }
} }
} }
@ -1128,27 +1128,27 @@ int main (int argc, char **argv)
/* We should only use ksoftlevel if we were in single user mode /* We should only use ksoftlevel if we were in single user mode
If not, we need to erase ksoftlevel now. */ If not, we need to erase ksoftlevel now. */
if (PREVLEVEL && if (PREVLEVEL &&
(strcmp (PREVLEVEL, "1") == 0 || (strcmp (PREVLEVEL, "1") == 0 ||
strcmp (PREVLEVEL, "S") == 0 || strcmp (PREVLEVEL, "S") == 0 ||
strcmp (PREVLEVEL, "N") == 0)) strcmp (PREVLEVEL, "N") == 0))
{ {
/* Try not to join boot and ksoftlevels together */ /* Try not to join boot and ksoftlevels together */
if (! newlevel || if (! newlevel ||
strcmp (newlevel, getenv ("RC_BOOTLEVEL")) != 0) strcmp (newlevel, getenv ("RC_BOOTLEVEL")) != 0)
if (get_ksoftlevel (ksoftbuffer, sizeof (ksoftbuffer))) if (get_ksoftlevel (ksoftbuffer, sizeof (ksoftbuffer)))
newlevel = ksoftbuffer; newlevel = ksoftbuffer;
} else if (! RUNLEVEL || } else if (! RUNLEVEL ||
(strcmp (RUNLEVEL, "1") != 0 && (strcmp (RUNLEVEL, "1") != 0 &&
strcmp (RUNLEVEL, "S") != 0 && strcmp (RUNLEVEL, "S") != 0 &&
strcmp (RUNLEVEL, "N") != 0)) strcmp (RUNLEVEL, "N") != 0))
{ {
set_ksoftlevel (NULL); set_ksoftlevel (NULL);
} }
if (newlevel && if (newlevel &&
(strcmp (newlevel, RC_LEVEL_REBOOT) == 0 || (strcmp (newlevel, RC_LEVEL_REBOOT) == 0 ||
strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0 || strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (newlevel, RC_LEVEL_SINGLE) == 0)) strcmp (newlevel, RC_LEVEL_SINGLE) == 0))
{ {
going_down = true; going_down = true;
rc_runlevel_set (newlevel); rc_runlevel_set (newlevel);
@ -1190,12 +1190,12 @@ int main (int argc, char **argv)
if ((dp = opendir (DEVBOOT))) { if ((dp = opendir (DEVBOOT))) {
while ((d = readdir (dp))) { while ((d = readdir (dp))) {
if (d->d_name[0] == '.' && if (d->d_name[0] == '.' &&
(d->d_name[1] == '\0' || (d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0'))) (d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue; continue;
if (rc_service_exists (d->d_name) && if (rc_service_exists (d->d_name) &&
rc_service_plugable (d->d_name)) rc_service_plugable (d->d_name))
rc_service_mark (d->d_name, RC_SERVICE_COLDPLUGGED); rc_service_mark (d->d_name, RC_SERVICE_COLDPLUGGED);
i = strlen (DEVBOOT "/") + strlen (d->d_name) + 1; i = strlen (DEVBOOT "/") + strlen (d->d_name) + 1;
@ -1204,7 +1204,7 @@ int main (int argc, char **argv)
if (tmp) { if (tmp) {
if (unlink (tmp)) if (unlink (tmp))
eerror ("%s: unlink `%s': %s", applet, tmp, eerror ("%s: unlink `%s': %s", applet, tmp,
strerror (errno)); strerror (errno));
free (tmp); free (tmp);
} }
} }
@ -1217,9 +1217,9 @@ int main (int argc, char **argv)
the device node to the init script to simulate the coldplug into the device node to the init script to simulate the coldplug into
runlevel for our dependency tree to work. */ runlevel for our dependency tree to work. */
if (newlevel && strcmp (newlevel, bootlevel) == 0 && if (newlevel && strcmp (newlevel, bootlevel) == 0 &&
(strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 ||
strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) && strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) &&
rc_conf_yesno ("rc_coldplug")) rc_conf_yesno ("rc_coldplug"))
{ {
#if defined(__DragonFly__) || defined(__FreeBSD__) #if defined(__DragonFly__) || defined(__FreeBSD__)
/* The net interfaces are easy - they're all in net /dev/net :) */ /* The net interfaces are easy - they're all in net /dev/net :) */
@ -1229,7 +1229,7 @@ int main (int argc, char **argv)
tmp = xmalloc (sizeof (char) * i); tmp = xmalloc (sizeof (char) * i);
snprintf (tmp, i, "net.%s", d->d_name); snprintf (tmp, i, "net.%s", d->d_name);
if (rc_service_exists (tmp) && if (rc_service_exists (tmp) &&
rc_service_plugable (tmp)) rc_service_plugable (tmp))
rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@ -1242,7 +1242,7 @@ int main (int argc, char **argv)
if ((dp = opendir ("/dev"))) { if ((dp = opendir ("/dev"))) {
while ((d = readdir (dp))) { while ((d = readdir (dp))) {
if (strncmp (d->d_name, "psm", 3) == 0 || if (strncmp (d->d_name, "psm", 3) == 0 ||
strncmp (d->d_name, "ums", 3) == 0) strncmp (d->d_name, "ums", 3) == 0)
{ {
char *p = d->d_name + 3; char *p = d->d_name + 3;
if (p && isdigit ((int) *p)) { if (p && isdigit ((int) *p)) {
@ -1250,7 +1250,7 @@ int main (int argc, char **argv)
tmp = xmalloc (sizeof (char) * i); tmp = xmalloc (sizeof (char) * i);
snprintf (tmp, i, "moused.%s", d->d_name); snprintf (tmp, i, "moused.%s", d->d_name);
if (rc_service_exists (tmp) && if (rc_service_exists (tmp) &&
rc_service_plugable (tmp)) rc_service_plugable (tmp))
rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
CHAR_FREE (tmp); CHAR_FREE (tmp);
} }
@ -1274,8 +1274,8 @@ int main (int argc, char **argv)
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
deporder = rc_deptree_depends (deptree, types_nua, deporder = rc_deptree_depends (deptree, types_nua,
(const char **) stop_services, (const char **) stop_services,
runlevel, depoptions | RC_DEP_STOP); runlevel, depoptions | RC_DEP_STOP);
rc_strlist_free (stop_services); rc_strlist_free (stop_services);
stop_services = deporder; stop_services = deporder;
@ -1310,8 +1310,8 @@ int main (int argc, char **argv)
rc_strlist_join (&coldplugged_services, tmplist); rc_strlist_join (&coldplugged_services, tmplist);
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 && if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 && strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0) strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
{ {
/* We need to include the boot runlevel services if we're not in it */ /* We need to include the boot runlevel services if we're not in it */
tmplist = rc_services_in_runlevel (bootlevel); tmplist = rc_services_in_runlevel (bootlevel);
@ -1394,8 +1394,8 @@ int main (int argc, char **argv)
going to be started depends on us */ going to be started depends on us */
rc_strlist_add (&stopdeps, service); rc_strlist_add (&stopdeps, service);
deporder = rc_deptree_depends (deptree, types_n, deporder = rc_deptree_depends (deptree, types_n,
(const char **) stopdeps, (const char **) stopdeps,
runlevel, RC_DEP_STRICT); runlevel, RC_DEP_STRICT);
rc_strlist_free (stopdeps); rc_strlist_free (stopdeps);
stopdeps = NULL; stopdeps = NULL;
found = false; found = false;
@ -1444,12 +1444,12 @@ int main (int argc, char **argv)
/* Run the halt script if needed */ /* Run the halt script if needed */
if (strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 || if (strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (runlevel, RC_LEVEL_REBOOT) == 0) strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
{ {
rc_logger_close (); rc_logger_close ();
execl (HALTSH, HALTSH, runlevel, (char *) NULL); execl (HALTSH, HALTSH, runlevel, (char *) NULL);
eerrorx ("%s: unable to exec `%s': %s", eerrorx ("%s: unable to exec `%s': %s",
applet, HALTSH, strerror (errno)); applet, HALTSH, strerror (errno));
} }
/* Single user is done now */ /* Single user is done now */
@ -1468,8 +1468,8 @@ int main (int argc, char **argv)
/* Order the services to start */ /* Order the services to start */
deporder = rc_deptree_depends (deptree, types_nua, deporder = rc_deptree_depends (deptree, types_nua,
(const char **) start_services, (const char **) start_services,
runlevel, depoptions | RC_DEP_START); runlevel, depoptions | RC_DEP_START);
rc_strlist_free (start_services); rc_strlist_free (start_services);
start_services = deporder; start_services = deporder;
deporder = NULL; deporder = NULL;

View File

@ -262,18 +262,18 @@ static void start_services (char **list) {
return; return;
if (state & RC_SERVICE_INACTIVE || if (state & RC_SERVICE_INACTIVE ||
state & RC_SERVICE_WASINACTIVE || state & RC_SERVICE_WASINACTIVE ||
state & RC_SERVICE_STARTING || state & RC_SERVICE_STARTING ||
state & RC_SERVICE_STARTED) state & RC_SERVICE_STARTED)
{ {
STRLIST_FOREACH (list, svc, i) { STRLIST_FOREACH (list, svc, i) {
if (rc_service_state (svc) & RC_SERVICE_STOPPED) { if (rc_service_state (svc) & RC_SERVICE_STOPPED) {
if (state & RC_SERVICE_INACTIVE || if (state & RC_SERVICE_INACTIVE ||
state & RC_SERVICE_WASINACTIVE) state & RC_SERVICE_WASINACTIVE)
{ {
rc_service_schedule_start (service, svc); rc_service_schedule_start (service, svc);
ewarn ("WARNING: %s is scheduled to started when %s has started", ewarn ("WARNING: %s is scheduled to started when %s has started",
svc, applet); svc, applet);
} else } else
rc_service_start (svc); rc_service_start (svc);
} }
@ -404,7 +404,7 @@ static bool svc_exec (const char *arg1, const char *arg2)
eerrorx ("%s: pipe: %s", service, applet); eerrorx ("%s: pipe: %s", service, applet);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
if ((flags = fcntl (signal_pipe[i], F_GETFD, 0) == -1 || if ((flags = fcntl (signal_pipe[i], F_GETFD, 0) == -1 ||
fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1)) fcntl (signal_pipe[i], F_SETFD, flags | FD_CLOEXEC) == -1))
eerrorx ("%s: fcntl: %s", service, strerror (errno)); eerrorx ("%s: fcntl: %s", service, strerror (errno));
/* Open a pty for our prefixed output /* Open a pty for our prefixed output
@ -439,15 +439,15 @@ static bool svc_exec (const char *arg1, const char *arg2)
if (exists (RC_SVCDIR "/runscript.sh")) { if (exists (RC_SVCDIR "/runscript.sh")) {
execl (RC_SVCDIR "/runscript.sh", RC_SVCDIR "/runscript.sh", execl (RC_SVCDIR "/runscript.sh", RC_SVCDIR "/runscript.sh",
service, arg1, arg2, (char *) NULL); service, arg1, arg2, (char *) NULL);
eerror ("%s: exec `" RC_SVCDIR "/runscript.sh': %s", eerror ("%s: exec `" RC_SVCDIR "/runscript.sh': %s",
service, strerror (errno)); service, strerror (errno));
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
} else { } else {
execl (RC_LIBDIR "/sh/runscript.sh", RC_LIBDIR "/sh/runscript.sh", execl (RC_LIBDIR "/sh/runscript.sh", RC_LIBDIR "/sh/runscript.sh",
service, arg1, arg2, (char *) NULL); service, arg1, arg2, (char *) NULL);
eerror ("%s: exec `" RC_LIBDIR "/sh/runscript.sh': %s", eerror ("%s: exec `" RC_LIBDIR "/sh/runscript.sh': %s",
service, strerror (errno)); service, strerror (errno));
_exit (EXIT_FAILURE); _exit (EXIT_FAILURE);
} }
} }
@ -584,9 +584,9 @@ static void make_exclusive ()
exclusive = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL); exclusive = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
if (mkfifo (exclusive, 0600) != 0 && errno != EEXIST && if (mkfifo (exclusive, 0600) != 0 && errno != EEXIST &&
(errno != EACCES || geteuid () == 0)) (errno != EACCES || geteuid () == 0))
eerrorx ("%s: unable to create fifo `%s': %s", eerrorx ("%s: unable to create fifo `%s': %s",
applet, exclusive, strerror (errno)); applet, exclusive, strerror (errno));
path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL); path = rc_strcatpaths (RC_SVCDIR, "exclusive", applet, (char *) NULL);
i = strlen (path) + 16; i = strlen (path) + 16;
@ -596,7 +596,7 @@ static void make_exclusive ()
if (exists (mtime_test) && unlink (mtime_test) != 0) { if (exists (mtime_test) && unlink (mtime_test) != 0) {
eerror ("%s: unlink `%s': %s", eerror ("%s: unlink `%s': %s",
applet, mtime_test, strerror (errno)); applet, mtime_test, strerror (errno));
free (mtime_test); free (mtime_test);
mtime_test = NULL; mtime_test = NULL;
return; return;
@ -604,7 +604,7 @@ static void make_exclusive ()
if (symlink (service, mtime_test) != 0) { if (symlink (service, mtime_test) != 0) {
eerror ("%s: symlink `%s' to `%s': %s", eerror ("%s: symlink `%s' to `%s': %s",
applet, service, mtime_test, strerror (errno)); applet, service, mtime_test, strerror (errno));
free (mtime_test); free (mtime_test);
mtime_test = NULL; mtime_test = NULL;
} }
@ -645,7 +645,7 @@ static void svc_start (bool deps)
if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) { if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) {
if (! state & RC_SERVICE_INACTIVE && if (! state & RC_SERVICE_INACTIVE &&
! state & RC_SERVICE_STOPPED) ! state & RC_SERVICE_STOPPED)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
background = true; background = true;
} }
@ -694,11 +694,11 @@ static void svc_start (bool deps)
rc_strlist_free (need_services); rc_strlist_free (need_services);
need_services = rc_deptree_depends (deptree, types_n, svcl, need_services = rc_deptree_depends (deptree, types_n, svcl,
softlevel, depoptions); softlevel, depoptions);
rc_strlist_free (use_services); rc_strlist_free (use_services);
use_services = rc_deptree_depends (deptree, types_nu, svcl, use_services = rc_deptree_depends (deptree, types_nu, svcl,
softlevel, depoptions); softlevel, depoptions);
if (! rc_runlevel_starting ()) { if (! rc_runlevel_starting ()) {
STRLIST_FOREACH (use_services, svc, i) STRLIST_FOREACH (use_services, svc, i)
@ -711,7 +711,7 @@ static void svc_start (bool deps)
/* Now wait for them to start */ /* Now wait for them to start */
services = rc_deptree_depends (deptree, types_nua, svcl, services = rc_deptree_depends (deptree, types_nua, svcl,
softlevel, depoptions); softlevel, depoptions);
/* We use tmplist to hold our scheduled by list */ /* We use tmplist to hold our scheduled by list */
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
@ -725,7 +725,7 @@ static void svc_start (bool deps)
/* Don't wait for services which went inactive but are now in /* Don't wait for services which went inactive but are now in
* starting state which we are after */ * starting state which we are after */
if (svcs & RC_SERVICE_STARTING && if (svcs & RC_SERVICE_STARTING &&
svcs & RC_SERVICE_WASINACTIVE) { svcs & RC_SERVICE_WASINACTIVE) {
bool use = false; bool use = false;
STRLIST_FOREACH (use_services, svc2, j) STRLIST_FOREACH (use_services, svc2, j)
if (strcmp (svc, svc2) == 0) { if (strcmp (svc, svc2) == 0) {
@ -744,11 +744,11 @@ static void svc_start (bool deps)
STRLIST_FOREACH (need_services, svc2, j) STRLIST_FOREACH (need_services, svc2, j)
if (strcmp (svc, svc2) == 0) { if (strcmp (svc, svc2) == 0) {
if (svcs & RC_SERVICE_INACTIVE || if (svcs & RC_SERVICE_INACTIVE ||
svcs & RC_SERVICE_WASINACTIVE) svcs & RC_SERVICE_WASINACTIVE)
rc_strlist_add (&tmplist, svc); rc_strlist_add (&tmplist, svc);
else else
eerrorx ("ERROR: cannot start %s as %s would not start", eerrorx ("ERROR: cannot start %s as %s would not start",
applet, svc); applet, svc);
} }
} }
@ -786,7 +786,7 @@ static void svc_start (bool deps)
p += snprintf (p, len, "%s", svc); p += snprintf (p, len, "%s", svc);
} }
ewarnx ("WARNING: %s is scheduled to start when %s has started", ewarnx ("WARNING: %s is scheduled to start when %s has started",
applet, tmp); applet, tmp);
} }
rc_strlist_free (services); rc_strlist_free (services);
@ -852,12 +852,12 @@ static void svc_stop (bool deps)
rc_service_state_t state = rc_service_state (service); rc_service_state_t state = rc_service_state (service);
if (rc_runlevel_stopping () && if (rc_runlevel_stopping () &&
state & RC_SERVICE_FAILED) state & RC_SERVICE_FAILED)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background) if (rc_yesno (getenv ("IN_HOTPLUG")) || in_background)
if (! (state & RC_SERVICE_STARTED) && if (! (state & RC_SERVICE_STARTED) &&
! (state & RC_SERVICE_INACTIVE)) ! (state & RC_SERVICE_INACTIVE))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (state & RC_SERVICE_STOPPED) { if (state & RC_SERVICE_STOPPED) {
@ -875,7 +875,7 @@ static void svc_stop (bool deps)
rc_plugin_run (RC_HOOK_SERVICE_STOP_IN, applet); rc_plugin_run (RC_HOOK_SERVICE_STOP_IN, applet);
if (! rc_runlevel_stopping () && if (! rc_runlevel_stopping () &&
rc_service_in_runlevel (service, RC_LEVEL_BOOT)) rc_service_in_runlevel (service, RC_LEVEL_BOOT))
ewarn ("WARNING: you are stopping a boot service"); ewarn ("WARNING: you are stopping a boot service");
if (deps && ! (state & RC_SERVICE_WASINACTIVE)) { if (deps && ! (state & RC_SERVICE_WASINACTIVE)) {
@ -896,17 +896,17 @@ static void svc_stop (bool deps)
tmplist = NULL; tmplist = NULL;
rc_strlist_free (services); rc_strlist_free (services);
services = rc_deptree_depends (deptree, types_m, svcl, services = rc_deptree_depends (deptree, types_m, svcl,
softlevel, depoptions); softlevel, depoptions);
rc_strlist_reverse (services); rc_strlist_reverse (services);
STRLIST_FOREACH (services, svc, i) { STRLIST_FOREACH (services, svc, i) {
rc_service_state_t svcs = rc_service_state (svc); rc_service_state_t svcs = rc_service_state (svc);
if (svcs & RC_SERVICE_STARTED || if (svcs & RC_SERVICE_STARTED ||
svcs & RC_SERVICE_INACTIVE) svcs & RC_SERVICE_INACTIVE)
{ {
svc_wait (deptree, svc); svc_wait (deptree, svc);
svcs = rc_service_state (svc); svcs = rc_service_state (svc);
if (svcs & RC_SERVICE_STARTED || if (svcs & RC_SERVICE_STARTED ||
svcs & RC_SERVICE_INACTIVE) svcs & RC_SERVICE_INACTIVE)
{ {
pid_t pid = rc_service_stop (svc); pid_t pid = rc_service_stop (svc);
if (! rc_conf_yesno ("rc_parallel")) if (! rc_conf_yesno ("rc_parallel"))
@ -928,15 +928,15 @@ static void svc_stop (bool deps)
if (rc_runlevel_stopping ()) { if (rc_runlevel_stopping ()) {
/* If shutting down, we should stop even if a dependant failed */ /* If shutting down, we should stop even if a dependant failed */
if (softlevel && if (softlevel &&
(strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 || (strcmp (softlevel, RC_LEVEL_SHUTDOWN) == 0 ||
strcmp (softlevel, RC_LEVEL_REBOOT) == 0 || strcmp (softlevel, RC_LEVEL_REBOOT) == 0 ||
strcmp (softlevel, RC_LEVEL_SINGLE) == 0)) strcmp (softlevel, RC_LEVEL_SINGLE) == 0))
continue; continue;
rc_service_mark (service, RC_SERVICE_FAILED); rc_service_mark (service, RC_SERVICE_FAILED);
} }
eerrorx ("ERROR: cannot stop %s as %s is still up", eerrorx ("ERROR: cannot stop %s as %s is still up",
applet, svc); applet, svc);
} }
} }
rc_strlist_free (tmplist); rc_strlist_free (tmplist);
@ -945,7 +945,7 @@ static void svc_stop (bool deps)
/* We now wait for other services that may use us and are stopping /* We now wait for other services that may use us and are stopping
This is important when a runlevel stops */ This is important when a runlevel stops */
services = rc_deptree_depends (deptree, types_mua, svcl, services = rc_deptree_depends (deptree, types_mua, svcl,
softlevel, depoptions); softlevel, depoptions);
STRLIST_FOREACH (services, svc, i) { STRLIST_FOREACH (services, svc, i) {
if (rc_service_state (svc) & RC_SERVICE_STOPPED) if (rc_service_state (svc) & RC_SERVICE_STOPPED)
continue; continue;
@ -1161,7 +1161,7 @@ int runscript (int argc, char **argv)
/* Right then, parse any options there may be */ /* Right then, parse any options there may be */
while ((opt = getopt_long (argc, argv, getoptstring, while ((opt = getopt_long (argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
switch (opt) { switch (opt) {
case 'd': case 'd':
setenv ("RC_DEBUG", "yes", 1); setenv ("RC_DEBUG", "yes", 1);
@ -1209,7 +1209,7 @@ int runscript (int argc, char **argv)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
if (strcmp (optarg, "status") != 0 && if (strcmp (optarg, "status") != 0 &&
strcmp (optarg, "help") != 0) { strcmp (optarg, "help") != 0) {
/* Only root should be able to run us */ /* Only root should be able to run us */
} }
@ -1223,7 +1223,7 @@ int runscript (int argc, char **argv)
doneone = true; doneone = true;
if (strcmp (optarg, "describe") == 0 || if (strcmp (optarg, "describe") == 0 ||
strcmp (optarg, "help") == 0) strcmp (optarg, "help") == 0)
{ {
char *save = prefix; char *save = prefix;
@ -1232,12 +1232,12 @@ int runscript (int argc, char **argv)
svc_exec (optarg, NULL); svc_exec (optarg, NULL);
eprefix (save); eprefix (save);
} else if (strcmp (optarg, "ineed") == 0 || } else if (strcmp (optarg, "ineed") == 0 ||
strcmp (optarg, "iuse") == 0 || strcmp (optarg, "iuse") == 0 ||
strcmp (optarg, "needsme") == 0 || strcmp (optarg, "needsme") == 0 ||
strcmp (optarg, "usesme") == 0 || strcmp (optarg, "usesme") == 0 ||
strcmp (optarg, "iafter") == 0 || strcmp (optarg, "iafter") == 0 ||
strcmp (optarg, "ibefore") == 0 || strcmp (optarg, "ibefore") == 0 ||
strcmp (optarg, "iprovide") == 0) { strcmp (optarg, "iprovide") == 0) {
int depoptions = RC_DEP_TRACE; int depoptions = RC_DEP_TRACE;
const char *t[] = { optarg, NULL }; const char *t[] = { optarg, NULL };
const char *s[] = { applet, NULL }; const char *s[] = { applet, NULL };
@ -1264,7 +1264,7 @@ int runscript (int argc, char **argv)
eerrorx ("%s: root access required", applet); eerrorx ("%s: root access required", applet);
if (strcmp (optarg, "conditionalrestart") == 0 || if (strcmp (optarg, "conditionalrestart") == 0 ||
strcmp (optarg, "condrestart") == 0) strcmp (optarg, "condrestart") == 0)
{ {
if (rc_service_state (service) & RC_SERVICE_STARTED) if (rc_service_state (service) & RC_SERVICE_STARTED)
svc_restart (deps); svc_restart (deps);
@ -1280,12 +1280,12 @@ int runscript (int argc, char **argv)
if (deps) { if (deps) {
if (! in_background && if (! in_background &&
! rc_runlevel_stopping () && ! rc_runlevel_stopping () &&
rc_service_state (service) & RC_SERVICE_STOPPED) rc_service_state (service) & RC_SERVICE_STOPPED)
uncoldplug (); uncoldplug ();
if (in_background && if (in_background &&
rc_service_state (service) & RC_SERVICE_INACTIVE) rc_service_state (service) & RC_SERVICE_INACTIVE)
{ {
int j; int j;
STRLIST_FOREACH (restart_services, svc, j) STRLIST_FOREACH (restart_services, svc, j)

View File

@ -168,7 +168,7 @@ static int parse_signal (const char *sig)
for (i = 0; i < sizeof (signallist) / sizeof (signallist[0]); i++) for (i = 0; i < sizeof (signallist) / sizeof (signallist[0]); i++)
if (strcmp (sig, signallist[i].name) == 0 || if (strcmp (sig, signallist[i].name) == 0 ||
(s && strcmp (s, signallist[i].name) == 0)) (s && strcmp (s, signallist[i].name) == 0))
return (signallist[i].signal); return (signallist[i].signal);
eerrorx ("%s: `%s' is not a valid signal", applet, sig); eerrorx ("%s: `%s' is not a valid signal", applet, sig);
@ -186,9 +186,9 @@ static void parse_schedule_item (schedulelist_t *item, const char *string)
errno = 0; errno = 0;
if (sscanf (string, "%d", &item->value) != 1) if (sscanf (string, "%d", &item->value) != 1)
eerrorx ("%s: invalid timeout value in schedule `%s'", applet, eerrorx ("%s: invalid timeout value in schedule `%s'", applet,
string); string);
} else if ((after_hyph = string + (string[0] == '-')) && } else if ((after_hyph = string + (string[0] == '-')) &&
((sig = parse_signal (after_hyph)) != -1)) ((sig = parse_signal (after_hyph)) != -1))
{ {
item->type = schedule_signal; item->type = schedule_signal;
item->value = (int) sig; item->value = (int) sig;
@ -253,7 +253,7 @@ static void parse_schedule (const char *string, int default_signal)
if (next->type == schedule_forever) { if (next->type == schedule_forever) {
if (repeatat) if (repeatat)
eerrorx ("%s: invalid schedule, `forever' appears more than once", eerrorx ("%s: invalid schedule, `forever' appears more than once",
applet); applet);
repeatat = next; repeatat = next;
continue; continue;
@ -305,8 +305,8 @@ static pid_t get_pid (const char *pidfile, bool quiet)
/* return number of processed killed, -1 on error */ /* return number of processed killed, -1 on error */
static int do_stop (const char *exec, const char *cmd, static int do_stop (const char *exec, const char *cmd,
const char *pidfile, uid_t uid,int sig, const char *pidfile, uid_t uid,int sig,
bool quiet, bool verbose, bool test) bool quiet, bool verbose, bool test)
{ {
pid_t *pids; pid_t *pids;
bool killed; bool killed;
@ -338,7 +338,7 @@ static int do_stop (const char *exec, const char *cmd,
killed = (kill (pids[i], sig) == 0 || errno == ESRCH ? true : false); killed = (kill (pids[i], sig) == 0 || errno == ESRCH ? true : false);
if (verbose) if (verbose)
eend (killed ? 0 : 1, "%s: failed to send signal %d to PID %d: %s", eend (killed ? 0 : 1, "%s: failed to send signal %d to PID %d: %s",
applet, sig, pids[i], strerror (errno)); applet, sig, pids[i], strerror (errno));
if (! killed) { if (! killed) {
nkilled = -1; nkilled = -1;
} else { } else {
@ -352,8 +352,8 @@ static int do_stop (const char *exec, const char *cmd,
} }
static int run_stop_schedule (const char *exec, const char *cmd, static int run_stop_schedule (const char *exec, const char *cmd,
const char *pidfile, uid_t uid, const char *pidfile, uid_t uid,
bool quiet, bool verbose, bool test) bool quiet, bool verbose, bool test)
{ {
schedulelist_t *item = schedule; schedulelist_t *item = schedule;
int nkilled = 0; int nkilled = 0;
@ -382,7 +382,7 @@ static int run_stop_schedule (const char *exec, const char *cmd,
case schedule_signal: case schedule_signal:
nrunning = 0; nrunning = 0;
nkilled = do_stop (exec, cmd, pidfile, uid, item->value, nkilled = do_stop (exec, cmd, pidfile, uid, item->value,
quiet, verbose, test); quiet, verbose, test);
if (nkilled == 0) { if (nkilled == 0) {
if (tkilled == 0) { if (tkilled == 0) {
if (! quiet) if (! quiet)
@ -407,7 +407,7 @@ static int run_stop_schedule (const char *exec, const char *cmd,
while (nloops) { while (nloops) {
if ((nrunning = do_stop (exec, cmd, pidfile, if ((nrunning = do_stop (exec, cmd, pidfile,
uid, 0, true, false, true)) == 0) uid, 0, true, false, true)) == 0)
return (true); return (true);
if (nanosleep (&ts, NULL) == -1) { if (nanosleep (&ts, NULL) == -1) {
@ -584,7 +584,7 @@ int start_stop_daemon (int argc, char **argv)
eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", applet, env); eerror ("%s: invalid nice level `%s' (SSD_NICELEVEL)", applet, env);
while ((opt = getopt_long (argc, argv, getoptstring, longopts, while ((opt = getopt_long (argc, argv, getoptstring, longopts,
(int *) 0)) != -1) (int *) 0)) != -1)
switch (opt) { switch (opt) {
case 'K': /* --stop */ case 'K': /* --stop */
stop = true; stop = true;
@ -702,7 +702,7 @@ int start_stop_daemon (int argc, char **argv)
redirect_stderr = optarg; redirect_stderr = optarg;
break; break;
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
quiet = rc_yesno (getenv ("EINFO_QUIET")); quiet = rc_yesno (getenv ("EINFO_QUIET"));
@ -712,9 +712,9 @@ int start_stop_daemon (int argc, char **argv)
* instead of forcing --stop --oknodo as well */ * instead of forcing --stop --oknodo as well */
if (! start && ! stop) if (! start && ! stop)
if (sig != SIGINT && if (sig != SIGINT &&
sig != SIGTERM && sig != SIGTERM &&
sig != SIGQUIT && sig != SIGQUIT &&
sig != SIGKILL) sig != SIGKILL)
{ {
oknodo = true; oknodo = true;
stop = true; stop = true;
@ -737,7 +737,7 @@ int start_stop_daemon (int argc, char **argv)
if ((redirect_stdout || redirect_stderr) && ! background) if ((redirect_stdout || redirect_stderr) && ! background)
eerrorx ("%s: --stdout and --stderr are only relevant with --background", eerrorx ("%s: --stdout and --stderr are only relevant with --background",
applet); applet);
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -839,7 +839,7 @@ int start_stop_daemon (int argc, char **argv)
if (nicelevel) { if (nicelevel) {
if (setpriority (PRIO_PROCESS, mypid, nicelevel) == -1) if (setpriority (PRIO_PROCESS, mypid, nicelevel) == -1)
eerrorx ("%s: setpritory %d: %s", applet, nicelevel, eerrorx ("%s: setpritory %d: %s", applet, nicelevel,
strerror(errno)); strerror(errno));
} }
if (ch_root && chroot (ch_root) < 0) if (ch_root && chroot (ch_root) < 0)
@ -852,7 +852,7 @@ int start_stop_daemon (int argc, char **argv)
FILE *fp = fopen (pidfile, "w"); FILE *fp = fopen (pidfile, "w");
if (! fp) if (! fp)
eerrorx ("%s: fopen `%s': %s", applet, pidfile, strerror eerrorx ("%s: fopen `%s': %s", applet, pidfile, strerror
(errno)); (errno));
fprintf (fp, "%d\n", mypid); fprintf (fp, "%d\n", mypid);
fclose (fp); fclose (fp);
} }
@ -902,7 +902,7 @@ int start_stop_daemon (int argc, char **argv)
/* Clean the environment of any RC_ variables */ /* Clean the environment of any RC_ variables */
STRLIST_FOREACH (environ, env, i) { STRLIST_FOREACH (environ, env, i) {
if (strncmp (env, "RC_", 3) == 0 || if (strncmp (env, "RC_", 3) == 0 ||
strncmp (env, "SSD_NICELEVEL=", strlen ("SSD_NICELEVEL=")) == 0) strncmp (env, "SSD_NICELEVEL=", strlen ("SSD_NICELEVEL=")) == 0)
continue; continue;
/* For the path, remove the rcscript bin dir from it */ /* For the path, remove the rcscript bin dir from it */
@ -918,9 +918,9 @@ int start_stop_daemon (int argc, char **argv)
p += 5; p += 5;
while ((token = strsep (&p, ":"))) { while ((token = strsep (&p, ":"))) {
if (strcmp (token, RC_LIBDIR "/bin") == 0 || if (strcmp (token, RC_LIBDIR "/bin") == 0 ||
strcmp (token, RC_LIBDIR "/sbin") == 0) strcmp (token, RC_LIBDIR "/sbin") == 0)
continue; continue;
t = strlen (token); t = strlen (token);
if (newpath) { if (newpath) {
l = strlen (newpath); l = strlen (newpath);
@ -949,15 +949,15 @@ int start_stop_daemon (int argc, char **argv)
stderr_fd = devnull_fd; stderr_fd = devnull_fd;
if (redirect_stdout) { if (redirect_stdout) {
if ((stdout_fd = open (redirect_stdout, O_WRONLY | O_CREAT | O_APPEND, if ((stdout_fd = open (redirect_stdout, O_WRONLY | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR)) == -1) S_IRUSR | S_IWUSR)) == -1)
eerrorx ("%s: unable to open the logfile for stdout `%s': %s", eerrorx ("%s: unable to open the logfile for stdout `%s': %s",
applet, redirect_stdout, strerror (errno)); applet, redirect_stdout, strerror (errno));
} }
if (redirect_stderr) { if (redirect_stderr) {
if ((stderr_fd = open (redirect_stderr, O_WRONLY | O_CREAT | O_APPEND, if ((stderr_fd = open (redirect_stderr, O_WRONLY | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR)) == -1) S_IRUSR | S_IWUSR)) == -1)
eerrorx ("%s: unable to open the logfile for stderr `%s': %s", eerrorx ("%s: unable to open the logfile for stderr `%s': %s",
applet, redirect_stderr, strerror (errno)); applet, redirect_stderr, strerror (errno));
} }
if (background) { if (background) {
@ -1011,7 +1011,7 @@ int start_stop_daemon (int argc, char **argv)
int nloops = START_WAIT / POLL_INTERVAL; int nloops = START_WAIT / POLL_INTERVAL;
int nloopsp = WAIT_PIDFILE / POLL_INTERVAL; int nloopsp = WAIT_PIDFILE / POLL_INTERVAL;
bool alive = false; bool alive = false;
ts.tv_sec = 0; ts.tv_sec = 0;
ts.tv_nsec = POLL_INTERVAL; ts.tv_nsec = POLL_INTERVAL;
@ -1049,7 +1049,7 @@ int start_stop_daemon (int argc, char **argv)
if (get_pid (pidfile, true) == -1) { if (get_pid (pidfile, true) == -1) {
if (! nloopsp) if (! nloopsp)
eerrorx ("%s: did not create a valid pid in `%s'", eerrorx ("%s: did not create a valid pid in `%s'",
applet, pidfile); applet, pidfile);
alive = true; alive = true;
} else } else
nloopsp = 0; nloopsp = 0;