switch (chldpid=fork()){
case -1:
if(VERBOSENESS>0) fprintf(MSGPIPE,"* ERROR: fork() failed!\n");
clean_exit(1);
case 0:
child();
default:
parent();
}
clean_exit(0);
}
void parent(void){
int num_read;
fd_set rfds;
struct sigaction act;
close(ipcpipe[0]);
act.sa_handler = sig_chld;
sigemptyset(&act.sa_mask);
//act.sa_flags = SA_NOCLDSTOP;
if (sigaction(SIGCHLD, &act, NULL) < 0){
if(VERBOSENESS>0) fprintf(MSGPIPE, "* ERROR: Sigaction failed\n");
clean_exit(1);
}
strncpy(buffer, COMMANDS, BUFSIZE);
write(ipcpipe[1], buffer, strlen(COMMANDS));
if(VERBOSENESS>0) fprintf(MSGPIPE, "* INFO: version %s\n", VERSION);
FD_ZERO(&rfds);
while(1){
FD_SET(0, &rfds);
if (select(1, &rfds, NULL, NULL, NULL) > 0) {
if ((num_read = read(STDIN_FILENO, buffer, BUFSIZE))== 0) {
if(VERBOSENESS>1) fprintf(MSGPIPE, "* DEBUG: EOF encountered, closing stdout and exit()\n");
strncpy(buffer, "* QUIT\n", BUFSIZE);
write(ipcpipe[1], buffer, 7);
clean_exit(0);
}
write(ipcpipe[1], buffer, num_read);
}
}
}
GENERATION 9: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
محمّد هو خنزي | "All that we are is the result of what we have thought." [Buddha] |
http://ra.phid.ae/