aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pies.c38
-rw-r--r--src/pies.h2
-rw-r--r--src/progman.c4
-rw-r--r--src/sysvinit.c70
4 files changed, 92 insertions, 22 deletions
diff --git a/src/pies.c b/src/pies.c
index 3734b47..653a865 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1927,7 +1927,6 @@ char **pies_master_argv;
int
main (int argc, char **argv)
{
- int index;
pid_t pid;
extern char **environ;
struct grecs_list_entry *ep;
@@ -2001,18 +2000,24 @@ main (int argc, char **argv)
config_file_add_type (CONF_INITTAB, "/etc/inittab");
config_file_add_type (CONF_PIES, "/etc/pies.init");
#endif
- for (index = 1; index < argc; index++)
+ sysvinit_parse_argv (argc, argv);
+ }
+ else
{
- if (!strcmp (argv[index], "single") || !strcmp (argv[index], "-s"))
- dfl_level = 'S';
- else if (strchr("0123456789sS", argv[index][0]) && !argv[index][1])
+ int index;
+
+ parse_options (argc, argv, &index);
+ argc -= index;
+ argv += index;
+
+ if (argc && !(command == COM_RESTART_COMPONENT
+ || command == COM_TRACE_DEPEND
+ || command == COM_TRACE_PREREQ))
{
- dfl_level = toupper (argv[index][0]);
- }
+ logmsg (LOG_ERR, "extra command line arguments");
+ exit (EX_USAGE);
}
}
- else
- parse_options (argc, argv, &index);
if (!instance)
{
@@ -2059,15 +2064,6 @@ main (int argc, char **argv)
/* Re-setup logging: it might have been reset in the config file */
diag_setup (log_to_stderr_only ? DIAG_TO_STDERR : 0);
- if (argc != index
- && !(command == COM_RESTART_COMPONENT
- || command == COM_TRACE_DEPEND
- || command == COM_TRACE_PREREQ))
- {
- logmsg (LOG_ERR, "extra command line arguments");
- exit (EX_CONFIG);
- }
-
if (!control.url)
{
char const *str = default_control_url[init_process];
@@ -2086,7 +2082,7 @@ main (int argc, char **argv)
pies_priv_setup (&pies_privs);
if (pies_umask)
umask (pies_umask);
- exit (request_restart_components (argc - index, argv + index));
+ exit (request_restart_components (argc, argv));
case COM_RELOAD:
exit (request_reload ());
@@ -2102,11 +2098,11 @@ main (int argc, char **argv)
exit (0);
case COM_TRACE_DEPEND:
- components_trace (argv + index, depmap_row);
+ components_trace (argv, depmap_row);
exit (0);
case COM_TRACE_PREREQ:
- components_trace (argv + index, depmap_col);
+ components_trace (argv, depmap_col);
exit (0);
default:
diff --git a/src/pies.h b/src/pies.h
index bcce32a..4a6160f 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -291,7 +291,6 @@ extern char *qotdfile;
extern int init_process;
extern char *console_device;
extern int initdefault;
-extern int dfl_level;
extern size_t pies_master_argc;
extern char **pies_master_argv;
@@ -523,6 +522,7 @@ void sysvinit_power (void);
void sysvinit_report (struct json_value *obj);
int sysvinit_set_runlevel (int newlevel);
+void sysvinit_parse_argv (int argc, char **argv);
extern char *sysvinit_environ_hint[];
extern char *init_fifo;
diff --git a/src/progman.c b/src/progman.c
index 8a5187c..1be7d27 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -1546,6 +1546,9 @@ progman_wake_sleeping (int onalrm)
{
if (IS_ACTIVE_COMPONENT (prog) && prog->v.p.wait)
{
+ /* The following works on the assumption that prog->v.p.wait is
+ set when enabling the component and gets cleared right after
+ it has finished. */
if (prog->v.p.status != status_running)
prog_start (prog);
return;
@@ -2411,4 +2414,5 @@ progman_stop_tag (const char *name)
struct prog *prog = progman_locate (name);
progman_stop_component (&prog);
}
+
/* EOF */
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 2d0671c..0370fcc 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -16,6 +16,7 @@
#include "pies.h"
#include "prog.h"
+#include <sys/ioctl.h>
#include <termios.h>
enum boot_state
@@ -59,6 +60,7 @@ int prevlevel = 'N';
int initdefault; /* Default runlevel */
int dfl_level;
+int emergency_shell;
int
console_open (int mode)
@@ -646,6 +648,56 @@ unintr_sleep (unsigned n)
;
}
+static void
+start_shell (const char *shell)
+{
+ pid_t pid, rc;
+ int st;
+ struct sigaction act, old;
+
+ act.sa_flags = SA_RESTART;
+ act.sa_handler = SIG_DFL;
+ sigemptyset (&act.sa_mask);
+ sigaction (SIGCHLD, &act, &old);
+
+ pid = fork ();
+ if (pid == -1)
+ {
+ logmsg (LOG_CRIT, "cannot run `%s': fork failed: %s",
+ shell, strerror (errno));
+ exit (1);
+ }
+
+ if (pid == 0)
+ {
+ int fd;
+
+ signal_setup (SIG_DFL);
+ setsid ();
+
+ fd = console_open (O_RDWR|O_NOCTTY);
+ if (fd < 0)
+ {
+ logmsg (LOG_CRIT, "open(%s): %s",
+ console_device, strerror (errno));
+ exit (1);
+ }
+ ioctl (fd, TIOCSCTTY, 1);
+ dup (fd);
+ dup (fd);
+
+ execl (shell, shell, NULL);
+ _exit (127);
+ }
+
+ while ((rc = wait (&st)) != pid)
+ if (rc == (pid_t) -1 && errno == ECHILD)
+ break;
+
+ logmsg (LOG_CRIT, "shell finished");
+ sigaction (SIGCHLD, &old, NULL);
+}
+
/* Memory allocation functions for INIT. They may not fail, therefore
they just retry allocation until it eventually succeeds.
*/
@@ -698,6 +750,8 @@ sysvinit_begin ()
sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
add_extra_sigv (sigv, ARRAY_SIZE (sigv));
sysvinit_sysdep_begin ();
+ if (emergency_shell)
+ start_shell ("/sbin/sulogin");
}
#define IS_RUNNING_DISABLED_PROG(prog) \
@@ -1140,3 +1194,19 @@ sysvinit_report (struct json_value *obj)
json_object_set_string (obj, "initdefault", "%c",
initdefault);
}
+
+void
+sysvinit_parse_argv (int argc, char **argv)
+{
+ while (--argc)
+ {
+ int c;
+ char *arg = *++argv;
+ if (!strcmp (arg, "single") || !strcmp (arg, "-s"))
+ dfl_level = 'S';
+ else if (!strcmp (arg, "-b") || !strcmp (arg, "emergency"))
+ emergency_shell = 1;
+ else if (!arg[1] && strchr (valid_runlevels, (c = toupper (arg[0]))))
+ dfl_level = c;
+ }
+}

Return to:

Send suggestions and report system problems to the System administrator.