00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00056 #include <global.h>
00057 #ifndef __CEXTRACT__
00058 #include <sproto.h>
00059 #endif
00060 #include <sys/ioctl.h>
00061 #ifdef hpux
00062 #include <sys/ptyio.h>
00063 #endif
00064
00065 #include <errno.h>
00066 #include <stdio.h>
00067 #include <sys/file.h>
00068
00072 void become_daemon(void) {
00073 register int i;
00074 int forkresult;
00075
00076 fputs("\n========================\n", logfile);
00077 fputs("Begin New Server Session\n", logfile);
00078 fputs("========================\n\n", logfile);
00079
00080
00081
00082
00083
00084
00085 if ((forkresult = fork())) {
00086 if (forkresult < 0) {
00087 perror("Fork error!");
00088 }
00089 exit(0);
00090 }
00091
00092
00093
00094
00095
00096 close(0);
00097 close(1);
00098 close(2);
00099
00100
00101
00102
00103 (void)open("/dev/null", O_RDONLY);
00104 (void)dup2(0, 1);
00105 (void)dup2(0, 2);
00106
00107 if ((i = open("/dev/tty", O_RDWR)) >= 0) {
00108 #if (defined(SYSV) || defined(hpux)) && defined(TIOCTTY)
00109 int zero = 0;
00110 (void)ioctl(i, TIOCTTY, &zero);
00111 #else
00112
00113 # ifdef HAVE_SYS_TERMIOS_H
00114 # include <sys/termios.h>
00115 # else
00116 # ifdef HAVE_SYS_TTYCOM_H
00117 # include <sys/ttycom.h>
00118 # endif
00119 # endif
00120 (void)ioctl(i, TIOCNOTTY, (char *)0);
00121 #endif
00122 (void)close(i);
00123 }
00124
00125 #ifdef HAVE_SETSID
00126 setsid();
00127 #else
00128
00129 # if defined(SYSV) || defined(SVR4)
00130 setpgrp(0, 0);
00131 # else
00132 setpgrp(0, getpid());
00133 # endif
00134 #endif
00135 }