[stunnel-users] stunnel with libwrap does not disconnect from terminal
Rodrigo Gallardo
rodrigo at debian.org
Sun Mar 1 10:44:41 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?
The following patch fixes the issue, but I think it's too heavy
handed, daemonizing each libwrap process by itself to get it detached
and thus putting each in its own process group. It confirms the
diagnostic that this is caused by those processes remaining attached
to the terminal, at least.
----------------------------------------------------------------------
diff --git a/src/libwrap.c b/src/libwrap.c
index b71fd28..7924eb3 100644
--- a/src/libwrap.c
+++ b/src/libwrap.c
@@ -80,6 +80,7 @@ void libwrap_init(int num) {
die(1);
case 0: /* child */
drop_privileges(); /* libwrap processes are not chrooted */
+ daemonize(); /* detach from terminal */
/* FIXME: other file descriptors are not closed */
close(ipc_socket[2*i]); /* server-side socket */
for(j=0; j<i; ++j) /* previously created client-side sockets */
diff --git a/src/prototypes.h b/src/prototypes.h
index e0efabd..fad8c59 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -76,6 +76,9 @@ void main_execute(void);
#if !defined (USE_WIN32) && !defined (__vms) && !defined(USE_OS2)
void drop_privileges(void);
#endif
+#if !defined (USE_WIN32) && !defined (__vms)
+void daemonize(void);
+#endif
void stunnel_info(int);
void die(int);
diff --git a/src/stunnel.c b/src/stunnel.c
index 9d18782..86df5ab 100644
--- a/src/stunnel.c
+++ b/src/stunnel.c
@@ -44,7 +44,6 @@ static void accept_connection(LOCAL_OPTIONS *);
static void get_limits(void); /* setup global max_clients and max_fds */
#if !defined (USE_WIN32) && !defined (__vms)
static void change_root(void);
-static void daemonize(void);
static void create_pid(void);
static void delete_pid(void);
#endif
@@ -347,7 +346,7 @@ void drop_privileges(void) {
}
}
-static void daemonize(void) { /* go to background */
+void daemonize(void) { /* go to background */
#if defined(HAVE_DAEMON) && !defined(__BEOS__)
if(daemon(0, 0)==-1) {
ioerror("daemon");
----------------------------------------------------------------------
More information about the stunnel-users
mailing list