]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/detach.c
Happy New Year!
[openldap] / libraries / liblutil / detach.c
index 90a6cf34ca8a43c601b99e9b47cac705bf9c771e..add996e580e69d8dacc0c1f70ac424152c0cd9aa 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2016 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include "lutil.h"
 
-void
+int
 lutil_detach( int debug, int do_close )
 {
-       int             i, sd, nbits;
+       int             i, sd, nbits, pid;
 
 #ifdef HAVE_SYSCONF
        nbits = sysconf( _SC_OPEN_MAX );
@@ -71,10 +71,11 @@ lutil_detach( int debug, int do_close )
        if ( debug == 0 ) {
                for ( i = 0; i < 5; i++ ) {
 #ifdef HAVE_THR
-                       switch ( fork1() )
+                       pid = fork1();
 #else
-                       switch ( fork() )
+                       pid = fork();
 #endif
+                       switch ( pid )
                        {
                        case -1:
                                sleep( 5 );
@@ -84,7 +85,7 @@ lutil_detach( int debug, int do_close )
                                break;
 
                        default:
-                               _exit( EXIT_SUCCESS );
+                               return pid;
                        }
                        break;
                }
@@ -128,7 +129,7 @@ lutil_detach( int debug, int do_close )
 
 #ifdef HAVE_SETSID
                (void) setsid();
-#elif TIOCNOTTY
+#elif defined(TIOCNOTTY)
                if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) {
                        (void) ioctl( sd, TIOCNOTTY, NULL );
                        (void) close( sd );
@@ -139,4 +140,5 @@ lutil_detach( int debug, int do_close )
 #ifdef SIGPIPE
        (void) SIGNAL( SIGPIPE, SIG_IGN );
 #endif
+       return 0;
 }