aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-05-24 12:45:25 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-05-24 13:50:39 +0300
commit6dd0ec08db301984b8f8f9082f28006d5915c183 (patch)
treee916ad37fbd3cbcaf85103667f28e0d47f3c2e45 /src/pies.c
parent2a646ee7cbbcb6f4bbd8f38bb3c1e1418550f3fc (diff)
downloadpies-6dd0ec08db301984b8f8f9082f28006d5915c183.tar.gz
pies-6dd0ec08db301984b8f8f9082f28006d5915c183.tar.bz2
Initial implementation of "startup" components.
These are components that are run at program startup. Starting other components is delayed until all startup components terminate. This is similar to SysV "bootwait" components. Upon termination, startup components are removed from the configuration. They are not renewed upon configuratuion reload. * src/comp.c (comp_array_remove): Remove from the depmap as well. (component_ref_decr): Use comp_array_remove for active components and plain component_free for inactive ones. (component_build_depmap): Use comp_array_remove. (component_config_commit): Special handling for pies_comp_startup components. * src/pies.c (modetab): New component modes: "startup" and "shutdown". (main): Run program_init_startup. * src/pies.h (pies_comp_mode): New modes: pies_comp_startup and pies_comp_shutdown. (program_init_startup): New proto. * src/progman.c (progman_waiting_p): Return 1 if a startup component is still running. (program_init_startup): New function. (progman_cleanup): Handle pies_comp_startup termination. * src/socket.c (switch_eids): Avoid unnecessary calls to setegid and seteuid. * tests/atlocal.in (auxdir): New variable. * tests/mailer: Move to tests/aux/ * tests/respawn: Move to tests/aux/ * tests/retcode: Move to tests/aux/ * tests/aux/startup: New auxiliary program. * tests/redirect.at: Start components from $auxdir. * tests/respawn.at: Likewise. * tests/ret-exec.at: Likewise. * tests/ret-notify.at: Likewise. * tests/startup.at: New file. * tests/testsuite.at: Include startup.at * tests/Makefile.am: Add new tests.
Diffstat (limited to 'src/pies.c')
-rw-r--r--src/pies.c115
1 files changed, 59 insertions, 56 deletions
diff --git a/src/pies.c b/src/pies.c
index 89c0b7e..98488a6 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -134,3 +134,3 @@ config_file_remove (const char *name)
struct grecs_list_entry *ep;
-
+
for (ep = config_list->head; ep; ep = ep->next)
@@ -158,3 +158,3 @@ config_file_list_serialize (struct json_value *ar)
struct grecs_list_entry *ep;
-
+
for (ep = config_list->head; ep; ep = ep->next)
@@ -329,3 +329,3 @@ action_free (struct action *act)
free (act->command);
-
+
free (act);
@@ -361,3 +361,3 @@ create_action (struct component *comp,
size_t len = strlen (arg);
-
+
if (isdigit (arg[0]))
@@ -396,3 +396,3 @@ create_action (struct component *comp,
}
-
+
/* Alles in ordnung */
@@ -401,3 +401,3 @@ create_action (struct component *comp,
}
-
+
if (retc == 0 && !allflag)
@@ -474,3 +474,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
}
-
+
switch (value->type)
@@ -480,3 +480,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_ARRAY:
@@ -485,3 +485,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_LIST:
@@ -494,3 +494,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
break;
-
+
case grecs_callback_section_end:
@@ -544,3 +544,3 @@ _cb_command (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_ARRAY:
@@ -704,3 +704,3 @@ _cb_redir (enum grecs_callback_command cmd,
int res;
-
+
switch (value->type)
@@ -721,3 +721,3 @@ _cb_redir (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_ARRAY:
@@ -741,3 +741,3 @@ _cb_redir (enum grecs_callback_command cmd,
return 0;
-
+
switch (res)
@@ -746,3 +746,3 @@ _cb_redir (enum grecs_callback_command cmd,
break;
-
+
case redir_syslog:
@@ -757,3 +757,3 @@ _cb_redir (enum grecs_callback_command cmd,
break;
-
+
case redir_file:
@@ -766,3 +766,3 @@ _cb_redir (enum grecs_callback_command cmd,
break;
-
+
default:
@@ -770,3 +770,3 @@ _cb_redir (enum grecs_callback_command cmd,
}
-
+
return 0;
@@ -775,4 +775,4 @@ _cb_redir (enum grecs_callback_command cmd,
static struct tokendef socktype_xtab[] = {
- { "stream", SOCK_STREAM },
- { "dgram", SOCK_DGRAM },
+ { "stream", SOCK_STREAM },
+ { "dgram", SOCK_DGRAM },
{ "seqpacket", SOCK_SEQPACKET },
@@ -822,2 +822,4 @@ static struct tokendef modetab[] = {
{"pass", pies_comp_pass_fd},
+ {"startup", pies_comp_startup},
+ {"shutdown", pies_comp_shutdown},
{"boot", pies_comp_boot},
@@ -827,3 +829,3 @@ static struct tokendef modetab[] = {
{"powerokwait", pies_comp_powerokwait},
- {"ctrlaltdel", pies_comp_ctrlaltdel},
+ {"ctrlaltdel", pies_comp_ctrlaltdel},
{"ondemand", pies_comp_ondemand},
@@ -922,3 +924,3 @@ _cb_flags (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_LIST:
@@ -926,3 +928,3 @@ _cb_flags (enum grecs_callback_command cmd,
struct grecs_list_entry *ep;
-
+
for (ep = value->v.list->head; ep; ep = ep->next)
@@ -941,3 +943,3 @@ _cb_flags (enum grecs_callback_command cmd,
break;
-
+
case GRECS_TYPE_ARRAY:
@@ -1230,3 +1232,3 @@ find_component_keyword (const char *ident)
struct grecs_keyword *kwp;
-
+
for (kwp = component_keywords; kwp->ident; kwp++)
@@ -1258,3 +1260,3 @@ component_section_parser (enum grecs_callback_command cmd,
break;
-
+
case grecs_callback_set_value:
@@ -1536,3 +1538,3 @@ pies_config_parse (char const *name)
return 1;
-
+
for (node = tree; node; node = node->next)
@@ -1552,3 +1554,3 @@ pies_config_parse (char const *name)
return 1;
-
+
return 0;
@@ -1575,3 +1577,3 @@ pies_read_config (void)
component_config_begin ();
-
+
for (ep = config_list->head; ep; ep = ep->next)
@@ -1585,6 +1587,6 @@ pies_read_config (void)
err = 0;
-
+
if (err)
component_config_rollback ();
-
+
return err;
@@ -1658,3 +1660,3 @@ setsigvhan (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc)
struct sigaction act;
-
+
act.sa_flags = 0;
@@ -1781,3 +1783,3 @@ request_restart_components (size_t cc, char **cv)
size_t i, j;
-
+
argv = grecs_calloc (5 + 3 * cc - 1, sizeof (*argv));
@@ -1805,3 +1807,3 @@ list_components (void)
char *argv[5];
-
+
argv[0] = "piesctl";
@@ -1944,3 +1946,3 @@ set_mailer_argcv (void)
struct wordsplit ws;
-
+
if (wordsplit (mailer_command_line, &ws, WRDSF_DEFFLAGS))
@@ -2035,3 +2037,3 @@ main (int argc, char **argv)
int i;
-
+
set_program_name (argv[0]);
@@ -2045,6 +2047,6 @@ main (int argc, char **argv)
grecs_print_diag_fun = pies_diag_printer;
-
+
pies_master_argc = argc;
pies_master_argv = argv;
-
+
set_quoting_style (NULL, shell_quoting_style);
@@ -2060,3 +2062,3 @@ main (int argc, char **argv)
}
-
+
/* Set default logging */
@@ -2069,5 +2071,5 @@ main (int argc, char **argv)
diag_flags = DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR);
-
+
diag_setup (diag_flags);
-
+
config_init ();
@@ -2075,3 +2077,3 @@ main (int argc, char **argv)
parse_options (&argc, &argv);
-
+
if (argc && !(command == COM_RESTART_COMPONENT
@@ -2083,3 +2085,3 @@ main (int argc, char **argv)
}
-
+
if (!instance)
@@ -2121,3 +2123,3 @@ main (int argc, char **argv)
set_mailer_argcv ();
-
+
if (lint_mode)
@@ -2127,3 +2129,3 @@ main (int argc, char **argv)
diag_setup (log_to_stderr_only ? DIAG_TO_STDERR : 0);
-
+
if (!control.url)
@@ -2139,3 +2141,3 @@ main (int argc, char **argv)
}
-
+
switch (command)
@@ -2147,3 +2149,3 @@ main (int argc, char **argv)
exit (request_restart_components (argc, argv));
-
+
case COM_RELOAD:
@@ -2164,7 +2166,7 @@ main (int argc, char **argv)
exit (0);
-
- case COM_TRACE_PREREQ:
+
+ case COM_TRACE_PREREQ:
components_trace (argv, depmap_col);
exit (0);
-
+
default:
@@ -2195,3 +2197,3 @@ main (int argc, char **argv)
break;
-
+
case pies_status_running:
@@ -2201,3 +2203,3 @@ main (int argc, char **argv)
}
-
+
if (!foreground)
@@ -2214,3 +2216,3 @@ main (int argc, char **argv)
logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version);
-
+
if (!init_process)
@@ -2221,3 +2223,3 @@ main (int argc, char **argv)
}
-
+
if (pies_master_argv[0][0] != '/')
@@ -2230,2 +2232,3 @@ main (int argc, char **argv)
progman_create_sockets ();
+ program_init_startup ();
progman_start ();
@@ -2263,3 +2266,3 @@ main (int argc, char **argv)
break;
-
+
case ACTION_STOP:
@@ -2278,3 +2281,3 @@ main (int argc, char **argv)
break;
-
+
case ACTION_KBREQUEST:

Return to:

Send suggestions and report system problems to the System administrator.