Unbuffer flag on penlogd

From: Branson Matheson (branson@windborne.net)
Date: Wed Apr 16 2003 - 00:39:17 CEST


 Have a patch with a couple of changes you might want to integrate:

  - pen sends two lines for every log.. penlogd only needs one
        to function.
  - added a -b ... unbuffer to the opts for penlogd so that you
        can actually see the lines as they come out.
  - changed one of the dubugs to so post processing of the input
        data.

 Also need to update the pen.1 manpage and options to refelect that
you can put a host:port after -l. I can start sending more patches. Do
you have a prefered method/format?

 - branson

 --- cut here ---
root@bigfoot # diff -c penlogd.c penlogd.c.new
*** penlogd.c Thu Jan 16 15:36:16 2003
--- penlogd.c.new Tue Apr 15 18:37:23 2003
***************
*** 28,33 ****
--- 28,34 ----
  
  static int debuglevel = 0;
  static int foreground = 0;
+ static int unbuffer = 0;
  static char *logfile = NULL;
  static FILE *logfp;
  static char *pidfile = NULL;
***************
*** 120,125 ****
--- 121,127 ----
                i--;
                if (i < 0) i = pen_max-1;
        }
+
        if (i == pen_n) { /* no match */
                fwrite(b, 1, n, logfp);
        } else {
***************
*** 143,154 ****
  #endif
  
        b[n] = '\0';
- if (debuglevel > 1) debug("store_pen(%s, %d)", b, n);
        if (sscanf(b, "+ %100[^ ] %100[^ ] %100[^\n]",
                   client, server, request) != 3) {
                debug("discarding bogus pen line %s", b);
                return;
        }
  #ifdef HAVE_INET_ATON
        if (inet_aton(server, &addr) == 0) {
                debug("bogus address %s", server);
--- 145,158 ----
  #endif
  
        b[n] = '\0';
        if (sscanf(b, "+ %100[^ ] %100[^ ] %100[^\n]",
                   client, server, request) != 3) {
                debug("discarding bogus pen line %s", b);
                return;
        }
+ if (debuglevel > 1)
+ debug("store_pen(%i: %s, %s, %s)",pen_n, client, server, request);
+
  #ifdef HAVE_INET_ATON
        if (inet_aton(server, &addr) == 0) {
                debug("bogus address %s", server);
***************
*** 159,164 ****
--- 163,170 ----
        hp = gethostbyname(server);
        memcpy(&penlog[pen_n].addr, hp->h_addr, hp->h_length);
  #endif
+
+
        strncpy(penlog[pen_n].client, client, 100);
        strncpy(penlog[pen_n].request, request, 100);
        pen_n++;
***************
*** 174,179 ****
--- 180,186 ----
               " -f stay in foreground\n"
               " -j dir run in chroot\n"
               " -l file write log to file\n"
+ " -b unbuffer output (Testing Only!)\n"
               " -n N number of pen log entries to cache [1000]\n"
               " -p file write pid to file\n"
               " -u user run as alternative user\n");
***************
*** 200,210 ****
  {
        int c;
  
! while ((c = getopt(argc, argv, "j:l:n:p:u:df")) != -1) {
                switch (c) {
                case 'd':
                        debuglevel++;
                        break;
                case 'f':
                        foreground = 1;
                        break;
--- 207,220 ----
  {
        int c;
  
! while ((c = getopt(argc, argv, "j:l:n:p:u:dfb")) != -1) {
                switch (c) {
                case 'd':
                        debuglevel++;
                        break;
+ case 'b':
+ unbuffer = 1;
+ break;
                case 'f':
                        foreground = 1;
                        break;
***************
*** 237,242 ****
--- 247,253 ----
        struct sockaddr_in a;
        int ld, len, p;
        char b[1024];
+
        int n = options(argc, argv);
        argc -= n;
        argv += n;
***************
*** 268,273 ****
--- 279,285 ----
                if (debuglevel) debug("Logging to %s", logfile);
                logfp = fopen(logfile, "a");
                if (!logfp) error("Can't open logfile %s", logfile);
+ if (unbuffer) setlinebuf(logfp);
        } else {
                if (debuglevel) debug("Logging to stdout");
                logfp = stdout;
***************
*** 314,319 ****
--- 326,332 ----
                                fclose(logfp);
                                logfp = fopen(logfile, "a");
                                if (!logfp) error("Can't open %s", logfile);
+ if (unbuffer) setlinebuf(logfp);
                        }
                        do_restart_log = 0;
                }
***************
*** 321,326 ****
--- 334,341 ----
  
                if (n < 0) {
                        perror("Error receiving data");
+ } else if (strstr(b, "Host:")) {
+ /* do nothing */
                } else if (b[0] == '+') {
                        store_pen(b, n);
                } else {



This archive was generated by hypermail 2.1.2 : Wed Apr 16 2003 - 00:51:38 CEST