[SVN] r894 - in /branches/cyrus23/cyrus-imapd-2.3-hmh/debian: ./ patches/

debian at incase.de debian at incase.de
Mon Jul 19 13:10:58 UTC 2010


Author: hmh
Date: Mon Jul 19 15:10:58 2010
New Revision: 894

URL: https://mail.incase.de/viewcvs?rev=894&root=cyrus22&view=rev
Log:
Update patch 10 based on cyrus-devel comments; Fix patch 12; Break up patch 13 by functionality

Added:
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13a-uid_t-cleanups
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13b-MAXFD-cleanups
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13c-master-reload
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13d-master-process-handling
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13e-master-janitor-delay
Removed:
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13-master_process_handling.dpatch
Modified:
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/changelog
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/10-fix_potential_overflows.dpatch
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/12-fix_timeout_handling.dpatch
    branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/series

Modified: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/changelog
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/changelog?rev=894&root=cyrus22&r1=893&r2=894&view=diff
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/changelog (original)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/changelog Mon Jul 19 15:10:58 2010
@@ -52,9 +52,19 @@
     * Patch 0025b-cve-2009-3235-extras: rediff, patch is now mostly
       useless (and doesn't fix any security hole), needs to go upstream or
       to be dropped
+    * Drop imap/message.c hunk from patch 10-fix_potential_overflows,
+      as it is useless
     * Document patches 08, 12 and 13 which are forward ports of patches
       originally written by me for Debian Cyrus 2.1 packages (and should
-      now all go upstream, almost 10 years later!)
+      now all go upstream, almost 10 years later!).  Patch 13 was broken
+      in separate parts, as it did more than one thing.
+    * Break up patch 13 into separate (and independent) patches, and
+      update them.
+      + 13a-uid_t-cleanups: use uid_t/gid_t instead of int
+      + 13b-MAXFD-cleanups: don't mislog on setrlimt/getrlimit (updated)
+      + 13c-master-reload: fixes related to config reload
+      + 13d-master-process-handling: master child accounting fixes
+      + 13e-master-janitor-delay: new master -J option
   * initscript: Required-Start/-Stop must refer to $remote_fs (lintian)
   * initscript: Default-Stop should not refer to runlevel S (lintian)
   * debian/rules: drop obsolete --with-tclsh option in configure

Modified: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/10-fix_potential_overflows.dpatch
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/10-fix_potential_overflows.dpatch?rev=894&root=cyrus22&r1=893&r2=894&view=diff
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/10-fix_potential_overflows.dpatch (original)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/10-fix_potential_overflows.dpatch Mon Jul 19 15:10:58 2010
@@ -8,18 +8,6 @@
 ## DP: been resolved upsteam (thanks mainly to Bron Gondwana).
 
 @DPATCH@
-diff -urNad git~/imap/message.c git/imap/message.c
---- git~/imap/message.c	2010-01-16 19:22:57.000000000 -0200
-+++ git/imap/message.c	2010-01-16 19:27:30.915091898 -0200
-@@ -996,7 +996,7 @@
-     /* Save header value */
-     len = hdrend - hdr;
-     message_ibuf_ensure(ibuf, len+2);
--    strncpy(ibuf->end, hdr, len);
-+    strncpy(ibuf->end, hdr, len+1);
-     ibuf->end += len;
-     *(ibuf->end)++ = '\r';
-     *(ibuf->end)++ = '\n';
 diff -urNad git~/imtest/imtest.c git/imtest/imtest.c
 --- git~/imtest/imtest.c	2010-01-16 19:22:57.000000000 -0200
 +++ git/imtest/imtest.c	2010-01-16 19:27:30.916091603 -0200

Modified: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/12-fix_timeout_handling.dpatch
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/12-fix_timeout_handling.dpatch?rev=894&root=cyrus22&r1=893&r2=894&view=diff
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/12-fix_timeout_handling.dpatch (original)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/12-fix_timeout_handling.dpatch Mon Jul 19 15:10:58 2010
@@ -12,10 +12,11 @@
 Is this patch correct?  Will it cause issues with other uses of alarm()
 in Cyrus code?
 
