[PATCH] D5693: Implement argv0-less getMainExecutable for FreeBSD
    Jan Beich via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Sep 25 15:10:46 PDT 2019
    
    
  
jbeich added inline comments.
Herald added a subscriber: krytarowski.
================
Comment at: lib/Support/Unix/Path.inc:51
 #endif
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
+#include <sys/sysctl.h>
----------------
Add `|| defined(__DragonFly__)` as it has `KERN_PROC_PATHNAME`.
================
Comment at: lib/Support/Unix/Path.inc:167
   }
-#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
-      defined(__OpenBSD__) || defined(__minix) || defined(__DragonFly__) || \
-      defined(__FreeBSD_kernel__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+      defined(__NetBSD__)
----------------
Add `|| defined(__DragonFly__)` as its `KERN_PROC_PATHNAME` [is similar](https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/f849311b84a9) to FreeBSD.
================
Comment at: lib/Support/Unix/Path.inc:171
+  size_t len = sizeof(exe_path);
+  int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME };
+
----------------
Not valid on NetBSD, see [sysctl(7)](https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-current). Try instead:
```lang=c
#if defined(__NetBSD__)
  int name[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
#else
  int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
#endif
```
================
Comment at: lib/Support/Unix/Path.inc:173
+
+  name[3] = getpid();
+  if (sysctl(name, 4, exe_path, &len, NULL, 0) == 0)
----------------
`getpid()` can be optimized to `-1`. Other LLVM consumers of `KERN_PROC_PATHNAME` already use `-1`.
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D5693/new/
https://reviews.llvm.org/D5693
    
    
More information about the llvm-commits
mailing list