[EMAIL PROTECTED] (Chin Fang) writes:

> In the past two hours, I was reading qmail-popup.c and thus found out
> the underlined line below was doing something unusual:

It is the behavior documented in the man page, though I'm not really
sure why it's written that way.

> Once deleted, I could get *some* :( stuff written by qmail-pop3d to
> STDERR logged via multilog, rather than spitted out to POP clients.
> The reason I said *some* is because I am stuck again.  The 2nd
> strerr_warn1 in the attached patch below (WARNING! unfinished) simply
> stays silent. The first one prints its msg correctly.  I have been
> looking up and down the src to see what I did wrong, but so far can't
> spot anything (yet).

There's no obvious reason why both calls to strerr_warn1() shouldn't
print, and it's hard to guess without more detailed information.  The
relevant portion of a trace along with your run file and the uname -a
of your system would be useful.

  [ I wrote ]
> > where stderrto is a small program that opens its first argument for
> > writing on fd 2 and execs the rest of its arguments[1].  In
> > retrospect, patching qmail-popup might have been a better idea.
>              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I just tried this, along with my own version of the patch you're
writing, and things works as expected on my machine.  (Yes, this is
extremely weak assurance. :)

The diffs to qmail-pop3d.c and qmail-popup.c are appended to this
message.


^L

-- 
Louis Theran
Nokia Research Center
(Not speaking for Nokia)


Patch to change the way qmail-popup treats stderr:

*** qmail-popup.c.orig  Sat May 20 20:03:27 2000
--- qmail-popup.c       Sat May 20 20:04:07 2000
***************
*** 88,94 ****
    int wstat;
    int pi[2];
   
-   if (fd_copy(2,1) == -1) die_pipe();
    close(3);
    if (pipe(pi) == -1) die_pipe();
    if (pi[0] != 3) die_pipe();
--- 88,93 ----


Patch to make qmail-pop3d log the number of bytes slurped in RETR
commands:

*** qmail-pop3d.c.orig  Sat May 20 19:54:14 2000
--- qmail-pop3d.c       Sat May 20 20:00:50 2000
***************
*** 17,22 ****
--- 17,37 ----
  #include "timeoutread.h"
  #include "timeoutwrite.h"
  
+ #include "strerr.h"
+ 
+ /* @@@ patched to log the number of bytes per connection. 
+  * 
+  * A simple patch to make qmail-pop3d emit log lines of the form:
+  *
+  *   qmail-pop3d <pid>: <nbytes> message bytes read
+  *
+  * to stderr, which is assumed to be pointed at multilog
+  *
+  * DON'T BLINDLY ASSUME THIS WORKS, it has undergone only cursory testing
+  * 
+  * --Louis Theran, 2000-05-20
+  */
+ 
  void die() { _exit(0); }
  
  int saferead(fd,buf,len) int fd; char *buf; int len;
***************
*** 35,40 ****
--- 50,79 ----
    return r;
  }
  
+ /* @@@ keep track of how many bytes we slurp from messages in pop3_top() */
+ static unsigned long msgbytesread = 0;
+ 
+ static int counted_read(fd,buf,len) int fd; char *buf; int len;
+ {
+   int rv;
+ 
+   rv = read(fd,buf,len);
+   if (rv > 0) msgbytesread += rv;
+   return rv;
+ }
+ 
+ /* @@@ generating log messages */
+ char msgbytes_str[FMT_ULONG];
+ char pid_str[FMT_ULONG];
+ 
+ static void log_bytes() 
+ {
+   msgbytes_str[fmt_ulong(msgbytes_str,msgbytesread)] = 0;
+   pid_str[fmt_uint(pid_str,getpid())] = 0;
+ 
+   strerr_warn5("qmail-pop3d ",pid_str,": ",msgbytes_str," message bytes read",0);
+ }
+ 
  char ssoutbuf[1024];
  substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf);
  
***************
*** 193,198 ****
--- 232,238 ----
        rename(m[i].fn,line.s); /* if it fails, bummer */
        }
    okay();
+   log_bytes();
    die();
  }
  
***************
*** 268,274 ****
    fd = open_read(m[i].fn);
    if (fd == -1) { err_nosuch(); return; }
    okay();
!   substdio_fdbuf(&ssmsg,read,fd,ssmsgbuf,sizeof(ssmsgbuf));
    blast(&ssmsg,limit);
    close(fd);
  }
--- 308,314 ----
    fd = open_read(m[i].fn);
    if (fd == -1) { err_nosuch(); return; }
    okay();
!   substdio_fdbuf(&ssmsg,counted_read,fd,ssmsgbuf,sizeof(ssmsgbuf));
    blast(&ssmsg,limit);
    close(fd);
  }


Reply via email to