diff -r bsd-airtools/dstumbler/README /home/dirkx/DStumbler/bsd-airtools/dstumbler/README 24a25,31 > www.wirelessleiden.nl / dumstertruck project > - a kill -HUP will reopen the logfile. Useful for > ratation. > - a log file starting with a | is taken as a pipe. > - a log file which looks like [hostname]: > will spawn a small deamon which can beconnected to > for live logging. diff -r bsd-airtools/dstumbler/dstumbler.h /home/dirkx/DStumbler/bsd-airtools/dstumbler/dstumbler.h 239a240 > #ifndef O_SYNC 240a242 > #endif diff -r bsd-airtools/dstumbler/log.c /home/dirkx/DStumbler/bsd-airtools/dstumbler/log.c 46a47,53 > #include > #include > #include > #include > #include > #include > 49a57,60 > #ifndef SHELL_PATH > #define SHELL_PATH "/bin/sh" > #endif > 189a201,335 > #define pdie(x) { perror(x); exit(1); } > > static void log_child(int fd, int port) > { > char * wbuff[ FD_SETSIZE], lline[ 1024 ],buff[1024]; > int offset = 0 ,curgen = 0,gen[ FD_SETSIZE]; > struct sockaddr_in any; > fd_set readset,writeset,exceptset; > int s,maxfd=0,i,n; > > if ((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1) > pdie("Could not open socket"); > > bzero((void*)&any,sizeof(any)); > any.sin_family = AF_INET; > any.sin_port = htons(port); > any.sin_addr.s_addr = INADDR_ANY; > > if (bind(s,(const struct sockaddr *)&any,sizeof(any)) == -1) > pdie("Could not bind to listen port"); > > if (listen(s,32) == -1) > pdie("Could not listen.."); > > FD_ZERO(&readset); > FD_ZERO(&writeset); > FD_ZERO(&exceptset); > > FD_SET(s,&readset); > FD_SET(s,&exceptset); > > FD_SET(fd,&readset); > FD_SET(fd,&exceptset); > > bzero(gen,sizeof(gen)); > bzero(wbuff,sizeof(wbuff)); > maxfd = MAX(fd,s); > while(1) { > fd_set r = readset; > fd_set w = writeset; > fd_set e = exceptset; > if (select(maxfd,&r,&w,&e,0) == -1) { > if (errno == EAGAIN) > continue; > if (errno == EINTR) > continue; > pdie("select failed"); > } > if (FD_ISSET(s,&r)) { > int n; > struct sockaddr addr; > int len = sizeof(addr); > if ((n = accept(s,&addr,&len)) == -1) { > perror("Failed to accept"); > continue; > }; > FD_SET(n,&writeset); > maxfd = MAX(n,maxfd); > if (wbuff[i]) free(wbuff[i]); > wbuff[n] = NULL; > gen[n] = 0; > } > if (FD_ISSET(fd,&r)) { > int n, i, lv = 0; > if ((n = read(fd,buff+offset,sizeof(buff)-offset))==-1) { > if ((errno=EAGAIN) || (errno == EINTR)) > continue; > pdie("Read error on logging com socket"); > }; > for(i=0;i if (buff[ offset+i ] == '\n') { > buff[offset+i] = '\0'; > strncpy(lline,buff,offset+i); > curgen++; > lv = i; > }; > }; > if (lv == offset+i) { > offset = 0; > } else > if (lv) { > offset=offset+n-lv; > strncpy(buff,buff+lv,offset); > } else > if (offset+n >= sizeof(buff)) { > offset =0; > } else { > offset += n; > } > } > if (FD_ISSET(s,&e)) > pdie("Connection error on listen socket"); > if (FD_ISSET(fd,&e)) > pdie("Connection error on logging comms socket"); > for(i=0;i if (i == s) > continue; > if (i == fd) > continue; > if (FD_ISSET(i,&w)) { > if (wbuff[i]) > free(wbuff[i]); > close(i); > FD_CLR(i,&writeset); > continue; > }; > if (FD_ISSET(i,&w)) { > if (gen[i] == curgen) > continue; > if (wbuff[i] == 0) { > wbuff[i] = strdup(lline); > gen[i] = curgen; > }; > n = write(i,wbuff[i],strlen(wbuff[i])); > if (n <= 0) { > if ((errno == EAGAIN) || (errno = EINTR)) > continue; > free(wbuff[i]); > close(i); > FD_CLR(i,&writeset); > continue; > }; > if (n == strlen(wbuff[i])) { > free(wbuff[i]); > wbuff[i] = NULL; > continue; > }; > strncpy(wbuff[i],wbuff[i]+n,strlen(wbuff[i]) - n); > } > } > > } > exit(1); > } > 204a351,392 > if (logfile[0] == '|') { > int fds[2]; > if (pipe(fds)<0) { > alert("error: unable to open log pipe for writing: %s", strerror(errno)); > return NULL; > }; > switch(fork()) { > case 0: /* I am the child... */ > close(STDIN_FILENO); > dup2(fds[0],STDIN_FILENO); > execl(SHELL_PATH,SHELL_PATH,"-c",logfile+1,NULL); > alert("Unabled to exec %s '%s': %s", > SHELL_PATH, logfile+1,strerror(errno)); > exit(1); > case -1:alert("error: unable to fork of a pipe for logging: %s", strerror(errno)); > return NULL; > break; > default:/* Mother */ > fd = fdopen(fds[1],"w"); > break; > } > } > else if (logfile[0] == ':') { > int fds[2]; > if (pipe(fds)<0) { > alert("error: unable to open connection to log child for writing: %s", strerror(errno)); > return NULL; > }; > switch(fork()) { > case 0: /* I am the child... */ > log_child(fds[0],atoi(logfile+1)); > exit(1); > case -1:alert("error: unable to fork of a log child: %s", strerror(errno)); > return NULL; > break; > default:/* Mother */ > fd = fdopen(fds[1],"w"); > break; > } > > } > else diff -r bsd-airtools/dstumbler/main.c /home/dirkx/DStumbler/bsd-airtools/dstumbler/main.c 46a47,48 > #include > #include 58a61,75 > void > restartlogs(int s) { > s=s; > if (!uselog) > return; > log_stop(log_fd); > if (uselog && (log_fd = log_start(logfile)) == NULL) { > fprintf(stderr,"Failed to reopen the log, logging disabled.\n"); > openlog("dstumbler",LOG_CONS|LOG_PERROR|LOG_PID,LOG_USER); > syslog(LOG_ERR,"Failed to reopen the log, logging disabled.\n"); > closelog(); > uselog = 0; > } > } > 297c314 < signal(SIGHUP, exitclean); --- > signal(SIGHUP, restartlogs);