More research:

I patched master.c to spew out its file descriptors using lsof via a
system() call, before and after the dup2()s.  It's fine.  However, the
imapd process that's running has those fds differently.  It looks like
something was royally trodden upon.  So, while I think that the rlim_t
patch is a good thing (you need to fix the printf conversions, too), I
think that the problem lies elsewhere, as it seems to not crop up until
after the service is exec'd off.

Attached are the output and the patch.

master.debug is the file generated by the patch.
lsof.output is the output of the command 'lsof -p <imapd-pid>'
master.debug.patch is the patch

-Bitt
STATUS_FD == 10
LISTEN_FD == 8
COMMAND   PID  USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
master  27934 cyrus  cwd   VDIR       0,23     1024 215040 
/usr/local/src/cyrus-imapd-2.0.11
master  27934 cyrus  txt   VREG       0,16    74549 462881 /usr/cyrus/bin/master
master  27934 cyrus  txt   VREG       0,16    61440 301454 /usr/libexec/ld.so
master  27934 cyrus  txt   VREG       0,16   216776  13466 /usr/lib/libssl.so.2.4
master  27934 cyrus  txt   VREG       0,16   764446  13444 /usr/lib/libcrypto.so.2.4
master  27934 cyrus  txt   VREG       0,16   576146  13442 /usr/lib/libc.so.25.2
master  27934 cyrus    0u  VCHR        2,2      0t0   5001 /dev/null
master  27934 cyrus    1u  VCHR        2,2      0t0   5001 /dev/null
master  27934 cyrus    2u  VCHR        2,2    0t374   5001 /dev/null
master  27934 cyrus    3u  unix 0xe0877600      0t0        ->0xe0829b00
master  27934 cyrus    4u  VCHR        2,2      0t0   5001 /dev/null
master  27934 cyrus    5r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    6r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    7r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    8u  IPv4 0xe0835100      0t0    TCP *:imap (LISTEN)
master  27934 cyrus    9u  PIPE 0xe085a580    16384        ->0xe085ad80
master  27934 cyrus   10u  PIPE 0xe085ad80    16384        ->0xe085a580
master  27934 cyrus   11u  IPv4 0xe0831100      0t0    TCP *:imaps (LISTEN)
master  27934 cyrus   12u  PIPE 0xe08bde00    16384        ->0xe085a280
master  27934 cyrus   13u  PIPE 0xe085a280    16384        ->0xe08bde00
master  27934 cyrus   14u  IPv4 0xe08b5200      0t0    TCP *:pop3 (LISTEN)
master  27934 cyrus   15u  PIPE 0xe08c3280    16384        ->0xe0887480
master  27934 cyrus   16u  PIPE 0xe0887480    16384        ->0xe08c3280
master  27934 cyrus   17u  IPv4 0xe07d8300      0t0    TCP *:pop3s (LISTEN)
master  27934 cyrus   18u  PIPE 0xe08dff00    16384        ->0xe08bd200
master  27934 cyrus   19u  PIPE 0xe08bd200    16384        ->0xe08dff00
master  27934 cyrus   20u  IPv4 0xe087af00      0t0    TCP *:sieve (LISTEN)
master  27934 cyrus   21u  PIPE 0xe08df700    16384        ->0xe0887f80
master  27934 cyrus   22u  PIPE 0xe0887f80    16384        ->0xe08df700
master  27934 cyrus   23u  unix 0xe082f900      0t0        ->(none)
master  27934 cyrus   24u  PIPE 0xe0887580    16384        ->0xe08df880
master  27934 cyrus   25u  PIPE 0xe08df880    16384        ->0xe0887580
COMMAND   PID  USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
master  27934 cyrus  cwd   VDIR       0,23     1024 215040 
/usr/local/src/cyrus-imapd-2.0.11
master  27934 cyrus  txt   VREG       0,16    74549 462881 /usr/cyrus/bin/master
master  27934 cyrus  txt   VREG       0,16    61440 301454 /usr/libexec/ld.so
master  27934 cyrus  txt   VREG       0,16   216776  13466 /usr/lib/libssl.so.2.4
master  27934 cyrus  txt   VREG       0,16   764446  13444 /usr/lib/libcrypto.so.2.4
master  27934 cyrus  txt   VREG       0,16   576146  13442 /usr/lib/libc.so.25.2
master  27934 cyrus    0u  VCHR        2,2      0t0   5001 /dev/null
master  27934 cyrus    1u  VCHR        2,2      0t0   5001 /dev/null
master  27934 cyrus    2u  VCHR        2,2    0t374   5001 /dev/null
master  27934 cyrus    3u  PIPE 0xe085ad80    16384        ->0xe085a580
master  27934 cyrus    4u  IPv4 0xe0835100      0t0    TCP *:imap (LISTEN)
master  27934 cyrus    5r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    6r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    7r  VREG        0,0      937   6746 /etc/cyrus.conf
master  27934 cyrus    8u  IPv4 0xe0835100      0t0    TCP *:imap (LISTEN)
master  27934 cyrus    9u  PIPE 0xe085a580    16384        ->0xe085ad80
master  27934 cyrus   10u  PIPE 0xe085ad80    16384        ->0xe085a580
master  27934 cyrus   11u  IPv4 0xe0831100      0t0    TCP *:imaps (LISTEN)
master  27934 cyrus   12u  PIPE 0xe08bde00    16384        ->0xe085a280
master  27934 cyrus   13u  PIPE 0xe085a280    16384        ->0xe08bde00
master  27934 cyrus   14u  IPv4 0xe08b5200      0t0    TCP *:pop3 (LISTEN)
master  27934 cyrus   15u  PIPE 0xe08c3280    16384        ->0xe0887480
master  27934 cyrus   16u  PIPE 0xe0887480    16384        ->0xe08c3280
master  27934 cyrus   17u  IPv4 0xe07d8300      0t0    TCP *:pop3s (LISTEN)
master  27934 cyrus   18u  PIPE 0xe08dff00    16384        ->0xe08bd200
master  27934 cyrus   19u  PIPE 0xe08bd200    16384        ->0xe08dff00
master  27934 cyrus   20u  IPv4 0xe087af00      0t0    TCP *:sieve (LISTEN)
master  27934 cyrus   21u  PIPE 0xe08df700    16384        ->0xe0887f80
master  27934 cyrus   22u  PIPE 0xe0887f80    16384        ->0xe08df700
master  27934 cyrus   23u  unix 0xe082f900      0t0        ->(none)
master  27934 cyrus   24u  PIPE 0xe0887580    16384        ->0xe08df880
master  27934 cyrus   25u  PIPE 0xe08df880    16384        ->0xe0887580
COMMAND   PID  USER   FD   TYPE     DEVICE SIZE/OFF   NODE NAME
imapd   27934 cyrus  cwd   VDIR       0,23     1024 215040 
/usr/local/src/cyrus-imapd-2.0.11
imapd   27934 cyrus  txt   VREG       0,16  2116418 462882 /usr/cyrus/bin/imapd
imapd   27934 cyrus  txt   VREG       0,16    61440 301454 /usr/libexec/ld.so
imapd   27934 cyrus  txt   VREG       0,23   227864   5767 
/usr/local/lib/libsasl.so.8.8
imapd   27934 cyrus  txt   VREG       0,16   216776  13466 /usr/lib/libssl.so.2.4
imapd   27934 cyrus  txt   VREG       0,16   764446  13444 /usr/lib/libcrypto.so.2.4
imapd   27934 cyrus  txt   VREG       0,16    25612  13469 /usr/lib/libwrap.so.1.1
imapd   27934 cyrus  txt   VREG       0,16   576146  13442 /usr/lib/libc.so.25.2
imapd   27934 cyrus    0u  IPv4 0xe0827700      0t0    TCP 
localhost:imap->localhost:33280 (ESTABLISHED)
imapd   27934 cyrus    1u  IPv4 0xe0827700      0t0    TCP 
localhost:imap->localhost:33280 (ESTABLISHED)
imapd   27934 cyrus    2u  IPv4 0xe0827700      0t0    TCP 
localhost:imap->localhost:33280 (ESTABLISHED)
imapd   27934 cyrus    3u  VREG       0,22    54650  46087 /var/imap -- log.0000000001
imapd   27934 cyrus    4u  IPv4 0xe0835100      0t0    TCP *:imap (LISTEN)
imapd   27934 cyrus    5r  VREG        0,0      937   6746 /etc/cyrus.conf
imapd   27934 cyrus    6r  VREG        0,0      937   6746 /etc/cyrus.conf
imapd   27934 cyrus    7r  VREG        0,0      937   6746 /etc/cyrus.conf
imapd   27934 cyrus    8r  VREG       0,22    54650  46087 /var/imap -- log.0000000001
imapd   27934 cyrus    9u  VREG       0,22    16384      3 /var/imap/mailboxes.db
imapd   27934 cyrus   10u  unix 0xe080bb00      0t0        ->(none)
imapd   27934 cyrus   11u  VREG       0,22       21  44163 /var/imap (/dev/wd1g)
imapd   27934 cyrus   12u  unix 0xe08beb00      0t0        ->0xe0829b00
*** master/master.c.orig        Mon Jan 29 16:53:26 2001
--- master/master.c     Tue Feb  6 18:53:58 2001
***************
*** 128,134 ****
  static struct centry *ctable[child_table_size];
  static struct centry *cfreelist;
  