-diff -urNad git~/configure.in git/configure.in
---- git~/configure.in	2010-01-16 22:11:38.118932338 -0200
-+++ git/configure.in	2010-01-16 22:11:38.287932356 -0200
-@@ -1445,7 +1445,11 @@
+Index: cyrus-imapd-2.3-pkg/configure.in
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/configure.in
++++ cyrus-imapd-2.3-pkg/configure.in
+@@ -1443,7 +1443,11 @@ enum {
      SQUAT_ENGINE = 1,
  
      /* should we have long LMTP error messages? */
@@ -28,9 +29,10 @@
  };
  
  #endif /* _CYRUS_IMAPD_CONFIG_H_ */
-diff -urNad git~/lib/lock.h git/lib/lock.h
---- git~/lib/lock.h	2010-01-16 21:14:39.000000000 -0200
-+++ git/lib/lock.h	2010-01-16 22:11:38.287932356 -0200
+Index: cyrus-imapd-2.3-pkg/lib/lock.h
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/lib/lock.h
++++ cyrus-imapd-2.3-pkg/lib/lock.h
 @@ -55,6 +55,8 @@
  
  #include <sys/stat.h>
@@ -40,9 +42,10 @@
  extern const char *lock_method_desc;
  
  extern int lock_reopen P((int fd, const char *filename,
-diff -urNad git~/lib/lock_fcntl.c git/lib/lock_fcntl.c
---- git~/lib/lock_fcntl.c	2010-01-16 21:14:39.000000000 -0200
-+++ git/lib/lock_fcntl.c	2010-01-16 22:11:38.287932356 -0200
+Index: cyrus-imapd-2.3-pkg/lib/lock_fcntl.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/lib/lock_fcntl.c
++++ cyrus-imapd-2.3-pkg/lib/lock_fcntl.c
 @@ -48,11 +48,43 @@
  #include <unistd.h>
  #include <fcntl.h>
@@ -87,7 +90,7 @@
  /*
   * Block until we obtain an exclusive lock on the file descriptor 'fd',
   * opened for reading and writing on the file named 'filename'.  If
-@@ -66,12 +98,10 @@
+@@ -66,12 +98,10 @@ const char *lock_method_desc = "fcntl";
   * 'failaction' is provided, it is filled in with a pointer to a fixed
   * string naming the action that failed.
   *
@@ -103,7 +106,7 @@
  {
      int r;
      struct flock fl;
-@@ -80,6 +110,8 @@
+@@ -80,6 +110,8 @@ const char **failaction;
  
      if (!sbuf) sbuf = &sbufspare;
  
@@ -112,7 +115,7 @@
      for (;;) {
  	fl.l_type= F_WRLCK;
  	fl.l_whence = SEEK_SET;
-@@ -87,8 +119,10 @@
+@@ -87,8 +119,10 @@ const char **failaction;
  	fl.l_len = 0;
  	r = fcntl(fd, F_SETLKW, &fl);
  	if (r == -1) {
@@ -125,7 +128,7 @@
  	    return -1;
  	}
  
-@@ -101,10 +135,16 @@
+@@ -101,10 +135,16 @@ const char **failaction;
  	    fl.l_start = 0;
  	    fl.l_len = 0;
  	    r = fcntl(fd, F_SETLKW, &fl);
@@ -143,7 +146,7 @@
  
  	newfd = open(filename, O_RDWR);
  	if (newfd == -1) {
-@@ -114,11 +154,15 @@
+@@ -114,11 +154,15 @@ const char **failaction;
  	    fl.l_start = 0;
  	    fl.l_len = 0;
  	    r = fcntl(fd, F_SETLKW, &fl);
@@ -159,7 +162,7 @@
  }
  
  /*
-@@ -126,22 +170,32 @@
+@@ -126,22 +170,32 @@ const char **failaction;
   * Returns 0 for success, -1 for failure, with errno set to an
   * appropriate error code.
   */
@@ -196,7 +199,7 @@
  }
  
  /*
-@@ -149,22 +203,32 @@
+@@ -149,22 +203,32 @@ int fd;
   * Returns 0 for success, -1 for failure, with errno set to an
   * appropriate error code.
   */
@@ -233,7 +236,7 @@
  }
  
  /*
-@@ -172,8 +236,7 @@
+@@ -172,8 +236,7 @@ int fd;
   * Returns 0 for success, -1 for failure, with errno set to an
   * appropriate error code.
   */
