--- smbmount.c.orig 2005-12-07 17:56:01.418146155 +0100 +++ smbmount.c 2005-12-11 12:19:10.414024672 +0100 @@ -61,6 +61,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; @@ -74,6 +79,13 @@ 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 ) { @@ -91,6 +103,14 @@ exit(WEXITSTATUS(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("/"); }