! void limit_fds(int);
  
  static char *mystrdup(const char *s)
  {
--- 128,134 ----
  static struct centry *ctable[child_table_size];
  static struct centry *cfreelist;
  
! void limit_fds(rlim_t);
  
  static char *mystrdup(const char *s)
  {
***************
*** 444,449 ****
--- 444,461 ----
            exit(1);
        }
  
+ {
+ FILE* f;
+ pid_t p;
+ char buf[1000];
+ f = fopen("/tmp/master.debug", "w");
+ fprintf(f, "STATUS_FD == %d\n", s->stat[1]);
+ fprintf(f, "LISTEN_FD == %d\n", s->socket);
+ fclose(f);
+ p = getpid();
+ sprintf(buf, "/usr/bin/sudo /usr/local/sbin/lsof -p %d >> /tmp/master.debug", p);
+ system(buf);
+ }
        get_prog(path, s->exec);
        if (dup2(s->stat[1], STATUS_FD) < 0) {
            syslog(LOG_ERR, "can't duplicate status fd: %m");
***************
*** 454,459 ****
--- 466,479 ----
            exit(1);
        }
  
+ {
+ pid_t p;
+ char buf[1000];
+ p = getpid();
+ sprintf(buf, "/usr/bin/sudo /usr/local/sbin/lsof -p %d >> /tmp/master.debug", p);
+ system(buf);
+ }
+ 
        fdflags = fcntl(LISTEN_FD, F_GETFD, 0);
        if (fdflags != -1) fdflags = fcntl(LISTEN_FD, F_SETFD, 
                                           fdflags & ~FD_CLOEXEC);
***************
*** 869,875 ****
  #  define RLIMIT_NUMFDS RLIMIT_OFILE
  # endif
  #endif
! void limit_fds(int x)
  {
      struct rlimit rl;
      int r;
--- 889,895 ----
  #  define RLIMIT_NUMFDS RLIMIT_OFILE
  # endif
  #endif
! void limit_fds(rlim_t x)
  {
      struct rlimit rl;
      int r;
***************
*** 881,887 ****
      }
  
      r = getrlimit(RLIMIT_NUMFDS, &rl);
!     syslog(LOG_DEBUG, "set maximum file descriptors to %d/%d", rl.rlim_cur,
           rl.rlim_max);
  }
  #else
--- 901,907 ----
      }
  
      r = getrlimit(RLIMIT_NUMFDS, &rl);
!     syslog(LOG_DEBUG, "set maximum file descriptors to %qd/%qd", rl.rlim_cur,
           rl.rlim_max);
  }
  #else

Reply via email to