[stunnel-users] stunnel with libwrap does not disconnect from terminal

Rodrigo Gallardo rodrigo at debian.org
Sun Mar 1 22:21:48 CET 2009


On Wed, Jan 21, 2009 at 02:20:16AM +0100, Lars Kruse wrote:
> Hi,
> 
> > starting with v4.21, stunnel does not disconnect from the terminal anymore.
> > This can cause problems, if the caller does not redirect stdout/stderr
> > to /dev/null. This did not happen with v4.20.
> 
> does anybody have any comments on this?

I've come up with a better looking patch. It appears that, on Linux at
least, simply closing std{in,out,err} in the libwrap helper processes
is enough to fix this.

I'd be glad if someone could check the behaviour in other OSs.

----------------------------------------------------------------------
--- stunnel4.orig/src/libwrap.c
+++ stunnel4/src/libwrap.c
@@ -81,6 +81,12 @@
         case  0:    /* child */
             drop_privileges(); /* libwrap processes are not chrooted */
             /* FIXME: other file descriptors are not closed */
+            if (!options.option.foreground) {
+              /* Detach from terminal. */
+              close(0);
+              close(1);
+              close(2);
+            }
             close(ipc_socket[2*i]); /* server-side socket */
             for(j=0; j<i; ++j) /* previously created client-side sockets */
                 close(ipc_socket[2*j+1]);
----------------------------------------------------------------------



More information about the stunnel-users mailing list