@@ -243,7 +246,7 @@
  {
      int r;
      struct flock fl;
-@@ -188,10 +251,13 @@
+@@ -188,10 +251,13 @@ int fd;
  	if (errno == EINTR) continue;
  	return -1;
      }
@@ -258,16 +261,17 @@
   */
  int lock_unlock(int fd)
  { 
-@@ -210,5 +276,6 @@
+@@ -210,5 +276,6 @@ int lock_unlock(int fd)
          /* xxx help! */
          return -1;
      }
 +    return 0;
  }
  
-diff -urNad git~/lib/lock_flock.c git/lib/lock_flock.c
---- git~/lib/lock_flock.c	2010-01-16 21:14:39.000000000 -0200
-+++ git/lib/lock_flock.c	2010-01-16 22:11:38.288931922 -0200
+Index: cyrus-imapd-2.3-pkg/lib/lock_flock.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/lib/lock_flock.c
++++ cyrus-imapd-2.3-pkg/lib/lock_flock.c
 @@ -47,6 +47,8 @@
  #include <sys/stat.h>
  #include <fcntl.h>
@@ -314,7 +318,7 @@
  /*
   * Block until we obtain an exclusive lock on the file descriptor 'fd',
   * opened for reading and writing on the file named 'filename'.  If
-@@ -68,12 +100,10 @@
+@@ -68,12 +100,10 @@ const char *lock_method_desc = "flock";
   * 'failaction' is provided, it is filled in with a pointer to a fixed
   * string naming the action that failed.
   *
@@ -330,7 +334,7 @@
  {
      int r;
      struct stat sbuffile, sbufspare;
-@@ -81,11 +111,15 @@
+@@ -81,11 +111,15 @@ const char **failaction;
  
      if (!sbuf) sbuf = &sbufspare;
  
@@ -347,7 +351,7 @@
  	    return -1;
  	}
  
-@@ -94,20 +128,32 @@
+@@ -94,20 +128,31 @@ const char **failaction;
  	if (r == -1) {
  	    if (failaction) *failaction = "stating";
  	    flock(fd, LOCK_UN);
@@ -362,7 +366,6 @@
 +	    setsigalrm(0);
 +	    return 0;
 +	}
-+ 
  
  	newfd = open(filename, O_RDWR);
  	if (newfd == -1) {
@@ -381,7 +384,7 @@
  }
  
  /*
-@@ -115,17 +161,27 @@
+@@ -115,17 +160,27 @@ const char **failaction;
   * Returns 0 for success, -1 for failure, with errno set to an
   * appropriate error code.
   */
@@ -413,7 +416,7 @@
  }
  
  /*
-@@ -133,17 +189,27 @@
+@@ -133,17 +188,27 @@ int fd;
   * Returns 0 for success, -1 for failure, with errno set to an
   * appropriate error code.
   */
@@ -445,7 +448,7 @@
  }
  
  /*
-@@ -165,7 +231,9 @@
+@@ -165,7 +230,9 @@ int fd;
  }
  
  /*
@@ -456,7 +459,7 @@
   */
  int lock_unlock(int fd)
  {
-@@ -175,8 +243,8 @@
+@@ -175,8 +242,8 @@ int lock_unlock(int fd)
          r = flock(fd, LOCK_UN);
          if (r != -1) return 0;
          if (errno == EINTR) continue;

Added: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13a-uid_t-cleanups
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13a-uid_t-cleanups?rev=894&root=cyrus22&view=auto
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13a-uid_t-cleanups (added)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13a-uid_t-cleanups Mon Jul 19 15:10:58 2010
@@ -1,0 +1,24 @@
+From: Henrique de Moraes Holschuh <hmh at debian.org>
+Subject: use uid_t and gid_t instead of int
+
+Origin: vendor, Debian Cyrus IMAPd 2.1.16-7 (2004-08-07)
+
+Use the proper types for UIDs and GIDs.
+
+Index: cyrus-imapd-2.3-pkg/lib/util.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/lib/util.c
++++ cyrus-imapd-2.3-pkg/lib/util.c
+@@ -365,9 +365,10 @@ int cyrus_mkdir(const char *path, mode_t
+ int become_cyrus(void)
+ {
+     struct passwd *p;
+-    int newuid, newgid;
++    uid_t newuid;
++    gid_t newgid;
+     int result;
+-    static int uid = 0;
++    static uid_t uid = 0;
+ 
+     if (uid) return setuid(uid);
+ 

Added: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13b-MAXFD-cleanups
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13b-MAXFD-cleanups?rev=894&root=cyrus22&view=auto
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13b-MAXFD-cleanups (added)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13b-MAXFD-cleanups Mon Jul 19 15:10:58 2010
@@ -1,0 +1,41 @@
+From: Henrique de Moraes Holschuh <hmh at debian.org>
+Subject: silence erroneous RLIMIT_NUMFDS-related log messages
+
+Origin: vendor, Debian Cyrus IMAPd 2.1.16-7 (2004-08-07)
+
+Fixes setrlimit(RLIMIT_NUMFDS) handling to be less obnoxious and
+not barf error messages to syslog incorrectly, nor log nonsense
+if getrlimit(RLIMIT_NUMFDS) failed.
+
+Index: cyrus-imapd-2.3-pkg/master/master.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/master/master.c
++++ cyrus-imapd-2.3-pkg/master/master.c
+@@ -1510,11 +1510,10 @@ void add_event(const char *name, struct 
+ void limit_fds(rlim_t x)
+ {
+     struct rlimit rl;
+-    int r;
+ 
+     rl.rlim_cur = x;
+     rl.rlim_max = x;
+-    if (setrlimit(RLIMIT_NUMFDS, &rl) < 0) {
++    if (setrlimit(RLIMIT_NUMFDS, &rl) < 0 && x != RLIM_INFINITY) {
+ 	syslog(LOG_ERR, "setrlimit: Unable to set file descriptors limit to %ld: %m", x);
+ 
+ #ifdef HAVE_GETRLIMIT
+@@ -1529,11 +1528,9 @@ void limit_fds(rlim_t x)
+     }
+ 
+ 
+-    if (verbose > 1) {
+-	r = getrlimit(RLIMIT_NUMFDS, &rl);
+-	syslog(LOG_DEBUG, "set maximum file descriptors to %ld/%ld", rl.rlim_cur,
+-	       rl.rlim_max);
+-    }
++    if (verbose > 1 && getrlimit(RLIMIT_NUMFDS, &rl) >=0)
++	syslog(LOG_DEBUG, "set maximum file descriptors to %ld/%ld",
++		rl.rlim_cur, rl.rlim_max);
+ #else
+     }
+ #endif /* HAVE_GETRLIMIT */

Added: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13c-master-reload
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13c-master-reload?rev=894&root=cyrus22&view=auto
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13c-master-reload (added)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13c-master-reload Mon Jul 19 15:10:58 2010
@@ -1,0 +1,60 @@
+From: Henrique de Moraes Holschuh <hmh at debian.org>
+Subject: Fixes related to master SIGHUP handling
+
+Origin: vendor, Debian Cyrus IMAPd 2.1.16-7 (2004-08-07)
+
+* Cleans up various data fields for reconfig.
+
+Index: cyrus-imapd-2.3-pkg/master/master.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/master/master.c
++++ cyrus-imapd-2.3-pkg/master/master.c
+@@ -1398,8 +1398,9 @@ void add_service(const char *name, struc
+ 	snprintf(buf, sizeof(buf),
+ 		 "cannot find executable for service '%s'", name);
+ 	
+-	/* if it is not, we're misconfigured, die. */
+-	fatal(buf, EX_CONFIG);
++	/* if it is not, we just skip it */
++	syslog(LOG_WARNING, "WARNING: %s -- ignored", buf);
++	return;
+     }
+ 
+     Services[i].maxforkrate = maxforkrate;
+@@ -1419,6 +1420,7 @@ void add_service(const char *name, struc
+ 	if (prefork > 1) prefork = 1;
+ 	Services[i].desired_workers = prefork;
+ 	Services[i].max_workers = 1;
++	Services[i].babysit = 0;
+     }
+     free(max);
+  
+@@ -1458,7 +1460,7 @@ void add_event(const char *name, struct 
+     if (!strcmp(cmd,"")) {
+ 	char buf[256];
+ 	snprintf(buf, sizeof(buf),
+-		 "unable to find command or port for event '%s'", name);
++		 "unable to find command for event '%s'", name);
+ 
+ 	if (ignore_err) {
+ 	    syslog(LOG_WARNING, "WARNING: %s -- ignored", buf);
+@@ -1564,13 +1566,18 @@ void reread_conf(void)
+ 		       Services[i].stat[0], Services[i].stat[1]);
+ 
+ 	    /* Only free the service info on the primary */
+-	    if(Services[i].associate == 0) {
++	    if (Services[i].associate == 0) {
++		free(Services[i].name);
+ 		free(Services[i].listen);
+ 		free(Services[i].proto);
+ 	    }
++	    Services[i].name = NULL;
+ 	    Services[i].listen = NULL;
+ 	    Services[i].proto = NULL;
+ 	    Services[i].desired_workers = 0;
++	    Services[i].nforks = 0;
++	    Services[i].nactive = 0;
++	    Services[i].nconnections = 0;
+ 
+ 	    /* send SIGHUP to all children */
+ 	    for (j = 0 ; j < child_table_size ; j++ ) {

Added: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13d-master-process-handling
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13d-master-process-handling?rev=894&root=cyrus22&view=auto
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13d-master-process-handling (added)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13d-master-process-handling Mon Jul 19 15:10:58 2010
@@ -1,0 +1,140 @@
+From: Henrique de Moraes Holschuh <hmh at debian.org>
+Subject: Fixes process (child) handling in Cyrus master
+
+Origin: vendor, Debian Cyrus IMAPd 2.1.16-7 (2004-08-07)
+
+* Allows Cyrus master to process all pending child messages once per
+  loop, which fixes a DoS situation if there is too much message churn
+  in a slower box.  If the pending messages never get processed, child
+  accounting goes bad and eventually master stops spawning the service
+  or handling connections.
+
+  It seems that the problem this patch fixes has also been reported in
+  Cyrus IMAP 2.2.12 by Earl Shannon, and Jules Agee actually tried to
+  get the fix from Debian integrated upstream.
+
+  Jules Agee described the problem quite well in a private message:
+
+     "The problem occurs when the child message queue is very backed up.
+     A child process dies with several messages in the queue. reap_child
+     marks it's state in the child table as dead and decrements the
+     number of ready_workers.  Then the janitor process removes that
+     child's entry from the child table.  When master finally gets
+     around to processing all the messages in the child message queue,
+     it has no idea where the message came from because the child's
+     entry has already been removed from the ctable.  So it creates a
+     new ctable entry, marking the child process state as unknown,
+     assuming the message is from a child process that's still alive.
+     When master finishes processing the messages from that long-dead
+     child, it again (an inaccurately) decrements the count of
+     ready_workers.
+
+     The easiest solution in my opinion is to make sure master stays
+     caught up with messages from its children by processing all child
+     messages on each loop.  After all, it's the duty of a parent."
+
+  Kenneth Murchison reported that they couldn't reproduce it in CMU.
+  However, it is clearly something that depends on pathological loads
+  and kernel behaviour to trigger.
+
+  This fix is a trade off: we risk increasing latency to hand off
+  connections/spawn new services (because we're in a loop processing
+  child messages).  If the messages never stop coming, or come in
+  extremely large bursts, master will backlog connections.  If syslog()
+  or memory allocation decides to introduce large latencies, the cost
+  of processing messages can get too high and master will backlog
+  connections.  Note: this *CAN* happen, and in fact it did happen to
+  Jules until he reduced the amount of data going to syslog.
+
+  Also, even with this patch, master behaviour will remain sane only if
+  we don't clean the child table BEFORE we processes any messages it
+  could have sent that are still in-flight (this *can* happen), as
+  described by Jules.  This is probably a bug in the decisions we take
+  when we promote something from SERVICE_STATE_UNKNOWN to some other
+  state.  We *could* account children when they are migrated from
+  SERVICE_STATE_UNKNOWN to some other state, so that we can do normal
+  accounting afterwards... but we need to do a full failure mode
+  analysis to know if there isn't another failure mode where this
+  causes trouble...
+
+  IMO, there must be a better way to do all this process accounting
+  and child messaging that doesn't require such a complicated
+  state machine.  I wonder how postfix does it?
+
+  Reported-analysed-and-tested-by: Jules Agee <julesa at pcf.com>.
+
+Index: cyrus-imapd-2.3-pkg/master/master.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/master/master.c
++++ cyrus-imapd-2.3-pkg/master/master.c
+@@ -1073,6 +1073,36 @@ void sighandler_setup(void)
+     }
+ }
+ 
++/*
++ * Receives a message from a service.
++ *
++ * Returns zero if all goes well
++ * 1 if no msg available
++ * 2 if bad message received (incorrectly sized)
++ * -1 on error (errno set)
++ */
++int read_msg(int fd, struct notify_message *msg)
++{
++    ssize_t r;
++    size_t off = 0;
++    int s = sizeof(struct notify_message);
++
++    while (s > 0) {
++        do
++            r = read(fd, msg + off, s);
++        while ((r == -1) && (errno == EINTR));
++        if (r <= 0) break;
++        s -= r;
++        off += r;
++    }
++    if ( ((r == 0) && (off == 0)) ||
++         ((r == -1) && (errno == EAGAIN)) )
++        return 1;
++    if (r == -1) return -1;
++    if (s != 0) return 2;
++    return 0;
++}
++
+ void process_msg(const int si, struct notify_message *msg) 
+ {
+     struct centry *c;
+@@ -1412,7 +1442,7 @@ void add_service(const char *name, struc
+ 	Services[i].desired_workers = prefork;
+ 	Services[i].babysit = babysit;
+ 	Services[i].max_workers = atoi(max);
+-	if (Services[i].max_workers == -1) {
++	if (Services[i].max_workers < 0) {
+ 	    Services[i].max_workers = INT_MAX;
+ 	}
+     } else {
+@@ -2072,13 +2102,19 @@ int main(int argc, char **argv)
+ 	    int j;
+ 
+ 	    if (FD_ISSET(x, &rfds)) {
+-		r = read(x, &msg, sizeof(msg));
+-		if (r != sizeof(msg)) {
+-		    syslog(LOG_ERR, "got incorrectly sized response from child: %x", i);
++		while ((r = read_msg(x, &msg)) == 0)
++		    process_msg(i, &msg);
++
++		if (r == 2) {
++		    syslog(LOG_ERR,
++			"got incorrectly sized response from child: %x", i);
++		    continue;
++		}
++		if (r < 0) {
++		    syslog(LOG_ERR,
++			"error while receiving message from child %x: %m", i);
+ 		    continue;
+ 		}
+-		
+-		process_msg(i, &msg);
+ 	    }
+ 
+ 	    if (Services[i].exec &&

Added: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13e-master-janitor-delay
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13e-master-janitor-delay?rev=894&root=cyrus22&view=3Dauto
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13e-master-janitor-delay (added)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/13e-master-janitor-delay Mon Jul 19 15:10:58 2010
@@ -1,0 +1,84 @@
+From: Henrique de Moraes Holschuh <hmh at debian.org>
+Subject: Allow user to set the delay before master forgets dead children
+
+Origin: vendor, Debian Cyrus IMAPd 2.1.16-7 (2004-08-07)
+
+* Allows tunning of the amount of time Cyrus master will remember dead
+  children ("janitor mourning time"), which can be useful when messages
+  are being delayed by extreme system load (use -J to increase the
+  default time of two seconds to something large enough to get the
+  messages), or there is way too much child churn to wait that long (use
+  -J to decrease mourning time to 1s).
+
+  Setting it to 0 would cause us to free the child PID as soon as possible.
+  Should the kernel decide to delay delivering the child control messages
+  and we process the SIGCHLD *and* do a janitor sweep before the messages
+  arrive, it would trigger the process accounting bug described in the
+  13d-master-process-handling patch.
+  
+  This option was added to help tune master on systems which are hitting
+  the kind of crap described by Jules Agee (see the description in patch
+  13d-master-process-handling).
+
+NOTE: patch is missing manpage fixes to describe -J
+
+Index: cyrus-imapd-2.3-pkg/master/master.c
+===============3D====================================================
+--- cyrus-imapd-2.3-pkg.orig/master/master.c
++++ cyrus-imapd-2.3-pkg/master/master.c
+@@ -174,6 +174,8 @@ struct centry {
+ static struct centry *ctable[child_table_size];
+ static struct centry *cfreelist;
+ 
++static int child_mourning_time = 2;    /* Time in seconds to remember child
++					  after processing SIGCHLD */
+ static int janitor_frequency = 1;	/* Janitor sweeps per second */
+ static int janitor_position;		/* Entry to begin at in next sweep */
+ static struct timeval janitor_mark;	/* Last time janitor did a sweep */
+@@ -908,7 +910,7 @@ void reap_child(void)
+ 		}
+ 	    }
+ 	    c->service_state = SERVICE_STATE_DEAD;
+-	    c->janitor_deadline = time(NULL) + 2;
++	    c->janitor_deadline = time(NULL) + child_mourning_time;
+ 	} else {
+ 	    /* weird. Are we multithreaded now? we don't know this child */
+ 	    syslog(LOG_WARNING,
+@@ -917,7 +919,7 @@ void reap_child(void)
+ 	    c = get_centry();
+ 	    c->pid = pid;
+ 	    c->service_state = SERVICE_STATE_DEAD;
+-	    c->janitor_deadline = time(NULL) + 2;
++	    c->janitor_deadline = time(NULL) + child_mourning_time;
+ 	    c->si = SERVICE_NONE;
+ 	    c->next = ctable[pid % child_table_size];
+ 	    ctable[pid % child_table_size] = c;
+@@ -1690,9 +1692,9 @@ int main(int argc, char **argv)
+     p = getenv("CYRUS_VERBOSE");
+     if (p) verbose = atoi(p) + 1;
+ #ifdef HAVE_NETSNMP
+-    while ((opt = getopt(argc, argv, "C:M:p:l:Ddj:P:x:")) != EOF) {
++    while ((opt = getopt(argc, argv, "C:M:p:l:DdjJ:P:x:")) != EOF) {
+ #else
+-    while ((opt = getopt(argc, argv, "C:M:p:l:Ddj:")) != EOF) {
++    while ((opt = getopt(argc, argv, "C:M:p:l:DdjJ:")) != EOF) {
+ #endif
+ 	switch (opt) {
+ 	case 'C': /* alt imapd.conf file */
+@@ -1725,8 +1727,15 @@ int main(int argc, char **argv)
+ 	    /* Janitor frequency */
+ 	    janitor_frequency = atoi(optarg);
+ 	    if(janitor_frequency < 1)
+-		fatal("The janitor period must be at least 1 second", EX_CONFIG);
++		fatal("The janitor frequency must be at least once per second", EX_CONFIG);
+ 	    break;   
++       case 'J':
++           /* Janitor delay before cleanup of a child */
++           child_mourning_time = atoi(optarg);
++           if(child_mourning_time < 1)
++               fatal("The janitor's mourning time interval must be at least 1 second",
++                       EX_CONFIG);
++           break;
+ #ifdef HAVE_NETSNMP
+ 	case 'P': /* snmp AgentXPingInterval */
+ 	    agentxpinginterval = atoi(optarg);

Modified: branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/series
URL: https://mail.incase.de/viewcvs/branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/series?rev=894&root=cyrus22&r1=893&r2=894&view=diff
==============================================================================
--- branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/series (original)
+++ branches/cyrus23/cyrus-imapd-2.3-hmh/debian/patches/series Mon Jul 19 15:10:58 2010
@@ -11,7 +11,11 @@
 10-fix_potential_overflows.dpatch
 11-fix_syslog_prefix.dpatch
 12-fix_timeout_handling.dpatch
-13-master_process_handling.dpatch
+13a-uid_t-cleanups
+13b-MAXFD-cleanups
+13c-master-reload
+13d-master-process-handling
+13e-master-janitor-delay
 14-xmalloc.dpatch
 16-fix_mib.dpatch
 17-fix_tail_syntax_in_xversion.h.dpatch




More information about the Pkg-Cyrus-imapd-Debian-devel mailing list