Earlier fix for smbmount timing window was the wrong patch.
[samba.git] / source / client / smbmount.c
index 95aeecde3c55f21965fd024887a09bddc33ca15e..2cfd166688eba34f3d5a472fa8e711987950dbbb 100644 (file)
@@ -28,6 +28,8 @@
 #endif
 
 #include "includes.h"
+
+#include <asm/types.h>
 #include <linux/smb_fs.h>
 static struct smb_conn_opt conn_options;
 
@@ -78,12 +80,10 @@ extern int DEBUGLEVEL;
 
 BOOL translation = False;
 
-extern int cnum;
-extern int mid;
-extern int pid;
-extern int tid;
-extern int gid;
-extern int uid;
+extern uint16 cnum;
+extern uint16 mid;
+extern uint16 pid;
+extern uint16 vuid;
 
 extern BOOL have_ip;
 extern int max_xmit;
@@ -95,7 +95,7 @@ extern BOOL tar_reset;
 /* clitar bits end */
  
 
-int myumask = 0755;
+mode_t myumask = 0755;
 
 extern pstring scope;
 
@@ -231,7 +231,7 @@ static BOOL mount_send_login(char *inbuf, char *outbuf)
   conn_options.protocol = opt.protocol;
   conn_options.case_handling = CASE_LOWER;
   conn_options.max_xmit = opt.max_xmit;
-  conn_options.server_uid = opt.server_uid;
+  conn_options.server_uid = opt.server_vuid;
   conn_options.tid = opt.tid;
   conn_options.secmode = opt.sec_mode;
   conn_options.maxmux = opt.max_mux;
@@ -255,6 +255,7 @@ static void
 send_fs_socket(char *mount_point, char *inbuf, char *outbuf)
 {
        int fd, closed = 0, res = 1;
+       int first_time = 1;
 
        while (1)
        {
@@ -290,6 +291,15 @@ 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 ...
                 */
@@ -358,18 +368,12 @@ static void cmd_mount(char *inbuf,char *outbuf)
 
        DEBUG(3, ("mount command: %s\n", mount_command));
 
-       /*
-        * Create the background process before trying the mount.
-        * (We delay closing files to allow diagnostic messages.)
-        */
-       daemonize();
-
-       /* The parent has exited here, the child handles the connection: */
        if ((retval = system(mount_command)) != 0)
        {
                DEBUG(0,("mount failed\n"));
                exit(1);
        }
+
        send_fs_socket(mount_point, inbuf, outbuf);
 }      
 
@@ -640,9 +644,8 @@ static void usage(char *pname)
   TimeInit();
   charset_initialise();
 
-  pid = getpid();
-  uid = getuid();
-  gid = getgid();
+  pid = (uint16)getpid();
+  vuid = (uint16)getuid();
   mid = pid + 100;
   myumask = umask(0);
   umask(myumask);