Commit fb07bc72 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

If we are going to start the client automatically, test that the

accept-sockets can actually be bound before we muck about with
daemon() or SHM files.

Belived to be implicated in #1262
parent ba9f21b0
...@@ -44,6 +44,8 @@ void MGT_Run(void); ...@@ -44,6 +44,8 @@ void MGT_Run(void);
void mgt_stop_child(void); void mgt_stop_child(void);
void mgt_got_fd(int fd); void mgt_got_fd(int fd);
void MGT_Child_Cli_Fail(void); void MGT_Child_Cli_Fail(void);
int MGT_open_sockets(void);
void MGT_close_sockets(void);
/* mgt_cli.c */ /* mgt_cli.c */
......
...@@ -222,13 +222,13 @@ mgt_child_inherit(int fd, const char *what) ...@@ -222,13 +222,13 @@ mgt_child_inherit(int fd, const char *what)
* (The child is priv-sep'ed, so it can't do it.) * (The child is priv-sep'ed, so it can't do it.)
*/ */
static int int
open_sockets(void) MGT_open_sockets(void)
{ {
struct listen_sock *ls, *ls2; struct listen_sock *ls;
int good = 0; int good = 0;
VTAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) { VTAILQ_FOREACH(ls, &heritage.socks, list) {
if (ls->sock >= 0) { if (ls->sock >= 0) {
good++; good++;
continue; continue;
...@@ -248,8 +248,8 @@ open_sockets(void) ...@@ -248,8 +248,8 @@ open_sockets(void)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void void
close_sockets(void) MGT_close_sockets(void)
{ {
struct listen_sock *ls; struct listen_sock *ls;
...@@ -326,7 +326,7 @@ mgt_launch_child(struct cli *cli) ...@@ -326,7 +326,7 @@ mgt_launch_child(struct cli *cli)
if (child_state != CH_STOPPED && child_state != CH_DIED) if (child_state != CH_STOPPED && child_state != CH_DIED)
return; return;
if (open_sockets() != 0) { if (MGT_open_sockets() != 0) {
child_state = CH_STOPPED; child_state = CH_STOPPED;
if (cli != NULL) { if (cli != NULL) {
VCLI_SetResult(cli, CLIS_CANT); VCLI_SetResult(cli, CLIS_CANT);
...@@ -410,7 +410,7 @@ mgt_launch_child(struct cli *cli) ...@@ -410,7 +410,7 @@ mgt_launch_child(struct cli *cli)
mgt_child_inherit(heritage.cli_out, NULL); mgt_child_inherit(heritage.cli_out, NULL);
closex(&heritage.cli_out); closex(&heritage.cli_out);
close_sockets(); MGT_close_sockets();
child_std_vlu = VLU_New(NULL, child_line, 0); child_std_vlu = VLU_New(NULL, child_line, 0);
AN(child_std_vlu); AN(child_std_vlu);
......
...@@ -602,6 +602,15 @@ main(int argc, char * const *argv) ...@@ -602,6 +602,15 @@ main(int argc, char * const *argv)
if (C_flag) if (C_flag)
exit (0); exit (0);
if (!d_flag) {
if (MGT_open_sockets()) {
fprintf(stderr,
"Failed to open (any) accept sockets.\n");
exit(1);
}
MGT_close_sockets();
}
/* If no -s argument specified, process default -s argument */ /* If no -s argument specified, process default -s argument */
if (!s_arg_given) if (!s_arg_given)
STV_Config(s_arg); STV_Config(s_arg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment