stderr flushing fix

Peter van Dijk peter at nextgear.nl
Wed May 25 05:37:02 PDT 2005


Hi,

I'm running memcached from daemontools (http://cr.yp.to/daemontools.html),
with logging via multilog (http://cr.yp.to/daemontools/multilog.html).
memcached is started with -vv (will switch to -v for production use
eventually). However, nothing appears in the logfile.

The problem is that memcached logs to stderr but doesn't flush. As long
as stderr is a tty, this is fine. However, in the multilog case stderr
is a pipe, which means that stdio will default to buffering output.

The fix is simple:


--- memcached-1.1.11/memcached.c        Mon Apr 26 23:26:48 2004
+++ /tmp/memcached-patched/memcached.c  Wed May 25 14:00:52 2005
@@ -1277,6 +1277,9 @@
     /* init settings */
     settings_init();
 
+    /* set stderr non-buffering */
+    setbuf(stderr, NULL);
+
     /* process arguments */
     while ((c = getopt(argc, argv, "p:m:Mc:khirvdl:u:")) != -1) {
         switch (c) {


With this addition, memcached logs line by line to my multilog output
directory. Could this patch be merged into the source tree, possibly
as an option? Thank you.

Cheers,
Peter van Dijk


More information about the memcached mailing list