diff -up autofs-5.0.2/modules/lookup_ldap.c.foreground-logging autofs-5.0.2/modules/lookup_ldap.c
--- autofs-5.0.2/modules/lookup_ldap.c.foreground-logging 2007-09-24 14:42:28.000000000 +0800
+++ autofs-5.0.2/modules/lookup_ldap.c 2007-09-24 14:44:18.000000000 +0800
@@ -468,17 +468,17 @@ int parse_ldap_config(struct lookup_cont
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);
diff -up autofs-5.0.2/modules/cyrus-sasl.c.foreground-logging autofs-5.0.2/modules/cyrus-sasl.c
--- autofs-5.0.2/modules/cyrus-sasl.c.foreground-logging 2007-06-18 15:18:08.000000000 +0800
+++ autofs-5.0.2/modules/cyrus-sasl.c 2007-09-24 14:44:18.000000000 +0800
@@ -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 -up autofs-5.0.2/daemon/automount.c.foreground-logging autofs-5.0.2/daemon/automount.c
--- autofs-5.0.2/daemon/automount.c.foreground-logging 2007-09-24 14:42:28.000000000 +0800
+++ autofs-5.0.2/daemon/automount.c 2007-09-24 14:44:18.000000000 +0800
@@ -58,14 +58,13 @@ unsigned int random_selection; /* use ra
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 foreg
{
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 foreg
}
/* 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 foreg
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 maste
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");
@@ -1043,7 +1035,6 @@ 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;
@@ -1056,15 +1047,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:
@@ -1179,6 +1167,10 @@ 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))
+ pthread_kill(state_mach_thid, SIGTERM);
+
return;
}
@@ -1357,7 +1349,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"
@@ -1632,14 +1624,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",
@@ -1684,6 +1668,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 -up autofs-5.0.2/lib/master.c.foreground-logging autofs-5.0.2/lib/master.c
--- autofs-5.0.2/lib/master.c.foreground-logging 2007-09-24 14:42:28.000000000 +0800
+++ autofs-5.0.2/lib/master.c 2007-09-24 14:44:18.000000000 +0800
@@ -954,6 +954,7 @@ void master_notify_state_change(struct m
switch (sig) {
case SIGTERM:
+ case SIGINT:
if (ap->state != ST_SHUTDOWN_PENDING &&
ap->state != ST_SHUTDOWN_FORCE) {
next = ST_SHUTDOWN_PENDING;
diff -up autofs-5.0.2/lib/log.c.foreground-logging autofs-5.0.2/lib/log.c
--- autofs-5.0.2/lib/log.c.foreground-logging 2007-06-18 15:18:08.000000000 +0800
+++ autofs-5.0.2/lib/log.c 2007-09-24 14:44:18.000000000 +0800
@@ -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 lo
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 -up autofs-5.0.2/man/automount.8.foreground-logging autofs-5.0.2/man/automount.8
--- autofs-5.0.2/man/automount.8.foreground-logging 2007-09-24 14:42:28.000000000 +0800
+++ autofs-5.0.2/man/automount.8 2007-09-24 14:44:18.000000000 +0800
@@ -47,6 +47,9 @@ Define a global macro substitution varia
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.