From e2dda7d1aa5b00505b84186b7e7c9626eae94660 Mon Sep 17 00:00:00 2001 From: Michael Warfield Date: Mon, 1 Feb 1999 22:03:11 +0000 Subject: ` --- source/client/smbmount.c | 73 +++++++++++++++++++++++++++++++++++------------ source/client/smbumount.c | 8 ++++++ 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/source/client/smbmount.c b/source/client/smbmount.c index 430e498d937..00331f36819 100644 --- a/source/client/smbmount.c +++ b/source/client/smbmount.c @@ -38,7 +38,7 @@ static struct smb_conn_opt conn_options; #endif /* Uncomment this to allow debug the smbmount daemon */ -#define SMBFS_DEBUG 1 +/* #define SMBFS_DEBUG 1 */ pstring cur_dir = "\\"; pstring cd_path = ""; @@ -71,7 +71,6 @@ extern int name_type; extern int max_protocol; int port = SMB_PORT; - time_t newer_than = 0; int archive_level = 0; @@ -181,20 +180,51 @@ static BOOL chkpath(char *path,BOOL report) return(CVAL(inbuf,smb_rcls) == 0); } +static void +exit_parent( int sig ) +{ + /* parent simply exits when child says go... */ + exit(0); +} + static void daemonize(void) { - int i; - if ((i = fork()) < 0) + int j, status; + pid_t child_pid; + + signal( SIGTERM, exit_parent ); + + if ((child_pid = fork()) < 0) { DEBUG(0, ("could not fork\n")); } - if (i > 0) + if (child_pid > 0) { - /* parent simply exits */ - exit(0); + while( 1 ) { + j = waitpid( child_pid, &status, 0 ); + if( j < 0 ) { + if( EINTR == errno ) { + continue; + } + status = errno; + } + break; + } + /* If we get here - the child exited with some error status */ + exit(status); } - setsid(); + /* Programmers Note: + Danger Will Robinson! Danger! + + There use to be a call to setsid() here. This does no + harm to normal mount operations, but it broke automounting. + The setsid call has been moved to just before the child + sends the SIGTERM to the parent. All of our deadly embrace + conditions with autofs will have been cleared by then... + -mhw- + */ + signal( SIGTERM, SIG_DFL ); chdir("/"); } @@ -255,7 +285,8 @@ static void send_fs_socket(char *mount_point, char *inbuf, char *outbuf) { int fd, closed = 0, res = 1; - int first_time = 1; + + pid_t parentpid = getppid(); while (1) { @@ -278,6 +309,15 @@ send_fs_socket(char *mount_point, char *inbuf, char *outbuf) DEBUG(0, ("smbmount: ioctl failed, res=%d\n", res)); } + if( parentpid ) { + /* Ok... We are going to kill the parent. Now + is the time to break the process group... */ + setsid(); + /* Send a signal to the parent to terminate */ + kill( parentpid, SIGTERM ); + parentpid = 0; + } + close_sockets(); close(fd); /* @@ -291,15 +331,6 @@ send_fs_socket(char *mount_point, char *inbuf, char *outbuf) } #endif - if( first_time ) { - /* - * Create the background process after trying the mount. - * to avoid race conditions with automount and other processes. - */ - first_time = 0; - daemonize(); - } - /* * Wait for a signal from smbfs ... */ @@ -368,6 +399,12 @@ static void cmd_mount(char *inbuf,char *outbuf) DEBUG(3, ("mount command: %s\n", mount_command)); + /* + Set up to return as a daemon child and wait in the parent + until the child say it's ready... + */ + daemonize(); + if ((retval = system(mount_command)) != 0) { DEBUG(0,("mount failed\n")); diff --git a/source/client/smbumount.c b/source/client/smbumount.c index 5e072274c95..84188542e59 100644 --- a/source/client/smbumount.c +++ b/source/client/smbumount.c @@ -15,6 +15,14 @@ #include #include +/* This is a (hopefully) temporary hack due to the fact that + sizeof( uid_t ) != sizeof( __kernel_uid_t ) under glibc. + This may change in the future and smb.h may get fixed in the + future. In the mean time, it's ugly hack time - get over it. +*/ +#undef SMB_IOC_GETMOUNTUID +#define SMB_IOC_GETMOUNTUID _IOR('u', 1, __kernel_uid_t) + static char *progname; static void -- cgit