diff -urN autofs-0.3.12/.version autofs-0.3.13-pre1/.version --- autofs-0.3.12/.version Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre1/.version Wed Sep 17 15:07:17 1997 @@ -1 +1 @@ -0.3.12 +0.3.13 diff -urN autofs-0.3.12/NEWS autofs-0.3.13-pre1/NEWS --- autofs-0.3.12/NEWS Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre1/NEWS Wed Sep 17 15:07:17 1997 @@ -1,3 +1,9 @@ +Since autofs-0.3.12: +-------------------- +* Added -p, --pid-file option to daemon. +* Fixed aestetic bug in new spawn() logic. +* Added new cleanup_exit() function in the daemon. + Since autofs-0.3.11: -------------------- * Rewrote the spawn() logic to not use stdio at all. diff -urN autofs-0.3.12/daemon/automount.c autofs-0.3.13-pre1/daemon/automount.c --- autofs-0.3.12/daemon/automount.c Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre1/daemon/automount.c Wed Sep 17 15:07:17 1997 @@ -43,8 +43,9 @@ static pid_t my_pgrp; /* The "magic" process group */ static pid_t my_pid; /* The pid of this process */ +static char *pid_file = NULL; /* File in which to keep pid */ -int kproto_version; /* Kernel protocol version */ +int kproto_version; /* Kernel protocol version used */ static int mounted = 0; @@ -443,13 +444,16 @@ static void become_daemon(void) { + FILE *pidfp; pid_t pid; int nullfd; /* Don't BUSY any directories unneccessarily */ + chdir("/"); - /* Detach */ + /* Detach from foreground process */ + pid = fork(); if ( pid > 0 ) exit(0); @@ -459,12 +463,15 @@ } /* Open syslog */ + openlog("automount", LOG_PID, LOG_DAEMON); - + /* Initialize global data */ + my_pid = getpid(); - + /* Make our own process group for "magic" reason */ + if ( setpgrp() ) { syslog(LOG_CRIT, "setpgrp: %m"); exit(1); @@ -472,7 +479,7 @@ my_pgrp = getpgrp(); /* Redirect all our file descriptors to /dev/null */ - + if ( (nullfd = open("/dev/null", O_RDWR)) < 0 ) { syslog(LOG_CRIT, "cannot open /dev/null: %m"); exit(1); @@ -485,6 +492,38 @@ exit(1); } close(nullfd); + + /* Write pid file if requested */ + + if ( pid_file ) { + if ( (pidfp = fopen(pid_file, "wt")) ) { + fprintf(pidfp, "%lu\n", (unsigned long) my_pid); + fclose(pidfp); + } else { + syslog(LOG_WARNING, "failed to write pid file %s: %m", pid_file); + pid_file = NULL; + } + } +} + +/* + * cleanup_exit() is valid to call once we have daemonized + */ +#ifndef __NORETURN +#define __NORETURN void +#endif + +static __NORETURN cleanup_exit(int exit_code) +{ + if ( ap.lookup ) + close_lookup(ap.lookup); + + if ( pid_file ) + unlink(pid_file); + + closelog(); + + exit(exit_code); } static unsigned long getnumopt(char *str, char option) @@ -512,9 +551,10 @@ struct sigaction sa; int mapargc, opt; static const struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"timeout", 1, 0, 't'}, - {"version", 0, 0, 'v'}, + {"help", 0, 0, 'h'}, + {"pid-file", 1, 0, 'p'}, + {"timeout", 1, 0, 't'}, + {"version", 0, 0, 'v'}, {0,0,0,0} }; @@ -523,12 +563,15 @@ ap.exp_timeout = DEFAULT_TIMEOUT; opterr = 0; - while ( (opt = getopt_long(argc, argv, "+ht:v", long_options, + while ( (opt = getopt_long(argc, argv, "+hp:t:v", long_options, NULL)) != EOF ) { switch( opt ) { case 'h': usage(); exit(0); + case 'p': + pid_file = optarg; + break; case 't': ap.exp_timeout = getnumopt(optarg, opt); break; @@ -556,6 +599,7 @@ exit(1); } + memset(&ap, 0, sizeof ap); /* Initialize ap so we can test for null */ become_daemon(); path = argv[0]; @@ -578,12 +622,11 @@ *(mapfmt++) = '\0'; if ( !(ap.lookup = open_lookup(map, "", mapfmt, mapargc, mapargv)) ) - exit(1); + cleanup_exit(1); if (mount_autofs(path) < 0) { syslog(LOG_CRIT, "%s: mount failed!", path); - close_lookup(ap.lookup); - exit(1); + cleanup_exit(1); } sa.sa_handler = sig_shutdown; @@ -661,8 +704,6 @@ close_lookup(ap.lookup); umount_autofs(1); - - closelog(); - - return 0; + + cleanup_exit(0); } diff -urN autofs-0.3.12/daemon/spawn.c autofs-0.3.13-pre1/daemon/spawn.c --- autofs-0.3.12/daemon/spawn.c Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre1/daemon/spawn.c Wed Sep 17 15:07:17 1997 @@ -12,6 +12,7 @@ * * ----------------------------------------------------------------------- */ +#include #include #include #include @@ -116,6 +117,12 @@ } } while ( errn > 0 ); close(pipefd[0]); + + if ( errp > 0 ) { + /* End of file without \n */ + errbuf[errp] = '\0'; + syslog(logpri, ">> %s", errbuf); + } if ( waitpid(f, &status, 0) != f ) status = -1; /* waitpid() failed */ diff -urN autofs-0.3.12/man/automount.8 autofs-0.3.13-pre1/man/automount.8 --- autofs-0.3.12/man/automount.8 Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre1/man/automount.8 Wed Sep 17 15:07:17 1997 @@ -6,7 +6,7 @@ .\" .\" This is free documentation. .\" -.TH AUTOMOUNT 8 "9 Sep 1997" +.TH AUTOMOUNT 8 "17 Sep 1997" .SH NAME automount \- configure mount points for autofs .SH SYNOPSIS @@ -19,6 +19,9 @@ within the base \fImount-point\fP when they are accessed in any way. The filesystems are then autounmounted after a period of inactivity. .SH OPTIONS +.TP +.I "\-p, \-\-pid-file" +Write the pid of the daemon to the specified file. .TP .I "\-t, \-\-timeout" Set the minimum timeout, in seconds, until directories are unmounted.