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/signal.h>
18 #include <ac/unistd.h>
20 #include <sys/types.h>
24 #include <sys/ioctl.h>
28 /* I'd really like to make do_close an fd_set, but that isn't portable. */
30 lutil_detach( int debug, int do_close )
35 nbits = sysconf( _SC_OPEN_MAX );
36 #elif HAVE_GETDTABLESIZE
37 nbits = getdtablesize();
43 if ( nbits > FD_SETSIZE ) {
46 #endif /* FD_SETSIZE */
49 for ( i = 0; i < 5; i++ ) {
70 for ( i = 3; i < nbits; i++ )
75 if ( (sd = open( "/dev/null", O_RDWR )) == -1 ) {
76 perror( "/dev/null" );
79 for ( i = 0; i < 3; i++ )
80 if ( sd != i && isatty( i ) )
87 #else /* HAVE_SETSID */
88 if ( (sd = open( "/dev/tty", O_RDWR )) != -1 ) {
89 (void) ioctl( sd, TIOCNOTTY, NULL );
92 #endif /* HAVE_SETSID */
95 (void) SIGNAL( SIGPIPE, SIG_IGN );