Try /proc/$PID/exe if /proc/self/exe doesn't work out.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 08 Jul 2009 17:53:48 -0400
changeset 1003 a28d30d275e2
parent 1002 001380a457a0
child 1005 cafe3867784c
Try /proc/$PID/exe if /proc/self/exe doesn't work out.
src/platform_unix.c
--- a/src/platform_unix.c	Wed Jul 08 17:47:05 2009 -0400
+++ b/src/platform_unix.c	Wed Jul 08 17:53:48 2009 -0400
@@ -245,6 +245,16 @@
      *  the /proc/self/exe symlink.
      */
     retval = readSymLink("/proc/self/exe");
+    if (retval == NULL)
+    {
+        /* older kernels don't have /proc/self ... try PID version... */
+        const unsigned long long pid = (unsigned long long) getpid();
+        char path[64];
+        const int rc = (int) snprintf(path,sizeof(path),"/proc/%llu/exe",pid);
+        if ( (rc > 0) && (rc < sizeof(path)) )
+            retval = readSymLink(path);
+    } /* if */
+
     if (retval != NULL)  /* chop off filename. */
     {
         char *ptr = strrchr(retval, '/');