[Gpm] another OPEN_MAX patch

Mike Castle gpm@lists.prosa.it
Wed, 23 May 2001 19:32:56 -0700


Having finally gotten around to recompiling gpm-1.19.3 with a recent glibc,
I came across the OPEN_MAX not being defined problem.

I didn't like any of the patches I saw on debian and redhat (granted I
didn't look too hard).

--- gpm-1.19.3.orig/special.c	Mon Jan 17 13:34:00 2000
+++ gpm-1.19.3/special.c	Wed May 23 19:16:43 2001
@@ -35,6 +35,7 @@
 #include <time.h>
 #include <errno.h>
 #include <sys/param.h>
+#include <limits.h>
 
 #include "gpmInt.h"
 
@@ -61,13 +62,25 @@
 static char *commandM="shutdown -h now";
 static char *commandR="shutdown -r now";
 
+/* More or less out of Stevens */
+static long int gpm_open_max(void)
+{
+#ifdef OPEN_MAX
+  return OPEN_MAX;
+#else
+  long int rc = sysconf(_SC_OPEN_MAX);
+  if (rc==-1) rc = 256;
+  return rc;
+#endif
+}
+
 /*
  * The return value is 0 if the event has been eaten,
  * 1 if the event is passed on
  */
 int processSpecial(Gpm_Event *event)
 {
-  char *command=NULL; int i;
+  char *command=NULL;
   FILE *consolef;
 
   if ((event->type & GPM_TRIPLE)
@@ -145,6 +158,7 @@
 
   switch(fork())
     {
+    long int i;
     case -1: /* error */
       fprintf(stderr,"%s: fork(): %s\n", prgname, strerror(errno));
       return 0; /* Hmmm.... error */
@@ -154,7 +168,7 @@
       open("/dev/null",O_RDONLY); /* stdin  */
       open("/dev/tty0",O_WRONLY); /* stdout */
       dup(1);                     /* stderr */
-      for (i=3;i<OPEN_MAX; i++) close(i);
+      for (i=3;i<gpm_open_max(); i++) close(i);
       execl("/bin/sh","sh","-c",command,(char *)NULL);
       exit(1); /* shouldn't happen */
       
@@ -162,8 +176,3 @@
       return 0;	
     }
 }
-
-
-
-
-

-- 
       Mike Castle       Life is like a clock:  You can work constantly
  dalgoda@ix.netcom.com  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen