diff -urN autofs-0.3.12/.version autofs-0.3.13-pre2/.version --- autofs-0.3.12/.version Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/.version Wed Sep 17 18:15:17 1997 @@ -1 +1 @@ -0.3.12 +0.3.13 diff -urN autofs-0.3.12/NEWS autofs-0.3.13-pre2/NEWS --- autofs-0.3.12/NEWS Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/NEWS Wed Sep 17 18:15:17 1997 @@ -1,3 +1,11 @@ +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. +* Integrated new sample stuff from Miquel van Smoorenburg and + Christoph Lameter. + 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-pre2/daemon/automount.c --- autofs-0.3.12/daemon/automount.c Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/daemon/automount.c Wed Sep 17 18:15:16 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,35 @@ 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 + */ + +static void 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 +548,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 +560,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 +596,7 @@ exit(1); } + memset(&ap, 0, sizeof ap); /* Initialize ap so we can test for null */ become_daemon(); path = argv[0]; @@ -578,14 +619,26 @@ *(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_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; +#ifdef SIGUNUSED + sigaction(SIGUNUSED, &sa, NULL); +#endif +#ifdef SIGLOST + sigaction(SIGLOST, &sa, NULL); +#endif + sigaction(SIGVTALRM, &sa, NULL); + sigaction(SIGPROF, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + sa.sa_handler = sig_shutdown; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGCHLD); @@ -599,9 +652,13 @@ sigaction(SIGBUS, &sa, NULL); sigaction(SIGFPE, &sa, NULL); sigaction(SIGSEGV, &sa, NULL); - sigaction(SIGPIPE, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGIO, &sa, NULL); + sigaction(SIGXCPU, &sa, NULL); + sigaction(SIGXFSZ, &sa, NULL); +#ifdef SIGSYS + sigaction(SIGSYS, &sa, NULL); +#endif #ifdef SIGPWR sigaction(SIGPWR, &sa, NULL); #endif @@ -609,7 +666,7 @@ sigaction(SIGSTKFLT, &sa, NULL); #endif sigaction(SIGUSR2, &sa, NULL); - + sa.sa_handler = sig_child; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; @@ -619,6 +676,7 @@ sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); + sigaction(SIGHUP, &sa, NULL); sa.sa_handler = sig_expire; sigemptyset(&sa.sa_mask); @@ -661,8 +719,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-pre2/daemon/spawn.c --- autofs-0.3.12/daemon/spawn.c Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/daemon/spawn.c Wed Sep 17 18:15:16 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-pre2/man/automount.8 --- autofs-0.3.12/man/automount.8 Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/man/automount.8 Wed Sep 17 18:15: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. diff -urN autofs-0.3.12/samples/auto.misc autofs-0.3.13-pre2/samples/auto.misc --- autofs-0.3.12/samples/auto.misc Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/samples/auto.misc Wed Sep 17 18:15:17 1997 @@ -6,4 +6,4 @@ boot -fstype=ext2 :/dev/hda1 removable -fstype=ext2 :/dev/hdd cd -fstype=iso9660,ro :/dev/hdc -floppy -fstype=msdos :/dev/fd0 +floppy -fstype=auto :/dev/fd0 diff -urN autofs-0.3.12/samples/rc.autofs autofs-0.3.13-pre2/samples/rc.autofs --- autofs-0.3.12/samples/rc.autofs Tue Sep 16 17:44:50 1997 +++ autofs-0.3.13-pre2/samples/rc.autofs Wed Sep 17 18:15:17 1997 @@ -1,83 +1,123 @@ -#!/bin/bash - +#! /bin/bash # -# On most distributions, this file should be called: -# /etc/rc.d/init.d/autofs or /etc/init.d/autofs +# rc file for automount using a Sun-style "master map". +# We first look for a local /etc/auto.master, then a YP +# map with that name +# +# On most distributions, this file should be called: +# /etc/rc.d/init.d/autofs or /etc/init.d/autofs # -# --- USED FOR THE DEBIAN DISTRIBUTION --- -# The following value is extracted by debstd to figure out how to generate -# the postinst script. Edit the field to change the way the script is -# registered through update-rc.d (see the manpage for update-rc.d!) -FLAGS="defaults 19" +# This is used in the Debian distribution to determine the proper +# location for the S- and K-links to this init file. +# The following value is extracted by debstd to figure out how to +# generate the postinst script. Edit the field to change the way the +# script is registered through update-rc.d (see the manpage for +# update-rc.d!) +# +FLAGS="defaults 21" -test -x /usr/sbin/automount || exit 0 +test -f /usr/sbin/automount || exit 0 PATH=/sbin:/usr/sbin:/bin:/usr/bin export PATH # -# rc file for automount using a Sun-style "master map". -# We first look for a local /etc/auto.master, then a YP map with that name +# We can add local options here +# e.g. localoptions='rsize=8192,wsize=8192' # - -# We can add local options here -# e.g. localoptions='rsize=8192,wsize=8192' localoptions='' -# This function will build a list of automount commands to execute in order -# to activate all the mount points. It is used to figure out the difference -# of automount points in case of a reload +# +# This function will build a list of automount commands to execute in +# order # to activate all the mount points. It is used to figure out +# the difference of automount points in case of a reload +# function getmounts() { -# Check for local maps to be loaded -if [ -f /etc/auto.master ]; then -cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| ( - while read dir map options; do - if [ ! -z "$dir" -a ! -z "$map" \ - -a x`echo "$map" | cut -c1` != 'x-' ]; then - map=`echo "/etc/$map" | sed -e 's:^/etc//:/:'` - options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'` - if [ -x $map ]; then - echo "automount $dir program $map $options $localoptions" - else - echo "automount $dir file $map $options $localoptions" - fi +# +# Check for local maps to be loaded +# +if [ -f /etc/auto.master ] +then + cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| ( + while read dir map options + do + if [ ! -z "$dir" -a ! -z "$map" \ + -a x`echo "$map" | cut -c1` != 'x-' ] + then + map=`echo "/etc/$map" | sed -e 's:^/etc//:/:'` + options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'` + if [ -x $map ]; then + echo "automount $dir program $map $options $localoptions" + else + echo "automount $dir file $map $options $localoptions" fi + fi done -) + ) fi -# Check for YellowPage maps to be loaded -if [ -e /usr/bin/ypcat ]; then - if [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]; then - ypcat -k auto.master | ( - while read dir map options; do - if [ -z "$dir" -a ! -z "$map" \ - -a x`echo "$map" | cut -c1` != 'x-' ]; then - map=`echo "$map" | sed -e 's/^auto_/auto./'` - options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'` - echo "automount $dir yp $map $options $localoptions" - fi - done - ) - fi + +# +# Check for YellowPage maps to be loaded +# +if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ] +then + ypcat -k auto.master | ( + while read dir map options + do + if [ ! -z "$dir" -a ! -z "$map" \ + -a x`echo "$map" | cut -c1` != 'x-' ] + then + map=`echo "$map" | sed -e 's/^auto_/auto./'` + options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'` + echo "automount $dir yp $map $options $localoptions" + fi + done + ) fi } -# See how we were called. +# +# Status lister. +# +function status() +{ + echo "Configured Mount Points:" + echo "------------------------" + getmounts + echo "" + echo "Active Mount Points:" + echo "--------------------" + ps ax|grep "[0-9]:[0-9][0-9] automount " | ( + while read pid tt stat time command; do echo $command; done + ) +} + + +# +# Redhat start/stop function. +# +function redhat() +{ + +# +# See how we were called. +# case "$1" in start) # Check if the automounter is already running? if [ ! -f /var/lock/automount ]; then echo 'Starting automounter: ' getmounts | sh - touch /var/lock/automount + touch /var/lock/subsys/automount fi ;; stop) killall -TERM automount - rm -f /var/lock/automount + rm -f /var/lock/subsys/automount ;; reload|restart) - if [ ! -f /var/lock/automount ]; then + if [ ! -f /var/lock/subsys/automount ]; then echo "Automounter not running" exit 1 fi @@ -103,19 +143,83 @@ rm $TMP1 $TMP2 ;; status) - echo "Configured Mount Points:" - echo "------------------------" - getmounts - echo "" - echo "Active Mount Points:" - echo "--------------------" - ps ax|grep "[0-9]:[0-9][0-9] automount " | ( - while read pid tt stat time command; do echo $command; done - ) + status ;; *) echo "Usage: /etc/init.d/autofs {start|stop|restart|reload|status}" exit 1 esac +} + +# +# Debian start/stop functions. +# +function debian() +{ + +DAEMON=/usr/sbin/automount + +# +# See how we were called. +# +case "$1" in + start) + echo -n 'Starting automounter:' + getmounts | while read cmd mnt rest + do + echo -n " $mnt" + pidfile=/var/run/automount`echo $mnt | sed 's/\//./'`.pid + start-stop-daemon --start --pidfile $pidfile --quiet \ + --exec $DAEMON -- $mnt $rest + # + # Automount needs a '--pidfile' or '-p' option. + # For now we look for the pid ourself. + # + ps ax | grep "[0-9]:[0-9][0-9] $DAEMON $mnt" | ( + read pid rest + echo $pid > $pidfile + echo "$mnt $rest" >> $pidfile + ) + done + echo "." + ;; + stop) + echo 'Stopping automounter.' + start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON + ;; + reload|restart) + echo "Reloading automounter: checking for changes ... " + TMP=/var/run/automount.tmp + getmounts >$TMP + for i in /var/run/automount.*.pid + do + pid=`head -n 1 $i 2>/dev/null` + [ "$pid" = "" ] && continue + command=`tail +2 $i` + if ! grep -q "^$command" $TMP + then + echo "Stopping automounter: $command" + kill -USR2 $pid + fi + done + rm -f $TMP + /etc/init.d/autofs start + ;; + status) + status + ;; + *) + echo "Usage: /etc/init.d/autofs {start|stop|restart|reload|status}" >&2 + exit 1 + ;; +esac +} + +if [ -f /etc/debian_version ] +then + debian "$@" +else + redhat "$@" +fi exit 0