aboutsummaryrefslogtreecommitdiff
path: root/src/rc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rc')
-rw-r--r--src/rc/_usage.c11
-rw-r--r--src/rc/_usage.h28
-rw-r--r--src/rc/checkpath.c44
-rw-r--r--src/rc/fstabinfo.c81
-rw-r--r--src/rc/mountinfo.c79
-rw-r--r--src/rc/rc-applets.c79
-rw-r--r--src/rc/rc-depend.c18
-rw-r--r--src/rc/rc-logger.c90
-rw-r--r--src/rc/rc-misc.c15
-rw-r--r--src/rc/rc-plugin.c33
-rw-r--r--src/rc/rc-service.c14
-rw-r--r--src/rc/rc-update.c51
-rw-r--r--src/rc/rc.c138
-rw-r--r--src/rc/runscript.c154
-rw-r--r--src/rc/start-stop-daemon.c318
15 files changed, 614 insertions, 539 deletions
diff --git a/src/rc/_usage.c b/src/rc/_usage.c
index cd621d9e..652a1e87 100644
--- a/src/rc/_usage.c
+++ b/src/rc/_usage.c
@@ -25,15 +25,16 @@
*/
#if lint
-# define _noreturn
+# define _noreturn
#endif
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
-# define _noreturn __attribute__ ((__noreturn__))
+# define _noreturn __attribute__ ((__noreturn__))
#else
-# define _noreturn
+# define _noreturn
#endif
-_noreturn static void usage(int exit_status)
+_noreturn static void
+usage(int exit_status)
{
const char * const has_arg[] = { "", "<arg>", "[arg]" };
int i;
@@ -53,7 +54,7 @@ _noreturn static void usage(int exit_status)
printf("\n\nOptions: [" getoptstring "]\n");
for (i = 0; longopts[i].name; ++i) {
len = printf(" -%c, --%s %s", longopts[i].val, longopts[i].name,
- has_arg[longopts[i].has_arg]);
+ has_arg[longopts[i].has_arg]);
lo = p = xstrdup(longopts_help[i]);
while ((token = strsep(&p, "\n"))) {
diff --git a/src/rc/_usage.h b/src/rc/_usage.h
index 3c170cab..67a24bbc 100644
--- a/src/rc/_usage.h
+++ b/src/rc/_usage.h
@@ -26,17 +26,17 @@
#define getoptstring_COMMON "Chqv"
-#define longopts_COMMON \
- { "help", 0, NULL, 'h'}, \
- { "nocolor", 0, NULL, 'C'}, \
- { "verbose", 0, NULL, 'v'}, \
- { "quiet", 0, NULL, 'q'}, \
+#define longopts_COMMON \
+ { "help", 0, NULL, 'h'}, \
+ { "nocolor", 0, NULL, 'C'}, \
+ { "verbose", 0, NULL, 'v'}, \
+ { "quiet", 0, NULL, 'q'}, \
{ NULL, 0, NULL, 0 }
-#define longopts_help_COMMON \
- "Display this help output", \
- "Disable color output", \
- "Run verbosely", \
+#define longopts_help_COMMON \
+ "Display this help output", \
+ "Disable color output", \
+ "Run verbosely", \
"Run quietly"
#define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1);
@@ -45,9 +45,9 @@
#define case_RC_COMMON_getopt_case_q setenv ("EINFO_QUIET", "YES", 1);
#define case_RC_COMMON_getopt_default usage (EXIT_FAILURE);
-#define case_RC_COMMON_GETOPT \
- case 'C': case_RC_COMMON_getopt_case_C; break; \
- case 'h': case_RC_COMMON_getopt_case_h; break; \
- case 'v': case_RC_COMMON_getopt_case_v; break; \
- case 'q': case_RC_COMMON_getopt_case_q; break; \
+#define case_RC_COMMON_GETOPT \
+ case 'C': case_RC_COMMON_getopt_case_C; break; \
+ case 'h': case_RC_COMMON_getopt_case_h; break; \
+ case 'v': case_RC_COMMON_getopt_case_v; break; \
+ case 'q': case_RC_COMMON_getopt_case_q; break; \
default: case_RC_COMMON_getopt_default; break;
diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c
index f9695697..16402dbd 100644
--- a/src/rc/checkpath.c
+++ b/src/rc/checkpath.c
@@ -1,8 +1,8 @@
/*
- checkpath.c
- Checks for the existance of a file or directory and creates it
- if necessary. It can also correct its ownership.
- */
+ checkpath.c
+ Checks for the existance of a file or directory and creates it
+ if necessary. It can also correct its ownership.
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -49,7 +49,8 @@
extern const char *applet;
-static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
+static int
+do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
{
struct stat st;
int fd;
@@ -57,8 +58,9 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
if (stat(path, &st)) {
if (file) {
einfo("%s: creating file", path);
- if (! mode)
- mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
+ if (!mode)
+ mode = S_IRUSR | S_IWUSR | S_IRGRP |
+ S_IWGRP | S_IROTH;
if ((fd = open(path, O_CREAT, mode)) == -1) {
eerror("%s: open: %s", applet, strerror(errno));
return -1;
@@ -66,17 +68,18 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
close (fd);
} else {
einfo("%s: creating directory", path);
- if (! mode)
+ if (!mode)
mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
if (mkdir(path, mode)) {
- eerror("%s: mkdir: %s", applet, strerror (errno));
+ eerror("%s: mkdir: %s", applet,
+ strerror (errno));
return -1;
}
mode = 0;
}
} else {
if ((file && S_ISDIR(st.st_mode)) ||
- (! file && ! S_ISDIR(st.st_mode)))
+ (!file && !S_ISDIR(st.st_mode)))
{
if (file)
eerror("%s: is a directory", path);
@@ -106,8 +109,8 @@ static int do_check(char *path, uid_t uid, gid_t gid, mode_t mode, int file)
return 0;
}
-static int parse_owner(struct passwd **user, struct group **group,
- const char *owner)
+static int
+parse_owner(struct passwd **user, struct group **group, const char *owner)
{
char *u = xstrdup (owner);
char *g = strchr (u, ':');
@@ -122,7 +125,7 @@ static int parse_owner(struct passwd **user, struct group **group,
*user = getpwuid((uid_t) id);
else
*user = getpwnam(u);
- if (! *user)
+ if (*user == NULL)
retval = -1;
}
@@ -131,7 +134,7 @@ static int parse_owner(struct passwd **user, struct group **group,
*group = getgrgid((gid_t) id);
else
*group = getgrnam(g);
- if (! *group)
+ if (*group == NULL)
retval = -1;
}
@@ -158,7 +161,8 @@ static const char * const longopts_help[] = {
};
#include "_usage.c"
-int checkpath(int argc, char **argv)
+int
+checkpath(int argc, char **argv)
{
int opt;
uid_t uid = geteuid();
@@ -170,7 +174,7 @@ int checkpath(int argc, char **argv)
int retval = EXIT_SUCCESS;
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'd':
@@ -181,14 +185,16 @@ int checkpath(int argc, char **argv)
break;
case 'm':
if (parse_mode(&mode, optarg) != 0)
- eerrorx("%s: invalid mode `%s'", applet, optarg);
+ eerrorx("%s: invalid mode `%s'",
+ applet, optarg);
break;
case 'o':
if (parse_owner(&pw, &gr, optarg) != 0)
- eerrorx("%s: owner `%s' not found", applet, optarg);
+ eerrorx("%s: owner `%s' not found",
+ applet, optarg);
break;
- case_RC_COMMON_GETOPT
+ case_RC_COMMON_GETOPT;
}
}
diff --git a/src/rc/fstabinfo.c b/src/rc/fstabinfo.c
index 9def953a..acb6ae51 100644
--- a/src/rc/fstabinfo.c
+++ b/src/rc/fstabinfo.c
@@ -1,7 +1,7 @@
/*
- fstabinfo.c
- Gets information about /etc/fstab.
- */
+ fstabinfo.c
+ Gets information about /etc/fstab.
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -42,31 +42,31 @@
Okay, we could use getfsent but the man page says use getmntent instead
AND we don't have getfsent on uclibc or dietlibc for some odd reason. */
#ifdef __linux__
-#define HAVE_GETMNTENT
-#include <mntent.h>
-#define ENT mntent
-#define START_ENT fp = setmntent ("/etc/fstab", "r");
-#define GET_ENT getmntent (fp)
-#define GET_ENT_FILE(_name) getmntfile (_name)
-#define END_ENT endmntent (fp)
-#define ENT_BLOCKDEVICE(_ent) ent->mnt_fsname
-#define ENT_FILE(_ent) ent->mnt_dir
-#define ENT_TYPE(_ent) ent->mnt_type
-#define ENT_OPTS(_ent) ent->mnt_opts
-#define ENT_PASS(_ent) ent->mnt_passno
+# define HAVE_GETMNTENT
+# include <mntent.h>
+# define ENT mntent
+# define START_ENT fp = setmntent ("/etc/fstab", "r");
+# define GET_ENT getmntent (fp)
+# define GET_ENT_FILE(_name) getmntfile (_name)
+# define END_ENT endmntent (fp)
+# define ENT_BLOCKDEVICE(_ent) ent->mnt_fsname
+# define ENT_FILE(_ent) ent->mnt_dir
+# define ENT_TYPE(_ent) ent->mnt_type
+# define ENT_OPTS(_ent) ent->mnt_opts
+# define ENT_PASS(_ent) ent->mnt_passno
#else
-#define HAVE_GETFSENT
-#include <fstab.h>
-#define ENT fstab
-#define START_ENT
-#define GET_ENT getfsent ()
-#define GET_ENT_FILE(_name) getfsfile (_name)
-#define END_ENT endfsent ()
-#define ENT_BLOCKDEVICE(_ent) ent->fs_spec
-#define ENT_TYPE(_ent) ent->fs_vfstype
-#define ENT_FILE(_ent) ent->fs_file
-#define ENT_OPTS(_ent) ent->fs_mntops
-#define ENT_PASS(_ent) ent->fs_passno
+# define HAVE_GETFSENT
+# include <fstab.h>
+# define ENT fstab
+# define START_ENT
+# define GET_ENT getfsent ()
+# define GET_ENT_FILE(_name) getfsfile (_name)
+# define END_ENT endfsent ()
+# define ENT_BLOCKDEVICE(_ent) ent->fs_spec
+# define ENT_TYPE(_ent) ent->fs_vfstype
+# define ENT_FILE(_ent) ent->fs_file
+# define ENT_OPTS(_ent) ent->fs_mntops
+# define ENT_PASS(_ent) ent->fs_passno
#endif
#include "builtins.h"
@@ -93,7 +93,8 @@ getmntfile(const char *file)
extern const char *applet;
-static int do_mount(struct ENT *ent)
+static int
+do_mount(struct ENT *ent)
{
char *argv[8];
pid_t pid;
@@ -176,7 +177,7 @@ fstabinfo(int argc, char **argv)
unsetenv("EINFO_QUIET");
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'M':
@@ -199,7 +200,7 @@ fstabinfo(int argc, char **argv)
case '>':
if (sscanf(optarg + 1, "%d", &i) != 1)
eerrorx("%s: invalid passno %s",
- argv[0], optarg + 1);
+ argv[0], optarg + 1);
filtered = true;
opt = optarg[0];
@@ -212,7 +213,7 @@ fstabinfo(int argc, char **argv)
(opt == '<' && i > p && p != 0) ||
(opt == '>' && i < p && p != 0))
rc_stringlist_add(files,
- ENT_FILE(ent));
+ ENT_FILE(ent));
}
END_ENT;
break;
@@ -222,7 +223,7 @@ fstabinfo(int argc, char **argv)
output = OUTPUT_PASSNO;
break;
}
- break;
+ break;
case 't':
filtered = true;
@@ -230,13 +231,14 @@ fstabinfo(int argc, char **argv)
START_ENT;
while ((ent = GET_ENT))
if (strcmp(token, ENT_TYPE(ent)) == 0)
- rc_stringlist_add(files, ENT_FILE(ent));
+ rc_stringlist_add(files,
+ ENT_FILE(ent));
END_ENT;
}
break;
case_RC_COMMON_GETOPT
- }
+ }
}
if (optind < argc) {
@@ -246,7 +248,8 @@ fstabinfo(int argc, char **argv)
if (strcmp(argv[i], file->value) == 0)
break;
if (i >= argc)
- rc_stringlist_delete(files, file->value);
+ rc_stringlist_delete(files,
+ file->value);
}
} else {
while (optind < argc)
@@ -290,10 +293,10 @@ fstabinfo(int argc, char **argv)
case OUTPUT_MOUNTARGS:
printf("-o %s -t %s %s %s\n",
- ENT_OPTS(ent),
- ENT_TYPE(ent),
- ENT_BLOCKDEVICE(ent),
- file->value);
+ ENT_OPTS(ent),
+ ENT_TYPE(ent),
+ ENT_BLOCKDEVICE(ent),
+ file->value);
break;
case OUTPUT_OPTIONS:
diff --git a/src/rc/mountinfo.c b/src/rc/mountinfo.c
index c6a421c3..9686230f 100644
--- a/src/rc/mountinfo.c
+++ b/src/rc/mountinfo.c
@@ -1,7 +1,7 @@
/*
- mountinfo.c
- Obtains information about mounted filesystems.
- */
+ mountinfo.c
+ Obtains information about mounted filesystems.
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -33,15 +33,15 @@
#include <sys/param.h>
#if defined(__DragonFly__) || defined(__FreeBSD__)
-# include <sys/ucred.h>
-# include <sys/mount.h>
-# define F_FLAGS f_flags
+# include <sys/ucred.h>
+# include <sys/mount.h>
+# define F_FLAGS f_flags
#elif defined(BSD)
-# include <sys/statvfs.h>
-# define statfs statvfs
-# define F_FLAGS f_flag
+# include <sys/statvfs.h>
+# define statfs statvfs
+# define F_FLAGS f_flag
#elif defined (__linux__)
-#include <mntent.h>
+# include <mntent.h>
#endif
#include <errno.h>
@@ -84,9 +84,10 @@ struct args {
net_opts netdev;
};
-static int process_mount(RC_STRINGLIST *list, struct args *args,
- char *from, char *to, char *fstype, char *options,
- int netdev)
+static int
+process_mount(RC_STRINGLIST *list, struct args *args,
+ char *from, char *to, char *fstype, char *options,
+ int netdev)
{
char *p;
RC_STRING *s;
@@ -105,7 +106,7 @@ static int process_mount(RC_STRINGLIST *list, struct args *args,
if (netdev != 0)
return 1;
} else if (args->netdev == net_no &&
- (netdev != -1 || TAILQ_FIRST(args->mounts)))
+ (netdev != -1 || TAILQ_FIRST(args->mounts)))
{
if (netdev != 1)
return 1;
@@ -134,8 +135,8 @@ static int process_mount(RC_STRINGLIST *list, struct args *args,
if (TAILQ_FIRST(args->mounts)) {
TAILQ_FOREACH(s, args->mounts, entries)
- if (strcmp(s->value, to) == 0)
- break;
+ if (strcmp(s->value, to) == 0)
+ break;
if (! s)
return -1;
}
@@ -211,7 +212,8 @@ static struct opt {
{ 0, NULL }
};
-static RC_STRINGLIST *find_mounts(struct args *args)
+static RC_STRINGLIST *
+find_mounts(struct args *args)
{
struct statfs *mnts;
int nmnts;
@@ -238,9 +240,11 @@ static RC_STRINGLIST *find_mounts(struct args *args)
if (! options)
options = xstrdup(o->o_name);
else {
- l = strlen(options) + strlen(o->o_name) + 2;
+ l = strlen(options) +
+ strlen(o->o_name) + 2;
tmp = xmalloc(sizeof (char) * l);
- snprintf(tmp, l, "%s,%s", options, o->o_name);
+ snprintf(tmp, l, "%s,%s", options,
+ o->o_name);
free(options);
options = tmp;
}
@@ -249,11 +253,11 @@ static RC_STRINGLIST *find_mounts(struct args *args)
}
process_mount(list, args,
- mnts[i].f_mntfromname,
- mnts[i].f_mntonname,
- mnts[i].f_fstypename,
- options,
- netdev);
+ mnts[i].f_mntfromname,
+ mnts[i].f_mntonname,
+ mnts[i].f_fstypename,
+ options,
+ netdev);
free(options);
options = NULL;
@@ -263,7 +267,8 @@ static RC_STRINGLIST *find_mounts(struct args *args)
}
#elif defined (__linux__)
-static struct mntent *getmntfile(const char *file)
+static struct mntent *
+getmntfile(const char *file)
{
struct mntent *ent = NULL;
FILE *fp;
@@ -277,7 +282,8 @@ static struct mntent *getmntfile(const char *file)
return ent;
}
-static RC_STRINGLIST *find_mounts(struct args *args)
+static RC_STRINGLIST *
+find_mounts(struct args *args)
{
FILE *fp;
char *buffer;
@@ -321,7 +327,8 @@ static RC_STRINGLIST *find_mounts(struct args *args)
# error "Operating system not supported!"
#endif
-static regex_t *get_regex(const char *string)
+static regex_t *
+get_regex(const char *string)
{
regex_t *reg = xmalloc(sizeof (*reg));
int result;
@@ -373,7 +380,8 @@ static const char * const longopts_help[] = {
};
#include "_usage.c"
-int mountinfo(int argc, char **argv)
+int
+mountinfo(int argc, char **argv)
{
struct args args;
regex_t *point_regex = NULL;
@@ -387,10 +395,10 @@ int mountinfo(int argc, char **argv)
/* Ensure that we are only quiet when explicitly told to be */
unsetenv("EINFO_QUIET");
-#define DO_REG(_var) \
- if (_var) free(_var); \
+#define DO_REG(_var) \
+ if (_var) free(_var); \
_var = get_regex(optarg);
-#define REG_FREE(_var) \
+#define REG_FREE(_var) \
if (_var) { regfree(_var); free(_var); }
memset (&args, 0, sizeof(args));
@@ -399,7 +407,7 @@ int mountinfo(int argc, char **argv)
args.mounts = rc_stringlist_new();
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'e':
@@ -442,13 +450,14 @@ int mountinfo(int argc, char **argv)
args.mount_type = mount_from;
break;
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
}
while (optind < argc) {
if (argv[optind][0] != '/')
- eerrorx("%s: `%s' is not a mount point", argv[0], argv[optind]);
+ eerrorx("%s: `%s' is not a mount point",
+ argv[0], argv[optind]);
rc_stringlist_add(args.mounts, argv[optind++]);
}
nodes = find_mounts(&args);
diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c
index bffc9385..34da282b 100644
--- a/src/rc/rc-applets.c
+++ b/src/rc/rc-applets.c
@@ -1,10 +1,10 @@
/*
- rc-applets.c
+ rc-applets.c
- Handle multicall applets for use in our init scripts.
- Basically this makes us a lot faster for the most part, and removes
- any shell incompatabilities we might otherwise encounter.
- */
+ Handle multicall applets for use in our init scripts.
+ Basically this makes us a lot faster for the most part, and removes
+ any shell incompatabilities we might otherwise encounter.
+*/
/*
* Copyright 2007-2009 Roy Marples <roy@marples.name>
@@ -60,7 +60,8 @@
/* Applet is first parsed in rc.c - no point in doing it again */
extern const char *applet;
-static int syslog_decode(char *name, CODE *codetab)
+static int
+syslog_decode(char *name, CODE *codetab)
{
CODE *c;
@@ -74,7 +75,8 @@ static int syslog_decode(char *name, CODE *codetab)
return -1;
}
-static int do_e(int argc, char **argv)
+static int
+do_e(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
int i;
@@ -93,12 +95,12 @@ static int do_e(int argc, char **argv)
if (strcmp(applet, "eval_ecolors") == 0) {
printf("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
- ecolor(ECOLOR_GOOD),
- ecolor(ECOLOR_WARN),
- ecolor(ECOLOR_BAD),
- ecolor(ECOLOR_HILITE),
- ecolor(ECOLOR_BRACKET),
- ecolor(ECOLOR_NORMAL));
+ ecolor(ECOLOR_GOOD),
+ ecolor(ECOLOR_WARN),
+ ecolor(ECOLOR_BAD),
+ ecolor(ECOLOR_HILITE),
+ ecolor(ECOLOR_BRACKET),
+ ecolor(ECOLOR_NORMAL));
exit(EXIT_SUCCESS);
}
@@ -120,9 +122,10 @@ static int do_e(int argc, char **argv)
argv++;
}
} else if (strcmp(applet, "esyslog") == 0 ||
- strcmp(applet, "elog") == 0) {
+ strcmp(applet, "elog") == 0) {
p = strchr(argv[0], '.');
- if (!p || (level = syslog_decode(p + 1, prioritynames)) == -1)
+ if (!p ||
+ (level = syslog_decode(p + 1, prioritynames)) == -1)
eerrorx("%s: invalid log level `%s'", applet, argv[0]);
if (argc < 3)
@@ -160,7 +163,7 @@ static int do_e(int argc, char **argv)
if (timercmp(&now, &stop, <))
continue;
eendv(EXIT_FAILURE,
- "timed out waiting for %s", argv[i]);
+ "timed out waiting for %s", argv[i]);
return EXIT_FAILURE;
}
eendv(EXIT_SUCCESS, NULL);
@@ -251,7 +254,8 @@ static int do_e(int argc, char **argv)
return retval;
}
-static int do_service(int argc, char **argv)
+static int
+do_service(int argc, char **argv)
{
bool ok = false;
char *service;
@@ -263,7 +267,7 @@ static int do_service(int argc, char **argv)
else
service = getenv("RC_SVCNAME");
- if (! service || *service == '\0')
+ if (service == NULL || *service == '\0')
eerrorx("%s: no service specified", applet);
if (strcmp(applet, "service_started") == 0)
@@ -297,15 +301,16 @@ static int do_service(int argc, char **argv)
} else if (strcmp(applet, "service_crashed") == 0) {
ok = (_rc_can_find_pids() &&
- rc_service_daemons_crashed(service) &&
- errno != EACCES);
+ rc_service_daemons_crashed(service) &&
+ errno != EACCES);
} else
eerrorx("%s: unknown applet", applet);
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int do_mark_service(int argc, char **argv)
+static int
+do_mark_service(int argc, char **argv)
{
bool ok = false;
char *svcname = getenv("RC_SVCNAME");
@@ -320,7 +325,7 @@ static int do_mark_service(int argc, char **argv)
else
service = getenv("RC_SVCNAME");
- if (! service || *service == '\0')
+ if (service == NULL || *service == '\0')
eerrorx("%s: no service specified", applet);
if (strcmp(applet, "mark_service_started") == 0)
@@ -340,22 +345,22 @@ static int do_mark_service(int argc, char **argv)
else
eerrorx("%s: unknown applet", applet);
- /* If we're marking ourselves then we need to inform our parent runscript
- process so they do not mark us based on our exit code */
+ /* If we're marking ourselves then we need to inform our parent
+ runscript process so they do not mark us based on our exit code */
if (ok && svcname && strcmp(svcname, service) == 0) {
runscript_pid = getenv("RC_RUNSCRIPT_PID");
if (runscript_pid && sscanf(runscript_pid, "%d", &pid) == 1)
if (kill(pid, SIGHUP) != 0)
eerror("%s: failed to signal parent %d: %s",
- applet, pid, strerror(errno));
+ applet, pid, strerror(errno));
/* Remove the exclusive time test. This ensures that it's not
in control as well */
l = strlen(RC_SVCDIR "/exclusive") + strlen(svcname) +
- strlen(runscript_pid) + 4;
+ strlen(runscript_pid) + 4;
mtime = xmalloc(l);
snprintf(mtime, l, RC_SVCDIR "/exclusive/%s.%s",
- svcname, runscript_pid);
+ svcname, runscript_pid);
if (exists(mtime) && unlink(mtime) != 0)
eerror("%s: unlink: %s", applet, strerror(errno));
free(mtime);
@@ -364,13 +369,14 @@ static int do_mark_service(int argc, char **argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int do_value(int argc, char **argv)
+static int
+do_value(int argc, char **argv)
{
bool ok = false;
char *service = getenv("RC_SVCNAME");
char *option;
- if (! service)
+ if (service == NULL)
eerrorx("%s: no service specified", applet);
if (argc < 2 || ! argv[1] || *argv[1] == '\0')
@@ -386,7 +392,7 @@ static int do_value(int argc, char **argv)
ok = true;
}
} 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[1], argv[2]);
else
eerrorx("%s: unknown applet", applet);
@@ -394,7 +400,8 @@ static int do_value(int argc, char **argv)
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
-static int do_shell_var(int argc, char **argv)
+static int
+do_shell_var(int argc, char **argv)
{
int i;
char *p;
@@ -402,10 +409,8 @@ static int do_shell_var(int argc, char **argv)
for (i = 1; i < argc; i++) {
p = argv[i];
-
if (i != 1)
putchar(' ');
-
while (*p) {
c = (unsigned char)*p++;
if (! isalnum(c))
@@ -414,11 +419,11 @@ static int do_shell_var(int argc, char **argv)
}
}
putchar('\n');
-
return EXIT_SUCCESS;
}
-void run_applets(int argc, char **argv)
+void
+run_applets(int argc, char **argv)
{
int i = 2;
char *p;
@@ -436,7 +441,7 @@ void run_applets(int argc, char **argv)
else if (strcmp(applet, "rc-status") == 0)
exit(rc_status(argc, argv));
else if (strcmp(applet, "rc-update") == 0 ||
- strcmp(applet, "update-rc") == 0)
+ strcmp(applet, "update-rc") == 0)
exit(rc_update(argc, argv));
else if (strcmp(applet, "runscript") == 0)
exit(runscript(argc, argv));
@@ -498,7 +503,7 @@ void run_applets(int argc, char **argv)
if (p && sscanf(p, "%d", &pid) == 1) {
if (kill(pid, SIGUSR1) != 0)
eerrorx("rc-abort: failed to signal parent %d: %s",
- pid, strerror(errno));
+ pid, strerror(errno));
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
diff --git a/src/rc/rc-depend.c b/src/rc/rc-depend.c
index bdf8838d..29267676 100644
--- a/src/rc/rc-depend.c
+++ b/src/rc/rc-depend.c
@@ -1,7 +1,7 @@
/*
- rc-depend
- rc service dependency and ordering
- */
+ rc-depend
+ rc service dependency and ordering
+*/
/*
* Copyright 2007-2009 Roy Marples <roy@marples.name>
@@ -85,7 +85,7 @@ _rc_deptree_load(int force, int *regen) {
if (st.st_mtime < t) {
eerror("Clock skew detected with `%s'", file);
eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE
- "' to %s", ctime(&t));
+ "' to %s", ctime(&t));
fp = fopen(RC_DEPTREE_SKEWED, "w");
if (fp != NULL) {
fprintf(fp, "%s\n", file);
@@ -144,7 +144,7 @@ rc_depend(int argc, char **argv)
types = rc_stringlist_new();
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'a':
@@ -167,8 +167,8 @@ rc_depend(int argc, char **argv)
options &= RC_DEP_TRACE;
break;
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
}
if (!(deptree = _rc_deptree_load(update, NULL)))
@@ -185,7 +185,7 @@ rc_depend(int argc, char **argv)
depends = rc_deptree_depends(deptree, NULL, list, runlevel, 0);
if (!depends && errno == ENOENT)
eerror("no dependency info for service `%s'",
- argv[optind]);
+ argv[optind]);
else
rc_stringlist_add(services, argv[optind]);
@@ -210,7 +210,7 @@ rc_depend(int argc, char **argv)
}
depends = rc_deptree_depends(deptree, types, services,
- runlevel, options);
+ runlevel, options);
if (TAILQ_FIRST(depends)) {
TAILQ_FOREACH(s, depends, entries) {
diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c
index 697ebddd..f0320778 100644
--- a/src/rc/rc-logger.c
+++ b/src/rc/rc-logger.c
@@ -1,8 +1,8 @@
/*
- rc-logger.c
- Spawns a logging daemon to capture stdout and stderr so we can log
- them to a buffer and/or files.
- */
+ rc-logger.c
+ Spawns a logging daemon to capture stdout and stderr so we can log
+ them to a buffer and/or files.
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -46,11 +46,11 @@
#include <unistd.h>
#ifdef __linux__
-# include <pty.h>
+# include <pty.h>
#elif defined(__NetBSD__) || defined(__OpenBSD__)
-# include <util.h>
+# include <util.h>
#else
-# include <libutil.h>
+# include <libutil.h>
#endif
#include "einfo.h"
@@ -60,7 +60,7 @@
#define LOGFILE RC_SVCDIR "/rc.log"
#define PERMLOG "/var/log/rc.log"
-#define MOVELOG "cat " LOGFILE " 2>/dev/null >>" PERMLOG " && " \
+#define MOVELOG "cat " LOGFILE " 2>/dev/null >>" PERMLOG " && " \
"rm -f " LOGFILE
static int signal_pipe[2] = { -1, -1 };
@@ -78,11 +78,12 @@ pid_t rc_logger_pid = -1;
int rc_logger_tty = -1;
bool rc_in_logger = false;
-static void write_log(int logfd, const char *buffer, size_t bytes)
+static void
+write_log(int logfd, const char *buffer, size_t bytes)
{
const char *p = buffer;
- while ((size_t) (p - buffer) < bytes) {
+ while ((size_t)(p - buffer) < bytes) {
switch (*p) {
case '\r':
goto cont;
@@ -110,7 +111,9 @@ cont:
p++;
}
}
-static void write_time(FILE *f, const char *s)
+
+static void
+write_time(FILE *f, const char *s)
{
time_t now = time(NULL);
struct tm *tm = localtime(&now);
@@ -119,7 +122,8 @@ static void write_time(FILE *f, const char *s)
fflush(f);
}
-void rc_logger_close(void)
+void
+rc_logger_close(void)
{
int sig = SIGTERM;
@@ -138,7 +142,8 @@ void rc_logger_close(void)
dup2(fd_stderr, STDERR_FILENO);
}
-void rc_logger_open(const char *level)
+void
+rc_logger_open(const char *level)
{
int slave_tty;
struct termios tt;
@@ -157,7 +162,7 @@ void rc_logger_open(const char *level)
eerrorx("pipe: %s", strerror(errno));
for (i = 0; i < 2; i++)
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));
if (isatty(STDOUT_FILENO)) {
@@ -202,36 +207,38 @@ void rc_logger_open(const char *level)
if (rc_logger_tty >= 0)
fd[1].fd = rc_logger_tty;
for (;;) {
- if ((s = poll(fd, rc_logger_tty >= 0 ? 2 : 1, -1)) == -1) {
+ if ((s = poll(fd,
+ rc_logger_tty >= 0 ? 2 : 1, -1)) == -1)
+ {
eerror("poll: %s", strerror(errno));
break;
- }
-
- if (s > 0) {
- if (fd[1].revents & (POLLIN | POLLHUP)) {
- memset(buffer, 0, BUFSIZ);
- bytes = read(rc_logger_tty, buffer, BUFSIZ);
- write(STDOUT_FILENO, buffer, bytes);
-
- if (log)
- write_log(fileno (log), buffer, bytes);
- else {
- if (logbuf_size - logbuf_len < bytes) {
- logbuf_size += BUFSIZ * 10;
- logbuf = xrealloc(logbuf,
- sizeof(char ) *
- logbuf_size);
- }
-
- memcpy(logbuf + logbuf_len, buffer, bytes);
- logbuf_len += bytes;
+ } else if (s == 0)
+ continue;
+
+ if (fd[1].revents & (POLLIN | POLLHUP)) {
+ memset(buffer, 0, BUFSIZ);
+ bytes = read(rc_logger_tty, buffer, BUFSIZ);
+ write(STDOUT_FILENO, buffer, bytes);
+
+ if (log)
+ write_log(fileno (log), buffer, bytes);
+ else {
+ if (logbuf_size - logbuf_len < bytes) {
+ logbuf_size += BUFSIZ * 10;
+ logbuf = xrealloc(logbuf,
+ sizeof(char ) *
+ logbuf_size);
}
- }
- /* Only SIGTERMS signals come down this pipe */
- if (fd[0].revents & (POLLIN | POLLHUP))
- break;
+ memcpy(logbuf + logbuf_len,
+ buffer, bytes);
+ logbuf_len += bytes;
+ }
}
+
+ /* Only SIGTERMS signals come down this pipe */
+ if (fd[0].revents & (POLLIN | POLLHUP))
+ break;
}
free(buffer);
if (logbuf) {
@@ -246,10 +253,9 @@ void rc_logger_open(const char *level)
fclose(log);
}
- /* Try and cat our new logfile to a more permament location and then
- * punt it */
+ /* Try and cat our new logfile to a more permament location
+ and then punt it */
system(MOVELOG);
-
exit(0);
/* NOTREACHED */
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c
index f86f1773..2382c2cb 100644
--- a/src/rc/rc-misc.c
+++ b/src/rc/rc-misc.c
@@ -1,7 +1,7 @@
/*
- librc-misc.c
- rc misc functions
- */
+ librc-misc.c
+ rc misc functions
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -34,8 +34,8 @@
#include <sys/utsname.h>
#ifdef __linux__
-#include <sys/sysinfo.h>
-#include <regex.h>
+# include <sys/sysinfo.h>
+# include <regex.h>
#endif
#include <ctype.h>
@@ -244,7 +244,8 @@ env_config(void)
if (sys)
setenv("RC_SYS", sys, 1);
- /* Some scripts may need to take a different code path if Linux/FreeBSD, etc
+ /* Some scripts may need to take a different code path if
+ Linux/FreeBSD, etc
To save on calling uname, we store it in an environment variable */
if (uname(&uts) == 0)
setenv("RC_UNAME", uts.sysname, 1);
@@ -346,7 +347,7 @@ exec_service(const char *service, const char *arg)
/* Safe to run now */
execl(file, file, "--lockfd", sfd, arg, (char *) NULL);
fprintf(stderr, "unable to exec `%s': %s\n",
- file, strerror(errno));
+ file, strerror(errno));
svc_unlock(basename_c(service), fd);
_exit(EXIT_FAILURE);
}
diff --git a/src/rc/rc-plugin.c b/src/rc/rc-plugin.c
index ffba4a83..33db6bde 100644
--- a/src/rc/rc-plugin.c
+++ b/src/rc/rc-plugin.c
@@ -1,7 +1,7 @@
/*
- librc-plugin.c
- Simple plugin handler
- */
+ librc-plugin.c
+ Simple plugin handler
+*/
/*
* Copyright 2007-2008 Roy Marples <roy@marples.name>
@@ -62,7 +62,8 @@ typedef struct plugin
TAILQ_HEAD(, plugin) plugins;
#ifndef __FreeBSD__
-dlfunc_t dlfunc(void * __restrict handle, const char * __restrict symbol)
+dlfunc_t
+dlfunc(void * __restrict handle, const char * __restrict symbol)
{
union {
void *d;
@@ -74,7 +75,8 @@ dlfunc_t dlfunc(void * __restrict handle, const char * __restrict symbol)
}
#endif
-void rc_plugin_load(void)
+void
+rc_plugin_load(void)
{
DIR *dp;
struct dirent *d;
@@ -89,7 +91,7 @@ void rc_plugin_load(void)
TAILQ_INIT(&plugins);
- if (! (dp = opendir(RC_PLUGINDIR)))
+ if (!(dp = opendir(RC_PLUGINDIR)))
return;
while ((d = readdir(dp))) {
@@ -98,14 +100,16 @@ void rc_plugin_load(void)
snprintf(file, sizeof(file), RC_PLUGINDIR "/%s", d->d_name);
h = dlopen(file, RTLD_LAZY);
- if (! h) {
+ if (h == NULL) {
eerror("dlopen: %s", dlerror());
continue;
}
- fptr = (int (*)(RC_HOOK, const char*))dlfunc(h, RC_PLUGIN_HOOK);
- if (! fptr) {
- eerror("%s: cannot find symbol `%s'", d->d_name, RC_PLUGIN_HOOK);
+ fptr = (int (*)(RC_HOOK, const char*))
+ dlfunc(h, RC_PLUGIN_HOOK);
+ if (fptr == NULL) {
+ eerror("%s: cannot find symbol `%s'",
+ d->d_name, RC_PLUGIN_HOOK);
dlclose(h);
} else {
plugin = xmalloc(sizeof(*plugin));
@@ -118,7 +122,8 @@ void rc_plugin_load(void)
closedir(dp);
}
-int rc_waitpid(pid_t pid)
+int
+rc_waitpid(pid_t pid)
{
int status;
@@ -131,7 +136,8 @@ int rc_waitpid(pid_t pid)
return status;
}
-void rc_plugin_run(RC_HOOK hook, const char *value)
+void
+rc_plugin_run(RC_HOOK hook, const char *value)
{
PLUGIN *plugin;
struct sigaction sa;
@@ -234,7 +240,8 @@ void rc_plugin_run(RC_HOOK hook, const char *value)
}
}
-void rc_plugin_unload(void)
+void
+rc_plugin_unload(void)
{
PLUGIN *plugin = TAILQ_FIRST(&plugins);
PLUGIN *next;
diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index ab3d47b2..82d4cf22 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -1,7 +1,7 @@
/*
- rc-service.c
- Finds all OpenRC services
- */
+ rc-service.c
+ Finds all OpenRC services
+*/
/*
* Copyright 2008 Roy Marples <roy@marples.name>
@@ -70,7 +70,7 @@ rc_service(int argc, char **argv)
unsetenv("EINFO_QUIET");
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'e':
@@ -87,7 +87,7 @@ rc_service(int argc, char **argv)
return EXIT_FAILURE;
rc_stringlist_sort(&list);
TAILQ_FOREACH(s, list, entries)
- printf("%s\n", s->value);
+ printf("%s\n", s->value);
#ifdef DEBUG_MEMORY
rc_stringlist_free(list);
#endif
@@ -104,8 +104,8 @@ rc_service(int argc, char **argv)
return EXIT_SUCCESS;
/* NOTREACHED */
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
}
argc -= optind;
diff --git a/src/rc/rc-update.c b/src/rc/rc-update.c
index 3e0c7959..6b31ba10 100644
--- a/src/rc/rc-update.c
+++ b/src/rc/rc-update.c
@@ -1,7 +1,7 @@
/*
- rc-update
- Manage init scripts and runlevels
- */
+ rc-update
+ Manage init scripts and runlevels
+*/
/*
* Copyright 2007-2009 Roy Marples <roy@marples.name>
@@ -57,19 +57,21 @@ add(const char *runlevel, const char *service)
if (!rc_service_exists(service)) {
if (errno == ENOEXEC)
- eerror("%s: service `%s' is not executeable", applet, service);
+ eerror("%s: service `%s' is not executeable",
+ applet, service);
else
- 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)) {
ewarn ("%s: %s already installed in runlevel `%s'; skipping",
- applet, service, runlevel);
+ applet, service, runlevel);
retval = 0;
} else if (rc_service_add(runlevel, service)) {
einfo ("%s added to runlevel %s", service, runlevel);
retval = 1;
} else
eerror("%s: failed to add service `%s' to runlevel `%s': %s",
- applet, service, runlevel, strerror (errno));
+ applet, service, runlevel, strerror (errno));
return retval;
}
@@ -87,10 +89,10 @@ delete(const char *runlevel, const char *service)
if (errno == ENOENT)
eerror ("%s: service `%s' is not in the runlevel `%s'",
- applet, service, runlevel);
+ applet, service, runlevel);
else
eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
- applet, service, runlevel, strerror (errno));
+ applet, service, runlevel, strerror (errno));
return retval;
}
@@ -112,7 +114,7 @@ show(RC_STRINGLIST *runlevels, bool verbose)
TAILQ_FOREACH(runlevel, runlevels, entries) {
if (rc_service_in_runlevel(service->value,
- runlevel->value))
+ runlevel->value))
{
rc_stringlist_add(in, runlevel->value);
inone = true;
@@ -127,7 +129,7 @@ show(RC_STRINGLIST *runlevels, bool verbose)
if (inone || verbose) {
printf(" %20s |", service->value);
TAILQ_FOREACH(runlevel, in, entries)
- printf (" %s", runlevel->value);
+ printf (" %s", runlevel->value);
printf ("\n");
}
rc_stringlist_free(in);
@@ -137,9 +139,9 @@ show(RC_STRINGLIST *runlevels, bool verbose)
}
#include "_usage.h"
-#define usagestring "" \
- "Usage: rc-update [options] add service <runlevel>\n" \
- " rc-update [options] del service <runlevel>\n" \
+#define usagestring "" \
+ "Usage: rc-update [options] add service <runlevel>\n" \
+ " rc-update [options] del service <runlevel>\n" \
" rc-update [options] show"
#define getoptstring "u" getoptstring_COMMON
static const struct option longopts[] = {
@@ -172,13 +174,13 @@ rc_update(int argc, char **argv)
int ret;
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *)0)) != -1)
+ longopts, (int *)0)) != -1)
switch (opt) {
case 'u':
_rc_deptree_load(-1, &ret);
return ret;
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
verbose = rc_yesno(getenv ("EINFO_VERBOSE"));
@@ -192,14 +194,15 @@ rc_update(int argc, char **argv)
if (strcmp(argv[optind], "add") == 0)
action = DOADD;
else if (strcmp(argv[optind], "delete") == 0 ||
- strcmp(argv[optind], "del") == 0)
+ strcmp(argv[optind], "del") == 0)
action = DODELETE;
else if (strcmp(argv[optind], "show") == 0)
action = DOSHOW;
if (action)
optind++;
else
- eerrorx("%s: invalid command `%s'", applet, argv[optind]);
+ eerrorx("%s: invalid command `%s'",
+ applet, argv[optind]);
}
if (!action)
action = DOSHOW;
@@ -219,7 +222,7 @@ rc_update(int argc, char **argv)
else {
rc_stringlist_free(runlevels);
eerrorx ("%s: `%s' is not a valid runlevel",
- applet, argv[optind]);
+ applet, argv[optind]);
}
}
@@ -254,13 +257,13 @@ rc_update(int argc, char **argv)
if (!TAILQ_FIRST(runlevels)) {
free(runlevels);
- eerrorx ("%s: no runlevels found", applet);
+ eerrorx("%s: no runlevels found", applet);
}
TAILQ_FOREACH(runlevel, runlevels, entries) {
if (!rc_runlevel_exists(runlevel->value)) {
eerror ("%s: runlevel `%s' does not exist",
- applet, runlevel->value);
+ applet, runlevel->value);
continue;
}
@@ -273,8 +276,8 @@ rc_update(int argc, char **argv)
if (retval == EXIT_SUCCESS &&
num_updated == 0 && action & DODELETE)
ewarnx("%s: service `%s' not found in any"
- " of the specified runlevels",
- applet, service);
+ " of the specified runlevels",
+ applet, service);
}
}
diff --git a/src/rc/rc.c b/src/rc/rc.c
index a3b17095..9a08546a 100644
--- a/src/rc/rc.c
+++ b/src/rc/rc.c
@@ -44,7 +44,7 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
#include <sys/wait.h>
#ifdef __linux__
-# include <asm/setup.h> /* for COMMAND_LINE_SIZE */
+# include <asm/setup.h> /* for COMMAND_LINE_SIZE */
#endif
#include <errno.h>
@@ -108,17 +108,17 @@ clean_failed(void)
while ((d = readdir(dp))) {
if (d->d_name[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;
l = strlen(RC_SVCDIR "/failed/") +
- strlen(d->d_name) + 1;
+ strlen(d->d_name) + 1;
path = xmalloc(sizeof(char) * l);
snprintf(path, l, RC_SVCDIR "/failed/%s", d->d_name);
if (path) {
if (unlink(path))
eerror("%s: unlink `%s': %s",
- applet, path, strerror(errno));
+ applet, path, strerror(errno));
free(path);
}
}
@@ -217,8 +217,8 @@ read_key(bool block)
if (!isatty(fd))
return false;
- /* Now save our terminal settings. We need to restore them at exit as we
- * will be changing it for non-blocking reads for Interactive */
+ /* Now save our terminal settings. We need to restore them at exit as
+ we will be changing it for non-blocking reads for Interactive */
if (!termios_orig) {
termios_orig = xmalloc(sizeof(*termios_orig));
tcgetattr(fd, termios_orig);
@@ -301,7 +301,7 @@ run_program(const char *prog)
execl(prog, prog, (char *) NULL);
eerror("%s: unable to exec `%s': %s", applet, prog,
- strerror(errno));
+ strerror(errno));
_exit(EXIT_FAILURE);
}
@@ -323,7 +323,7 @@ sulogin(bool cont)
{
execl("/sbin/halt", "/sbin/halt", "-f", (char *) NULL);
eerrorx("%s: unable to exec `/sbin/halt': %s",
- applet, strerror(errno));
+ applet, strerror(errno));
}
#endif
if (!cont) {
@@ -343,7 +343,7 @@ single_user(void)
rc_logger_close();
execl(SHUTDOWN, SHUTDOWN, "now", (char *) NULL);
eerrorx("%s: unable to exec `" SHUTDOWN "': %s",
- applet, strerror(errno));
+ applet, strerror(errno));
}
static bool
@@ -359,7 +359,7 @@ set_krunlevel(const char *level)
if (exists(RC_KRUNLEVEL) &&
unlink(RC_KRUNLEVEL) != 0)
eerror("unlink `%s': %s", RC_KRUNLEVEL,
- strerror(errno));
+ strerror(errno));
return false;
}
@@ -409,11 +409,11 @@ remove_pid(pid_t pid)
RC_PID *p;
LIST_FOREACH(p, &service_pids, entries)
- if (p->pid == pid) {
- LIST_REMOVE(p, entries);
- free(p);
- return;
- }
+ if (p->pid == pid) {
+ LIST_REMOVE(p, entries);
+ free(p);
+ return;
+ }
}
static void
@@ -484,7 +484,7 @@ handle_signal(int sig)
/* Kill any running services we have started */
LIST_FOREACH(pi, &service_pids, entries)
- kill(pi->pid, SIGTERM);
+ kill(pi->pid, SIGTERM);
/* Notify plugins we are aborting */
rc_plugin_run(RC_HOOK_ABORT, NULL);
@@ -514,15 +514,15 @@ do_sysinit()
uname(&uts);
printf("\n %sOpenRC %s" VERSION "%s is starting up %s",
- ecolor(ECOLOR_GOOD), ecolor(ECOLOR_HILITE),
- ecolor(ECOLOR_NORMAL), ecolor(ECOLOR_BRACKET));
+ ecolor(ECOLOR_GOOD), ecolor(ECOLOR_HILITE),
+ ecolor(ECOLOR_NORMAL), ecolor(ECOLOR_BRACKET));
#ifdef BRANDING
printf(BRANDING " (%s)", uts.machine);
#else
printf("%s %s (%s)",
- uts.sysname,
- uts.release,
- uts.machine);
+ uts.sysname,
+ uts.release,
+ uts.machine);
#endif
if ((sys = rc_sys()))
@@ -533,7 +533,7 @@ do_sysinit()
if (!rc_yesno(getenv ("EINFO_QUIET")) &&
rc_conf_yesno("rc_interactive"))
printf("Press %sI%s to enter interactive boot mode\n\n",
- ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
+ ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
setenv("RC_RUNLEVEL", RC_LEVEL_SYSINIT, 1);
run_program(INITSH);
@@ -611,13 +611,14 @@ do_stop_services(const char *newlevel, bool parallel)
if (!svc1) {
tmplist = rc_stringlist_new();
rc_stringlist_add(tmplist, service->value);
- deporder = rc_deptree_depends(deptree, types_n, tmplist,
- newlevel ? newlevel : runlevel,
- RC_DEP_STRICT | RC_DEP_TRACE);
+ deporder = rc_deptree_depends(deptree, types_n,
+ tmplist, newlevel ? newlevel : runlevel,
+ RC_DEP_STRICT | RC_DEP_TRACE);
rc_stringlist_free(tmplist);
svc2 = NULL;
TAILQ_FOREACH(svc1, deporder, entries) {
- svc2 = rc_stringlist_find(start_services, svc1->value);
+ svc2 = rc_stringlist_find(start_services,
+ svc1->value);
if (svc2)
break;
}
@@ -661,21 +662,21 @@ do_start_services(bool parallel)
interactive = want_interactive();
if (interactive) {
-interactive_retry:
+ interactive_retry:
printf("\n");
einfo("About to start the service %s",
- service->value);
+ service->value);
eindent();
einfo("1) Start the service\t\t2) Skip the service");
einfo("3) Continue boot process\t\t4) Exit to shell");
eoutdent();
-interactive_option:
+ interactive_option:
switch (read_key(true)) {
- case '1': break;
- case '2': continue;
- case '3': interactive = false; break;
- case '4': sulogin(true); goto interactive_retry;
- default: goto interactive_option;
+ case '1': break;
+ case '2': continue;
+ case '3': interactive = false; break;
+ case '4': sulogin(true); goto interactive_retry;
+ default: goto interactive_option;
}
}
@@ -693,7 +694,7 @@ interactive_option:
/* Store our interactive status for boot */
if (interactive &&
(strcmp(runlevel, RC_LEVEL_SYSINIT) == 0 ||
- strcmp(runlevel, getenv("RC_BOOTLEVEL")) == 0))
+ strcmp(runlevel, getenv("RC_BOOTLEVEL")) == 0))
mark_interactive();
else {
if (exists(INTERACTIVE))
@@ -711,17 +712,17 @@ handle_bad_signal(int sig)
pid_t crashed_pid = getpid();
switch (fork()) {
- case -1:
- _exit(sig);
- /* NOTREACHED */
- case 0:
- sprintf(pid, "%i", crashed_pid);
- printf("\nAuto launching gdb!\n\n");
- _exit(execlp("gdb", "gdb", "--quiet", "--pid", pid,
- "-ex", "bt full", NULL));
- /* NOTREACHED */
- default:
- wait(&status);
+ case -1:
+ _exit(sig);
+ /* NOTREACHED */
+ case 0:
+ sprintf(pid, "%i", crashed_pid);
+ printf("\nAuto launching gdb!\n\n");
+ _exit(execlp("gdb", "gdb", "--quiet", "--pid", pid,
+ "-ex", "bt full", NULL));
+ /* NOTREACHED */
+ default:
+ wait(&status);
}
_exit(1);
/* NOTREACHED */
@@ -737,7 +738,8 @@ static const struct option longopts[] = {
longopts_COMMON
};
static const char * const longopts_help[] = {
- "override the next runlevel to change into\nwhen leaving single user or boot runlevels",
+ "override the next runlevel to change into\n"
+ "when leaving single user or boot runlevels",
"runs the service specified with the rest\nof the arguments",
"output the RC system type, if any",
longopts_help_COMMON
@@ -783,9 +785,9 @@ main(int argc, char **argv)
printf(" [%s]", bootlevel);
printf(") " VERSION
#ifdef BRANDING
- " (" BRANDING ")"
+ " (" BRANDING ")"
#endif
- "\n");
+ "\n");
exit(EXIT_SUCCESS);
}
@@ -806,7 +808,7 @@ main(int argc, char **argv)
argc++;
argv--;
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *) 0)) != -1)
+ longopts, (int *) 0)) != -1)
{
switch (opt) {
case 'o':
@@ -825,7 +827,7 @@ main(int argc, char **argv)
newlevel = rc_service_resolve(optarg);
if (!newlevel)
eerrorx("%s: service `%s' does not exist",
- applet, optarg);
+ applet, optarg);
argv += optind - 1;
*argv = newlevel;
execv(*argv, argv);
@@ -837,8 +839,8 @@ main(int argc, char **argv)
printf("%s\n", bootlevel);
exit(EXIT_SUCCESS);
/* NOTREACHED */
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
}
newlevel = argv[optind++];
@@ -886,7 +888,7 @@ main(int argc, char **argv)
if (newlevel &&
(strcmp(newlevel, RC_LEVEL_SHUTDOWN) == 0 ||
- strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
+ strcmp(newlevel, RC_LEVEL_SINGLE) == 0))
{
going_down = true;
if (!exists(RC_KRUNLEVEL))
@@ -895,10 +897,10 @@ main(int argc, char **argv)
setenv("RC_RUNLEVEL", newlevel, 1);
setenv("RC_GOINGDOWN", "YES", 1);
} else {
- /* We should not use krunevel in sysinit or the boot runlevel */
+ /* We should not use krunevel in sysinit or boot runlevels */
if (!newlevel ||
(strcmp(newlevel, RC_LEVEL_SYSINIT) != 0 &&
- strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0))
+ strcmp(newlevel, getenv("RC_BOOTLEVEL")) != 0))
{
if (get_krunlevel(krunlevel, sizeof(krunlevel))) {
newlevel = krunlevel;
@@ -960,7 +962,7 @@ main(int argc, char **argv)
if (errno == EACCES)
eerrorx("%s: superuser access required", applet);
eerrorx("%s: failed to create stopping dir `%s': %s",
- applet, RC_STOPPING, strerror(errno));
+ applet, RC_STOPPING, strerror(errno));
}
/* Build a list of all services to stop and then work out the
@@ -982,7 +984,7 @@ main(int argc, char **argv)
if (stop_services) {
tmplist = rc_deptree_depends(deptree, types_nua, stop_services,
- runlevel, depoptions | RC_DEP_STOP);
+ runlevel, depoptions | RC_DEP_STOP);
rc_stringlist_free(stop_services);
stop_services = tmplist;
}
@@ -990,7 +992,7 @@ main(int argc, char **argv)
/* Load our list of start services */
hotplugged_services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
start_services = rc_services_in_runlevel(newlevel ?
- newlevel : runlevel);
+ newlevel : runlevel);
if (strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
strcmp(newlevel ? newlevel : runlevel, RC_LEVEL_SYSINIT) != 0)
{
@@ -998,10 +1000,10 @@ main(int argc, char **argv)
TAILQ_CONCAT(start_services, tmplist, entries);
free(tmplist);
if (strcmp(newlevel ? newlevel : runlevel,
- RC_LEVEL_SINGLE) != 0)
+ RC_LEVEL_SINGLE) != 0)
{
if (strcmp(newlevel ? newlevel : runlevel,
- bootlevel) != 0)
+ bootlevel) != 0)
{
tmplist = rc_services_in_runlevel(bootlevel);
TAILQ_CONCAT(start_services, tmplist, entries);
@@ -1009,9 +1011,9 @@ main(int argc, char **argv)
}
if (hotplugged_services) {
TAILQ_FOREACH(service, hotplugged_services,
- entries)
- rc_stringlist_addu(start_services,
- service->value);
+ entries)
+ rc_stringlist_addu(start_services,
+ service->value);
}
}
}
@@ -1027,7 +1029,7 @@ main(int argc, char **argv)
/* Notify the plugins we have finished */
rc_plugin_run(RC_HOOK_RUNLEVEL_STOP_OUT,
- going_down ? newlevel : runlevel);
+ going_down ? newlevel : runlevel);
hook_out = 0;
rmdir(RC_STOPPING);
@@ -1054,14 +1056,14 @@ main(int argc, char **argv)
/* Re-add our hotplugged services if they stopped */
if (hotplugged_services)
TAILQ_FOREACH(service, hotplugged_services, entries)
- rc_service_mark(service->value, RC_SERVICE_HOTPLUGGED);
+ rc_service_mark(service->value, RC_SERVICE_HOTPLUGGED);
/* Order the services to start */
if (start_services) {
rc_stringlist_sort(&start_services);
deporder = rc_deptree_depends(deptree, types_nua,
- start_services, runlevel,
- depoptions | RC_DEP_START);
+ start_services, runlevel,
+ depoptions | RC_DEP_START);
rc_stringlist_free(start_services);
start_services = deporder;
}
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index 8cfe5039..b0fb9aa2 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -54,11 +54,11 @@
#include <unistd.h>
#ifdef __linux__
-# include <pty.h>
+# include <pty.h>
#elif defined(__NetBSD__) || defined(__OpenBSD__)
-# include <util.h>
+# include <util.h>
#else
-# include <libutil.h>
+# include <libutil.h>
#endif
#include "builtins.h"
@@ -121,9 +121,9 @@ setup_selinux(int argc, char **argv)
}
selinux_run_init_old = (void (*)(void))
- dlfunc(lib_handle, "selinux_runscript");
+ dlfunc(lib_handle, "selinux_runscript");
selinux_run_init_new = (void (*)(int, char **))
- dlfunc(lib_handle, "selinux_runscript2");
+ dlfunc(lib_handle, "selinux_runscript2");
/* Use new run_init if it exists, else fall back to old */
if (selinux_run_init_new)
@@ -154,7 +154,7 @@ handle_signal(int sig)
if (signal_pipe[1] > -1) {
if (write(signal_pipe[1], &sig, sizeof(sig)) == -1)
eerror("%s: send: %s",
- service, strerror(errno));
+ service, strerror(errno));
} else
rc_waitpid(-1);
break;
@@ -217,16 +217,16 @@ start_services(RC_STRINGLIST *list)
{
TAILQ_FOREACH(svc, list, entries) {
if (!(rc_service_state(svc->value) &
- RC_SERVICE_STOPPED))
+ RC_SERVICE_STOPPED))
continue;
if (state & RC_SERVICE_INACTIVE ||
state & RC_SERVICE_WASINACTIVE)
{
rc_service_schedule_start(service,
- svc->value);
+ svc->value);
ewarn("WARNING: %s is scheduled to started"
- " when %s has started",
- svc->value, applet);
+ " when %s has started",
+ svc->value, applet);
} else
service_start(svc->value);
}
@@ -269,10 +269,10 @@ cleanup(void)
rc_plugin_run(hook_out, applet);
if (hook_out == RC_HOOK_SERVICE_START_DONE)
rc_plugin_run(RC_HOOK_SERVICE_START_OUT,
- applet);
+ applet);
else if (hook_out == RC_HOOK_SERVICE_STOP_DONE)
rc_plugin_run(RC_HOOK_SERVICE_STOP_OUT,
- applet);
+ applet);
}
if (restart_services)
@@ -369,7 +369,7 @@ svc_exec(const char *arg1, const char *arg2)
eerrorx("%s: pipe: %s", service, applet);
for (i = 0; i < 2; i++)
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));
/* Open a pty for our prefixed output
@@ -387,11 +387,11 @@ svc_exec(const char *arg1, const char *arg2)
openpty(&master_tty, &slave_tty, NULL, &tt, &ws);
if (master_tty >= 0 &&
(flags = fcntl(master_tty, F_GETFD, 0)) == 0)
- fcntl(master_tty, F_SETFD, flags | FD_CLOEXEC);
+ fcntl(master_tty, F_SETFD, flags | FD_CLOEXEC);
if (slave_tty >=0 &&
(flags = fcntl(slave_tty, F_GETFD, 0)) == 0)
- fcntl(slave_tty, F_SETFD, flags | FD_CLOEXEC);
+ fcntl(slave_tty, F_SETFD, flags | FD_CLOEXEC);
}
service_pid = fork();
@@ -405,17 +405,17 @@ svc_exec(const char *arg1, const char *arg2)
if (exists(RC_SVCDIR "/runscript.sh")) {
execl(RC_SVCDIR "/runscript.sh",
- RC_SVCDIR "/runscript.sh",
- service, arg1, arg2, (char *) NULL);
+ RC_SVCDIR "/runscript.sh",
+ service, arg1, arg2, (char *) NULL);
eerror("%s: exec `" RC_SVCDIR "/runscript.sh': %s",
- service, strerror(errno));
+ service, strerror(errno));
_exit(EXIT_FAILURE);
} else {
execl(RC_LIBDIR "/sh/runscript.sh",
- RC_LIBDIR "/sh/runscript.sh",
- service, arg1, arg2, (char *) NULL);
+ RC_LIBDIR "/sh/runscript.sh",
+ service, arg1, arg2, (char *) NULL);
eerror("%s: exec `" RC_LIBDIR "/sh/runscript.sh': %s",
- service, strerror(errno));
+ service, strerror(errno));
_exit(EXIT_FAILURE);
}
}
@@ -434,7 +434,7 @@ svc_exec(const char *arg1, const char *arg2)
if ((s = poll(fd, master_tty >= 0 ? 2 : 1, -1)) == -1) {
if (errno != EINTR) {
eerror("%s: poll: %s",
- service, strerror(errno));
+ service, strerror(errno));
break;
}
}
@@ -488,7 +488,7 @@ svc_wait(const char *svc)
rc_stringlist_free(keywords);
snprintf(file, sizeof(file), RC_SVCDIR "/exclusive/%s",
- basename_c(svc));
+ basename_c(svc));
interval.tv_sec = 0;
interval.tv_nsec = WAIT_INTERVAL;
@@ -521,7 +521,7 @@ svc_wait(const char *svc)
timespecsub(&warn, &interval, &warn);
if (warn.tv_sec <= 0) {
ewarn("%s: waiting for %s (%zu)", applet, svc,
- timeout.tv_sec);
+ timeout.tv_sec);
warn.tv_sec = WARN_TIMEOUT;
warn.tv_nsec = 0;
}
@@ -593,7 +593,7 @@ svc_start(bool deps)
rc_service_mark(service, RC_SERVICE_HOTPLUGGED);
if (strcmp(runlevel, RC_LEVEL_SYSINIT) == 0)
ewarnx("WARNING: %s will be started in the"
- " next runlevel", applet);
+ " next runlevel", applet);
}
if (exclusive_fd == -1)
@@ -607,14 +607,14 @@ svc_start(bool deps)
ewarnx("WARNING: %s is already starting", applet);
}
fcntl(exclusive_fd, F_SETFD,
- fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
+ fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
if (state & RC_SERVICE_STARTED) {
ewarn("WARNING: %s has already been started", applet);
return;
} else if (state & RC_SERVICE_INACTIVE && ! background)
ewarnx("WARNING: %s has already started, but is inactive",
- applet);
+ applet);
rc_service_mark(service, RC_SERVICE_STARTING);
hook_out = RC_HOOK_SERVICE_START_OUT;
@@ -631,7 +631,7 @@ svc_start(bool deps)
setup_types();
services = rc_deptree_depends(deptree, types_b, applet_list,
- runlevel, 0);
+ runlevel, 0);
if (TAILQ_FIRST(services)) {
eerrorn("ERROR: `%s' needs ", applet);
first = true;
@@ -648,11 +648,11 @@ svc_start(bool deps)
services = NULL;
need_services = rc_deptree_depends(deptree, types_n,
- applet_list, runlevel,
- depoptions);
+ applet_list, runlevel,
+ depoptions);
use_services = rc_deptree_depends(deptree, types_nu,
- applet_list, runlevel,
- depoptions);
+ applet_list, runlevel,
+ depoptions);
if (!rc_runlevel_starting()) {
TAILQ_FOREACH(svc, use_services, entries) {
@@ -673,7 +673,7 @@ svc_start(bool deps)
/* Now wait for them to start */
services = rc_deptree_depends(deptree, types_nua, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
/* We use tmplist to hold our scheduled by list */
tmplist = rc_stringlist_new();
TAILQ_FOREACH(svc, services, entries) {
@@ -687,15 +687,15 @@ svc_start(bool deps)
state & RC_SERVICE_WASINACTIVE)
{
if (!rc_stringlist_find(need_services,
- svc->value) &&
+ svc->value) &&
!rc_stringlist_find(use_services,
- svc->value))
+ svc->value))
continue;
}
if (!svc_wait(svc->value))
eerror("%s: timed out waiting for %s",
- applet, svc->value);
+ applet, svc->value);
state = rc_service_state(svc->value);
if (state & RC_SERVICE_STARTED)
continue;
@@ -706,8 +706,8 @@ svc_start(bool deps)
rc_stringlist_add(tmplist, svc->value);
} else if (!TAILQ_FIRST(tmplist))
eerrorx("ERROR: cannot start %s as"
- " %s would not start",
- applet, svc->value);
+ " %s would not start",
+ applet, svc->value);
}
}
@@ -723,11 +723,11 @@ svc_start(bool deps)
TAILQ_FOREACH(svc, tmplist, entries) {
rc_service_schedule_start(svc->value, service);
use_services = rc_deptree_depend(deptree,
- "iprovide",
- svc->value);
+ "iprovide",
+ svc->value);
TAILQ_FOREACH(svc2, use_services, entries)
- rc_service_schedule_start(svc2->value,
- service);
+ rc_service_schedule_start(svc2->value,
+ service);
rc_stringlist_free(use_services);
use_services = NULL;
len += strlen(svc->value) + 2;
@@ -740,12 +740,12 @@ svc_start(bool deps)
if (p != tmp)
p += snprintf(p, len, ", ");
p += snprintf(p, len - (p - tmp),
- "%s", svc->value);
+ "%s", svc->value);
}
rc_stringlist_free(tmplist);
tmplist = NULL;
ewarnx("WARNING: %s is scheduled to start when "
- "%s has started", applet, tmp);
+ "%s has started", applet, tmp);
free(tmp);
}
@@ -766,7 +766,7 @@ svc_start(bool deps)
else {
if (rc_service_state(service) & RC_SERVICE_INACTIVE)
ewarnx("WARNING: %s has started, but is inactive",
- applet);
+ applet);
}
rc_service_mark(service, RC_SERVICE_STARTED);
@@ -777,8 +777,8 @@ svc_start(bool deps)
/* Now start any scheduled services */
services = rc_services_scheduled(service);
TAILQ_FOREACH(svc, services, entries)
- if (rc_service_state(svc->value) & RC_SERVICE_STOPPED)
- service_start(svc->value);
+ if (rc_service_state(svc->value) & RC_SERVICE_STOPPED)
+ service_start(svc->value);
rc_stringlist_free(services);
services = NULL;
@@ -788,9 +788,9 @@ svc_start(bool deps)
TAILQ_FOREACH(svc, tmplist, entries) {
services = rc_services_scheduled(svc->value);
TAILQ_FOREACH(svc2, services, entries)
- if (rc_service_state(svc2->value) &
- RC_SERVICE_STOPPED)
- service_start(svc2->value);
+ if (rc_service_state(svc2->value) &
+ RC_SERVICE_STOPPED)
+ service_start(svc2->value);
rc_stringlist_free(services);
services = NULL;
}
@@ -829,7 +829,7 @@ svc_stop(bool deps)
eerrorx("ERROR: %s has been stopped by something else", applet);
}
fcntl(exclusive_fd, F_SETFD,
- fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
+ fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
if (state & RC_SERVICE_STOPPED) {
ewarn("WARNING: %s is already stopped", applet);
@@ -859,7 +859,7 @@ svc_stop(bool deps)
setup_types();
services = rc_deptree_depends(deptree, types_m, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
tmplist = rc_stringlist_new();
TAILQ_FOREACH_REVERSE(svc, services, rc_stringlist, entries) {
state = rc_service_state(svc->value);
@@ -898,14 +898,14 @@ svc_stop(bool deps)
* if a dependant failed */
if (runlevel &&
(strcmp(runlevel,
- RC_LEVEL_SHUTDOWN) == 0 ||
- strcmp(runlevel,
+ RC_LEVEL_SHUTDOWN) == 0 ||
+ strcmp(runlevel,
RC_LEVEL_SINGLE) == 0))
continue;
rc_service_mark(service, RC_SERVICE_FAILED);
}
eerrorx("ERROR: cannot stop %s as %s "
- "is still up", applet, svc->value);
+ "is still up", applet, svc->value);
}
rc_stringlist_free(tmplist);
tmplist = NULL;
@@ -914,7 +914,7 @@ svc_stop(bool deps)
/* We now wait for other services that may use us and are
* stopping. This is important when a runlevel stops */
services = rc_deptree_depends(deptree, types_mua, applet_list,
- runlevel, depoptions);
+ runlevel, depoptions);
TAILQ_FOREACH(svc, services, entries) {
if (rc_service_state(svc->value) & RC_SERVICE_STOPPED)
continue;
@@ -1062,7 +1062,7 @@ runscript(int argc, char **argv)
if (stat(argv[1], &stbuf) != 0) {
fprintf(stderr, "runscript `%s': %s\n",
- argv[1], strerror(errno));
+ argv[1], strerror(errno));
exit(EXIT_FAILURE);
}
@@ -1158,7 +1158,7 @@ runscript(int argc, char **argv)
/* Right then, parse any options there may be */
while ((opt = getopt_long(argc, argv, getoptstring,
- longopts, (int *)0)) != -1)
+ longopts, (int *)0)) != -1)
switch (opt) {
case 'd':
setenv("RC_DEBUG", "YES", 1);
@@ -1175,8 +1175,8 @@ runscript(int argc, char **argv)
case 'D':
deps = false;
break;
- case_RC_COMMON_GETOPT
- }
+ case_RC_COMMON_GETOPT
+ }
/* If we're changing runlevels and not called by rc then we cannot
work with any dependencies */
@@ -1238,12 +1238,12 @@ runscript(int argc, char **argv)
eprefix(save);
prefix = save;
} else if (strcmp(optarg, "ineed") == 0 ||
- strcmp(optarg, "iuse") == 0 ||
- strcmp(optarg, "needsme") == 0 ||
- strcmp(optarg, "usesme") == 0 ||
- strcmp(optarg, "iafter") == 0 ||
- strcmp(optarg, "ibefore") == 0 ||
- strcmp(optarg, "iprovide") == 0)
+ strcmp(optarg, "iuse") == 0 ||
+ strcmp(optarg, "needsme") == 0 ||
+ strcmp(optarg, "usesme") == 0 ||
+ strcmp(optarg, "iafter") == 0 ||
+ strcmp(optarg, "ibefore") == 0 ||
+ strcmp(optarg, "iprovide") == 0)
{
errno = 0;
if (rc_conf_yesno("rc_depend_strict") ||
@@ -1257,11 +1257,11 @@ runscript(int argc, char **argv)
tmplist = rc_stringlist_new();
rc_stringlist_add(tmplist, optarg);
services = rc_deptree_depends(deptree, tmplist,
- applet_list,
- runlevel, depoptions);
+ applet_list,
+ runlevel, depoptions);
rc_stringlist_free(tmplist);
TAILQ_FOREACH(svc, services, entries)
- printf("%s ", svc->value);
+ printf("%s ", svc->value);
printf ("\n");
rc_stringlist_free(services);
services = NULL;
@@ -1297,20 +1297,20 @@ runscript(int argc, char **argv)
RC_SERVICE_INACTIVE)
{
TAILQ_FOREACH(svc,
- restart_services,
- entries)
- if (rc_service_state(svc->value) &
- RC_SERVICE_STOPPED)
- rc_service_schedule_start(service, svc->value);
+ restart_services,
+ entries)
+ if (rc_service_state(svc->value) &
+ RC_SERVICE_STOPPED)
+ rc_service_schedule_start(service, svc->value);
}
}
} else if (strcmp(optarg, "zap") == 0) {
einfo("Manually resetting %s to stopped state",
- applet);
+ applet);
if (!rc_service_mark(applet,
- RC_SERVICE_STOPPED))
+ RC_SERVICE_STOPPED))
eerrorx("rc_service_mark: %s",
- strerror(errno));
+ strerror(errno));
unhotplug();
} else
svc_exec(optarg, NULL);
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c
index 0d612c48..8237e1e8 100644
--- a/src/rc/start-stop-daemon.c
+++ b/src/rc/start-stop-daemon.c
@@ -1,11 +1,11 @@
/*
- start-stop-daemon
- Starts, stops, tests and signals daemons
+ start-stop-daemon
+ Starts, stops, tests and signals daemons
- This is essentially a ground up re-write of Debians
- start-stop-daemon for cleaner code and to integrate into our RC
- system so we can monitor daemons a little.
- */
+ This is essentially a ground up re-write of Debians
+ start-stop-daemon for cleaner code and to integrate into our RC
+ system so we can monitor daemons a little.
+*/
/*
* Copyright 2007-2009 Roy Marples <roy@marples.name>
@@ -75,9 +75,9 @@ static struct pam_conv conv = { NULL, NULL};
/* Some libc implementations don't define this */
#ifndef LIST_FOREACH_SAFE
-#define LIST_FOREACH_SAFE(var, head, field, tvar) \
- for ((var) = LIST_FIRST((head)); \
- (var) && ((tvar) = LIST_NEXT((var), field), 1); \
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = LIST_FIRST((head)); \
+ (var) && ((tvar) = LIST_NEXT((var), field), 1); \
(var) = (tvar))
#endif
@@ -85,12 +85,12 @@ static struct pam_conv conv = { NULL, NULL};
typedef struct scheduleitem
{
enum
- {
- SC_TIMEOUT,
- SC_SIGNAL,
- SC_GOTO,
- SC_FOREVER
- } type;
+ {
+ SC_TIMEOUT,
+ SC_SIGNAL,
+ SC_GOTO,
+ SC_FOREVER
+ } type;
int value;
struct scheduleitem *gotoitem;
TAILQ_ENTRY(scheduleitem) entries;
@@ -103,7 +103,8 @@ static char *changeuser, *ch_root, *ch_dir;
extern char **environ;
-static void free_schedulelist(void)
+static void
+free_schedulelist(void)
{
SCHEDULEITEM *s1 = TAILQ_FIRST(&schedule);
SCHEDULEITEM *s2;
@@ -117,7 +118,8 @@ static void free_schedulelist(void)
}
#ifdef DEBUG_MEMORY
-static void cleanup(void)
+static void
+cleanup(void)
{
free(changeuser);
free(nav);
@@ -125,7 +127,8 @@ static void cleanup(void)
}
#endif
-static int parse_signal(const char *sig)
+static int
+parse_signal(const char *sig)
{
typedef struct signalpair
{
@@ -181,7 +184,8 @@ static int parse_signal(const char *sig)
/* NOTREACHED */
}
-static SCHEDULEITEM *parse_schedule_item(const char *string)
+static SCHEDULEITEM *
+parse_schedule_item(const char *string)
{
const char *after_hyph;
int sig;
@@ -195,21 +199,21 @@ static SCHEDULEITEM *parse_schedule_item(const char *string)
item->type = SC_TIMEOUT;
errno = 0;
if (sscanf(string, "%d", &item->value) != 1)
- eerrorx("%s: invalid timeout value in schedule `%s'", applet,
- string);
+ eerrorx("%s: invalid timeout value in schedule `%s'",
+ applet, string);
} else if ((after_hyph = string + (string[0] == '-')) &&
- ((sig = parse_signal(after_hyph)) != -1))
+ ((sig = parse_signal(after_hyph)) != -1))
{
item->type = SC_SIGNAL;
item->value = (int)sig;
- }
- else
+ } else
eerrorx("%s: invalid schedule item `%s'", applet, string);
return item;
}
-static void parse_schedule(const char *string, int timeout)
+static void
+parse_schedule(const char *string, int timeout)
{
char buffer[20];
const char *slash;
@@ -238,7 +242,8 @@ static void parse_schedule(const char *string, int timeout)
TAILQ_INSERT_TAIL(&schedule, item, entries);
if (string) {
if (sscanf(string, "%d", &item->value) != 1)
- eerrorx("%s: invalid timeout value in schedule", applet);
+ eerrorx("%s: invalid timeout in schedule",
+ applet);
} else
item->value = 5;
@@ -251,8 +256,9 @@ static void parse_schedule(const char *string, int timeout)
else
len = strlen(string);
- if (len >= (ptrdiff_t) sizeof(buffer))
- eerrorx("%s: invalid schedule item, far too long", applet);
+ if (len >= (ptrdiff_t)sizeof(buffer))
+ eerrorx("%s: invalid schedule item, far too long",
+ applet);
memcpy(buffer, string, len);
buffer[len] = 0;
@@ -263,7 +269,7 @@ static void parse_schedule(const char *string, int timeout)
if (item->type == SC_FOREVER) {
if (repeatat)
eerrorx("%s: invalid schedule, `forever' "
- "appears more than once", applet);
+ "appears more than once", applet);
repeatat = item;
continue;
@@ -281,7 +287,8 @@ static void parse_schedule(const char *string, int timeout)
return;
}
-static pid_t get_pid(const char *pidfile, bool quiet)
+static pid_t
+get_pid(const char *pidfile, bool quiet)
{
FILE *fp;
pid_t pid;
@@ -291,7 +298,8 @@ static pid_t get_pid(const char *pidfile, bool quiet)
if ((fp = fopen(pidfile, "r")) == NULL) {
if (!quiet)
- eerror("%s: fopen `%s': %s", applet, pidfile, strerror(errno));
+ eerror("%s: fopen `%s': %s",
+ applet, pidfile, strerror(errno));
return -1;
}
@@ -308,9 +316,10 @@ static pid_t get_pid(const char *pidfile, bool quiet)
}
/* return number of processed killed, -1 on error */
-static int do_stop(const char *exec, const char *const *argv,
- pid_t pid, uid_t uid,int sig,
- bool quiet, bool verbose, bool test)
+static int
+do_stop(const char *exec, const char *const *argv,
+ pid_t pid, uid_t uid,int sig,
+ bool quiet, bool verbose, bool test)
{
RC_PIDLIST *pids;
RC_PID *pi;
@@ -330,19 +339,19 @@ static int do_stop(const char *exec, const char *const *argv,
if (test) {
if (!quiet)
einfo("Would send signal %d to PID %d",
- sig, pi->pid);
+ sig, pi->pid);
nkilled++;
} else {
if (verbose)
ebegin("Sending signal %d to PID %d",
- sig, pi->pid);
+ sig, pi->pid);
errno = 0;
killed = (kill(pi->pid, sig) == 0 ||
- errno == ESRCH ? true : false);
+ errno == ESRCH ? true : false);
if (verbose)
eend(killed ? 0 : 1,
- "%s: failed to send signal %d to PID %d: %s",
- applet, sig, pi->pid, strerror(errno));
+ "%s: failed to send signal %d to PID %d: %s",
+ applet, sig, pi->pid, strerror(errno));
if (!killed) {
nkilled = -1;
} else {
@@ -357,9 +366,10 @@ static int do_stop(const char *exec, const char *const *argv,
return nkilled;
}
-static int run_stop_schedule(const char *exec, const char *const *argv,
- const char *pidfile, uid_t uid,
- bool quiet, bool verbose, bool test)
+static int
+run_stop_schedule(const char *exec, const char *const *argv,
+ const char *pidfile, uid_t uid,
+ bool quiet, bool verbose, bool test)
{
SCHEDULEITEM *item = TAILQ_FIRST(&schedule);
int nkilled = 0;
@@ -403,12 +413,12 @@ static int run_stop_schedule(const char *exec, const char *const *argv,
case SC_SIGNAL:
nrunning = 0;
nkilled = do_stop(exec, argv, pid, uid, item->value,
- quiet, verbose, test);
+ quiet, verbose, test);
if (nkilled == 0) {
if (tkilled == 0) {
if (! quiet)
eerror("%s: no matching "
- "processes found", applet);
+ "processes found", applet);
}
return tkilled;
}
@@ -429,24 +439,26 @@ static int run_stop_schedule(const char *exec, const char *const *argv,
while (nloops) {
if ((nrunning = do_stop(exec, argv, pid,
- uid, 0, true, false, true)) == 0)
+ uid, 0, true, false, true)) == 0)
return 0;
if (nanosleep(&ts, NULL) == -1) {
if (errno == EINTR)
- eerror("%s: caught an interrupt", applet);
+ eerror("%s: caught an"
+ " interrupt", applet);
else {
eerror("%s: nanosleep: %s",
- applet, strerror(errno));
+ applet, strerror(errno));
return 0;
}
}
- nloops --;
+ nloops --;
}
break;
default:
- eerror("%s: invalid schedule item `%d'", applet, item->type);
+ eerror("%s: invalid schedule item `%d'",
+ applet, item->type);
return 0;
}
@@ -459,15 +471,18 @@ static int run_stop_schedule(const char *exec, const char *const *argv,
if (! quiet) {
if (nrunning == 1)
- eerror("%s: %d process refused to stop", applet, nrunning);
+ eerror("%s: %d process refused to stop",
+ applet, nrunning);
else
- eerror("%s: %d process(es) refused to stop", applet, nrunning);
+ eerror("%s: %d process(es) refused to stop",
+ applet, nrunning);
}
return -nrunning;
}
-static void handle_signal(int sig)
+static void
+handle_signal(int sig)
{
int status;
int serrno = errno;
@@ -492,7 +507,8 @@ static void handle_signal(int sig)
for (;;) {
if (waitpid(-1, &status, WNOHANG) < 0) {
if (errno != ECHILD)
- eerror("%s: waitpid: %s", applet, strerror(errno));
+ eerror("%s: waitpid: %s",
+ applet, strerror(errno));
break;
}
}
@@ -606,7 +622,8 @@ static const char * const longopts_help[] = {
};
#include "_usage.c"
-int start_stop_daemon(int argc, char **argv)
+int
+start_stop_daemon(int argc, char **argv)
{
int devnull_fd = -1;
#ifdef TIOCNOTTY
@@ -674,7 +691,7 @@ int start_stop_daemon(int argc, char **argv)
if ((tmp = getenv("SSD_NICELEVEL")))
if (sscanf(tmp, "%d", &nicelevel) != 1)
eerror("%s: invalid nice level `%s' (SSD_NICELEVEL)",
- applet, tmp);
+ applet, tmp);
/* Get our user name and initial dir */
p = getenv("USER");
@@ -692,7 +709,7 @@ int start_stop_daemon(int argc, char **argv)
}
while ((opt = getopt_long(argc, argv, getoptstring, longopts,
- (int *) 0)) != -1)
+ (int *) 0)) != -1)
switch (opt) {
case 'K': /* --stop */
stop = true;
@@ -700,7 +717,7 @@ int start_stop_daemon(int argc, char **argv)
case 'N': /* --nice */
if (sscanf(optarg, "%d", &nicelevel) != 1)
eerrorx("%s: invalid nice level `%s'",
- applet, optarg);
+ applet, optarg);
break;
case 'R': /* --retry <schedule>|<timeout> */
@@ -717,44 +734,44 @@ int start_stop_daemon(int argc, char **argv)
case 'u': /* --user <username>|<uid> */
case 'c': /* --chuid <username>|<uid> */
- {
- p = optarg;
- tmp = strsep(&p, ":");
- changeuser = xstrdup(tmp);
+ {
+ p = optarg;
+ tmp = strsep(&p, ":");
+ changeuser = xstrdup(tmp);
+ if (sscanf(tmp, "%d", &tid) != 1)
+ pw = getpwnam(tmp);
+ else
+ pw = getpwuid((uid_t)tid);
+
+ if (pw == NULL)
+ eerrorx("%s: user `%s' not found",
+ applet, tmp);
+ uid = pw->pw_uid;
+ home = pw->pw_dir;
+ unsetenv("HOME");
+ if (pw->pw_dir)
+ setenv("HOME", pw->pw_dir, 1);
+ unsetenv("USER");
+ if (pw->pw_name)
+ setenv("USER", pw->pw_name, 1);
+ if (gid == 0)
+ gid = pw->pw_gid;
+
+ if (p) {
+ tmp = strsep (&p, ":");
if (sscanf(tmp, "%d", &tid) != 1)
- pw = getpwnam(tmp);
+ gr = getgrnam(tmp);
else
- pw = getpwuid((uid_t)tid);
-
- if (pw == NULL)
- eerrorx("%s: user `%s' not found",
- applet, tmp);
- uid = pw->pw_uid;
- home = pw->pw_dir;
- unsetenv("HOME");
- if (pw->pw_dir)
- setenv("HOME", pw->pw_dir, 1);
- unsetenv("USER");
- if (pw->pw_name)
- setenv("USER", pw->pw_name, 1);
- if (gid == 0)
- gid = pw->pw_gid;
+ gr = getgrgid((gid_t) tid);
- if (p) {
- tmp = strsep (&p, ":");
- if (sscanf(tmp, "%d", &tid) != 1)
- gr = getgrnam(tmp);
- else
- gr = getgrgid((gid_t) tid);
-
- if (gr == NULL)
- eerrorx("%s: group `%s'"
- " not found",
- applet, tmp);
- gid = gr->gr_gid;
- }
+ if (gr == NULL)
+ eerrorx("%s: group `%s'"
+ " not found",
+ applet, tmp);
+ gid = gr->gr_gid;
}
- break;
+ }
+ break;
case 'd': /* --chdir /new/dir */
ch_dir = optarg;
@@ -771,7 +788,7 @@ int start_stop_daemon(int argc, char **argv)
gr = getgrgid((gid_t)tid);
if (gr == NULL)
eerrorx("%s: group `%s' not found",
- applet, optarg);
+ applet, optarg);
gid = gr->gr_gid;
break;
@@ -782,7 +799,7 @@ int start_stop_daemon(int argc, char **argv)
case 'k':
if (parse_mode(&numask, optarg))
eerrorx("%s: invalid mode `%s'",
- applet, optarg);
+ applet, optarg);
break;
case 'm': /* --make-pidfile */
@@ -819,7 +836,7 @@ int start_stop_daemon(int argc, char **argv)
case 'w':
if (sscanf(optarg, "%d", &start_wait) != 1)
eerrorx("%s: `%s' not a number",
- applet, optarg);
+ applet, optarg);
break;
case 'x': /* --exec <executable> */
exec = optarg;
@@ -834,7 +851,7 @@ int start_stop_daemon(int argc, char **argv)
break;
case_RC_COMMON_GETOPT
- }
+ }
endpwent();
argc -= optind;
@@ -873,25 +890,25 @@ int start_stop_daemon(int argc, char **argv)
sig = SIGTERM;
if (!*argv && !pidfile && !name && !uid)
eerrorx("%s: --stop needs --exec, --pidfile,"
- " --name or --user", applet);
+ " --name or --user", applet);
if (background)
eerrorx("%s: --background is only relevant with"
- " --start", applet);
+ " --start", applet);
if (makepidfile)
eerrorx("%s: --make-pidfile is only relevant with"
- " --start", applet);
+ " --start", applet);
if (redirect_stdout || redirect_stderr)
eerrorx("%s: --stdout and --stderr are only relevant"
- " with --start", applet);
+ " with --start", applet);
} else {
if (!exec)
eerrorx("%s: nothing to start", applet);
if (makepidfile && !pidfile)
eerrorx("%s: --make-pidfile is only relevant with"
- " --pidfile", applet);
+ " --pidfile", applet);
if ((redirect_stdout || redirect_stderr) && !background)
eerrorx("%s: --stdout and --stderr are only relevant"
- " with --background", applet);
+ " with --background", applet);
}
/* Expand ~ */
@@ -908,10 +925,10 @@ int start_stop_daemon(int argc, char **argv)
/* Full or relative path */
if (ch_root)
snprintf(exec_file, sizeof(exec_file),
- "%s/%s", ch_root, exec);
+ "%s/%s", ch_root, exec);
else
snprintf(exec_file, sizeof(exec_file),
- "%s", exec);
+ "%s", exec);
} else {
/* Something in $PATH */
p = tmp = xstrdup(getenv("PATH"));
@@ -919,11 +936,11 @@ int start_stop_daemon(int argc, char **argv)
while ((token = strsep(&p, ":"))) {
if (ch_root)
snprintf(exec_file, sizeof(exec_file),
- "%s/%s/%s",
- ch_root, token, exec);
+ "%s/%s/%s",
+ ch_root, token, exec);
else
snprintf(exec_file, sizeof(exec_file),
- "%s/%s", token, exec);
+ "%s/%s", token, exec);
if (exists(exec_file))
break;
*exec_file = '\0';
@@ -933,7 +950,7 @@ int start_stop_daemon(int argc, char **argv)
}
if (start && !exists(exec_file)) {
eerror("%s: %s does not exist", applet,
- *exec_file ? exec_file : exec);
+ *exec_file ? exec_file : exec);
exit(EXIT_FAILURE);
}
@@ -984,7 +1001,7 @@ int start_stop_daemon(int argc, char **argv)
else
parse_schedule(NULL, sig);
i = run_stop_schedule(exec, (const char *const *)margv,
- pidfile, uid, quiet, verbose, test);
+ pidfile, uid, quiet, verbose, test);
if (i < 0)
/* We failed to stop something */
@@ -1000,8 +1017,8 @@ int start_stop_daemon(int argc, char **argv)
unlink(pidfile);
if (svcname)
rc_service_daemon_set(svcname, exec,
- (const char *const *)argv,
- pidfile, false);
+ (const char *const *)argv,
+ pidfile, false);
exit(EXIT_SUCCESS);
}
@@ -1011,7 +1028,7 @@ int start_stop_daemon(int argc, char **argv)
pid = 0;
if (do_stop(exec, (const char * const *)margv, pid, uid,
- 0, true, false, true) > 0)
+ 0, true, false, true) > 0)
eerrorx("%s: %s is already running", applet, exec);
if (test) {
@@ -1067,30 +1084,35 @@ int start_stop_daemon(int argc, char **argv)
if (nicelevel) {
if (setpriority(PRIO_PROCESS, mypid, nicelevel) == -1)
- eerrorx("%s: setpritory %d: %s", applet, nicelevel,
- strerror(errno));
+ eerrorx("%s: setpritory %d: %s",
+ applet, nicelevel,
+ strerror(errno));
}
if (ch_root && chroot(ch_root) < 0)
- eerrorx("%s: chroot `%s': %s", applet, ch_root, strerror(errno));
+ eerrorx("%s: chroot `%s': %s",
+ applet, ch_root, strerror(errno));
if (ch_dir && chdir(ch_dir) < 0)
- eerrorx("%s: chdir `%s': %s", applet, ch_dir, strerror(errno));
+ eerrorx("%s: chdir `%s': %s",
+ applet, ch_dir, strerror(errno));
if (makepidfile && pidfile) {
fp = fopen(pidfile, "w");
if (! fp)
eerrorx("%s: fopen `%s': %s", applet, pidfile,
- strerror(errno));
+ strerror(errno));
fprintf(fp, "%d\n", mypid);
fclose(fp);
}
#ifdef HAVE_PAM
if (changeuser != NULL)
- pamr = pam_start("start-stop-daemon", changeuser, &conv, &pamh);
+ pamr = pam_start("start-stop-daemon",
+ changeuser, &conv, &pamh);
else
- pamr = pam_start("start-stop-daemon", "nobody", &conv, &pamh);
+ pamr = pam_start("start-stop-daemon",
+ "nobody", &conv, &pamh);
if (pamr == PAM_SUCCESS)
pamr = pam_authenticate(pamh, PAM_SILENT);
@@ -1099,15 +1121,19 @@ int start_stop_daemon(int argc, char **argv)
if (pamr == PAM_SUCCESS)
pamr = pam_open_session(pamh, PAM_SILENT);
if (pamr != PAM_SUCCESS)
- eerrorx("%s: pam error: %s", applet, pam_strerror(pamh, pamr));
+ eerrorx("%s: pam error: %s",
+ applet, pam_strerror(pamh, pamr));
#endif
if (gid && setgid(gid))
- eerrorx("%s: unable to set groupid to %d", applet, gid);
+ eerrorx("%s: unable to set groupid to %d",
+ applet, gid);
if (changeuser && initgroups(changeuser, gid))
- eerrorx("%s: initgroups (%s, %d)", applet, changeuser, gid);
+ eerrorx("%s: initgroups (%s, %d)",
+ applet, changeuser, gid);
if (uid && setuid(uid))
- eerrorx ("%s: unable to set userid to %d", applet, uid);
+ eerrorx ("%s: unable to set userid to %d",
+ applet, uid);
/* Close any fd's to the passwd database */
endpwent();
@@ -1137,8 +1163,8 @@ int start_stop_daemon(int argc, char **argv)
TAILQ_FOREACH(env, env_list, entries) {
if ((strncmp(env->value, "RC_", 3) == 0 &&
- strncmp(env->value, "RC_SERVICE=", 10) != 0 &&
- strncmp(env->value, "RC_SVCNAME=", 10) != 0) ||
+ strncmp(env->value, "RC_SERVICE=", 10) != 0 &&
+ strncmp(env->value, "RC_SVCNAME=", 10) != 0) ||
strncmp(env->value, "SSD_NICELEVEL=", 14) == 0)
{
p = strchr(env->value, '=');
@@ -1179,16 +1205,20 @@ int start_stop_daemon(int argc, char **argv)
stdout_fd = devnull_fd;
stderr_fd = devnull_fd;
if (redirect_stdout) {
- if ((stdout_fd = open(redirect_stdout, O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR)) == -1)
- eerrorx("%s: unable to open the logfile for stdout `%s': %s",
- applet, redirect_stdout, strerror(errno));
+ if ((stdout_fd = open(redirect_stdout,
+ O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR)) == -1)
+ eerrorx("%s: unable to open the logfile"
+ " for stdout `%s': %s",
+ applet, redirect_stdout, strerror(errno));
}
if (redirect_stderr) {
- if ((stderr_fd = open(redirect_stderr, O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR)) == -1)
- eerrorx("%s: unable to open the logfile for stderr `%s': %s",
- applet, redirect_stderr, strerror(errno));
+ if ((stderr_fd = open(redirect_stderr,
+ O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR)) == -1)
+ eerrorx("%s: unable to open the logfile"
+ " for stderr `%s': %s",
+ applet, redirect_stderr, strerror(errno));
}
/* We don't redirect stdin as some daemons may need it */
@@ -1207,7 +1237,7 @@ int start_stop_daemon(int argc, char **argv)
pam_close_session(pamh, PAM_SILENT);
#endif
eerrorx("%s: failed to exec `%s': %s",
- applet, exec,strerror(errno));
+ applet, exec,strerror(errno));
}
/* Parent process */
@@ -1220,13 +1250,15 @@ int start_stop_daemon(int argc, char **argv)
do {
pid = waitpid(spid, &i, 0);
if (pid < 1) {
- eerror("waitpid %d: %s", spid, strerror(errno));
+ eerror("waitpid %d: %s",
+ spid, strerror(errno));
return -1;
}
} while (!WIFEXITED(i) && !WIFSIGNALED(i));
if (!WIFEXITED(i) || WEXITSTATUS(i) != 0) {
if (!quiet)
- eerrorx("%s: failed to start `%s'", applet, exec);
+ eerrorx("%s: failed to start `%s'",
+ applet, exec);
exit(EXIT_FAILURE);
}
pid = spid;
@@ -1236,7 +1268,7 @@ int start_stop_daemon(int argc, char **argv)
We do this as some badly written daemons fork and then barf */
if (start_wait == 0 &&
((p = getenv("SSD_STARTWAIT")) ||
- (p = rc_conf_value("rc_start_wait"))))
+ (p = rc_conf_value("rc_start_wait"))))
{
if (sscanf(p, "%u", &start_wait) != 1)
start_wait = 0;
@@ -1253,7 +1285,7 @@ int start_stop_daemon(int argc, char **argv)
eerror("%s: caught an interrupt", applet);
else {
eerror("%s: nanosleep: %s",
- applet, strerror(errno));
+ applet, strerror(errno));
return 0;
}
}
@@ -1265,14 +1297,14 @@ int start_stop_daemon(int argc, char **argv)
pid = get_pid(pidfile, true);
if (pid == -1) {
eerrorx("%s: did not "
- "create a valid"
- " pid in `%s'",
- applet, pidfile);
+ "create a valid"
+ " pid in `%s'",
+ applet, pidfile);
}
} else
pid = 0;
if (do_stop(exec, (const char *const *)margv,
- pid, uid, 0, true, false, true) > 0)
+ pid, uid, 0, true, false, true) > 0)
alive = true;
}
@@ -1281,8 +1313,8 @@ int start_stop_daemon(int argc, char **argv)
}
if (svcname)
- rc_service_daemon_set(svcname, exec, (const char *const *)margv,
- pidfile, true);
+ rc_service_daemon_set(svcname, exec,
+ (const char *const *)margv, pidfile, true);
exit(EXIT_SUCCESS);
/* NOTREACHED */