aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac46
m---------grecs0
-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
11 files changed, 254 insertions, 170 deletions
diff --git a/configure.ac b/configure.ac
index ae3a9c7..3a23a1a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,42 +116,88 @@ if test $status_pam = yes; then
AC_DEFINE_UNQUOTED(WITH_PAM, 1, [PAM support enabled])
fi
# Build inetd
AC_ARG_ENABLE([inetd],
AC_HELP_STRING([--enable-inetd],
[build and install a replacement for SBINDIR/inetd]),
[case $enableval in
yes) AC_SUBST([INETD], [inetd]);;
no) ;;
esac])
+sysvinit_status=maybe
+AC_ARG_ENABLE([sysvinit],
+ AC_HELP_STRING([--enable-sysvinit],
+ [compile the SystemV init support]),
+ [sysvinit_status=$enableval])
+
+if test $sysvinit_status = "maybe"; then
+ AC_TRY_COMPILE([#ifdef HAVE_UTMPX_H
+# include <utmpx.h>
+#else
+# include <utmp.h>
+#endif
+],
+[int x = RUN_LVL;],
+[sysvinit_status=yes],
+[sysvinit_status=no])
+fi
+
+test $sysvinit_status = "no"
+PIES_SYSVINIT_ENABLED=$?
+AC_DEFINE_UNQUOTED([PIES_SYSVINIT_ENABLED],[$PIES_SYSVINIT_ENABLED],
+ [whether SystemV init support is compiled])
+AM_CONDITIONAL([PIES_COND_SYSVINIT],[test $sysvinit_status = "yes"])
+
AH_BOTTOM([
# ifndef ATTRIBUTE_NORETURN
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
])
AC_SUBST([DEFAULT_PIES_CONTROL_URL],['unix:///tmp/$${PIES_INSTANCE}.ctl'])
AC_ARG_VAR([DEFAULT_PIES_CONTROL_URL],
[URL of the default control socket])
AC_SUBST([DEFAULT_INIT_CONTROL_URL],['unix:///dev/init.ctl'])
AC_ARG_VAR([DEFAULT_INIT_CONTROL_URL],
[URL of the default control socket])
AC_SUBST([EMERGENCY_SHELL],['/sbin/sulogin'])
AC_ARG_VAR([EMERGENCY_SHELL],[Filename of the emergency shell])
IMPRIMATUR_INIT
# Initialize the test suite.
AC_CONFIG_TESTDIR(tests)
AC_CONFIG_FILES([tests/Makefile tests/atlocal])
AM_MISSING_PROG([AUTOM4TE], [autom4te])
+AC_CONFIG_COMMANDS([status],[
+cat <<EOF
+Configuration summary:
+
+URL of the control API ............................. $control_url
+PAM support ........................................ $status_pam
+SystemV initialization support ..................... $sysvinit_status
+EOF
+if test $sysvinit_status = "yes"; then
+ cat <<EOF
+URL of the SystemV init ............................ $sysvinit_control_url
+Emergency shell .................................... $emergency_shell
+EOF
+fi
+],
+[sysvinit_status=$sysvinit_status
+control_url=`echo "$DEFAULT_PIES_CONTROL_URL" | sed 's/\\\$/\\\\\$/g'`
+sysvinit_control_url=$DEFAULT_INIT_CONTROL_URL
+emergency_shell=$EMERGENCY_SHELL
+status_pam=$status_pam
+])
+
AC_CONFIG_FILES([Makefile
gnu/Makefile
lib/Makefile
src/Makefile
ident/Makefile
doc/Makefile
po/Makefile.in])
AC_OUTPUT
diff --git a/grecs b/grecs
-Subproject 12304127b52650588877f00b0c4b32dae083e85
+Subproject ee35adccec058a5a8cc62f5030b9a925168236d
diff --git a/src/Makefile.am b/src/Makefile.am
index 16f8a75..925da88 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,29 +21,33 @@ pies_SOURCES = \
acl.c\
comp.c\
ctl.c\
depmap.c\
diag.c\
inetd.c\
inetd-bi.c\
limits.c\
meta1parse.c\
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\
meta1parse.h\
pies.h\
prog.h\
piesctl-cl.h\
telinit.h
BUILT_SOURCES=cmdline.h piesctl-cl.h telinit.h
incdir=$(pkgdatadir)/$(VERSION)/include
diff --git a/src/cmdline.opt b/src/cmdline.opt
index d2aaf6d..d9d90e1 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -109,30 +109,32 @@ OPTION(syslog,,,
[<log to syslog>])
BEGIN
log_to_stderr_only = 0;
END
OPTION(lint,t,,
[<parse configuration file and exit>])
BEGIN
log_to_stderr_only = 1;
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)
OPTION(include-directory,I,DIR,
[<add include directory>])
BEGIN
grecs_preproc_add_include_dir(optarg);
END
OPTION(define,D,[<NAME[=VALUE]>],
[<define a preprocessor symbol NAME as having VALUE or empty>])
BEGIN
@@ -211,24 +213,24 @@ BEGIN
debug_level = strtoul (optarg, NULL, 0);
END
OPTIONS_END
void
parse_options (int *pargc, char ***pargv)
{
int argc = *pargc;
char **argv = *pargv;
int index;
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
sysvinit_parse_argv (argc, argv);
index = argc;
}
else
{
GETOPT(argc, argv, index);
}
*pargc -= index;
*pargv += index;
}
diff --git a/src/comp.c b/src/comp.c
index 6eeeeed..7b2b373 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -665,24 +665,27 @@ component_verify (struct component *comp, grecs_locus_t *locus)
else if (comp->tcpmux)
{
comp->flags |= CF_TCPMUX;
pies_url_destroy (&comp->socket_url);
}
else if (!comp->socket_url)
{
COMPERR (grecs_error,
"%s", _("socket must be specified in this mode"));
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;
}
if (comp->mode == pies_comp_inetd)
{
if ((comp->flags & CF_WAIT) && comp->socket_type == SOCK_STREAM)
{
if (comp->max_instances)
COMPERR (grecs_error, "%s", _("max-instances ignored"));
else
comp->max_instances = 1;
diff --git a/src/ctl.c b/src/ctl.c
index d9a8998..5609f19 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -909,51 +909,56 @@ method_decode (char const *method)
for (i = 0; method_names[i]; i++)
{
if (strcmp (method_names[i], method) == 0)
return i;
}
return METH_INVALID;
}
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
{
char const *uri;
size_t uri_len;
int states;
int (*predicate) (void);
void (*handler) (struct ctlio *, enum http_method,
char const *uri, struct json_value *);
};
static struct ctlio_resource restab[] = {
#define S(s) #s, (sizeof (#s)-1)
{ S(/instance), CTL_ADMIN_STATE, NULL, res_instance },
{ 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
};
static struct ctlio_resource *
find_resource (struct ctlio *io, const char *endpoint)
{
struct ctlio_resource *p;
size_t len = strcspn (endpoint, "?");
if (len == 0)
return NULL;
@@ -2108,24 +2113,25 @@ res_programs_component (struct ctlio *io, enum http_method meth,
}
static void
res_programs (struct ctlio *io, enum http_method meth,
char const *uri, struct json_value *json)
{
if (uri)
res_programs_component (io, meth, uri, json);
else
res_programs_select (io, meth, uri, json);
}
+#if PIES_SYSVINIT_ENABLED
static int
pred_sysvinit (void)
{
return init_process;
}
static void
res_runlevel (struct ctlio *io, enum http_method meth,
char const *uri, struct json_value *json)
{
if (uri)
ctlio_reply (io, 404, NULL);
@@ -2154,24 +2160,107 @@ res_runlevel (struct ctlio *io, enum http_method meth,
}
else
{
json_object_set_string (io->output.reply, "status", "ER");
json_object_set_string (io->output.reply, "error_message",
"invalid runlevel value");
}
}
}
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
* POST /conf/runtime - Post new configuration
*
* GET /conf/files - List configuration files
* DELETE /conf/files - Delete some or all configuration files
* from the list
* POST /conf/files - Install new list configuration file
*/
static void
@@ -2398,94 +2487,13 @@ res_conf (struct ctlio *io, enum http_method meth,
case METH_PUT:
conf_reload (io);
break;
default:
ctlio_reply (io, 405, NULL);
}
}
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
@@ -64,25 +64,25 @@ stderr_printer (LOGSTREAM *str, int prio, const char *fmt, va_list ap)
fprintf (fp, "%s: ", program_name);
va_copy (aq, ap);
vfprintf (fp, fmt, aq);
va_end (aq);
fprintf (fp, "\n");
return 0;
}
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)
return -1;
str->file = fdopen (fd, "w");
if (!str->file)
{
close (fd);
return -1;
}
str->open = 1;
}
diff --git a/src/pies.c b/src/pies.c
index 2564af5..75285dc 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -66,25 +66,27 @@ char *default_control_url[2] = {
struct config_syntax
{
const char *name;
int (*parser) (char const *);
};
static int pies_config_parse (char const *);
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
{
struct config_syntax *syntax;
char *name;
};
struct grecs_list *config_list;
struct config_syntax *
str_to_config_syntax (const char *str)
@@ -1196,74 +1198,24 @@ _cb_flags (enum grecs_callback_command cmd,
}
}
}
break;
case GRECS_TYPE_ARRAY:
grecs_error (locus, 0, _("too many arguments"));
return 1;
}
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"),
N_("Component execution mode."),
grecs_type_string, GRECS_DFLT,
NULL, offsetof (struct component, mode),
_cb_mode,
},
{"program",
NULL,
N_("Full name of the program."),
grecs_type_string, GRECS_DFLT,
@@ -1285,30 +1237,32 @@ struct grecs_keyword component_keywords[] = {
},
{"dependents",
N_("list"),
N_("List of components for which this one is a prerequisite."),
grecs_type_string, GRECS_LIST, NULL, offsetof (struct component, depend),
NULL,
},
{"flags",
N_("list"),
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."),
grecs_type_string, GRECS_DFLT,
NULL, offsetof (struct component, pass_fd_socket),
NULL,
},
{"pass-fd-timeout",
NULL,
N_("Time to wait for pass-fd socket to become available."),
grecs_type_uint, GRECS_DFLT,
NULL, offsetof (struct component, pass_fd_timeout),
@@ -1713,30 +1667,32 @@ struct grecs_keyword pies_keywords[] = {
N_("arg: number"),
N_("Force this umask."),
grecs_type_string, GRECS_DFLT,
&pies_umask, 0,
_cb_umask,
},
{"limits",
NULL,
N_("Set global system limits."),
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."),
grecs_type_uint, GRECS_DFLT,
&shutdown_timeout, 0,
NULL,
},
{"return-code",
N_("tag: exit-code-list"),
N_("Define what to do when the component finishes."),
grecs_type_section, GRECS_DFLT,
&default_component, 0,
@@ -1850,25 +1806,25 @@ pies_read_config (void)
struct grecs_list_entry *ep;
int err = 0;
component_config_begin ();
for (ep = config_list->head; ep; ep = ep->next)
{
struct config_file *file = ep->data;
if (file->syntax->parser (file->name))
++err;
}
- if (init_process)
+ if (SYSVINIT_ACTIVE)
err = 0;
if (err)
component_config_rollback ();
return err;
}
int
pies_reread_config (void)
{
logmsg (LOG_INFO, _("reading configuration"));
@@ -1889,25 +1845,25 @@ pies_schedule_action (int act)
action = act;
}
void
pies_schedule_children (int op)
{
children_op |= op;
}
RETSIGTYPE
sig_handler (int sig)
{
- if (init_process && sysvinit_sigtrans (sig, &action))
+ if (SYSVINIT_ACTIVE && sysvinit_sigtrans (sig, &action))
return;
switch (sig)
{
case SIGCHLD:
pies_schedule_children (PIES_CHLD_CLEANUP);
break;
case SIGINT:
case SIGTERM:
case SIGQUIT:
logmsg (LOG_NOTICE, "received signal %d", sig);
pies_schedule_action (ACTION_STOP);
@@ -2269,25 +2225,25 @@ init_emu (void)
"\n"
" To override the default FIFO name, define:\n"
" INIT_FIFO=<pathname>\n");
fprintf (stderr, "%s: End of notice\n", program_name);
}
#endif
return 0;
}
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");
}
else if (!config_list && !init_emu ())
{
char *name = mkfilename (SYSCONFDIR, base, ".conf");
config_file_add (current_syntax, name);
free (name);
}
}
@@ -2329,25 +2285,25 @@ main (int argc, char **argv)
init_process = getpid () == 1;
for (i = 1; i < argc; i++)
{
if (strcmp (argv[i], "--no-init") == 0)
{
init_process = 0;
break;
}
}
/* Set default logging */
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
log_facility = LOG_DAEMON;
diag_flags = DIAG_TO_STDERR | DIAG_REOPEN_LOG;
}
else
diag_flags = DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR);
diag_setup (diag_flags);
config_init ();
parse_options (&argc, &argv);
@@ -2364,25 +2320,25 @@ main (int argc, char **argv)
{
instance = strrchr (program_name, '/');
if (!instance)
instance = (char*) program_name;
else
instance++;
}
setenv ("PIES_INSTANCE", instance, 1);
log_tag = grecs_strdup (instance);
set_conf_file_names (instance);
- if (init_process || !DEFAULT_PREPROCESSOR)
+ if (SYSVINIT_ACTIVE || !DEFAULT_PREPROCESSOR)
grecs_preprocessor = NULL;
else
grecs_preprocessor = pp_command_line ();
if (preprocess_only)
{
for (ep = config_list->head; ep; ep = ep->next)
{
struct config_file *file = ep->data;
if (file->syntax == &config_syntax_tab[CONF_PIES]
&& grecs_preproc_run (file->name, grecs_preprocessor))
@@ -2442,25 +2398,25 @@ main (int argc, char **argv)
exit (0);
case COM_TRACE_PREREQ:
components_trace (argv, depmap_col);
exit (0);
default:
pies_priv_setup (&pies_privs);
if (pies_umask)
umask (pies_umask);
}
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
foreground = 1;
sysvinit_begin ();
}
else
switch (pies_check_status (&pid))
{
case pies_status_ctr:
break;
case pies_status_stale:
case pies_status_noresp:
if (!force_option)
@@ -2482,116 +2438,119 @@ main (int argc, char **argv)
{
check_pidfile (pidfile);
if (daemon (0, 0) == -1)
{
logfuncall ("daemon", NULL, errno);
exit (EX_SOFTWARE);
}
diag_setup (DIAG_TO_SYSLOG);
}
logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version);
- if (!init_process)
+ if (!SYSVINIT_ACTIVE)
{
if (ctl_open ())
exit (EX_UNAVAILABLE);
create_pidfile (pidfile);
}
if (pies_master_argv[0][0] != '/')
logmsg (LOG_NOTICE,
_("not started as an absolute pathname; "
"restart will not work"));
signal_setup (sig_handler);
progman_create_sockets ();
program_init_startup ();
progman_start ();
do
{
if (children_op == PIES_CHLD_NONE)
pies_pause ();
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;
}
break;
case ACTION_RELOAD:
if (pies_reread_config ())
{
action = ACTION_CONT;
break;
}
/* 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 ();
pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;
case ACTION_STOP:
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
debug (1, ("ignoring stop/restart"));
action = ACTION_CONT;
}
break;
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;
}
if (action == ACTION_CONT)
{
if (children_op & PIES_CHLD_RESCHEDULE_ALARM)
progman_recompute_alarm ();
if (children_op & PIES_CHLD_GC)
progman_gc ();
if (children_op & PIES_CHLD_CLEANUP)
progman_cleanup (0);
if (children_op & PIES_CHLD_WAKEUP)
progman_wake_sleeping (1);
children_op = PIES_CHLD_NONE;
}
}
- while (init_process || action == ACTION_CONT);
+ while (SYSVINIT_ACTIVE || action == ACTION_CONT);
progman_stop ();
remove_pidfile (pidfile);
if (action == ACTION_RESTART)
{
int minfd = DIAG_OUTPUT (DIAG_TO_STDERR) ? 2 : 0;
int i;
for (i = getmaxfd (); i > minfd; i--)
close (i);
diff --git a/src/pies.h b/src/pies.h
index 4d52ce4..201a719 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -267,25 +267,29 @@ struct component
char *max_ip_connections_message;
/* Redirectors: */
int facility; /* Syslog facility. */
struct redirector redir[2]; /* Repeaters for stdout and stderr */
/* Actions to execute on various exit codes: */
struct grecs_list *act_list;
/* ACLs for control interface */
pies_acl_t list_acl; /* List access control list */
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,
ACTION_STOP,
ACTION_RESTART,
ACTION_RELOAD,
ACTION_CTRLALTDEL,
ACTION_KBREQUEST,
ACTION_POWER,
ACTION_COMMIT
};
@@ -556,24 +560,31 @@ int sysvinit_sigtrans (int sig, int *pact);
void sysvinit_runlevel_setup (int mask);
void sysvinit_sysdep_begin (void);
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);
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;
#ifndef INIT_FIFO
# define INIT_FIFO "/dev/initctl"
#endif
#ifndef POWER_STAT_FILE
# define POWER_STAT_FILE "/var/run/powerstatus"
#endif
/* Power status values */
diff --git a/src/progman.c b/src/progman.c
index 88f9afa..70ebf68 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -815,25 +815,25 @@ prog_start_prologue (struct prog *prog)
logmsg (LOG_ERR, _("%s: cannot change to directory %s: %s"),
prog_tag (prog), prog->v.p.comp->dir, strerror (errno));
}
prog->v.p.env = environ_create (environ);
if (prog->v.p.comp->flags & CF_SOCKENV)
{
size_t i;
for (i = 0; sockenv_var[i]; i++)
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++)
environ_add (prog->v.p.env, sysvinit_environ_hint[i]);
}
debug_environ (prog, 4);
pies_priv_setup (&prog->v.p.comp->privs);
if (prog->v.p.comp->umask)
umask (prog->v.p.comp->umask);
set_limits (prog_tag (prog),
@@ -890,25 +890,25 @@ progman_run_comp (struct component *comp, int fd,
static void
prog_start (struct prog *prog)
{
pid_t pid;
int redir[2];
fd_set fdset;
if (prog->pid > 0 || !IS_COMPONENT (prog))
return;
if (is_sysvinit (prog->v.p.comp))
{
- if (!init_process)
+ if (!SYSVINIT_ACTIVE)
{
if (prog->active)
{
logmsg (LOG_NOTICE, "disabling sysvinit component %s",
prog_tag (prog));
prog->v.p.status = status_stopped;
prog->active = 0;
}
return;
}
}
@@ -986,25 +986,25 @@ prog_start (struct prog *prog)
{
case pies_comp_accept:
case pies_comp_inetd:
prog_sockenv (prog);
dup2 (prog->v.p.socket, 0);
dup2 (prog->v.p.socket, 1);
close (prog->v.p.socket);
prog->v.p.socket = -1;
break;
default:
- if (init_process)
+ if (SYSVINIT_ACTIVE)
{
int fd = console_open (O_RDWR|O_NOCTTY);
if (fd < 0)
{
logmsg (LOG_CRIT, "open(%s): %s",
console_device, strerror (errno));
fd = open ("/dev/null", O_RDWR);
}
if (fd != 0)
dup2 (fd, 0);
if (fd != 1)
dup2 (fd, 1);
@@ -1028,25 +1028,25 @@ prog_start (struct prog *prog)
{
close (1);
open ("/dev/null", O_WRONLY);
}
else if (redir[RETR_OUT] != 1)