diff --git a/CHANGELOG b/CHANGELOG index 933b1a1..0340940 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ - work around segv at exit due to libxml2 tsd usage. - re-read config on HUP signal. - add LDAP_URI, LDAP_TIMEOUT and LDAP_NETWORK_TIMEOUT configuration options. +- fix forground logging and add option to man page. 18/06/2007 autofs-5.0.2 ----------------------- diff --git a/daemon/automount.c b/daemon/automount.c index 58f1901..51f6a8b 100644 --- a/daemon/automount.c +++ b/daemon/automount.c @@ -58,14 +58,13 @@ unsigned int global_random_selection; /* use random policy when selecting static int start_pipefd[2]; static int st_stat = 0; static int *pst_stat = &st_stat; +static pthread_t state_mach_thid; /* Pre-calculated kernel packet length */ static size_t kpkt_len; /* 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}; @@ -75,9 +74,6 @@ struct startup_cond suc = { pthread_key_t key_thread_stdenv_vars; -/* re-entrant syslog default context data */ -#define AUTOFS_SYSLOG_CONTEXT {-1, 0, 0, LOG_PID, (const char *)0, LOG_DAEMON, 0xff}; - #define MAX_OPEN_FILES 10240 static int umount_all(struct autofs_point *ap, int force); @@ -792,7 +788,6 @@ static void become_daemon(unsigned foreground) { FILE *pidfp; char buf[MAX_ERR_BUF]; - unsigned to_stderr = 0; pid_t pid; /* Don't BUSY any directories unnecessarily */ @@ -809,7 +804,9 @@ static void become_daemon(unsigned foreground) } /* Detach from foreground process */ - if (!foreground) { + if (foreground) + log_to_stderr(); + else { pid = fork(); if (pid > 0) { int r; @@ -834,13 +831,8 @@ static void become_daemon(unsigned foreground) fprintf(stderr, "setsid: %s", estr); exit(1); } - } - - /* Setup logging */ - if (to_stderr) - log_to_stderr(); - else log_to_syslog(); + } /* Write pid file if requested */ if (pid_file) { @@ -929,7 +921,7 @@ static pthread_t do_signals(struct master *master, int sig) if (status) fatal(status); - status = pthread_create(&thid, &thread_attr_nodetach, do_notify_state, &r_sig); + status = pthread_create(&thid, &thread_attr, do_notify_state, &r_sig); if (status) { error(master->default_logging, "mount state notify thread create failed"); @@ -1045,7 +1037,6 @@ static int do_hup_signal(struct master *master, time_t age) /* 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; @@ -1058,15 +1049,12 @@ static void *statemachine(void *arg) switch (sig) { case SIGTERM: + case SIGINT: case SIGUSR2: + if (master_list_empty(master_list)) + return NULL; case SIGUSR1: - thid = do_signals(master_list, sig); - if (thid) { - pthread_join(thid, NULL); - if (master_list_empty(master_list)) - return NULL; - thid = 0; - } + do_signals(master_list, sig); break; case SIGHUP: @@ -1181,6 +1169,10 @@ static void handle_mounts_cleanup(void *arg) msg("shut down path %s", path); + /* If we are the last tell the state machine to shutdown */ + if (!submount && master_list_empty(master_list)) + pthread_kill(state_mach_thid, SIGTERM); + return; } @@ -1375,7 +1367,7 @@ static void usage(void) " -v --verbose be verbose\n" " -d --debug log debuging info\n" " -D --define define global macro variable\n" - /*" -f --foreground do not fork into background\n" */ + " -f --foreground do not fork into background\n" " -r --random-multimount-selection\n" " use ramdom replicated server selection\n" " -O --global-options\n" @@ -1650,14 +1642,6 @@ 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", @@ -1702,6 +1686,7 @@ int main(int argc, char *argv[]) res = write(start_pipefd[1], pst_stat, sizeof(pst_stat)); close(start_pipefd[1]); + state_mach_thid = pthread_self(); statemachine(NULL); master_kill(master_list); diff --git a/lib/log.c b/lib/log.c index e639e60..b747e12 100644 --- a/lib/log.c +++ b/lib/log.c @@ -27,9 +27,6 @@ #include "automount.h" -/* re-entrant syslog default context data */ -#define AUTOFS_SYSLOG_CONTEXT {-1, 0, 0, LOG_PID, (const char *) 0, LOG_DAEMON, 0xff}; - /* struct syslog_data syslog_context = AUTOFS_SYSLOG_CONTEXT; struct syslog_data *slc = &syslog_context; @@ -134,30 +131,40 @@ static void syslog_debug(unsigned int logopt, const char *msg, ...) va_end(ap); } +static void to_stderr(unsigned int logopt, const char *msg, ...) +{ + va_list ap; + va_start(ap, msg); + vfprintf(stderr, msg, ap); + fputc('\n',stderr); + va_end(ap); +} + void set_mnt_logging(struct autofs_point *ap) { unsigned int opt_verbose = ap->logopt & LOGOPT_VERBOSE; unsigned int opt_debug = ap->logopt & LOGOPT_DEBUG; - if (opt_debug) - log_debug = syslog_debug; + if (opt_debug) { + if (logging_to_syslog) + log_debug = syslog_debug; + else + log_debug = to_stderr; + } if (opt_verbose || opt_debug) { - log_info = syslog_info; - log_notice = syslog_notice; - log_warn = syslog_warn; + if (logging_to_syslog) { + log_info = syslog_info; + log_notice = syslog_notice; + log_warn = syslog_warn; + } else { + log_info = to_stderr; + log_notice = to_stderr; + log_warn = to_stderr; + } } } -static void to_stderr(unsigned int logopt, const char *msg, ...) -{ - va_list ap; - va_start(ap, msg); - vfprintf(stderr, msg, ap); - fputc('\n',stderr); - va_end(ap); -} - void log_to_syslog(void) { char buf[MAX_ERR_BUF]; diff --git a/lib/master.c b/lib/master.c index 637ce04..abc3bc2 100644 --- a/lib/master.c +++ b/lib/master.c @@ -954,6 +954,7 @@ void master_notify_state_change(struct master *master, int sig) switch (sig) { case SIGTERM: + case SIGINT: if (ap->state != ST_SHUTDOWN_PENDING && ap->state != ST_SHUTDOWN_FORCE) { next = ST_SHUTDOWN_PENDING; diff --git a/man/automount.8 b/man/automount.8 index da67a5c..e203a3e 100644 --- a/man/automount.8 +++ b/man/automount.8 @@ -47,6 +47,9 @@ Define a global macro substitution variable. Global definitions are over-ridden macro definitions of the same name specified in mount entries. .TP +.I "\-f, \-\-foreground" +Run the daemon in the forground and log to stderr instead of syslog." +.TP .I "\-r, \-\-random-multimount-selection" Enables the use of ramdom selection when choosing a host from a list of replicated servers. diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c index 9aac792..68e5dd7 100644 --- a/modules/cyrus-sasl.c +++ b/modules/cyrus-sasl.c @@ -197,7 +197,7 @@ get_server_SASL_mechanisms(LDAP *ld) if (mechanisms == NULL) { /* Well, that was a waste of time. */ msg("No SASL authentication mechanisms are supported" - " by the LDAP server.\n"); + " by the LDAP server."); return NULL; } diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c index 4068561..c0f228b 100644 --- a/modules/lookup_ldap.c +++ b/modules/lookup_ldap.c @@ -857,17 +857,17 @@ int parse_ldap_config(struct lookup_context *ctxt) ctxt->client_princ = client_princ; debug(LOGOPT_NONE, - "ldap authentication configured with the following options:\n"); + "ldap authentication configured with the following options:"); debug(LOGOPT_NONE, "use_tls: %u, " "tls_required: %u, " "auth_required: %u, " - "sasl_mech: %s\n", + "sasl_mech: %s", use_tls, tls_required, auth_required, authtype); debug(LOGOPT_NONE, "user: %s, " "secret: %s, " - "client principal: %s\n", + "client principal: %s", user, secret ? "specified" : "unspecified", client_princ);