diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-06-24 12:56:24 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-06-24 12:56:24 +0300 |
commit | 006bfbc5235c181783445d321ce7a7e3c6d8bd8a (patch) | |
tree | f483e0d30c3e801add01b372b24a342281b70b86 | |
parent | cb90ca582a46ef9f0779837dc4c6fb00656e70c9 (diff) | |
download | pies-006bfbc5235c181783445d321ce7a7e3c6d8bd8a.tar.gz pies-006bfbc5235c181783445d321ce7a7e3c6d8bd8a.tar.bz2 |
Enable/disable SystemV init code at compile time
* configure.ac: New option --enable-sysvinit. Disable the init
code if RUN_LVL is not available.
(PIES_SYSVINIT_ENABLED): New configuration define.
(PIES_COND_SYSVINIT): New condition
Print configuration settings summary.
* src/pies.h (is_sysvinit): Check for PIES_SYSVINIT_ENABLED.
(SYSVINIT_ACTIVE): New macro.
* grecs: Upgrade.
* src/Makefile.am: Conditionally link sysvinit-related code.
* src/cmdline.opt: Disable the --telinit option if sysvinit support
is not available.
(parse_options): Use SYSVINIT_ACTIVE in the conditional.
* src/comp.c (component_verify): Check if component definition is
allowed by the current state of the sysvinit support.
* src/ctl.c: Disable the /runlevel entry point if sysvinit support
is not compiled.
* src/diag.c (stderr_open): Make sure sysvinit-related code is not
compiled if the sysvinit support is not available.
* src/pies.c (config_syntax_tab): Add entry for CONF_INITTAB only if
sysvinit support is available.
(_cb_initdefault,_cb_runlevels): Remove. Use cb_initdefault and cb_runlevels
instead.
(component_keywords): Disable runlevels without sysvinit support.
(pies_keywords): Same for initdefault.
Use SYSVINIT_ACTIVE to suppress compilation of sysvinit code without
sysvinit support.
* src/progman.c: Use SYSVINIT_ACTIVE to suppress compilation of
sysvinit code without sysvinit support.
* src/sysvinit.c (cb_initdefault,cb_runlevels): New functions.
-rw-r--r-- | configure.ac | 46 | ||||
m--------- | grecs | 0 | ||||
-rw-r--r-- | src/Makefile.am | 10 | ||||
-rw-r--r-- | src/cmdline.opt | 4 | ||||
-rw-r--r-- | src/comp.c | 3 | ||||
-rw-r--r-- | src/ctl.c | 176 | ||||
-rw-r--r-- | src/diag.c | 2 | ||||
-rw-r--r-- | src/pies.c | 91 | ||||
-rw-r--r-- | src/pies.h | 13 | ||||
-rw-r--r-- | src/progman.c | 15 | ||||
-rw-r--r-- | src/sysvinit.c | 64 |
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 @@ -127,2 +127,26 @@ AC_ARG_ENABLE([inetd], +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([ @@ -149,2 +173,24 @@ 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 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 @@ -32,7 +32,11 @@ pies_SOURCES = \ 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 = \ diff --git a/src/cmdline.opt b/src/cmdline.opt index d2aaf6d..d9d90e1 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -120,2 +120,3 @@ END +CPP(#if PIES_SYSVINIT_ENABLED) OPTION(telinit,T,, @@ -126,2 +127,3 @@ BEGIN END +CPP(#endif) @@ -222,3 +224,3 @@ parse_options (int *pargc, char ***pargv) - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -676,2 +676,5 @@ component_verify (struct component *comp, grecs_locus_t *locus) 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 */ @@ -920,2 +920,6 @@ 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 *, @@ -924,6 +928,5 @@ 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 + @@ -945,4 +948,6 @@ static struct ctlio_resource restab[] = { 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 } @@ -2119,2 +2124,3 @@ res_programs (struct ctlio *io, enum http_method meth, +#if PIES_SYSVINIT_ENABLED static int @@ -2165,2 +2171,85 @@ res_runlevel (struct ctlio *io, enum http_method meth, } + +/* 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 @@ -2409,83 +2498,2 @@ res_conf (struct ctlio *io, enum http_method meth, } - -/* 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); - -} @@ -75,3 +75,3 @@ stderr_open (int logf, LOGSTREAM *str) { - if (logf & DIAG_REOPEN_LOG) + if (PIES_SYSVINIT_ENABLED && (logf & DIAG_REOPEN_LOG)) { @@ -77,3 +77,5 @@ static struct config_syntax config_syntax_tab[] = { [CONF_INETD] = { "inetd", inetd_config_parse }, +#if PIES_SYSVINIT_ENABLED [CONF_INITTAB] = { "inittab", inittab_parse }, +#endif }; @@ -1207,52 +1209,2 @@ _cb_flags (enum grecs_callback_command cmd, -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[] = { @@ -1296,2 +1248,3 @@ struct grecs_keyword component_keywords[] = { _cb_flags }, +#if PIES_SYSVINIT_ENABLED {"runlevels", @@ -1301,3 +1254,4 @@ struct grecs_keyword component_keywords[] = { NULL, offsetof (struct component, runlevels), - _cb_runlevels }, + cb_runlevels }, +#endif {"pass-fd-socket", @@ -1724,2 +1678,3 @@ struct grecs_keyword pies_keywords[] = { }, +#if PIES_SYSVINIT_ENABLED {"initdefault", @@ -1728,4 +1683,5 @@ struct grecs_keyword pies_keywords[] = { grecs_type_string, GRECS_DFLT, - &initdefault, 0, _cb_initdefault, + NULL, 0, cb_initdefault, }, +#endif {"shutdown-timeout", @@ -1861,3 +1817,3 @@ pies_read_config (void) - if (init_process) + if (SYSVINIT_ACTIVE) err = 0; @@ -1900,3 +1856,3 @@ sig_handler (int sig) { - if (init_process && sysvinit_sigtrans (sig, &action)) + if (SYSVINIT_ACTIVE && sysvinit_sigtrans (sig, &action)) return; @@ -2280,3 +2236,3 @@ set_conf_file_names (const char *base) { - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -2340,3 +2296,3 @@ main (int argc, char **argv) /* Set default logging */ - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -2375,3 +2331,3 @@ main (int argc, char **argv) - if (init_process || !DEFAULT_PREPROCESSOR) + if (SYSVINIT_ACTIVE || !DEFAULT_PREPROCESSOR) grecs_preprocessor = NULL; @@ -2453,3 +2409,3 @@ main (int argc, char **argv) - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -2493,3 +2449,3 @@ main (int argc, char **argv) - if (!init_process) + if (!SYSVINIT_ACTIVE) { @@ -2518,3 +2474,3 @@ main (int argc, char **argv) case ACTION_RESTART: - if (pies_master_argv[0][0] != '/' || init_process) + if (pies_master_argv[0][0] != '/' || SYSVINIT_ACTIVE) { @@ -2534,3 +2490,3 @@ main (int argc, char **argv) component_config_commit (); - if (init_process) + if (SYSVINIT_ACTIVE) sysvinit_runlevel_setup (PIES_COMP_DEFAULT); @@ -2544,3 +2500,3 @@ main (int argc, char **argv) case ACTION_STOP: - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -2553,3 +2509,4 @@ main (int argc, char **argv) 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); @@ -2560,3 +2517,4 @@ main (int argc, char **argv) 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); @@ -2567,3 +2525,4 @@ main (int argc, char **argv) debug (1, ("SIGPWR")); - sysvinit_power (); + if (SYSVINIT_ACTIVE) + sysvinit_power (); pies_schedule_children (PIES_CHLD_WAKEUP); @@ -2584,3 +2543,3 @@ main (int argc, char **argv) } - while (init_process || action == ACTION_CONT); + while (SYSVINIT_ACTIVE || action == ACTION_CONT); @@ -278,3 +278,7 @@ struct component -#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) @@ -567,2 +571,9 @@ 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[]; diff --git a/src/progman.c b/src/progman.c index 88f9afa..70ebf68 100644 --- a/src/progman.c +++ b/src/progman.c @@ -826,3 +826,3 @@ prog_start_prologue (struct prog *prog) envop_exec (prog->v.p.comp->envop, prog->v.p.env); - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -901,3 +901,3 @@ prog_start (struct prog *prog) { - if (!init_process) + if (!SYSVINIT_ACTIVE) { @@ -997,3 +997,3 @@ prog_start (struct prog *prog) default: - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -1039,3 +1039,3 @@ prog_start (struct prog *prog) - if (!init_process) + if (!SYSVINIT_ACTIVE) { @@ -1602,3 +1602,3 @@ print_status (const char *tag, pid_t pid, int status, int expect_term) - if (init_process) + if (SYSVINIT_ACTIVE) { @@ -2149,3 +2149,4 @@ progman_cleanup (int expect_term) { - 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) @@ -2305,3 +2306,3 @@ 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) diff --git a/src/sysvinit.c b/src/sysvinit.c index 3ba986b..c5d25da 100644 --- a/src/sysvinit.c +++ b/src/sysvinit.c @@ -57,9 +57,9 @@ 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; @@ -342,3 +342,3 @@ is_valid_runlevel (int c) } - + #define ENVAR_CONSOLE "CONSOLE=" @@ -1285 +1285,51 @@ sysvinit_parse_argv (int argc, char **argv) } + +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; +} + |