bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #4938] gdnc should close file descriptors


From: nobody
Subject: [bug #4938] gdnc should close file descriptors
Date: Tue, 16 Sep 2003 23:40:35 -0400
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/85 (KHTML, like Gecko) OmniWeb/v496

=================== BUG #4938: LATEST MODIFICATIONS ==================
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=4938&group_id=99

Changes by: Adam Fedor <fedor@gnu.org>
Date: Tue 09/16/2003 at 21:40 (US/Mountain)

            What     | Removed                   | Added
---------------------------------------------------------------------------
          Resolution | None                      | Fixed
              Status | Open                      | Closed


------------------ Additional Follow-up Comments ----------------------------
2003-08-31  Adam Fedor  <fedor@gnu.org>



        * Tools/gdnc.m (main): Close any open file descriptors so we can

        be a proper daemon.





=================== BUG #4938: FULL BUG SNAPSHOT ===================


Submitted by: ehz                     Project: GNUstep                      
Submitted on: Sat 08/23/2003 at 08:31
Category:  Base/Foundation            Severity:  5 - Major                  
Bug Group:  Bug                       Resolution:  Fixed                    
Assigned to:  fedor                   Status:  Closed                       

Summary:  gdnc should close file descriptors

Original Submission:  Like gdomap and gnustep_sndd, gdnc should close any open 
file descriptors to properly daemonize.



Try something like that :



--- gnustep-base-1.7.2.orig/Tools/gdnc.m

+++ gnustep-base-1.7.2/Tools/gdnc.m

@@ -23,6 +23,7 @@

 

 #include        <stdio.h>

 #include       <unistd.h>

+#include       <fcntl.h>

 

 #ifdef __MINGW__

 #include       "process.h"

@@ -909,8 +910,10 @@

 int

 main(int argc, char** argv, char** env)

 {

+  int                  desc;

   GDNCServer           *server;

   NSString             *str;

+  BOOL                 isDaemon = NO;

   BOOL                 shouldFork = YES;

   BOOL                 debugging = NO;

   CREATE_AUTORELEASE_POOL(pool);

@@ -948,6 +951,7 @@

 #else

   if (shouldFork)

     {

+      isDaemon = YES;

       switch (fork())

        {

          case -1:

@@ -969,6 +973,43 @@

            exit(EXIT_SUCCESS);

        }

     }

+

+  /*

+   *   Ensure we don't have any open file descriptors which may refer

+   *   to sockets bound to ports we may try to use.

+   *

+   *   Use '/dev/null' for stdin and stdout.  Assume stderr is ok.

+   */

+  for (desc = 0; desc < FD_SETSIZE; desc++)

+    {

+      if (isDaemon /*|| (desc != 2)*/)

+       {

+         (void)close(desc);

+       }

+    }

+  if (open("/dev/null", O_RDONLY) != 0)

+    {

+      NSLog(@"gdnc - failed to open stdin from /dev/null (%s)",

+           strerror(errno));

+      exit(EXIT_FAILURE);

+    }

+  if (open("/dev/null", O_WRONLY) != 1)

+    {

+      NSLog(@"gdnc - failed to open stdout from /dev/null (%s)",

+           strerror(errno));

+      exit(EXIT_FAILURE);

+    }

+  if (isDaemon && open("/dev/null", O_WRONLY) != 2)

+    {

+      NSLog(@"gdnc - failed to open stderr from /dev/null (%s)",

+           strerror(errno));

+      exit(EXIT_FAILURE);

+    }

+  if (0)

+    {

+      NSLog(@"gdnc - Closed descriptors");

+    }

+

 #endif /* !MINGW */

 

   {





-----------

P.S.

Is it better to start gdnc at boot time (as recommended by the GNUstep Unix 
Build Guide ) or at login time (as suggested by the gdnc manpage) ?



Eric Heintzmann and the Debian GNUstep maintainers

Follow-up Comments
*******************

-------------------------------------------------------
Date: Tue 09/16/2003 at 21:40       By: fedor
2003-08-31  Adam Fedor  <fedor@gnu.org>



        * Tools/gdnc.m (main): Close any open file descriptors so we can

        be a proper daemon.



-------------------------------------------------------
Date: Wed 08/27/2003 at 21:37       By: fedor
gdnc is a user program, passing information between different applications, so 
it should be started at login, so it is owned by the user.






CC list is empty


File Attachments
****************

-------------------------------------------------------
Date: Sat 08/23/2003 at 08:31  Name: gdnc.m.diff  Size: 1KB   By: ehz
patch for gdnc (close file descriptors)
http://savannah.gnu.org/bugs/download.php?group_id=99&amp;bug_id=4938&amp;bug_file_id=621


For detailed info, follow this link:
http://savannah.gnu.org/bugs/?func=detailbug&bug_id=4938&group_id=99

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]