Fortuned's Main Loop /* this is the main loop */ while(1){ FILE* pipe_in; char readbuf[1024]; fd_set wset; /* first of all, open the device file for writing */ fd = open(device_file, OPEN_FLAGS, OPEN_COMMON); log ("succesfully opened!"); if (fd == -1){ snprintf(errstring, sizeof(errstring), "failed to open the fifo. error '%s'", strerror(errno)); goto cleanup; } /* first of all, make sure we handle SIGPIPE gracefully */ signal(SIGPIPE, sigpipehandler); /* we open a pipe with the fortune binary */ if ((pipe_in = popen(FORTUNE_BINARY, "r")) == NULL){ snprintf(errstring, sizeof(errstring), "could not popen(%s)", FORTUNE_BINARY); goto cleanup; }