Add rc-service and update all softlevel refs to runlevel.
This commit is contained in:
@@ -76,7 +76,7 @@
|
||||
# define RC_LOCAL_CONFDIR LOCAL_PREFIX SYSCONFDIR "/conf.d"
|
||||
#endif
|
||||
|
||||
#define RC_KSOFTLEVEL RC_SVCDIR "/ksoftlevel"
|
||||
#define RC_KRUNLEVEL RC_SVCDIR "/krunlevel"
|
||||
#define RC_STARTING RC_SVCDIR "/rc.starting"
|
||||
#define RC_STOPPING RC_SVCDIR "/rc.stopping"
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ const char librc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
|
||||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
#define SOFTLEVEL RC_SVCDIR "/softlevel"
|
||||
#define RC_RUNLEVEL RC_SVCDIR "/softlevel"
|
||||
|
||||
#ifndef S_IXUGO
|
||||
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
|
||||
@@ -268,7 +268,7 @@ char *rc_runlevel_get(void)
|
||||
FILE *fp;
|
||||
char *runlevel = NULL;
|
||||
|
||||
if ((fp = fopen(SOFTLEVEL, "r"))) {
|
||||
if ((fp = fopen(RC_RUNLEVEL, "r"))) {
|
||||
runlevel = xmalloc(sizeof(char) * PATH_MAX);
|
||||
if (fgets(runlevel, PATH_MAX, fp)) {
|
||||
int i = strlen(runlevel) - 1;
|
||||
@@ -290,7 +290,7 @@ librc_hidden_def(rc_runlevel_get)
|
||||
|
||||
bool rc_runlevel_set(const char *runlevel)
|
||||
{
|
||||
FILE *fp = fopen(SOFTLEVEL, "w");
|
||||
FILE *fp = fopen(RC_RUNLEVEL, "w");
|
||||
|
||||
if (! fp)
|
||||
return false;
|
||||
|
||||
@@ -11,7 +11,7 @@ SBINDIR= ${PREFIX}/sbin
|
||||
LINKDIR= ${PREFIX}/${LIBNAME}/${PROG}
|
||||
|
||||
BINLINKS= rc-status
|
||||
SBINLINKS= rc-update runscript start-stop-daemon
|
||||
SBINLINKS= rc-service rc-update runscript start-stop-daemon
|
||||
RC_BINLINKS= einfon einfo ewarnn ewarn eerrorn eerror ebegin eend ewend \
|
||||
eindent eoutdent esyslog eval_ecolors \
|
||||
veinfo vewarn vebegin veend vewend veindent veoutdent \
|
||||
|
||||
@@ -362,6 +362,18 @@ static int do_shell_var(int argc, char **argv)
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int rc_service(_unused int argc, char **argv)
|
||||
{
|
||||
char *service = rc_service_resolve(argv[1]);
|
||||
|
||||
if (!service)
|
||||
eerrorx("%s: service `%s' does not exist", applet, optarg);
|
||||
|
||||
*++argv = service;
|
||||
execv(*argv, argv);
|
||||
eerrorx("%s: %s", applet, strerror(errno));
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
void run_applets(int argc, char **argv)
|
||||
{
|
||||
@@ -377,6 +389,8 @@ void run_applets(int argc, char **argv)
|
||||
exit(mountinfo(argc, argv));
|
||||
else if (strcmp(applet, "rc-depend") == 0)
|
||||
exit(rc_depend(argc, argv));
|
||||
else if (strcmp(applet, "rc-service") == 0)
|
||||
exit(rc_service(argc, argv));
|
||||
else if (strcmp(applet, "rc-status") == 0)
|
||||
exit(rc_status(argc, argv));
|
||||
else if (strcmp(applet, "rc-update") == 0 ||
|
||||
|
||||
@@ -107,7 +107,7 @@ int rc_depend(int argc, char **argv)
|
||||
int options = RC_DEP_TRACE;
|
||||
bool first = true;
|
||||
bool update = false;
|
||||
char *runlevel = xstrdup(getenv("RC_SOFTLEVEL"));
|
||||
char *runlevel = xstrdup(getenv("RC_RUNLEVEL"));
|
||||
int opt;
|
||||
char *token;
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ void env_config(void)
|
||||
setenv("RC_RUNLEVEL", e, 1);
|
||||
free(e);
|
||||
|
||||
if ((fp = fopen(RC_KSOFTLEVEL, "r"))) {
|
||||
if ((fp = fopen(RC_KRUNLEVEL, "r"))) {
|
||||
memset(buffer, 0, sizeof (buffer));
|
||||
if (fgets(buffer, sizeof (buffer), fp)) {
|
||||
l = strlen (buffer) - 1;
|
||||
|
||||
33
src/rc/rc.c
33
src/rc/rc.c
@@ -367,14 +367,14 @@ static bool set_ksoftlevel(const char *level)
|
||||
strcmp(level, RC_LEVEL_SINGLE) == 0 ||
|
||||
strcmp(level, RC_LEVEL_SYSINIT) == 0)
|
||||
{
|
||||
if (exists(RC_KSOFTLEVEL) &&
|
||||
unlink(RC_KSOFTLEVEL) != 0)
|
||||
eerror("unlink `%s': %s", RC_KSOFTLEVEL, strerror(errno));
|
||||
if (exists(RC_KRUNLEVEL) &&
|
||||
unlink(RC_KRUNLEVEL) != 0)
|
||||
eerror("unlink `%s': %s", RC_KRUNLEVEL, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! (fp = fopen(RC_KSOFTLEVEL, "w"))) {
|
||||
eerror("fopen `%s': %s", RC_KSOFTLEVEL, strerror(errno));
|
||||
if (! (fp = fopen(RC_KRUNLEVEL, "w"))) {
|
||||
eerror("fopen `%s': %s", RC_KRUNLEVEL, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -388,11 +388,11 @@ static int get_ksoftlevel(char *buffer, int buffer_len)
|
||||
FILE *fp;
|
||||
int i = 0;
|
||||
|
||||
if (! exists(RC_KSOFTLEVEL))
|
||||
if (! exists(RC_KRUNLEVEL))
|
||||
return 0;
|
||||
|
||||
if (! (fp = fopen(RC_KSOFTLEVEL, "r"))) {
|
||||
eerror("fopen `%s': %s", RC_KSOFTLEVEL, strerror(errno));
|
||||
if (! (fp = fopen(RC_KRUNLEVEL, "r"))) {
|
||||
eerror("fopen `%s': %s", RC_KRUNLEVEL, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ static void do_newlevel(const char *newlevel)
|
||||
printf("Press %sI%s to enter interactive boot mode\n\n",
|
||||
ecolor(ECOLOR_GOOD), ecolor(ECOLOR_NORMAL));
|
||||
|
||||
setenv("RC_SOFTLEVEL", newlevel, 1);
|
||||
setenv("RC_RUNLEVEL", newlevel, 1);
|
||||
rc_plugin_run(RC_HOOK_RUNLEVEL_START_IN, newlevel);
|
||||
hook_out = RC_HOOK_RUNLEVEL_START_OUT;
|
||||
run_script(INITSH);
|
||||
@@ -902,10 +902,12 @@ interactive_option:
|
||||
#define getoptstring "o:" getoptstring_COMMON
|
||||
static const struct option longopts[] = {
|
||||
{ "override", 1, NULL, 'o' },
|
||||
{ "service", 1, NULL, 's' },
|
||||
longopts_COMMON
|
||||
};
|
||||
static const char * const longopts_help[] = {
|
||||
"override the next runlevel to change into\nwhen leaving single user or boot runlevels",
|
||||
"runs the service specified with the rest\nof the arguments",
|
||||
longopts_help_COMMON
|
||||
};
|
||||
#include "_usage.c"
|
||||
@@ -958,8 +960,7 @@ int main(int argc, char **argv)
|
||||
chdir("/");
|
||||
|
||||
/* RUNLEVEL is set by sysvinit as is a magic number
|
||||
* RC_SOFTLEVEL is set by us and is the name for this magic number
|
||||
* even though all our userland documentation refers to runlevel */
|
||||
* RC_RUNLEVEL is set by us and is the name for this magic number */
|
||||
RUNLEVEL = getenv("RUNLEVEL");
|
||||
PREVLEVEL = getenv("PREVLEVEL");
|
||||
|
||||
@@ -979,6 +980,16 @@ int main(int argc, char **argv)
|
||||
optarg = NULL;
|
||||
exit(set_ksoftlevel(optarg) ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
/* NOTREACHED */
|
||||
case 's':
|
||||
newlevel = rc_service_resolve(optarg);
|
||||
if (!newlevel)
|
||||
eerrorx("%s: service `%s' does not exist",
|
||||
applet, optarg);
|
||||
argv += optind - 1;
|
||||
*argv = newlevel;
|
||||
execv(*argv, argv);
|
||||
eerrorx("%s: %s", applet, strerror(errno));
|
||||
/* NOTREACHED */
|
||||
case_RC_COMMON_GETOPT
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user