From f3db3e0a8f1ddcb5af7d0de35c827048ebfa562d Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 5 Nov 1998 01:56:41 +0000 Subject: [PATCH] replace detach.c with lutil_detach() --- clients/gopher/Makefile.in | 6 +-- clients/gopher/detach.c | 87 ------------------------------- clients/gopher/go500.c | 3 +- clients/gopher/go500gw.c | 3 +- servers/ldapd/Makefile.in | 4 +- servers/ldapd/detach.c | 95 ---------------------------------- servers/ldapd/main.c | 16 +++--- servers/slurpd/Makefile.in | 4 +- servers/slurpd/detach.c | 103 ------------------------------------- servers/slurpd/main.c | 5 +- 10 files changed, 23 insertions(+), 303 deletions(-) delete mode 100644 clients/gopher/detach.c delete mode 100644 servers/ldapd/detach.c delete mode 100644 servers/slurpd/detach.c diff --git a/clients/gopher/Makefile.in b/clients/gopher/Makefile.in index baa5437cb0..6ce58c5014 100644 --- a/clients/gopher/Makefile.in +++ b/clients/gopher/Makefile.in @@ -3,10 +3,10 @@ ## PROGRAMS= go500gw go500 -SRCS= detach.c go500.c go500gw.c +SRCS= go500.c go500gw.c XSRCS= gwversion.o goversion.o -GOOBJS = go500.o detach.o -GWOBJS = go500gw.o detach.o +GOOBJS = go500.o +GWOBJS = go500gw.o LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/clients/gopher/detach.c b/clients/gopher/detach.c deleted file mode 100644 index 8a8baa670c..0000000000 --- a/clients/gopher/detach.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1990, 1994 Regents of the University of Michigan. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that this notice is preserved and that due credit is given - * to the University of Michigan at Ann Arbor. The name of the University - * may not be used to endorse or promote products derived from this - * software without specific prior written permission. This software - * is provided ``as is'' without express or implied warranty. - */ - -#include "portable.h" - -#include -#include - -#include -#include -#include - -#include - -detach( debug ) -int debug; -{ - int i, sd, nbits; - -#if defined( HAVE_SYSCONF ) - nbits = sysconf( _SC_OPEN_MAX ); -#elif defined( HAVE_GETDTABLESIZE ) - nbits = getdtablesize(); -#else - nbits = FD_SETSIZE; -#endif - -#ifdef FD_SETSIZE - if (nbits > FD_SETSIZE) { - nbits = FD_SETSIZE; - } -#endif /* FD_SETSIZE*/ - - if ( debug == 0 || !(isatty( 1 )) ) { - for ( i = 0; i < 5; i++ ) { - switch ( fork() ) { - case -1: - sleep( 5 ); - continue; - - case 0: - break; - - default: - _exit( 0 ); - } - break; - } - - for ( i = 3; i < nbits; i++ ) - close( i ); - - (void) chdir( "/" ); - - if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) { - if ( debug ) perror( "/dev/null" ); - exit( 1 ); - } - if ( isatty( 0 ) ) - (void) dup2( sd, 0 ); - if ( isatty( 1 ) ) - (void) dup2( sd, 1 ); - if ( isatty(2) ) - (void) dup2( sd, 2 ); - close( sd ); - -#ifdef HAVE_SETSID - (void) setsid(); -#else /* HAVE_SETSID */ - if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) { - (void) ioctl( sd, TIOCNOTTY, NULL ); - (void) close( sd ); - } -#endif /* HAVE_SETSID */ - } - - (void) signal( SIGPIPE, SIG_IGN ); -} diff --git a/clients/gopher/go500.c b/clients/gopher/go500.c index 3a951d9a6f..e9cb600ef8 100644 --- a/clients/gopher/go500.c +++ b/clients/gopher/go500.c @@ -35,6 +35,7 @@ #include "lber.h" #include "ldap.h" #include "ldap_log.h" +#include "lutil.h" #include "disptmpl.h" @@ -158,7 +159,7 @@ char **argv; /* detach if stderr is redirected or no debugging */ if ( inetd == 0 ) - (void) detach( debug ); + lutil_detach( debug && !isatty( 1 ), 1 ); if ( (myname = strrchr( argv[0], '/' )) == NULL ) myname = strdup( argv[0] ); diff --git a/clients/gopher/go500gw.c b/clients/gopher/go500gw.c index 3a0dab6775..bf25933d3f 100644 --- a/clients/gopher/go500gw.c +++ b/clients/gopher/go500gw.c @@ -34,6 +34,7 @@ #include "lber.h" #include "ldap.h" #include "ldap_log.h" +#include "lutil.h" #include "disptmpl.h" @@ -180,7 +181,7 @@ char **argv; /* detach if stderr is redirected or no debugging */ if ( inetd == 0 ) - (void) detach( debug ); + lutil_detach( debug && !isatty( 1 ), 1 ); if ( (myname = strrchr( argv[0], '/' )) == NULL ) myname = strdup( argv[0] ); diff --git a/servers/ldapd/Makefile.in b/servers/ldapd/Makefile.in index d45e02e38c..190e570f60 100644 --- a/servers/ldapd/Makefile.in +++ b/servers/ldapd/Makefile.in @@ -3,10 +3,10 @@ ## PROGRAMS=ldapd XPROGRAMS=sldapd -SRCS = main.c detach.c request.c bind.c result.c error.c \ +SRCS = main.c request.c bind.c result.c error.c \ search.c util.c compare.c message.c add.c delete.c modrdn.c modify.c \ abandon.c syntax.c association.c kerberos.c certificate.c -OBJS = main.o detach.o request.o bind.o result.o error.o \ +OBJS = main.o request.o bind.o result.o error.o \ search.o util.o compare.o message.o add.o delete.o modrdn.o modify.o \ abandon.o syntax.o association.o kerberos.o LDAP_tables.o \ certificate.o diff --git a/servers/ldapd/detach.c b/servers/ldapd/detach.c deleted file mode 100644 index 672ccfda13..0000000000 --- a/servers/ldapd/detach.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1990, 1994 Regents of the University of Michigan. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that this notice is preserved and that due credit is given - * to the University of Michigan at Ann Arbor. The name of the University - * may not be used to endorse or promote products derived from this - * software without specific prior written permission. This software - * is provided ``as is'' without express or implied warranty. - */ - -#include "portable.h" - -#include - -#include -#include - -#include -#include -#include -#include - - -detach() -{ - int i, sd, nbits; -#ifdef LDAP_DEBUG - extern int ldap_debug; -#endif - -#ifdef HAVE_SYSCONF - nbits = sysconf( _SC_OPEN_MAX ); -#elif HAVE_GETDTABLESIZE - nbits = getdtablesize(); -#else - nbits = FD_SETSIZE -#endif - -#ifdef FD_SETSIZE - if( nbits > FD_SETSIZE ) { - nbits = FD_SETSIZE; - } -#endif /* FD_SETSIZE */ - -#ifdef LDAP_DEBUG - if ( ldap_debug == 0 ) { -#endif - for ( i = 0; i < 5; i++ ) { - switch ( fork() ) { - case -1: - sleep( 5 ); - continue; - - case 0: - break; - - default: - _exit( 0 ); - } - break; - } - - for ( i = 3; i < nbits; i++ ) - close( i ); - - (void) chdir( "/" ); - - if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) { - perror( "/dev/null" ); - exit( 1 ); - } - if ( isatty( 0 ) ) - (void) dup2( sd, 0 ); - if ( isatty( 1 ) ) - (void) dup2( sd, 1 ); - if ( isatty(2) ) - (void) dup2( sd, 2 ); - close( sd ); - -#ifdef HAVE_SETSID - setsid(); -#else /* HAVE_SETSID */ - if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) { - (void) ioctl( sd, TIOCNOTTY, NULL ); - (void) close( sd ); - } -#endif /* HAVE_SETSID */ -#ifdef LDAP_DEBUG - } -#endif - - (void) signal( SIGPIPE, SIG_IGN ); -} diff --git a/servers/ldapd/main.c b/servers/ldapd/main.c index 51d5791b46..0d7933d202 100644 --- a/servers/ldapd/main.c +++ b/servers/ldapd/main.c @@ -263,11 +263,15 @@ char **argv; * that have exited */ if (!RunFromInetd) { -#ifdef LDAP_SETPROCTITLE +#ifdef LDAP_PROCTITLE setproctitle( "initializing" ); #endif #ifndef VMS - (void) detach(); +# ifdef LDAP_DEBUG + lutil_detach( ldap_debug, 1 ); +# else + lutil_detach( 0, 1 ); +# endif #endif (void) SIGNAL( SIGCHLD, (void *) wait4child ); (void) SIGNAL( SIGINT, (void *) log_and_exit ); @@ -333,7 +337,7 @@ char **argv; inet_ntoa( from.sin_addr ) ); } -#ifdef LDAP_SETPROCTITLE +#ifdef LDAP_PROCTITLE sprintf( title, "%s %d\n", hp == NULL ? inet_ntoa( from.sin_addr ) : hp->h_name, myport ); setproctitle( title ); @@ -358,7 +362,7 @@ char **argv; * if we are doing CLDAP as well, handle those requests on the fly */ -#ifdef LDAP_SETPROCTITLE +#ifdef LDAP_PROCTITLE #ifdef LDAP_CONNECTIONLESS sprintf( title, "listening %s/%s %d", do_tcp ? "tcp" : "", do_udp ? "udp" : "", myport ); @@ -439,7 +443,7 @@ char **argv; #ifdef VMS /* This is for debug on terminal on VMS */ close( tcps ); -#ifdef LDAP_SETPROCTITLE +#ifdef LDAP_PROCTITLE setproctitle( hp == NULL ? inet_ntoa( from.sin_addr ) : hp->h_name ); #endif @@ -453,7 +457,7 @@ char **argv; switch( pid = fork() ) { case 0: /* child */ close( tcps ); -#ifdef LDAP_SETPROCTITLE +#ifdef LDAP_PROCTITLE sprintf( title, "%s (%d)\n", hp == NULL ? inet_ntoa( from.sin_addr ) : hp->h_name, myport ); diff --git a/servers/slurpd/Makefile.in b/servers/slurpd/Makefile.in index 38d674afc0..cabff13e50 100644 --- a/servers/slurpd/Makefile.in +++ b/servers/slurpd/Makefile.in @@ -3,11 +3,11 @@ ## PROGRAMS = slurpd -SRCS = admin.c args.c ch_malloc.c config.c detach.c \ +SRCS = admin.c args.c ch_malloc.c config.c \ fm.c globals.c ldap_op.c lock.c main.c re.c \ reject.c replica.c replog.c ri.c rq.c sanity.c st.c \ tsleep.c -OBJS = admin.o args.o ch_malloc.o config.o detach.o \ +OBJS = admin.o args.o ch_malloc.o config.o \ fm.o globals.o ldap_op.o lock.o main.o re.o \ reject.o replica.o replog.o ri.o rq.o sanity.o st.o \ tsleep.o diff --git a/servers/slurpd/detach.c b/servers/slurpd/detach.c deleted file mode 100644 index 0f0d36f580..0000000000 --- a/servers/slurpd/detach.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 1990, 1994 Regents of the University of Michigan. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that this notice is preserved and that due credit is given - * to the University of Michigan at Ann Arbor. The name of the University - * may not be used to endorse or promote products derived from this - * software without specific prior written permission. This software - * is provided ``as is'' without express or implied warranty. - */ - -#include "portable.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "portable.h" - -detach() -{ - int i, sd, nbits; -#ifdef LDAP_DEBUG - extern int ldap_debug; -#endif - -#ifdef HAVE_SYSCONF - nbits = sysconf( _SC_OPEN_MAX ); -#elif HAVE_GETDTABLESIZE - nbits = getdtablesize(); -#else - nbits = FD_SETSIZE; -#endif - -#ifdef FD_SETSIZE - if ( nbits > FD_SETSIZE ) { - nbits = FD_SETSIZE; - } -#endif /* FD_SETSIZE */ - -#ifdef LDAP_DEBUG - if ( ldap_debug == 0 ) { -#endif - for ( i = 0; i < 5; i++ ) { -#if HAVE_THR - switch ( fork1() ) { -#else - switch ( fork() ) { -#endif - case -1: - sleep( 5 ); - continue; - - case 0: - break; - - default: - _exit( 0 ); - } - break; - } - -/* - for ( i = 3; i < nbits; i++ ) - close( i ); -*/ - - (void) chdir( "/" ); - - if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) { - perror( "/dev/null" ); - exit( 1 ); - } - if ( isatty( 0 ) ) - (void) dup2( sd, 0 ); - if ( isatty( 1 ) ) - (void) dup2( sd, 1 ); - if ( isatty(2) ) - (void) dup2( sd, 2 ); - close( sd ); - -#ifdef HAVE_SETSID - setsid(); -#else /* HAVE_SETSID */ - if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) { - (void) ioctl( sd, TIOCNOTTY, NULL ); - (void) close( sd ); - } -#endif /* HAVE_SETSID */ -#ifdef LDAP_DEBUG - } -#endif - - (void) SIGNAL( SIGPIPE, SIG_IGN ); -} diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index d780ed3038..061aefa080 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -21,6 +21,7 @@ #include "slurp.h" #include "globals.h" +#include "lutil.h" extern int doargs( int, char **, Globals * ); @@ -100,9 +101,7 @@ main( #else /* LDAP_DEBUG */ if ( !sglob->one_shot_mode ) #endif /* LDAP_DEBUG */ - { - detach(); - } + lutil_detach( 0, 0 ); #if defined( HAVE_LWP ) /* -- 2.39.5