$NetBSD: patch-af,v 1.1.1.1 2010/09/01 15:52:58 drochner 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
