summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/comp.c87
-rw-r--r--src/pies.c115
-rw-r--r--src/pies.h38
-rw-r--r--src/progman.c291
-rw-r--r--src/socket.c54
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/atlocal.in2
-rwxr-xr-xtests/aux/mailer (renamed from tests/mailer)0
-rwxr-xr-xtests/aux/respawn (renamed from tests/respawn)0
-rwxr-xr-xtests/aux/retcode (renamed from tests/retcode)0
-rwxr-xr-xtests/aux/startup7
-rw-r--r--tests/redirect.at2
-rw-r--r--tests/respawn.at2
-rw-r--r--tests/ret-exec.at4
-rw-r--r--tests/ret-notify.at6
-rw-r--r--tests/startup.at84
-rw-r--r--tests/testsuite.at1
17 files changed, 442 insertions, 260 deletions
diff --git a/src/comp.c b/src/comp.c
index c3e998a..2346306 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -25,4 +25,9 @@ struct complist
};
+/* 0 on the first load, and 1 on all subsequent reloads. Tells the
+ component_config_commit whether we're starting from scratch or just
+ updating an already loaded configuration */
+static int loaded;
+
static struct complist comp_list[2];
static int cur;
@@ -33,5 +38,5 @@ static size_t comp_count;
static pies_depmap_t depmap;
-static int
+static inline int
next_index (void)
{
@@ -39,5 +44,5 @@ next_index (void)
}
-static int
+static inline int
prev_index (void)
{
@@ -86,4 +91,20 @@ component_append (struct component *comp)
void
+comp_array_remove (size_t i)
+{
+ struct component *comp = comp_array[i];
+
+ depmap_remove (depmap, i);
+ while (i < comp_count -1)
+ {
+ comp_array[i] = comp_array[i+1];
+ comp_array[i]->arridx = i;
+ i++;
+ }
+ component_free (comp);
+ comp_count--;
+}
+
+void
component_unlink (struct component *comp)
{
@@ -202,5 +223,10 @@ component_ref_decr (struct component *comp)
assert (comp->ref_count > 0);
if (--comp->ref_count == 0)
- component_free (comp);
+ {
+ if (component_is_active (comp))
+ comp_array_remove (comp->arridx);
+ else
+ component_free (comp);
+ }
}
@@ -426,15 +452,4 @@ report_cyclic_dependency (pies_depmap_t dp, size_t idx)
void
-comp_array_remove (size_t i)
-{
- struct component *comp = comp_array[i];
- if (i < comp_count - 1)
- memmove (&comp_array[i], &comp_array[i+1],
- (comp_count - i - 1) * sizeof comp_array[0]);
- component_free (comp);
- comp_count--;
-}
-
-void
component_build_depmap (void)
{
@@ -461,5 +476,4 @@ component_build_depmap (void)
comp->tag, tag);
comp_array_remove (i);
- depmap_remove (depmap, i);
continue;
}
@@ -498,8 +512,5 @@ component_build_depmap (void)
for (i = 0; i < comp_count;)
if (comp_array[i]->flags & CF_REMOVE)
- {
- comp_array_remove (i);
- depmap_remove (depmap, i);
- }
+ comp_array_remove (i);
else
i++;
@@ -529,20 +540,34 @@ component_config_commit (void)
comp_count = i;
- /* Rearrange components, registering prog entries for the new ones */
- for (comp = list->head, i = 0; comp; comp = comp->next, i++)
+ /* Rearrange components, registering entries for the new ones */
+ for (comp = list->head, i = 0; comp; )
{
- match = complist_find_match (prev, comp);
- if (match)
+ struct component *next = comp->next;
+ if (loaded && comp->mode == pies_comp_startup)
{
- component_merge (match, comp);
- component_unlink (match);
- match->listidx = cur;
- component_link (match, comp->prev);
+ /* Ignore startup components */
+ component_unlink (comp);
component_free (comp);
- comp = match;
}
- comp_array[i] = comp;
- comp->arridx = i;
+ else
+ {
+ match = complist_find_match (prev, comp);
+ if (match)
+ {
+ component_merge (match, comp);
+ component_unlink (match);
+ match->listidx = cur;
+ component_link (match, comp->prev);
+ component_free (comp);
+ comp = match;
+ }
+ comp_array[i] = comp;
+ comp->arridx = i;
+ i++;
+ }
+ comp = next;
}
+ /* Adjust comp_count */
+ comp_count = i;
/* Mark orphaned progs for termination */
@@ -561,4 +586,6 @@ component_config_commit (void)
if (!comp->prog)
register_prog (comp);
+
+ loaded = 1;
}
diff --git a/src/pies.c b/src/pies.c
index 89c0b7e..98488a6 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -133,5 +133,5 @@ config_file_remove (const char *name)
{
struct grecs_list_entry *ep;
-
+
for (ep = config_list->head; ep; ep = ep->next)
{
@@ -157,5 +157,5 @@ config_file_list_serialize (struct json_value *ar)
{
struct grecs_list_entry *ep;
-
+
for (ep = config_list->head; ep; ep = ep->next)
{
@@ -328,5 +328,5 @@ action_free (struct action *act)
free (act->message);
free (act->command);
-
+
free (act);
}
@@ -360,5 +360,5 @@ create_action (struct component *comp,
const char *arg = getarg (val, i, locus);
size_t len = strlen (arg);
-
+
if (isdigit (arg[0]))
{
@@ -395,10 +395,10 @@ create_action (struct component *comp,
continue;
}
-
+
/* Alles in ordnung */
retv[retc++] = n;
}
}
-
+
if (retc == 0 && !allflag)
{
@@ -473,5 +473,5 @@ return_code_section_parser (enum grecs_callback_command cmd,
return 1;
}
-
+
switch (value->type)
{
@@ -479,10 +479,10 @@ return_code_section_parser (enum grecs_callback_command cmd,
act = create_action (comp, locus, value, 1, _get_string_arg);
break;
-
+
case GRECS_TYPE_ARRAY:
act = create_action (comp, locus, value,
value->v.arg.c, _get_array_arg);
break;
-
+
case GRECS_TYPE_LIST:
count = grecs_list_size (value->v.list);
@@ -493,5 +493,5 @@ return_code_section_parser (enum grecs_callback_command cmd,
*(struct action **) cb_data = act;
break;
-
+
case grecs_callback_section_end:
break;
@@ -543,5 +543,5 @@ _cb_command (enum grecs_callback_command cmd,
wordsplit_free (&ws);
break;
-
+
case GRECS_TYPE_ARRAY:
comp->argv = config_array_to_argv (value, locus, &comp->argc);
@@ -703,5 +703,5 @@ _cb_redir (enum grecs_callback_command cmd,
};
int res;
-
+
switch (value->type)
{
@@ -720,5 +720,5 @@ _cb_redir (enum grecs_callback_command cmd,
}
break;
-
+
case GRECS_TYPE_ARRAY:
if (assert_grecs_value_type (locus, value->v.arg.v[0],
@@ -740,10 +740,10 @@ _cb_redir (enum grecs_callback_command cmd,
GRECS_TYPE_STRING))
return 0;
-
+
switch (res)
{
case redir_null:
break;
-
+
case redir_syslog:
if (string_to_syslog_priority (value->v.arg.v[1]->v.string,
@@ -756,5 +756,5 @@ _cb_redir (enum grecs_callback_command cmd,
}
break;
-
+
case redir_file:
rp->v.file = grecs_strdup (value->v.arg.v[1]->v.string);
@@ -765,15 +765,15 @@ _cb_redir (enum grecs_callback_command cmd,
}
break;
-
+
default:
grecs_error (locus, 0, _("unexpected list"));
}
-
+
return 0;
}
static struct tokendef socktype_xtab[] = {
- { "stream", SOCK_STREAM },
- { "dgram", SOCK_DGRAM },
+ { "stream", SOCK_STREAM },
+ { "dgram", SOCK_DGRAM },
{ "seqpacket", SOCK_SEQPACKET },
{ "raw", SOCK_RAW },
@@ -821,4 +821,6 @@ static struct tokendef modetab[] = {
{"pass-fd", pies_comp_pass_fd},
{"pass", pies_comp_pass_fd},
+ {"startup", pies_comp_startup},
+ {"shutdown", pies_comp_shutdown},
{"boot", pies_comp_boot},
{"bootwait", pies_comp_boot},
@@ -826,5 +828,5 @@ static struct tokendef modetab[] = {
{"powerwait", pies_comp_powerwait},
{"powerokwait", pies_comp_powerokwait},
- {"ctrlaltdel", pies_comp_ctrlaltdel},
+ {"ctrlaltdel", pies_comp_ctrlaltdel},
{"ondemand", pies_comp_ondemand},
{"sysinit", pies_comp_sysinit},
@@ -921,9 +923,9 @@ _cb_flags (enum grecs_callback_command cmd,
}
break;
-
+
case GRECS_TYPE_LIST:
{
struct grecs_list_entry *ep;
-
+
for (ep = value->v.list->head; ep; ep = ep->next)
{
@@ -940,5 +942,5 @@ _cb_flags (enum grecs_callback_command cmd,
}
break;
-
+
case GRECS_TYPE_ARRAY:
grecs_error (locus, 0, _("too many arguments"));
@@ -1229,5 +1231,5 @@ find_component_keyword (const char *ident)
{
struct grecs_keyword *kwp;
-
+
for (kwp = component_keywords; kwp->ident; kwp++)
if (strcmp (kwp->ident, ident) == 0)
@@ -1257,5 +1259,5 @@ component_section_parser (enum grecs_callback_command cmd,
component_finish (comp, locus);
break;
-
+
case grecs_callback_set_value:
grecs_error (locus, 0, _("expected block statement"));
@@ -1535,5 +1537,5 @@ pies_config_parse (char const *name)
if (!tree)
return 1;
-
+
for (node = tree; node; node = node->next)
{
@@ -1551,5 +1553,5 @@ pies_config_parse (char const *name)
if (grecs_error_count)
return 1;
-
+
return 0;
}
@@ -1574,5 +1576,5 @@ pies_read_config (void)
component_config_begin ();
-
+
for (ep = config_list->head; ep; ep = ep->next)
{
@@ -1584,8 +1586,8 @@ pies_read_config (void)
if (init_process)
err = 0;
-
+
if (err)
component_config_rollback ();
-
+
return err;
}
@@ -1657,5 +1659,5 @@ setsigvhan (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc)
int i;
struct sigaction act;
-
+
act.sa_flags = 0;
sigemptyset (&act.sa_mask);
@@ -1780,5 +1782,5 @@ request_restart_components (size_t cc, char **cv)
char **argv;
size_t i, j;
-
+
argv = grecs_calloc (5 + 3 * cc - 1, sizeof (*argv));
argv[0] = "piesctl";
@@ -1804,5 +1806,5 @@ list_components (void)
{
char *argv[5];
-
+
argv[0] = "piesctl";
argv[1] = "--url";
@@ -1943,5 +1945,5 @@ set_mailer_argcv (void)
int i;
struct wordsplit ws;
-
+
if (wordsplit (mailer_command_line, &ws, WRDSF_DEFFLAGS))
{
@@ -2034,5 +2036,5 @@ main (int argc, char **argv)
int diag_flags;
int i;
-
+
set_program_name (argv[0]);
#ifdef ENABLE_NLS
@@ -2044,8 +2046,8 @@ 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);
@@ -2059,5 +2061,5 @@ main (int argc, char **argv)
}
}
-
+
/* Set default logging */
if (init_process)
@@ -2068,11 +2070,11 @@ main (int argc, char **argv)
else
diag_flags = DIAG_TO_SYSLOG | (stderr_closed_p () ? 0 : DIAG_TO_STDERR);
-
+
diag_setup (diag_flags);
-
+
config_init ();
parse_options (&argc, &argv);
-
+
if (argc && !(command == COM_RESTART_COMPONENT
|| command == COM_TRACE_DEPEND
@@ -2082,5 +2084,5 @@ main (int argc, char **argv)
exit (EX_USAGE);
}
-
+
if (!instance)
{
@@ -2120,5 +2122,5 @@ main (int argc, char **argv)
set_state_file_names (instance);
set_mailer_argcv ();
-
+
if (lint_mode)
exit (0);
@@ -2126,5 +2128,5 @@ main (int argc, char **argv)
/* Re-setup logging: it might have been reset in the config file */
diag_setup (log_to_stderr_only ? DIAG_TO_STDERR : 0);
-
+
if (!control.url)
{
@@ -2138,5 +2140,5 @@ main (int argc, char **argv)
}
}
-
+
switch (command)
{
@@ -2146,5 +2148,5 @@ main (int argc, char **argv)
umask (pies_umask);
exit (request_restart_components (argc, argv));
-
+
case COM_RELOAD:
exit (request_reload ());
@@ -2163,9 +2165,9 @@ main (int argc, char **argv)
components_trace (argv, depmap_row);
exit (0);
-
- case COM_TRACE_PREREQ:
+
+ case COM_TRACE_PREREQ:
components_trace (argv, depmap_col);
exit (0);
-
+
default:
pies_priv_setup (&pies_privs);
@@ -2194,5 +2196,5 @@ main (int argc, char **argv)
}
break;
-
+
case pies_status_running:
logmsg (LOG_ERR, _("another pies instance already running (pid %lu)"),
@@ -2200,5 +2202,5 @@ main (int argc, char **argv)
exit (EX_USAGE);
}
-
+
if (!foreground)
{
@@ -2213,5 +2215,5 @@ main (int argc, char **argv)
logmsg (LOG_INFO, _("%s %s starting"), proginfo.package, proginfo.version);
-
+
if (!init_process)
{
@@ -2220,5 +2222,5 @@ main (int argc, char **argv)
create_pidfile (pidfile);
}
-
+
if (pies_master_argv[0][0] != '/')
logmsg (LOG_NOTICE,
@@ -2229,4 +2231,5 @@ main (int argc, char **argv)
progman_create_sockets ();
+ program_init_startup ();
progman_start ();
@@ -2262,5 +2265,5 @@ main (int argc, char **argv)
action = ACTION_CONT;
break;
-
+
case ACTION_STOP:
if (init_process)
@@ -2277,5 +2280,5 @@ main (int argc, char **argv)
action = ACTION_CONT;
break;
-
+
case ACTION_KBREQUEST:
debug (1, ("kbrequest"));
diff --git a/src/pies.h b/src/pies.h
index a7f6567..bdc406b 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -105,5 +105,5 @@ struct action
char *addr; /* Addresses to notify about it. */
char *message; /* Notification mail. */
- char *command; /* Execute this command */
+ char *command; /* Execute this command */
};
@@ -138,5 +138,12 @@ enum pies_comp_mode
`start_action = pass' in MeTA1. */
pies_comp_pass_fd,
-
+
+ /* Components of this type runs once on program startup. Running other
+ components is delayed until the last startup component finishes. */
+ pies_comp_startup,
+
+ /* FIXME: Runs before program termination */
+ pies_comp_shutdown,
+
/*
** Init-style components
@@ -145,5 +152,5 @@ enum pies_comp_mode
/* Start the process when the specified runlevel is entered and wait
for its termination */
- pies_comp_wait = pies_mark_sysvinit,
+ pies_comp_wait = pies_mark_sysvinit,
/* Execute the component once, when the specified runlevel is entered */
pies_comp_once,
@@ -163,5 +170,5 @@ enum pies_comp_mode
/* Execute the process when SIGINT is delivered, i.e. someone has
pressed the Ctrl+Alt+Del combination. */
- pies_comp_ctrlaltdel,
+ pies_comp_ctrlaltdel,
/* Execute the component when a specified ondemand runlevel is called */
pies_comp_ondemand,
@@ -185,14 +192,14 @@ enum pies_comp_mode
#define CF_DISABLED 0x001 /* The componenet is disabled */
#define CF_PRECIOUS 0x002 /* The component is precious (should not
- be disabled) */
+ be disabled) */
#define CF_WAIT 0x004 /* Wait for the component instance to
- terminate. */
+ terminate. */
#define CF_TCPMUX 0x008 /* A plain TCPMUX service */
#define CF_TCPMUXPLUS 0x010 /* A TCPMUX-plus service, i.e. pies
- must emit a '+' response before starting
- it */
+ must emit a '+' response before starting
+ it */
#define CF_INTERNAL 0x020 /* An internal inetd service */
#define CF_SOCKENV 0x040 /* Component wants socket information in
- the environment */
+ the environment */
#define CF_RESOLVE 0x080 /* Resolve IP addresses */
#define CF_SIGGROUP 0x100 /* Send signals to the process group */
@@ -211,7 +218,7 @@ struct component
int listidx; /* Index of the list. */
size_t arridx; /* Index of this component. */
- size_t ref_count; /* Reference count. */
+ size_t ref_count; /* Reference count. */
struct prog *prog; /* Prog associated with this component. */
-
+
enum pies_comp_mode mode;
char *tag; /* Entry tag (for diagnostics purposes) */
@@ -233,5 +240,5 @@ struct component
/* For exec (init) components */
char *runlevels;
-
+
/* For inetd components */
size_t max_rate; /* Maximum number of invocations per minute */
@@ -254,7 +261,7 @@ struct component
char *max_instances_message;
char *max_ip_connections_message;
-
+
/* Redirectors: */
- int facility; /* Syslog facility. */
+ int facility; /* Syslog facility. */
struct redirector redir[2]; /* Repeaters for stdout and stderr */
/* Actions to execute on various exit codes: */
@@ -335,4 +342,5 @@ int pies_reread_config (void);
void register_prog (struct component *comp);
+void program_init_startup (void);
int progman_waiting_p (void);
void progman_start (void);
@@ -595,5 +603,5 @@ struct sysvinit_request
#define SYSV_ACCT_RUNLEVEL 1
#define SYSV_ACCT_PROC_START 2
-#define SYSV_ACCT_PROC_STOP 3
+#define SYSV_ACCT_PROC_STOP 3
void sysvinit_acct (int what, const char *user, const char *id, pid_t pid,
diff --git a/src/progman.c b/src/progman.c
index 1b09cd5..5bc4eb3 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -66,5 +66,5 @@ progman_lookup_component (const char *tag)
return prog->v.p.comp;
return NULL;
-}
+}
struct component *
@@ -123,5 +123,5 @@ link_prog (struct prog *prog, struct prog *ref)
prog->prev = ref;
prog->next = ref->next;
-
+
if ((x = ref->next))
x->prev = prog;
@@ -152,5 +152,5 @@ destroy_prog (struct prog **pp)
{
struct prog *p = *pp;
-
+
unlink_prog (p);
switch (p->type)
@@ -159,6 +159,6 @@ destroy_prog (struct prog **pp)
component_ref_decr (p->v.p.comp);
if (p->v.p.status == status_listener && p->v.p.socket != -1)
- deregister_socket (p->v.p.socket);
- /* FIXME: Remove also all dependent progs (esp. tcpmux) */
+ deregister_socket (p->v.p.socket);
+ /* FIXME: Remove also all dependent progs (esp. tcpmux) */
if (p->v.p.redir[RETR_OUT])
p->v.p.redir[RETR_OUT]->v.r.master = NULL;
@@ -166,5 +166,5 @@ destroy_prog (struct prog **pp)
p->v.p.redir[RETR_ERR]->v.r.master = NULL;
break;
-
+
case TYPE_REDIRECTOR:
{
@@ -183,5 +183,5 @@ destroy_prog (struct prog **pp)
}
break;
-
+
case TYPE_COMMAND:
free (p->v.c.tag);
@@ -257,5 +257,5 @@ find_prog_ref (struct component *comp)
return NULL; /* FIXME: Skip redirectors? */
}
-
+
if (comp->prog)
{
@@ -271,10 +271,10 @@ find_prog_ref (struct component *comp)
return prog;
}
-
+
static struct prog *
register_prog0 (struct component *comp)
{
struct prog *newp;
-
+
newp = grecs_zalloc (sizeof (*newp));
newp->type = TYPE_COMPONENT;
@@ -292,5 +292,5 @@ register_prog0 (struct component *comp)
else
newp->active = 1;
-
+
if (comp->mode != pies_comp_exec)
comp->redir[RETR_OUT].type = redir_null;
@@ -318,12 +318,27 @@ register_command (char *tag, char *command, pid_t pid)
}
+static inline int
+progman_startup_phase (void)
+{
+ struct prog *prog;
+
+ for (prog = proghead; prog; prog = prog->next)
+ {
+ if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_startup)
+ return 1;
+ }
+ return 0;
+}
+
int
progman_waiting_p (void)
{
struct prog *prog;
-
+
for (prog = proghead; prog; prog = prog->next)
{
- if (IS_COMPONENT (prog) && prog->wait && prog->pid > 0)
+ if (IS_COMPONENT (prog)
+ && prog->pid > 0
+ && (prog->wait || prog->v.p.comp->mode == pies_comp_startup))
{
debug (3, ("%s: waiting for %s (%lu)",
@@ -407,9 +422,9 @@ open_redirector (struct prog *master, int stream)
case redir_file:
return redirect_to_file (master, stream);
-
+
case redir_syslog:
break;
}
-
+
if (pipe (p))
{
@@ -417,5 +432,5 @@ open_redirector (struct prog *master, int stream)
return -1;
}
-
+
switch (pid = fork ())
{
@@ -429,8 +444,8 @@ open_redirector (struct prog *master, int stream)
FD_SET (p[0], &fdset);
close_fds (&fdset);
-
+
diag_setup (0);
signal_setup (redir_exit);
-
+
close (p[1]);
fp = fdopen (p[0], "r");
@@ -442,5 +457,5 @@ open_redirector (struct prog *master, int stream)
syslog (prio, "%s", buf);
_exit (0);
-
+
case -1:
logmsg (LOG_CRIT,
@@ -467,5 +482,5 @@ conn_class_hasher (void *data, unsigned long n_buckets)
unsigned char ch;
size_t len;
-
+
while ((ch = *tag++))
value = (value * 31 + ch) % n_buckets;
@@ -531,5 +546,5 @@ conn_class_lookup (const char *tag,
break;
}
-
+
probe->count = 0;
if (!conn_tab)
@@ -726,5 +741,5 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
char *res;
size_t len;
-
+
if (a && b)
{
@@ -754,5 +769,5 @@ env_concat (const char *name, size_t namelen, const char *a, const char *b)
return res;
}
-
+
static void
environ_setup (char **hint)
@@ -761,5 +776,5 @@ environ_setup (char **hint)
char **new_env;
size_t count, i, j, n;
-
+
if (!hint)
return;
@@ -770,5 +785,5 @@ environ_setup (char **hint)
hint++;
}
-
+
/* Count new environment size */
count = 0;
@@ -776,5 +791,5 @@ environ_setup (char **hint)
for (i = 0; old_env[i]; i++)
count++;
-
+
for (i = 0; hint[i]; i++)
count++;
@@ -782,8 +797,8 @@ environ_setup (char **hint)
/* Allocate new environment. */
new_env = grecs_calloc (count + 1, sizeof new_env[0]);
-
+
/* Populate the environment. */
n = 0;
-
+
if (old_env)
for (i = 0; old_env[i]; i++)
@@ -796,5 +811,5 @@ environ_setup (char **hint)
{
char *p;
-
+
if (hint[i][0] == '-')
{
@@ -807,10 +822,10 @@ environ_setup (char **hint)
if (find_env_pos (new_env, hint[i], &j, NULL))
j = n;
-
+
if ((p = strchr (hint[i], '=')))
{
if (p == hint[i])
continue; /* Ignore erroneous entry */
- if (p[-1] == '+')
+ if (p[-1] == '+')
new_env[j] = env_concat (hint[i], p - hint[i] - 1,
find_env_ptr (environ, hint[i], 1),
@@ -836,5 +851,5 @@ environ_setup (char **hint)
if (envsize)
free (environ);
-
+
environ = new_env;
envsize = count + 1;
@@ -853,5 +868,5 @@ prog_sockenv (struct prog *prog)
socklen_t cltlen = prog->v.p.sa_len;
const char *proto = NULL;
-
+
if (!(prog->v.p.comp->flags & CF_SOCKENV))
return;
@@ -860,5 +875,5 @@ prog_sockenv (struct prog *prog)
proto = umaxtostr (prog->v.p.comp->socket_type, buf);
add_env (ENV_SOCKTYPE, proto);
-
+
if (prog->v.p.comp->socket_url)
proto = prog->v.p.comp->socket_url->proto_s;
@@ -869,5 +884,5 @@ prog_sockenv (struct prog *prog)
add_env (ENV_PROTO, proto);
-
+
if (getsockname (prog->v.p.socket,
(struct sockaddr *) &sa_server, &len) < 0)
@@ -921,5 +936,5 @@ check_rate (struct prog *prog, unsigned testtime, size_t max_count)
{
time_t now;
-
+
time (&now);
@@ -931,5 +946,5 @@ check_rate (struct prog *prog, unsigned testtime, size_t max_count)
prog->v.p.timestamp = now;
}
-
+
if (prog->v.p.failcount > max_count)
{
@@ -939,5 +954,5 @@ check_rate (struct prog *prog, unsigned testtime, size_t max_count)
return 1;
}
-
+
return 0;
}
@@ -962,5 +977,5 @@ check_connection_rate (struct prog *prog)
{
size_t max_rate = prog->v.p.comp->max_rate
- ? prog->v.p.comp->max_rate : default_max_rate;
+ ? prog->v.p.comp->max_rate : default_max_rate;
if (max_rate && check_rate (prog, 60, max_rate))
{
@@ -1010,5 +1025,5 @@ prog_start_prologue (struct prog *prog)
prog_tag (prog), prog->v.p.comp->dir, strerror (errno));
}
-
+
environ_setup (prog->v.p.comp->env ?
prog->v.p.comp->env :
@@ -1021,14 +1036,14 @@ prog_start_prologue (struct prog *prog)
if (prog->v.p.comp->umask)
umask (prog->v.p.comp->umask);
-
+
set_limits (prog_tag (prog),
prog->v.p.comp->limits ?
prog->v.p.comp->limits : pies_limits);
-
+
if (debug_level >= 1)
{
int i;
struct component *comp = prog->v.p.comp;
-
+
logmsg_printf (LOG_DEBUG, "executing");
for (i = 0; i < comp->argc; i++)
@@ -1048,5 +1063,5 @@ prog_execute (struct prog *prog)
_exit (0);
}
-
+
execvp (prog->v.p.comp->program ?
prog->v.p.comp->program : prog->v.p.comp->argv[0],
@@ -1078,5 +1093,5 @@ prog_start (struct prog *prog)
int redir[2];
fd_set fdset;
-
+
if (prog->pid > 0 || !IS_COMPONENT (prog))
return;
@@ -1124,5 +1139,5 @@ prog_start (struct prog *prog)
return;
break;
-
+
case pies_comp_accept:
if (check_spawn_rate (prog))
@@ -1140,7 +1155,7 @@ prog_start (struct prog *prog)
break;
}
-
+
debug (1, (_("starting %s"), prog_tag (prog)));
-
+
if (prog->v.p.comp->rmfile)
{
@@ -1159,5 +1174,5 @@ prog_start (struct prog *prog)
redir[RETR_OUT] = open_redirector (prog, RETR_OUT);
redir[RETR_ERR] = open_redirector (prog, RETR_ERR);
-
+
switch (pid = fork ())
{
@@ -1168,14 +1183,14 @@ prog_start (struct prog *prog)
prog_start_prologue (prog);
switch (prog->v.p.comp->mode)
- {
- case pies_comp_accept:
- case pies_comp_inetd:
+ {
+ 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);
+ dup2 (prog->v.p.socket, 0);
+ dup2 (prog->v.p.socket, 1);
+ close (prog->v.p.socket);
prog->v.p.socket = -1;
- break;
+ break;
default:
@@ -1183,5 +1198,5 @@ prog_start (struct prog *prog)
{
int fd = console_open (O_RDWR|O_NOCTTY);
- if (fd < 0)
+ if (fd < 0)
{
logmsg (LOG_CRIT, "open(%s): %s",
@@ -1219,6 +1234,6 @@ prog_start (struct prog *prog)
}
}
- break;
- }
+ break;
+ }
if (!init_process)
@@ -1237,5 +1252,5 @@ prog_start (struct prog *prog)
}
}
-
+
/* Close unneeded descripitors */
FD_ZERO (&fdset);
@@ -1248,6 +1263,6 @@ prog_start (struct prog *prog)
prog_execute (prog);
-
-
+
+
case -1:
logmsg (LOG_CRIT,
@@ -1292,5 +1307,5 @@ check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen,
struct acl_input input;
int rc;
-
+
if (!acl)
return 0;
@@ -1299,5 +1314,5 @@ check_acl (pies_acl_t acl, struct sockaddr *s, socklen_t salen,
input.addrlen = salen;
input.identity = identity;
-
+
rc = pies_acl_check (acl, &input, 1);
if (rc == 0)
@@ -1316,5 +1331,5 @@ fd_report (int fd, const char *msg)
{
size_t len;
-
+
if (!msg)
return;
@@ -1335,5 +1350,5 @@ fd_report (int fd, const char *msg)
msg += rc;
}
-}
+}
static int
@@ -1345,5 +1360,5 @@ _prog_accept (struct prog *p)
socklen_t addrlen = sizeof addr;
struct conn_class *pcclass;
-
+
fd = accept (p->v.p.socket, (struct sockaddr*) &addr, &addrlen);
if (fd == -1)
@@ -1352,5 +1367,5 @@ _prog_accept (struct prog *p)
return 1;
}
-
+
if (debug_level >= 1)
{
@@ -1395,5 +1410,5 @@ _prog_accept (struct prog *p)
return 1;
}
-
+
if (check_connection_rate (p))
{
@@ -1448,5 +1463,5 @@ _prog_wait (struct prog *p)
return 0;
}
-
+
int
progman_accept (int socket, void *data)
@@ -1457,5 +1472,5 @@ progman_accept (int socket, void *data)
&& !(p->v.p.comp->flags & CF_WAIT))
return _prog_accept (p);
-
+
return _prog_wait (p);
}
@@ -1527,4 +1542,23 @@ progman_recompute_alarm (void)
void
+program_init_startup (void)
+{
+ struct prog *prog;
+
+ for (prog = proghead; prog; prog = prog->next)
+ if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_startup)
+ {
+ debug (1, ("running startup components"));
+ break;
+ }
+
+ for (; prog; prog = prog->next)
+ if (IS_COMPONENT (prog) && prog->v.p.comp->mode == pies_comp_startup)
+ {
+ prog_start (prog);
+ }
+}
+
+void
progman_start (void)
{
@@ -1532,7 +1566,8 @@ progman_start (void)
if (progman_waiting_p ())
- /* Noting to do if there are processes left in the previous runlevel */
+ /* Noting to do if there are processes left in the previous runlevel
+ (in sysv-init mode) or startup components running. */
return;
-
+
debug (1, ("starting components"));
for (prog = proghead; prog; prog = prog->next)
@@ -1566,6 +1601,6 @@ check_stopping (struct prog *prog, time_t now)
{
if (prog->pid == 0)
- logmsg (LOG_EMERG,
- _("INTERNAL ERROR: attempting to kill unexisting process %s"),
+ logmsg (LOG_EMERG,
+ _("INTERNAL ERROR: attempting to kill unexisting process %s"),
prog_tag (prog));
else if (prog->v.p.comp->flags & CF_SIGGROUP)
@@ -1626,5 +1661,5 @@ progman_wake_sleeping (int onalrm)
}
break;
-
+
case status_stopping:
check_stopping (prog, now);
@@ -1635,5 +1670,5 @@ progman_wake_sleeping (int onalrm)
prog_start (prog);
break;
-
+
default:
break;
@@ -1648,5 +1683,5 @@ prog_start_prerequisites (struct prog *prog)
struct component *comp;
int warned = 0;
-
+
if (!prog->active)
return 1;
@@ -1656,5 +1691,5 @@ prog_start_prerequisites (struct prog *prog)
{
struct prog *p;
-
+
if (!comp->prog || comp->flags & CF_PRECIOUS)
continue;
@@ -1670,5 +1705,5 @@ prog_start_prerequisites (struct prog *prog)
return 1;
}
-
+
p = comp->prog;
switch (p->v.p.status)
@@ -1676,8 +1711,8 @@ prog_start_prerequisites (struct prog *prog)
case status_running:
continue;
-
+
case status_stopped:
break;
-
+
case status_listener:
continue;
@@ -1701,5 +1736,5 @@ prog_start_prerequisites (struct prog *prog)
}
depmap_end (pos);
-
+
return ret;
}
@@ -1758,5 +1793,5 @@ prog_stop (struct prog *prog, int sig)
else
kill (prog->pid, sig);
-}
+}
static int
@@ -1788,5 +1823,5 @@ print_status (const char *tag, pid_t pid, int status, int expect_term)
else
prio = LOG_ERR;
-
+
if (WIFEXITED (status))
{
@@ -1802,5 +1837,5 @@ print_status (const char *tag, pid_t pid, int status, int expect_term)
{
char const *coremsg = "";
-
+
if (expect_term && WTERMSIG (status) == SIGTERM)
prio = LOG_DEBUG;
@@ -1824,5 +1859,5 @@ print_status (const char *tag, pid_t pid, int status, int expect_term)
static void propagate_child_exit (pid_t) ATTRIBUTE_NORETURN;
-
+
static void
propagate_child_exit (pid_t pid)
@@ -1856,5 +1891,5 @@ wordsplit_string (struct wordsplit const *ws)
size_t i;
size_t len = 0;
-
+
for (i = 0; i < count; i++)
{
@@ -1884,5 +1919,5 @@ send_msg (char *rcpts, const char *msg_text)
int p[2];
size_t size;
-
+
ws.ws_offs = mailer_argc;
ws.ws_delim = ",";
@@ -1897,5 +1932,5 @@ send_msg (char *rcpts, const char *msg_text)
debug (1, (_("sending notification to %s"), rcpts));
-
+
/* Copy mailer arguments */
for (i = 0; i < mailer_argc; i++)
@@ -1912,5 +1947,5 @@ send_msg (char *rcpts, const char *msg_text)
char *arg = ws.ws_wordv[i];
size_t len;
-
+
while (*arg && c_isblank (*arg))
arg++;
@@ -1935,8 +1970,8 @@ send_msg (char *rcpts, const char *msg_text)
}
ws.ws_wordv[k] = NULL;
-
+
/* Fork a child: */
child_pid = fork ();
-
+
if (child_pid < 0)
{
@@ -1956,5 +1991,5 @@ send_msg (char *rcpts, const char *msg_text)
return;
}
-
+
/* Child process */
/* ============= */
@@ -1968,5 +2003,5 @@ send_msg (char *rcpts, const char *msg_text)
exit (EX_OSERR);
}
-
+
grand_child_pid = fork ();
if (grand_child_pid < 0)
@@ -2031,5 +2066,5 @@ notify_get_tag (char **ret, void *data)
return WRDSE_NOSPACE;
*ret = s;
- return WRDSE_OK;
+ return WRDSE_OK;
}
@@ -2040,5 +2075,5 @@ notify_get_termination (char **ret, void *data)
char const *msg;
char *s;
-
+
if (WIFEXITED (clos->status))
/* TRANSLATORS: The subject of this statement is 'component' */
@@ -2054,7 +2089,7 @@ notify_get_termination (char **ret, void *data)
return WRDSE_NOSPACE;
*ret = s;
- return WRDSE_OK;
+ return WRDSE_OK;
}
-
+
static int
notify_get_retcode (char **ret, void *data)
@@ -2063,5 +2098,5 @@ notify_get_retcode (char **ret, void *data)
char *s = NULL;
size_t l = 0;
-
+
if (WIFEXITED (clos->status))
grecs_asprintf (&s, &l, "%d", WEXITSTATUS (clos->status));
@@ -2073,7 +2108,7 @@ notify_get_retcode (char **ret, void *data)
return WRDSE_NOSPACE;
*ret = s;
- return WRDSE_OK;
-}
-
+ return WRDSE_OK;
+}
+
struct notify_variable
{
@@ -2091,5 +2126,5 @@ static struct notify_variable notify_vartab[] = {
{ NULL }
};
-
+
static int
notify_getvar (char **ret, const char *vptr, size_t vlen, void *data)
@@ -2101,5 +2136,5 @@ notify_getvar (char **ret, const char *vptr, size_t vlen, void *data)
return WRDSE_UNDEF;
}
-
+
static void
notify (const char *tag, int status, struct action *act)
@@ -2121,5 +2156,5 @@ notify (const char *tag, int status, struct action *act)
closure.status = status;
closure.act = act;
-
+
env[PROGRAM_NAME_IDX] = program_name;
env[INSTANCE_IDX] = instance;
@@ -2145,5 +2180,5 @@ status_matches_p (struct action *act, unsigned status)
{
int i;
-
+
if (act->nstat == 0)
return 1;
@@ -2185,5 +2220,5 @@ run_command (struct action *act, struct prog *prog, unsigned retcode,
close_fds (NULL);
-
+
argv[0] = "/bin/sh";
argv[1] = "-c";
@@ -2209,5 +2244,5 @@ react (struct prog *prog, int status, pid_t pid)
if (!list)
list = default_component.act_list;
-
+
if (WIFEXITED (status))
{
@@ -2234,5 +2269,5 @@ react (struct prog *prog, int status, pid_t pid)
{
struct action *act = ep->data;
-
+
if (status_matches_p (act, retcode))
{
@@ -2241,5 +2276,5 @@ react (struct prog *prog, int status, pid_t pid)
run_command (act, prog, retcode, pid);
}
-
+
switch (act->act)
{
@@ -2248,5 +2283,5 @@ react (struct prog *prog, int status, pid_t pid)
prog_start (prog);
break;
-
+
case action_disable:
logmsg (LOG_NOTICE, _("disabling component %s"),
@@ -2264,5 +2299,5 @@ react (struct prog *prog, int status, pid_t pid)
}
}
-
+
if (!list && prog->v.p.comp->mode != pies_comp_inetd)
/* Default action: */
@@ -2295,5 +2330,5 @@ progman_cleanup (int expect_term)
{
struct prog *listener = prog->v.p.listener;
-
+
listener->v.p.num_instances--;
if (prog->v.p.cclass)
@@ -2308,5 +2343,5 @@ progman_cleanup (int expect_term)
}
}
-
+
prog_stop_redirectors (prog);
if (listener->v.p.num_instances == 0
@@ -2322,4 +2357,12 @@ progman_cleanup (int expect_term)
destroy_prog (&prog);
}
+ else if (prog->v.p.comp->mode == pies_comp_startup)
+ {
+ debug (1, (_("removing startup component %s, pid=%lu"),
+ prog_tag (prog), (unsigned long)pid));
+ destroy_prog (&prog);
+ if (!progman_startup_phase ())
+ pies_schedule_children (PIES_CHLD_WAKEUP);
+ }
else
{
@@ -2330,5 +2373,5 @@ progman_cleanup (int expect_term)
pid, "");
prog->v.p.status = status_finished;
-
+
if (prog->wait)
{
@@ -2352,5 +2395,5 @@ progman_cleanup (int expect_term)
destroy_prog (&prog);
}
-
+
break;
@@ -2372,5 +2415,5 @@ progman_cleanup (int expect_term)
}
}
-
+
if (!expect_term)
/* This will also recompute alarm settings, if necessary */
@@ -2390,5 +2433,5 @@ progman_stop_component (struct prog **progptr)
prog_stop (prog, SIGTERM);
break;
-
+
case status_listener:
prog_deactivate_listener (prog);
@@ -2414,5 +2457,5 @@ progman_stop_component (struct prog **progptr)
case status_stopping:
break;
-
+
case status_finished:
prog->stop = 0;
@@ -2442,5 +2485,5 @@ prog_activate_listener (struct prog *prog)
{
struct component *comp = prog->v.p.comp;
-
+
logmsg (LOG_INFO, _("activating listener %s"), prog_tag (prog));
if (comp->mode == pies_comp_inetd && !ISCF_TCPMUX (comp->flags)
@@ -2536,8 +2579,8 @@ progman_gc (void)
break;
}
-
+
/* FIXME: Report remaining programs */
-
+
}
-
+
/* EOF */
diff --git a/src/socket.c b/src/socket.c
index aa01543..40c7aa7 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -24,11 +24,14 @@ switch_eids (uid_t *puid, gid_t *pgid, mode_t *pumask)
gid_t ogid = getegid ();
mode_t omask = umask (*pumask);
-
- if (setegid (*pgid))
- logmsg (LOG_ERR, _("cannot switch to EGID %lu: %s"),
- (unsigned long) *pgid, strerror (errno));
- if (seteuid (*puid))
- logmsg (LOG_ERR, _("cannot switch to EUID %lu: %s"),
- (unsigned long) *puid, strerror (errno));
+
+ if ((*puid && *puid != ouid) || (*pgid && *pgid != ogid))
+ {
+ if (setegid (*pgid))
+ logmsg (LOG_ERR, _("cannot switch to EGID %lu: %s"),
+ (unsigned long) *pgid, strerror (errno));
+ if (seteuid (*puid))
+ logmsg (LOG_ERR, _("cannot switch to EUID %lu: %s"),
+ (unsigned long) *puid, strerror (errno));
+ }
*puid = ouid;
*pgid = ogid;
@@ -52,5 +55,5 @@ create_socket (struct pies_url *url, int socket_type,
gid_t gid = 0;
int switch_back;
-
+
if (strcmp (url->scheme, "unix") == 0
|| strcmp (url->scheme, "file") == 0
@@ -59,5 +62,5 @@ create_socket (struct pies_url *url, int socket_type,
struct stat st;
const char *group = NULL;
-
+
user = url->user;
if (url->argc)
@@ -100,5 +103,5 @@ create_socket (struct pies_url *url, int socket_type,
}
}
-
+
if (user)
{
@@ -112,5 +115,5 @@ create_socket (struct pies_url *url, int socket_type,
gid = pw->pw_gid;
}
-
+
if (group)
{
@@ -123,5 +126,5 @@ create_socket (struct pies_url *url, int socket_type,
gid = grp->gr_gid;
}
-
+
if (strlen (url->path) > sizeof addr.s_un.sun_path)
{
@@ -160,5 +163,5 @@ create_socket (struct pies_url *url, int socket_type,
const char *host = url->host;
short port = url->port;
-
+
uid = 0;
gid = 0;
@@ -167,5 +170,5 @@ create_socket (struct pies_url *url, int socket_type,
addr.sa.sa_family = PF_INET;
socklen = sizeof (addr.s_in);
-
+
if (!host)
addr.s_in.sin_addr.s_addr = INADDR_ANY;
@@ -186,5 +189,5 @@ create_socket (struct pies_url *url, int socket_type,
addr.s_in.sin_port = htons (port);
break;
-
+
default:
logmsg (LOG_ERR, _("%s: unsupported address family"),
@@ -199,5 +202,5 @@ create_socket (struct pies_url *url, int socket_type,
return -1;
}
-
+
fd = socket (addr.sa.sa_family, socket_type, url->proto);
if (fd == -1)
@@ -251,5 +254,5 @@ pass_fd0 (int fd, int payload)
# define CMSG_SPACE(size) (sizeof(struct cmsghdr) + (size))
# endif /* ! CMSG_SPACE */
-
+
char control[CMSG_SPACE (sizeof (int))];
struct cmsghdr *cmptr;
@@ -291,5 +294,5 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime)
int res = -1;
struct sockaddr_un addr;
-
+
if (strlen (socket_name) > sizeof addr.sun_path)
{
@@ -299,5 +302,5 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime)
addr.sun_family = AF_UNIX;
strcpy (addr.sun_path, socket_name);
-
+
for (;;)
{
@@ -363,5 +366,5 @@ pass_fd (const char *socket_name, int fd, unsigned maxtime)
fd_set fds;
struct timeval tv;
-
+
FD_ZERO (&fds);
FD_SET (sockfd, &fds);
@@ -431,5 +434,5 @@ calc_fd_max (void)
void *
-register_socket (int fd,
+register_socket (int fd,
socket_handler_t rd,
socket_handler_t wr,
@@ -455,5 +458,5 @@ register_socket (int fd,
si_head = sip;
}
-
+
si_tail = sip;
if (rd)
@@ -494,5 +497,5 @@ delete_sockinst (struct sockinst *sp)
FD_CLR (sp->fd, &fdset[PIES_EVT_EX]);
fd_max = -1;
-
+
if (sp->prev)
sp->prev->next = sp->next;
@@ -573,5 +576,5 @@ pies_pause (void)
if (pies_pause_hook && pies_pause_hook ())
return;
-
+
if (fd_max == -1)
calc_fd_max ();
@@ -582,5 +585,5 @@ pies_pause (void)
fd_set wrset = fdset[PIES_EVT_WR];
fd_set exset = fdset[PIES_EVT_EX];
-
+
int rc = select (fd_max + 1, &rdset, &wrset, &exset, NULL);
if (rc > 0)
@@ -638,3 +641,2 @@ pies_pause (void)
}
}
-
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 447104b..b2f2719 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,5 +15,11 @@
# along with GNU Pies. If not, see <http://www.gnu.org/licenses/>.
-EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 respawn retcode mailer
+AUXTOOLS = \
+ aux/respawn\
+ aux/retcode\
+ aux/mailer\
+ aux/startup
+
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS)
DISTCLEANFILES = atconfig $(check_SCRIPTS)
MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
@@ -47,4 +53,5 @@ TESTSUITE_AT = \
ret-exec.at\
ret-notify.at\
+ startup.at\
version.at
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 9069bbd..1992b80 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -5,5 +5,5 @@
PATH=@abs_builddir@:@abs_top_builddir@/src:$srcdir:$PATH
XFAILFILE=$abs_builddir/.badversion
-
+auxdir="$abs_srcdir/aux"
trimws() {
sed 's/[ ][ ]*$//'
diff --git a/tests/mailer b/tests/aux/mailer
index f832ff5..f832ff5 100755
--- a/tests/mailer
+++ b/tests/aux/mailer
diff --git a/tests/respawn b/tests/aux/respawn
index 11d59f6..11d59f6 100755
--- a/tests/respawn
+++ b/tests/aux/respawn
diff --git a/tests/retcode b/tests/aux/retcode
index b827ba9..b827ba9 100755
--- a/tests/retcode
+++ b/tests/aux/retcode
diff --git a/tests/aux/startup b/tests/aux/startup
new file mode 100755
index 0000000..b9d92a3
--- a/dev/null
+++ b/tests/aux/startup
@@ -0,0 +1,7 @@
+#!/bin/sh
+dir=${1:?}
+time=${2:?}
+tag=${3:?}
+
+touch $dir/$tag
+sleep $time
diff --git a/tests/redirect.at b/tests/redirect.at
index 9e53ba2..3a8cca7 100644
--- a/tests/redirect.at
+++ b/tests/redirect.at
@@ -25,5 +25,5 @@ cat > pies.conf <<_EOT
component test {
mode respawn;
- command "$abs_srcdir/respawn -tag respawn -append -pid $comp_pid_file";
+ command "$auxdir/respawn -tag respawn -append -pid $comp_pid_file";
stdout file "$outfile";
}
diff --git a/tests/respawn.at b/tests/respawn.at
index 8d72c40..4a8e3a7 100644
--- a/tests/respawn.at
+++ b/tests/respawn.at
@@ -24,5 +24,5 @@ cat > pies.conf <<_EOT
component test {
mode respawn;
- command "$abs_srcdir/respawn -append -pid $comp_pid_file";
+ command "$auxdir/respawn -append -pid $comp_pid_file";
}
_EOT
diff --git a/tests/ret-exec.at b/tests/ret-exec.at
index bf2c1a4..0b3d716 100644
--- a/tests/ret-exec.at
+++ b/tests/ret-exec.at
@@ -27,8 +27,8 @@ component test {
mode respawn;
return-code 10 {
- exec "$abs_srcdir/retcode $report_file";
+ exec "$auxdir/retcode $report_file";
action disable;
}
- command "$abs_srcdir/respawn -sleep 2 -pid $comp_pid_file -exit 10";
+ command "$auxdir/respawn -sleep 2 -pid $comp_pid_file -exit 10";
}
_EOT
diff --git a/tests/ret-notify.at b/tests/ret-notify.at
index d1a7f39..a7768aa 100644
--- a/tests/ret-notify.at
+++ b/tests/ret-notify.at
@@ -23,6 +23,6 @@ PIES_CONTROL_INIT
report_file=$PWD/report
cat > pies.conf <<_EOT
-mailer-program "$abs_srcdir/mailer";
-mailer-command-line "$abs_srcdir/mailer $report_file";
+mailer-program "$auxdir/mailer";
+mailer-command-line "$auxdir/mailer $report_file";
component test {
mode respawn;
@@ -31,5 +31,5 @@ component test {
action disable;
}
- command "$abs_srcdir/respawn -sleep 2 -exit 10";
+ command "$auxdir/respawn -sleep 2 -exit 10";
}
_EOT
diff --git a/tests/startup.at b/tests/startup.at
new file mode 100644
index 0000000..72017ce
--- a/dev/null
+++ b/tests/startup.at
@@ -0,0 +1,84 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2019 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Startup components])
+
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+comp_pid_file=$PWD/comp.pid
+
+cat > pies.conf <<_EOT
+component b1 {
+ mode startup;
+ command "$auxdir/startup $PWD 1 b1";
+}
+
+component b2 {
+ mode startup;
+ command "$auxdir/startup $PWD 2 b2";
+}
+
+component test {
+ mode respawn;
+ command "$auxdir/respawn -append -pid $comp_pid_file";
+}
+_EOT
+
+pies --config-file control.conf --config-file pies.conf
+
+n=0
+res=
+b1=
+b2=
+while :
+do
+ echo "n=$n" >> tracefile
+ if test -z "$b1" && test -f b1; then
+ res="${res}b1"
+ b1=1
+ echo "got b1" >> tracefile
+ fi
+ if test -z "$b2" && test -f b2; then
+ res="${res}b2"
+ b2=1
+ echo "got b2" >> tracefile
+ fi
+ if test -f $comp_pid_file; then
+ echo "got pidfile" >> tracefile
+ res="${res}pid"
+ break
+ fi
+ sleep 1
+ n=$(($n + 1))
+ if test $n -gt 10; then
+ echo >&2 "timed out"
+ break
+ fi
+done
+
+PIES_STOP
+case $res in
+b1b2pid|b2b1pid) echo b1b2pid;;
+*) echo $res
+esac
+],
+[0],
+[b1b2pid
+])
+
+AT_CLEANUP
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 03ddd50..2a1167d 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -66,2 +66,3 @@ m4_include([redirect.at])
m4_include([ret-exec.at])
m4_include([ret-notify.at])
+m4_include([startup.at])

Return to:

Send suggestions and report system problems to the System administrator.