diff options
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 85 |
1 files changed, 22 insertions, 63 deletions
@@ -72,13 +72,15 @@ struct config_syntax 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; @@ -1202,62 +1204,12 @@ _cb_flags (enum grecs_callback_command cmd, 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), @@ -1291,18 +1243,20 @@ struct grecs_keyword component_keywords[] = { }, {"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, @@ -1719,18 +1673,20 @@ struct grecs_keyword pies_keywords[] = { {"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, @@ -1856,13 +1812,13 @@ pies_read_config (void) { 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; @@ -1895,13 +1851,13 @@ 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; @@ -2275,13 +2231,13 @@ init_emu (void) 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 ()) { @@ -2335,13 +2291,13 @@ main (int argc, char **argv) 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); @@ -2370,13 +2326,13 @@ main (int argc, char **argv) } 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) { @@ -2448,13 +2404,13 @@ main (int argc, char **argv) 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)) @@ -2488,13 +2444,13 @@ main (int argc, char **argv) } 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); } @@ -2513,13 +2469,13 @@ main (int argc, char **argv) { 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; @@ -2529,45 +2485,48 @@ main (int argc, char **argv) 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")); + 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")); + 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")); + if (SYSVINIT_ACTIVE) sysvinit_power (); pies_schedule_children (PIES_CHLD_WAKEUP); action = ACTION_CONT; } if (action == ACTION_CONT) { @@ -2579,13 +2538,13 @@ main (int argc, char **argv) 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) { |