[Samba] smbmount patch

Nickey tux at hotbox.ru
Wed Nov 12 07:30:51 GMT 2003


Hi there!

Samba-2.2.8a

There is possible deadlock in smbmount (smbmount.c) when parent process forking.
Maybe this is a Linux-only bug (2.4 and 2.6 shows the same). But this is enough to
apply my patch (or make other proper thing[s]).
Explaining:

Smbmount need to be a daemon to serve the mountpoint.
Parent make [sys_]fork() to create this young daemon.
After sys_fork() children go ahead and kill(parentpid, SIGTERM).
BUT! Parent sometimes late to finish his sys_fork() :((
I don't know why. And when he still in fork() and children kill(perentpid,SIGTERM)'s him
parent calls exit(), but after this begin some maybe "proper" freeing of something by libs (saw with gdb)
and process deadlocking somehow.
This moment need proper syncronization in any case.
The mechanism is just like the children say to perant to exit: parent says to children to wake up
after sys_fork() when parent exits from it too.
So, this is the patch to smbmount.c:
--- a/source/client/smbmount.c       2002-04-30 16:26:19.000000000 +0300
+++ b/source/client/smbmount.c    2003-11-12 08:13:41.580181864 +0200
@@ -59,6 +59,11 @@
        exit(0);
 }

+static void parent_is_ready(int sig)
+{
+       /* just continue to execute - parent is ready to die :)) */
+}
+
 static void daemonize(void)
 {
        int j, status;
@@ -72,6 +77,12 @@

        if (child_pid > 0) {
                while( 1 ) {
+                       /*
+                        * Funny, isn't it? ;))
+                        * But children is pause()ing for this signal
+                        * to go and do preporly thing with parent.
+                        */
+                       kill(child_pid, SIGTERM);
                        j = waitpid( child_pid, &status, 0 );
                        if( j < 0 ) {
                                if( EINTR == errno ) {
@@ -85,6 +96,14 @@
                exit(status);
        }

+        /*
+         * Sometimes parent stay in sys_fork() during children already kill()ing him!
+         * Deadlock in parent's code as result :(
+         * Wait for parent's SIGTERM to indicate it's readyness after sys_fork()ing.
+         */
+       signal( SIGTERM, parent_is_ready );
+       pause();
+
        signal( SIGTERM, SIG_DFL );
        chdir("/");
 }


More information about the samba mailing list