bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSProcessInfo kernel dependency


From: James Knight
Subject: NSProcessInfo kernel dependency
Date: Tue, 14 Jan 2003 18:36:02 -0500

NSProcessInfo seems to have a gratuitous dependance on the particular kernel version in use. In particular, in +load, it attempts to count the number of arguments from the file in /proc. However, some versions of the kernel null terminate the last argument, and some don't. Currently, gnustep handles this by using a configure check to determine which kind of kernel you're on. That is less than ideal situation, because 1) it is easy to do the check at runtime, and 2) people can and do use the same binaries on different kernels. 3) getting the argument count wrong causes a segfault.

This patch fixes the bug.

The CMDLINE_TERMINATED check in configure can also be removed.

RCS file: /cvsroot/gnustep/gnustep/core/base/Source/NSProcessInfo.m,v
retrieving revision 1.88
diff -u -r1.88 NSProcessInfo.m
--- NSProcessInfo.m     29 Dec 2002 02:00:04 -0000      1.88
+++ NSProcessInfo.m     14 Jan 2003 23:30:08 -0000
@@ -293,7 +293,7 @@
   extern char  **environ;
   char         *proc_file_name = NULL;
   FILE         *ifp;
-  int          c;
+  int          c, lastc = 0;
   int          argument;
   int          length;
   int          position;
@@ -351,15 +351,17 @@
     goto proc_fs_error;
   while (1)
     {
+      lastc = c;
       c = getc(ifp);
       if (c == 0)
-       _gnu_noobjc_argc++;
+          _gnu_noobjc_argc++;
       else if (c == EOF)
-       break;
+        {
+          if(lastc != 0)
+            _gnu_noobjc_argc++;
+         break;
+        }
     }
-#if (CMDLINE_TERMINATED == 0)
-  _gnu_noobjc_argc++;
-#endif
   fclose(ifp);

   /*





reply via email to

[Prev in Thread] Current Thread [Next in Thread]