2 * Copyright (c) 1990, 1994 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
17 #include <ac/stdlib.h>
18 #include <ac/signal.h>
19 #include <ac/socket.h>
20 #include <ac/unistd.h>
25 #ifdef HAVE_SYS_FILE_H
28 #ifdef HAVE_SYS_IOCTL_H
29 #include <sys/ioctl.h>
35 lutil_detach( int debug, int do_close )
40 nbits = sysconf( _SC_OPEN_MAX );
41 #elif HAVE_GETDTABLESIZE
42 nbits = getdtablesize();
48 if ( nbits > FD_SETSIZE ) {
51 #endif /* FD_SETSIZE */
54 for ( i = 0; i < 5; i++ ) {
69 _exit( EXIT_SUCCESS );
75 for ( i = 3; i < nbits; i++ )
80 if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) {
81 perror( "/dev/null" );
84 for ( i = 0; i < 3; i++ )
85 if ( sd != i && isatty( i ) )
93 if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) {
94 (void) ioctl( sd, TIOCNOTTY, NULL );
101 (void) SIGNAL( SIGPIPE, SIG_IGN );