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: Wed, 27 Aug 2003 23:37:23 -0400
User-agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.2.1) Gecko/20030228

=================== 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: Wed 08/27/2003 at 21:37 (US/Mountain)

            What     | Removed                   | Added
---------------------------------------------------------------------------
            Category | None                      | Base/Foundation
           Bug Group | None                      | Bug
         Assigned to | None                      | fedor


------------------ Additional Follow-up Comments ----------------------------
gdnc is a user program, passing information between different applications, so 
it should be started at login, so it is owned by the user.







=================== 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:  None                     
Assigned to:  fedor                   Status:  Open                         

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: 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]