fclose(foo);
void runDaemon(int sock) {   struct sockaddr_un addr;   int x,len,addrlen,recvsock,done=0;   char *message;   struct stat s1,s2;   struct pollfd pfds;    FILE *foo;        foo=fopen("./foo","a");	    daemon(0,-1);    /* try not to leave stale sockets lying around */    /* Hopefully, we won't actually get any of these */    signal(SIGHUP,cleanup);    signal(SIGINT,cleanup);    signal(SIGQUIT,cleanup);    signal(SIGILL,cleanup);    signal(SIGABRT,cleanup);    signal(SIGFPE,cleanup);    signal(SIGSEGV,cleanup);    signal(SIGPIPE,cleanup);    signal(SIGBUS,cleanup);    signal(SIGTERM,cleanup);   done = 0;   /* Get stat info on dev log so we can later check to make sure we    * still own it... */   stat(_PATH_LOG,&s1);   while (!done) {      pfds.fd = sock;      pfds.events = POLLIN|POLLPRI;      if ( ( (x=poll(&pfds,1,500))==-1) && errno !=EINTR) {	 perror("poll");	 cleanup(-1);      }      if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) {	 printf("foo!\n");	 message = calloc(8192,sizeof(char));	 recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen);	 len = read(recvsock,message,8192);	 if (buffer)	   buffer = realloc(buffer,(buflines+1)*sizeof(char *));	 else	   buffer = malloc(sizeof(char *));	 if (len>0) {	     message[strlen(message)]='\n';	     fprintf(foo,"%s",message);	    buffer[buflines]=message;	    buflines++;	    close(recvsock);	 }	 else {	    close(recvsock);	    recvsock=-1;	 }      }      if ( (x>0) && ( pfds.revents & (POLLHUP | POLLNVAL)) )	done = 1;      /* Check to see if syslogd's yanked our socket out from under us */      if ( (stat(_PATH_LOG,&s2)!=0) ||	    (s1.st_ino != s2.st_ino ) || (s1.st_ctime != s2.st_ctime) ||	    (s1.st_mtime != s2.st_mtime) || (s1.st_atime != s2.st_atime) ) {	 done = 1;	 we_own_log = 0;      }   }    fclose(foo);   cleanup(0);}