Daemons should always close stdin, stdout and stderr after forking otherwise
the controlling terminal will have issues closing.
Examples include starting over ssh or baselayout-2
http://bugs.gentoo.org/show_bug.cgi?id=182721


diff --git a/src/prog/gpm-root.y b/src/prog/gpm-root.y
index 3a97602..b496550 100644
--- a/src/prog/gpm-root.y
+++ b/src/prog/gpm-root.y
@@ -526,7 +526,9 @@ int f_bgcmd(int mode, DrawItem *self, int uid)
 	            open("/dev/null",O_RDONLY); /* stdin  */
 	            open(consolename,O_WRONLY); /* stdout */
 	            dup(1);                     /* stderr */  
-	            for (i=3;i<OPEN_MAX; i++) close(i);
+		    int open_max = sysconf(_SC_OPEN_MAX);
+		    if (open_max == -1) open_max = 1024;
+	            for (i=3;i<open_max; i++) close(i);
 	            execl("/bin/sh","sh","-c",self->arg,(char *)NULL);
 	            exit(1); /* shouldn't happen */
 	         default: return 0;
diff --git a/src/special.c b/src/special.c
index 5bed91a..c6cd04d 100644
--- a/src/special.c
+++ b/src/special.c
@@ -156,7 +156,9 @@ int processSpecial(Gpm_Event *event)
       open(GPM_NULL_DEV,O_RDONLY); /* stdin  */
       open(console.device, O_WRONLY); /* stdout */
       dup(1);                     /* stderr */
-      for (i=3;i<OPEN_MAX; i++) close(i);
+      int open_max = sysconf(_SC_OPEN_MAX);
+      if (open_max == -1) open_max = 1024;
+      for (i=3;i<open_max; i++) close(i);
       execl("/bin/sh","sh","-c",command,(char *)NULL);
       exit(1); /* shouldn't happen */