pkgsrc-wip/omniORB/patches/patch-af
2008-08-25 15:00:35 +00:00

63 lines
1.4 KiB
Text

$NetBSD: patch-af,v 1.3 2008/08/25 15:00:35 tonnerre Exp $
--- src/appl/omniNames/omniNames.cc.orig 2008-02-05 17:44:52.000000000 +0100
+++ src/appl/omniNames/omniNames.cc
@@ -105,7 +105,9 @@ usage()
int
main(int argc, char **argv)
{
+ int devnull = -1;
int port = 0;
+ pid_t proc = 0;
const char* logdir = 0;
const char* errlog = 0;
CORBA::Boolean ignoreport = 0;
@@ -122,6 +124,48 @@ main(int argc, char **argv)
int new_argc = 1;
char** new_argv = new char*[argc];
+ /* Daemonize part 1: Close all file descriptors */
+ devnull = open("/dev/null", O_RDWR);
+ if (devnull == -1)
+ {
+ perror("/dev/null");
+ exit(EXIT_FAILURE);
+ }
+
+ close(STDIN_FILENO);
+ if (dup2(devnull, STDIN_FILENO) == -1)
+ {
+ perror("dup2 (STDIN)");
+ exit(EXIT_FAILURE);
+ }
+
+ close(STDOUT_FILENO);
+ if (dup2(devnull, STDOUT_FILENO) == -1)
+ {
+ perror("dup2 (STDOUT)");
+ exit(EXIT_FAILURE);
+ }
+
+ close(STDERR_FILENO);
+ if (dup2(devnull, STDERR_FILENO) == -1)
+ {
+ perror("dup2 (STDERR)");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Daemonize part 1: Close all file descriptors */
+ proc = fork();
+ if (proc == -1)
+ {
+ perror("fork");
+ exit(EXIT_FAILURE);
+ }
+ else if (proc != 0)
+ {
+ /* Parent process */
+ exit(EXIT_SUCCESS);
+ }
+
new_argv[0] = argv[0];
// Process command line arguments