autofs-5.0.1 - fix return start status on fail From: Ian Kent <raven@themaw.net> We're not returning the status to the parent when automount(8) is waiting for the daemon to finish its startup. --- daemon/automount.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) --- autofs-5.0.1.orig/daemon/automount.c +++ autofs-5.0.1/daemon/automount.c @@ -60,7 +60,7 @@ unsigned int global_random_selection; /* long global_negative_timeout = -1; static int start_pipefd[2]; -static int st_stat = 0; +static int st_stat = 1; static int *pst_stat = &st_stat; static pthread_t state_mach_thid; @@ -1081,6 +1081,7 @@ static void become_daemon(unsigned foreg { FILE *pidfp; char buf[MAX_ERR_BUF]; + int res; pid_t pid; /* Don't BUSY any directories unnecessarily */ @@ -1102,10 +1103,9 @@ static void become_daemon(unsigned foreg else { pid = fork(); if (pid > 0) { - int r; close(start_pipefd[1]); - r = read(start_pipefd[0], pst_stat, sizeof(*pst_stat)); - if (r < 0) + res = read(start_pipefd[0], pst_stat, sizeof(*pst_stat)); + if (res < 0) exit(1); exit(*pst_stat); } else if (pid < 0) { @@ -1122,7 +1122,9 @@ static void become_daemon(unsigned foreg if (setsid() == -1) { char *estr = strerror_r(errno, buf, MAX_ERR_BUF); fprintf(stderr, "setsid: %s", estr); - exit(1); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); + close(start_pipefd[1]); + exit(*pst_stat); } log_to_syslog(); } @@ -2010,7 +2012,7 @@ int main(int argc, char *argv[]) if (is_automount_running() > 0) { fprintf(stderr, "%s: program is already running.\n", program); - exit(1); + exit(0); } #if 0 if (!load_autofs4_module()) { @@ -2053,6 +2055,7 @@ int main(int argc, char *argv[]) if (!master_list) { logerr("%s: can't create master map %s", program, argv[0]); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2060,6 +2063,7 @@ int main(int argc, char *argv[]) if (pthread_attr_init(&th_attr)) { logerr("%s: failed to init thread attribute struct!", program); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2067,6 +2071,7 @@ int main(int argc, char *argv[]) if (pthread_attr_init(&th_attr_detached)) { logerr("%s: failed to init thread attribute struct!", program); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2075,6 +2080,7 @@ int main(int argc, char *argv[]) &th_attr_detached, PTHREAD_CREATE_DETACHED)) { logerr("%s: failed to set detached thread attribute!", program); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2084,6 +2090,7 @@ int main(int argc, char *argv[]) &th_attr_detached, PTHREAD_STACK_MIN*128)) { logerr("%s: failed to set stack size thread attribute!", program); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2100,6 +2107,7 @@ int main(int argc, char *argv[]) logerr("%s: failed to create thread data key for std env vars!", program); master_kill(master_list); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2107,6 +2115,7 @@ int main(int argc, char *argv[]) if (!alarm_start_handler()) { logerr("%s: failed to create alarm handler thread!", program); master_kill(master_list); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2114,6 +2123,7 @@ int main(int argc, char *argv[]) if (!st_start_handler()) { logerr("%s: failed to create FSM handler thread!", program); master_kill(master_list); + res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); exit(1); } @@ -2132,6 +2142,7 @@ int main(int argc, char *argv[]) exit(3); } + st_stat = 0; res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]);