#undef OSF1 /* ** This code written by danny@wildstar.net <-- wildThang --> ** You are free to use this code under the stipulation that it ** is not used to design any sort of clone/flood, or otherwise harassing ** type of application. I wrote this quickly and tried to keep it as ** basic as i could think up but enough to keep it interesting. ** Use it to LEARN! let me know if you have questions about it. ** -- this notice must remain in all code based on this code. */ /* DAEMON.C This file handles moving program into the background. and it also contains the routine needed to establish a port in case of wanting to have it listne to a port as well */ #include #include #include #include #include #include #include /*#ifdef SIGTSTP */ #include #include /*#endif */ #include #include #include #include #include #include #include #include #include "config.h" handle_kids() {int pid; #ifdef OSF1 union wait *status; while( (pid = wait3(status,WNOHANG, (struct rusage *)0)) > 0) { } #else /* union wait status; */ int status; while( (pid = wait3(&status,WNOHANG, (struct rusage *)0)) > 0) { } #endif /* OSF1 */ } /* this function releases tty conrol and moves program into background */ goto_bg() { register int child,fd; close(0); close(1); close(2); if(getppid() == 1) goto out; #ifdef SIGTTOU signal(SIGTTOU,SIG_IGN); #endif #ifdef SIGTTIN signal(SIGTTIN,SIG_IGN); #endif #ifdef SIGTSTP signal(SIGTSTP,SIG_IGN); #endif if( (child =fork()) < 0) perror("fork"); else if (child > 0) exit(0); #ifdef SIGTSTP if (setpgrp(0,getpid()) == -1) perror("SETGROUP"); if( (fd = open("/dev/tty",O_RDWR)) >= 0) { ioctl(fd, TIOCNOTTY, (char *)NULL); close(fd); } #else if(setpgrp() == -1) perror("set group"); signal(SIGHUP,SIG_IGN); if( (child = fork()) < 0) perror("cant fork"); else if (child > 0) exit(0); #endif out: for(fd=0;fd 9) exit(-1); ; } else break; } listen(sock,3); return(sock); }