char *b, *buf=calloc(8192,sizeof(char));
char *b, *buf=calloc(8193,sizeof(char));
int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet, int debug) {    struct pollfd *pfds;    char *outbuf=NULL;    char *tmpstr=NULL;    int x,y,rc=-1;    int done=0;    int output=0;    char **cmdargs=NULL;    char **tmpargs=NULL;    int cmdargc;    char *procpath = NULL;        if (reexec) {	procpath=malloc(20*sizeof(char));	snprintf(procpath,20,"/proc/%d",pid);    }        pfds = malloc(numfds*sizeof(struct pollfd));    for (x=0;x<numfds;x++) {	pfds[x].fd = fds[x];	pfds[x].events = POLLIN | POLLPRI;    }	    while (!done) {       usleep(500);       if (((x=poll(pfds,numfds,500))==-1)&&errno!=EINTR) {	  perror("poll");          free(pfds);          if (procpath)             free(procpath);	  return -1;       }       if (!reexec) {	  if (waitpid(pid,&rc,WNOHANG))	    done=1;       } else {	   struct stat sbuf;	   /* if /proc/pid ain't there and /proc is, it's dead... */	   if (stat(procpath,&sbuf)&&!stat("/proc/cpuinfo",&sbuf))	     done=1;       }       if (x<0)          continue;       y=0;       while (y<numfds) {	  if ( x && ((pfds[y].revents & (POLLIN | POLLPRI)) )) {	     int bytesread = 0;	     	     do {		char *b, *buf=calloc(8192,sizeof(char));		b = buf;		bytesread = read(pfds[y].fd,buf,8192);		if (bytesread==-1) {		   perror("read");                   free(pfds);                   if (procpath)                      free(procpath);                   free(buf);		   return -1;		}		if (bytesread) {		  if (!quiet && !reexec)		    write(1,buf,bytesread);		  if (quiet) {			  outbuf=realloc(outbuf,(outbuf ? strlen(outbuf)+bytesread+1 : bytesread+1));			  if (!output) outbuf[0]='\0';			  strcat(outbuf,buf);			  output = 1;		  }		  while ((tmpstr=getLine(&buf))) {		      int ignore=0;		      		      if (regList) {			  int count=0;			 			  while (regList[count]) {			      if (!regexec(regList[count],tmpstr,0,NULL,0)) {				  ignore=1;				  break;			      }			      count++;			  }		      }		      if (!ignore) {			  if (!reexec) {			      if (getenv("IN_INITLOG")) {				  char *buffer=calloc(8192,sizeof(char));				  DDEBUG("sending =%s= to initlog parent\n",tmpstr);				  snprintf(buffer,8192,"-n %s -s \"%s\"\n",					   cmdname,tmpstr);				  /* don't blow up if parent isn't there */				  signal(SIGPIPE,SIG_IGN);				  write(CMD_FD,buffer,strlen(buffer));				  signal(SIGPIPE,SIG_DFL);				  free(buffer);			      } else {				  logString(cmdname,tmpstr);			      }			  } else {			      int z; 						      cmdargs=NULL;			      tmpargs=NULL;			      cmdargc=0;			      			      poptParseArgvString(tmpstr,&cmdargc,&tmpargs);			      cmdargs=malloc( (cmdargc+2) * sizeof(char *) );			      cmdargs[0]=strdup("initlog");			      for (z=0;z<(cmdargc);z++) {				  cmdargs[z+1]=tmpargs[z];			      }			      cmdargs[cmdargc+1]=NULL;			      processArgs(cmdargc+1,cmdargs,1);			      for (z=0;z<(cmdargc);z++) {				  free(cmdargs[z]);			      }			      free(cmdargs);			  }		      }		      if (tmpstr) free(tmpstr);		  }		}                free(b);	     } while ( bytesread==8192 );	  }	  y++;       }    }    if ((!WIFEXITED(rc)) || (rc=WEXITSTATUS(rc))) {      /* If there was an error and we're quiet, be loud */            if (quiet && output) {	    write(1,outbuf,strlen(outbuf));      }      free(pfds);      if (procpath)         free(procpath);      if(outbuf)         free(outbuf);      return (rc);   }   free(pfds);   if (procpath)      free(procpath);   if(outbuf)      free(outbuf);   return 0;}