aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am10
-rw-r--r--src/cmdline.opt4
-rw-r--r--src/comp.c3
-rw-r--r--src/ctl.c176
-rw-r--r--src/diag.c2
-rw-r--r--src/pies.c91
-rw-r--r--src/pies.h13
-rw-r--r--src/progman.c15
-rw-r--r--src/sysvinit.c64
9 files changed, 208 insertions, 170 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 16f8a75..925da88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,11 +30,15 @@ pies_SOURCES = \
pies.c\
progman.c\
socket.c\
- sysdep.c\
- sysvinit.c\
- utmp.c\
userprivs.c
+if PIES_COND_SYSVINIT
+pies_SOURCES += \
+ sysvinit.c\
+ sysdep.c\
+ utmp.c
+endif
+
noinst_HEADERS = \
acl.h\
cmdline.h\
diff --git a/src/cmdline.opt b/src/cmdline.opt
index d2aaf6d..d9d90e1 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -118,12 +118,14 @@ BEGIN
lint_mode = 1;
END
+CPP(#if PIES_SYSVINIT_ENABLED)
OPTION(telinit,T,,
[<telinit command: run "pies -T --help" for help>])
BEGIN
log_to_stderr_only = 1;
exit (telinit (argc - (optind - 1), argv + (optind - 1)));
END
+CPP(#endif)
GROUP(Preprocessor)
@@ -220,7 +222,7 @@ parse_options (int *pargc, char ***pargv)
char **argv = *pargv;
int index;
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
sysvinit_parse_argv (argc, argv);
index = argc;
diff --git a/src/comp.c b/src/comp.c
index 6eeeeed..7b2b373 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -674,6 +674,9 @@ component_verify (struct component *comp, grecs_locus_t *locus)
return 1;
}
default:
+ if (PIES_SYSVINIT_ENABLED && comp->mode >= pies_mark_sysvinit)
+ COMPERR (grecs_error,
+ "%s", _("SystemV init support is not compiled in"));
/* FIXME: more checks perhaps */
break;
}
diff --git a/src/ctl.c b/src/ctl.c
index d9a8998..5609f19 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -918,14 +918,17 @@ static void res_instance (struct ctlio *, enum http_method, char const *,
struct json_value *);
static void res_programs (struct ctlio *, enum http_method, char const *,
struct json_value *);
+static void res_conf (struct ctlio *, enum http_method, char const *,
+ struct json_value *);
+
+#if PIES_SYSVINIT_ENABLED
static void res_runlevel (struct ctlio *, enum http_method, char const *,
struct json_value *);
static void res_environ (struct ctlio *, enum http_method, char const *,
struct json_value *);
-static void res_conf (struct ctlio *, enum http_method, char const *,
- struct json_value *);
-
static int pred_sysvinit (void);
+#endif
+
struct ctlio_resource
{
@@ -943,8 +946,10 @@ static struct ctlio_resource restab[] = {
{ S(/conf), CTL_ADMIN_STATE, NULL, res_conf },
{ S(/programs), CTL_ADMIN_STATE|CTL_USER_STATE, NULL,
res_programs },
+#if PIES_SYSVINIT_ENABLED
{ S(/runlevel), CTL_ADMIN_STATE, pred_sysvinit, res_runlevel },
{ S(/environ), CTL_ADMIN_STATE, pred_sysvinit, res_environ },
+#endif
{ NULL }
#undef S
};
@@ -2117,6 +2122,7 @@ res_programs (struct ctlio *io, enum http_method meth,
res_programs_select (io, meth, uri, json);
}
+#if PIES_SYSVINIT_ENABLED
static int
pred_sysvinit (void)
{
@@ -2163,6 +2169,89 @@ res_runlevel (struct ctlio *io, enum http_method meth,
else
ctlio_reply (io, 405, NULL);
}
+
+/* GET /environ - List entire environment
+ * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
+ * GET /environ/NAME - Get value of variable NAME
+ * { "status":"OK", "value":"..." }
+ * { "status":"ER", "error_message":"..." }
+ * DELETE /environ/NAME - Unset variable
+ * { "status":"OK" }
+ * { "status":"ER", "error_message":"..." }
+ * PUT /environ/NAME=VALUE - Set variable
+ * { "status":"OK" }
+ * { "status":"ER", "error_message":"..." }
+ */
+static void
+env_reply (struct ctlio *io, int ok, int rc)
+{
+ switch (rc)
+ {
+ case 0:
+ io->code = ok;
+ io->output.reply = json_reply_create ();
+ json_object_set_string (io->output.reply, "status", "OK");
+ break;
+
+ case 1:
+ ctlio_reply (io, 403, NULL);
+ break;
+
+ case -1:
+ ctlio_reply (io, 404, NULL);
+ }
+}
+
+static void
+res_environ (struct ctlio *io, enum http_method meth,
+ char const *uri, struct json_value *json)
+{
+ if (meth == METH_GET)
+ {
+ if (uri && uri[1])
+ {
+ char *value;
+
+ if (sysvinit_envlocate (uri + 1, &value) == -1)
+ ctlio_reply (io, 404, NULL);
+ else
+ {
+ env_reply (io, 200, 0);
+ json_object_set_string (io->output.reply, "value", "%s", value);
+ }
+ }
+ else
+ {
+ size_t i;
+
+ io->output.reply = json_new_array ();
+ io->code = 200;
+ for (i = 0; sysvinit_environ_hint[i]; i++)
+ {
+ json_array_append (io->output.reply,
+ json_new_string (sysvinit_environ_hint[i]));
+ }
+ }
+ }
+ else if (meth == METH_DELETE)
+ {
+ if (!(uri && uri[0]))
+ ctlio_reply (io, 400, NULL);
+ else
+ env_reply (io, 200, sysvinit_envupdate (uri + 1));
+ }
+ else if (meth == METH_PUT)
+ {
+ if (!(uri && uri[0]))
+ ctlio_reply (io, 400, NULL);
+ else
+ env_reply (io, 201, sysvinit_envupdate (uri + 1));
+ }
+ else
+ ctlio_reply (io, 405, NULL);
+
+}
+#endif
/* GET /conf/runtime - List configuration
* PUT /conf/runtime - Reload configuration
@@ -2407,85 +2496,4 @@ res_conf (struct ctlio *io, enum http_method meth,
else
ctlio_reply (io, 404, NULL);
}
-
-/* GET /environ - List entire environment
- * ["RUNLEVEL=3", "CONSOLE=/dev/tty", ...]
- * GET /environ/NAME - Get value of variable NAME
- * { "status":"OK", "value":"..." }
- * { "status":"ER", "error_message":"..." }
- * DELETE /environ/NAME - Unset variable
- * { "status":"OK" }
- * { "status":"ER", "error_message":"..." }
- * PUT /environ/NAME=VALUE - Set variable
- * { "status":"OK" }
- * { "status":"ER", "error_message":"..." }
- */
-static void
-env_reply (struct ctlio *io, int ok, int rc)
-{
- switch (rc)
- {
- case 0:
- io->code = ok;
- io->output.reply = json_reply_create ();
- json_object_set_string (io->output.reply, "status", "OK");
- break;
- case 1:
- ctlio_reply (io, 403, NULL);
- break;
-
- case -1:
- ctlio_reply (io, 404, NULL);
- }
-}
-
-static void
-res_environ (struct ctlio *io, enum http_method meth,
- char const *uri, struct json_value *json)
-{
- if (meth == METH_GET)
- {
- if (uri && uri[1])
- {
- char *value;
-
- if (sysvinit_envlocate (uri + 1, &value) == -1)
- ctlio_reply (io, 404, NULL);
- else
- {
- env_reply (io, 200, 0);
- json_object_set_string (io->output.reply, "value", "%s", value);
- }
- }
- else
- {
- size_t i;
-
- io->output.reply = json_new_array ();
- io->code = 200;
- for (i = 0; sysvinit_environ_hint[i]; i++)
- {
- json_array_append (io->output.reply,
- json_new_string (sysvinit_environ_hint[i]));
- }
- }
- }
- else if (meth == METH_DELETE)
- {
- if (!(uri && uri[0]))
- ctlio_reply (io, 400, NULL);
- else
- env_reply (io, 200, sysvinit_envupdate (uri + 1));
- }
- else if (meth == METH_PUT)
- {
- if (!(uri && uri[0]))
- ctlio_reply (io, 400, NULL);
- else
- env_reply (io, 201, sysvinit_envupdate (uri + 1));
- }
- else
- ctlio_reply (io, 405, NULL);
-
-}
diff --git a/src/diag.c b/src/diag.c
index 78e2741..bd5eff2 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -73,7 +73,7 @@ stderr_printer (LOGSTREAM *str, int prio, const char *fmt, va_list ap)
static int
stderr_open (int logf, LOGSTREAM *str)
{
- if (logf & DIAG_REOPEN_LOG)
+ if (PIES_SYSVINIT_ENABLED && (logf & DIAG_REOPEN_LOG))
{
int fd = console_open (O_WRONLY|O_NOCTTY|O_NDELAY);
if (fd == -1)
diff --git a/src/pies.c b/src/pies.c
index 2564af5..75285dc 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -75,7 +75,9 @@ static struct config_syntax config_syntax_tab[] = {
[CONF_PIES] = { "pies" , pies_config_parse },
[CONF_META1] = { "meta1", meta1_config_parse },
[CONF_INETD] = { "inetd", inetd_config_parse },
+#if PIES_SYSVINIT_ENABLED
[CONF_INITTAB] = { "inittab", inittab_parse },
+#endif
};
struct config_file
@@ -1205,56 +1207,6 @@ _cb_flags (enum grecs_callback_command cmd,
return 0;
}
-static int
-_cb_initdefault (enum grecs_callback_command cmd,
- grecs_node_t *node,
- void *varptr, void *cb_data)
-{
- grecs_locus_t *locus = &node->locus;
- grecs_value_t *value = node->v.value;
- int *val = varptr;
-
- if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING))
- return 1;
- if (strlen (value->v.string) != 1)
- {
- grecs_error (locus, 0, _("argument must be a single character"));
- return 1;
- }
- if (!is_valid_runlevel (value->v.string[0]))
- {
- grecs_error (locus, 0, _("not a valid runlevel"));
- return 1;
- }
- *val = toupper (value->v.string[0]);
- return 0;
-}
-
-static int
-_cb_runlevels (enum grecs_callback_command cmd,
- grecs_node_t *node,
- void *varptr, void *cb_data)
-{
- grecs_locus_t *locus = &node->locus;
- grecs_value_t *value = node->v.value;
- char **sptr = varptr, *p;
-
- if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING))
- return 1;
- for (p = value->v.string; *p; p++)
- {
- if (!is_valid_runlevel (*p))
- {
- grecs_error (locus, 0, _("not a valid runlevel: %c"), *p);
- return 1;
- }
- }
- *sptr = grecs_strdup (value->v.string);
- for (p = *sptr; *p; p++)
- *p = toupper (*p);
- return 0;
-}
-
struct grecs_keyword component_keywords[] = {
{"mode",
N_("mode"),
@@ -1294,12 +1246,14 @@ struct grecs_keyword component_keywords[] = {
N_("List of flags."),
grecs_type_string, GRECS_LIST, NULL, offsetof (struct component, flags),
_cb_flags },
+#if PIES_SYSVINIT_ENABLED
{"runlevels",
N_("chars"),
N_("Runlevels to start that component in."),
grecs_type_string, GRECS_DFLT,
NULL, offsetof (struct component, runlevels),
- _cb_runlevels },
+ cb_runlevels },
+#endif
{"pass-fd-socket",
N_("name"),
N_("Pass fd through this socket."),
@@ -1722,12 +1676,14 @@ struct grecs_keyword pies_keywords[] = {
grecs_type_string, GRECS_DFLT,
&pies_limits, 0, _cb_limits,
},
+#if PIES_SYSVINIT_ENABLED
{"initdefault",
N_("arg: char"),
N_("Default runlevel"),
grecs_type_string, GRECS_DFLT,
- &initdefault, 0, _cb_initdefault,
+ NULL, 0, cb_initdefault,
},
+#endif
{"shutdown-timeout",
"n",
N_("Wait <n> seconds for all components to shut down."),
@@ -1859,7 +1815,7 @@ pies_read_config (void)
++err;
}
- if (init_process)
+ if (SYSVINIT_ACTIVE)
err = 0;
if (err)
@@ -1898,7 +1854,7 @@ pies_schedule_children (int op)
RETSIGTYPE
sig_handler (int sig)
{
- if (init_process && sysvinit_sigtrans (sig, &action))
+ if (SYSVINIT_ACTIVE && sysvinit_sigtrans (sig, &action))
return;
switch (sig)
{
@@ -2278,7 +2234,7 @@ init_emu (void)
static void
set_conf_file_names (const char *base)
{
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
config_file_add_type (CONF_INITTAB, "/etc/inittab");
config_file_add_type (CONF_PIES, "/etc/pies.init");
@@ -2338,7 +2294,7 @@ main (int argc, char **argv)
}
/* Set default logging */
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
log_facility = LOG_DAEMON;
diag_flags = DIAG_TO_STDERR | DIAG_REOPEN_LOG;
@@ -2373,7 +2329,7 @@ main (int argc, char **argv)
set_conf_file_names (instance);
- if (init_process || !DEFAULT_PREPROCESSOR)
+ if (SYSVINIT_ACTIVE || !DEFAULT_PREPROCESSOR)
grecs_preprocessor = NULL;
else
grecs_preprocessor = pp_command_line ();
@@ -2451,7 +2407,7 @@ main (int argc, char **argv)
umask (pies_umask);
}
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
foreground = 1;
sysvinit_begin ();
@@ -2491,7 +2447,7 @@ main (int argc, char **argv)
logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version);
- if (!init_process)
+ if (!SYSVINIT_ACTIVE)
{
if (ctl_open ())
exit (EX_UNAVAILABLE);
@@ -2516,7 +2472,7 @@ main (int argc, char **argv)
switch (action)
{
case ACTION_RESTART:
- if (pies_master_argv[0][0] != '/' || init_process)
+ if (pies_master_argv[0][0] != '/' || SYSVINIT_ACTIVE)
{
logmsg (LOG_INFO, _("restart command ignored"));
action = ACTION_CONT;
@@ -2532,7 +2488,7 @@ main (int argc, char **argv)
/* fall through */
case ACTION_COMMIT:
component_config_commit ();
- if (init_process)
+ if (SYSVINIT_ACTIVE)
sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
progman_create_sockets ();
progman_start ();
@@ -2542,7 +2498,7 @@ main (int argc, char **argv)
break;
case ACTION_STOP:
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
debug (1, ("ignoring stop/restart"));
action = ACTION_CONT;
@@ -2551,21 +2507,24 @@ main (int argc, char **argv)
case ACTION_CTRLALTDEL:
debug (1, ("ctrl-alt-del"));
- sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_ctrlaltdel));
+ if (SYSVINIT_ACTIVE)
+ sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_ctrlaltdel));
pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
case ACTION_KBREQUEST:
debug (1, ("kbrequest"));
- sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_kbrequest));
+ if (SYSVINIT_ACTIVE)
+ sysvinit_runlevel_setup (PIES_COMP_MASK (pies_comp_kbrequest));
pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
case ACTION_POWER:
debug (1, ("SIGPWR"));
- sysvinit_power ();
+ if (SYSVINIT_ACTIVE)
+ sysvinit_power ();
pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
}
@@ -2582,7 +2541,7 @@ main (int argc, char **argv)
children_op = PIES_CHLD_NONE;
}
}
- while (init_process || action == ACTION_CONT);
+ while (SYSVINIT_ACTIVE || action == ACTION_CONT);
progman_stop ();
remove_pidfile (pidfile);
diff --git a/src/pies.h b/src/pies.h
index 4d52ce4..201a719 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -276,7 +276,11 @@ struct component
pies_acl_t adm_acl; /* Administrative ACL (stop, start, etc.) */
};
-#define is_sysvinit(cp) ((cp)->mode >= pies_mark_sysvinit || (cp)->runlevels)
+#define is_sysvinit(cp) \
+ (PIES_SYSVINIT_ENABLED \
+ && ((cp)->mode >= pies_mark_sysvinit || (cp)->runlevels))
+
+#define SYSVINIT_ACTIVE (PIES_SYSVINIT_ENABLED && init_process)
enum pies_action {
ACTION_CONT,
@@ -565,6 +569,13 @@ int sysvinit_envlocate (char const *name, char **value);
int sysvinit_envdelete (char const *name);
int sysvinit_envupdate (char const *var);
+int cb_initdefault (enum grecs_callback_command cmd,
+ grecs_node_t *node,
+ void *varptr, void *cb_data);
+int cb_runlevels (enum grecs_callback_command cmd,
+ grecs_node_t *node,
+ void *varptr, void *cb_data);
+
extern char *sysvinit_environ_hint[];
extern char *init_fifo;
diff --git a/src/progman.c b/src/progman.c
index 88f9afa..70ebf68 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -824,7 +824,7 @@ prog_start_prologue (struct prog *prog)
environ_unset (prog->v.p.env, sockenv_var[i], NULL);
}
envop_exec (prog->v.p.comp->envop, prog->v.p.env);
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
size_t i;
for (i = 0; sysvinit_environ_hint[i]; i++)
@@ -899,7 +899,7 @@ prog_start (struct prog *prog)
if (is_sysvinit (prog->v.p.comp))
{
- if (!init_process)
+ if (!SYSVINIT_ACTIVE)
{
if (prog->active)
{
@@ -995,7 +995,7 @@ prog_start (struct prog *prog)
break;
default:
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
int fd = console_open (O_RDWR|O_NOCTTY);
if (fd < 0)
@@ -1037,7 +1037,7 @@ prog_start (struct prog *prog)
break;
}
- if (!init_process)
+ if (!SYSVINIT_ACTIVE)
{
if (redir[RETR_ERR] == -1)
{
@@ -1600,7 +1600,7 @@ print_status (const char *tag, pid_t pid, int status, int expect_term)
{
int prio;
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
if (debug_level <= 1)
return;
@@ -2147,7 +2147,8 @@ progman_cleanup (int expect_term)
}
else
{
- if (prog->v.p.comp->mode >= pies_mark_sysvinit
+ if (PIES_SYSVINIT_ENABLED
+ && prog->v.p.comp->mode >= pies_mark_sysvinit
&& prog->v.p.comp->mode != pies_comp_ondemand)
{
sysvinit_acct (SYSV_ACCT_PROC_STOP, "", prog_tag (prog),
@@ -2303,7 +2304,7 @@ prog_to_stop (struct prog *prog)
}
#define DIAG_CON \
- (init_process ? (DIAG_TO_STDERR|DIAG_REOPEN_LOG) : diag_output)
+ (SYSVINIT_ACTIVE ? (DIAG_TO_STDERR|DIAG_REOPEN_LOG) : diag_output)
/* Stop all program components marked for termination. Wait at most
2*shutdown_timeout seconds. */
diff --git a/src/sysvinit.c b/src/sysvinit.c
index 3ba986b..c5d25da 100644
--- a/src/sysvinit.c
+++ b/src/sysvinit.c
@@ -55,13 +55,13 @@ static int boot_trans_tab[max_boot_state][sizeof(valid_runlevels)-1] = {
};
enum boot_state boot_state;
-int runlevel = 0;
-int prevlevel = 'N';
+static int runlevel = 0;
+static int prevlevel = 'N';
-int initdefault; /* Default runlevel */
-int dfl_level;
-char *emergency_shell = EMERGENCY_SHELL;
-int emergency;
+int initdefault;
+static int dfl_level;
+static char *emergency_shell = EMERGENCY_SHELL;
+static int emergency;
static int inittrans (void);
@@ -340,7 +340,7 @@ is_valid_runlevel (int c)
{
return !!strchr (valid_runlevel_arg, c);
}
-
+
#define ENVAR_CONSOLE "CONSOLE="
#define ENVTMPL_CONSOLE "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@@ -1283,3 +1283,53 @@ sysvinit_parse_argv (int argc, char **argv)
dfl_level = c;
}
}
+
+int
+cb_initdefault (enum grecs_callback_command cmd,
+ grecs_node_t *node,
+ void *varptr, void *cb_data)
+{
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+
+ if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING))
+ return 1;
+ if (strlen (value->v.string) != 1)
+ {
+ grecs_error (locus, 0, _("argument must be a single character"));
+ return 1;
+ }
+ if (!is_valid_runlevel (value->v.string[0]))
+ {
+ grecs_error (locus, 0, _("not a valid runlevel"));
+ return 1;
+ }
+ initdefault = toupper (value->v.string[0]);
+ return 0;
+}
+
+int
+cb_runlevels (enum grecs_callback_command cmd,
+ grecs_node_t *node,
+ void *varptr, void *cb_data)
+{
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+ char **sptr = varptr, *p;
+
+ if (grecs_assert_node_value_type (cmd, node, GRECS_TYPE_STRING))
+ return 1;
+ for (p = value->v.string; *p; p++)
+ {
+ if (!is_valid_runlevel (*p))
+ {
+ grecs_error (locus, 0, _("not a valid runlevel: %c"), *p);
+ return 1;
+ }
+ }
+ *sptr = grecs_strdup (value->v.string);
+ for (p = *sptr; *p; p++)
+ *p = toupper (*p);
+ return 0;
+}
+

Return to:

Send suggestions and report system problems to the System administrator.