View Issue Details

IDProjectCategoryView StatusLast Update
0001614SOGoSOPEpublic2012-10-25 18:18
Reporterdekkers Assigned Towsourdeau 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.3.11 
Fixed in Version2.0.2 
Summary0001614: Close all open file descriptors when daemonizing
Description

SOPE doesn't close all open file descriptors when daemonizing. Normally this isn't really a problem because there aren't any open file descriptors when SOGo is started, but it is a problem when SOGo is started from the Debian maintainer scripts and you're using debconf in those scripts.

TagsNo tags attached.

Activities

2012-02-06 20:18

 

0003-close-all-fds-on-daemon-start.patch (1,236 bytes)   
From: Jeroen Dekkers <jeroen@dekkers.ch>
Date: Mon, 5 Dec 2011 19:35:34 +0100
Subject: close-all-fds-on-daemon-start

---
 .../NGObjWeb/WOWatchDogApplicationMain.m           |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/sope-appserver/NGObjWeb/WOWatchDogApplicationMain.m b/sope-appserver/NGObjWeb/WOWatchDogApplicationMain.m
index 94e7bae..bb46229 100644
--- a/sope-appserver/NGObjWeb/WOWatchDogApplicationMain.m
+++ b/sope-appserver/NGObjWeb/WOWatchDogApplicationMain.m
@@ -973,7 +973,7 @@ int WOWatchDogApplicationMain
   NSAutoreleasePool *pool;
   NSUserDefaults *ud;
   NSString *logFile, *nsPidFile;
-  int rc;
+  int rc, i;
   pid_t childPid;
   NSProcessInfo *processInfo;
   Class WOAppClass;
@@ -1001,6 +1001,11 @@ int WOWatchDogApplicationMain
     logFile = [NSString stringWithFormat: @"/var/log/%@/%@.log",
                         [processInfo processName],
                         [processInfo processName]];
+
+  /* Close all open file descriptors */
+  for (i = getdtablesize(); i >= 3; --i)
+    close(i);
+  freopen("/dev/null", "a", stdin);
   if (![logFile isEqualToString: @"-"]) {
     freopen([logFile cString], "a", stdout);
     freopen([logFile cString], "a", stderr);
-- 
wsourdeau

wsourdeau

2012-02-06 20:53

viewer   ~0003374

Looking at your patch, I understand what this is about. Note that I would expeet the parent process to close its file descriptors instead.

dekkers

dekkers

2012-02-06 21:01

reporter   ~0003375

No, the problem is that when you exec() something, you inherent all file descriptors unless they are marked close-on-exec. This causes debconf to hang (see also http://www.fifi.org/doc/debconf-doc/tutorial.html#AEN198) because it waits on the file descriptors that are kept open by the SOGo process. My patch doesn't touch stdout/stderr because those are already handled correctly. It does reopen stdin to /dev/null (because we don't use it for anything) and closes all other file descriptors (fd 3 and higher).

Issue History

Date Modified Username Field Change
2012-02-06 20:18 dekkers New Issue
2012-02-06 20:18 dekkers File Added: 0003-close-all-fds-on-daemon-start.patch
2012-02-06 20:53 wsourdeau Note Added: 0003374
2012-02-06 21:01 dekkers Note Added: 0003375
2012-10-25 18:18 wsourdeau Status new => resolved
2012-10-25 18:18 wsourdeau Fixed in Version => 2.0.2
2012-10-25 18:18 wsourdeau Resolution open => fixed
2012-10-25 18:18 wsourdeau Assigned To => wsourdeau