diff -Nurp autofs-5.0.1.orig/daemon/automount.c autofs-5.0.1/daemon/automount.c --- autofs-5.0.1.orig/daemon/automount.c 2007-10-18 21:13:43.000000000 +0800 +++ autofs-5.0.1/daemon/automount.c 2007-10-18 21:14:30.000000000 +0800 @@ -60,6 +60,8 @@ static int *pst_stat = &st_stat; /* Attribute to create detached thread */ pthread_attr_t thread_attr; +/* Attribute to create normal thread */ +pthread_attr_t thread_attr_nodetach; struct master_readmap_cond mrc = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0, 0, 0}; @@ -896,7 +898,7 @@ static void *do_notify_state(void *arg) return NULL; } -static int do_signals(struct master *master, int sig) +static pthread_t do_signals(struct master *master, int sig) { pthread_t thid; int r_sig = sig; @@ -906,7 +908,7 @@ static int do_signals(struct master *mas if (status) fatal(status); - status = pthread_create(&thid, &thread_attr, do_notify_state, &r_sig); + status = pthread_create(&thid, &thread_attr_nodetach, do_notify_state, &r_sig); if (status) { error(master->default_logging, "mount state notify thread create failed"); @@ -930,7 +932,7 @@ static int do_signals(struct master *mas pthread_cleanup_pop(1); - return 1; + return thid; } static void *do_read_master(void *arg) @@ -1022,6 +1024,7 @@ static int do_hup_signal(struct master * /* Deal with all the signal-driven events in the state machine */ static void *statemachine(void *arg) { + pthread_t thid = 0; sigset_t signalset; int sig; @@ -1032,15 +1035,17 @@ static void *statemachine(void *arg) while (1) { sigwait(&signalset, &sig); - - if (master_list_empty(master_list)) - return NULL; - switch (sig) { case SIGTERM: case SIGUSR2: case SIGUSR1: - do_signals(master_list, sig); + thid = do_signals(master_list, sig); + if (thid) { + pthread_join(thid, NULL); + if (master_list_empty(master_list)) + return NULL; + thid = 0; + } break; case SIGHUP: @@ -1155,10 +1160,6 @@ static void handle_mounts_cleanup(void * msg("shut down path %s", path); - /* If we are the last tell the state machine to shutdown */ - if (!submount && master_list_empty(master_list)) - kill(getpid(), SIGTERM); - return; } @@ -1627,6 +1628,14 @@ int main(int argc, char *argv[]) } #endif + if (pthread_attr_init(&thread_attr_nodetach)) { + crit(LOGOPT_ANY, + "%s: failed to init thread attribute struct!", + program); + close(start_pipefd[1]); + exit(1); + } + msg("Starting automounter version %s, master map %s", version, master_list->name); msg("using kernel protocol version %d.%02d", diff -Nurp autofs-5.0.1.orig/lib/master.c autofs-5.0.1/lib/master.c --- autofs-5.0.1.orig/lib/master.c 2007-10-18 21:13:43.000000000 +0800 +++ autofs-5.0.1/lib/master.c 2007-10-18 21:14:30.000000000 +0800 @@ -802,8 +802,8 @@ int master_read_master(struct master *ma if (list_empty(&master->mounts)) { master_mutex_unlock(); - error(LOGOPT_ANY, "no mounts in table"); - return 0; + warn(LOGOPT_ANY, "no mounts in table"); + return 1; } master_mutex_unlock();