stderr flushing fix

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


I'm running memcached from daemontools (,
with logging via multilog (
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 */
+    /* 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.

Peter van Dijk

More information about the memcached mailing list