bugGNUstep - Bugs: bug #4938, gdnc should close file descriptors

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #4938: gdnc should close file descriptors

Submitted by:  Eric Heintzmann <ehz>
Submitted on:  Sat 23 Aug 2003 02:31:41 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: Adam Fedor <fedor>
Open/Closed: Closed

Wed 17 Sep 2003 03:40:34 AM UTC, comment #2:

2003-08-31 Adam Fedor <fedor@gnu.org>

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

Adam Fedor <fedor>
Project AdministratorIn charge of this item.
Thu 28 Aug 2003 03:37:22 AM UTC, comment #1:

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

Adam Fedor <fedor>
Project AdministratorIn charge of this item.
Sat 23 Aug 2003 02:31:41 PM UTC, 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

Eric Heintzmann <ehz>

 

Attached Files
file #630:  gdnc.m.diff added by ehz (2KiB - application/octet-stream - patch for gdnc (close file descriptors))

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 5 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Wed 17 Sep 2003 03:40:34 AM UTCfedorStatusNone=>(Error - Not Found)
  Open/ClosedOpen=>(Error - Not Found)
Thu 28 Aug 2003 03:37:22 AM UTCfedorCategoryNone=>(Error - Not Found)
  Item GroupNone=>(Error - Not Found)
  Assigned toNone=>NA

Back to the top


Powered by Savane 3.1-cleanup1