[PATCH] D56975: [Support] Reimplement getMainExecutable() using sysctl on NetBSD
Michał Górny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 3 02:06:38 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355283: [llvm] [Support] Reimplement getMainExecutable() using sysctl on NetBSD (authored by mgorny, committed by ).
Herald added a subscriber: jdoerfert.
Herald added a project: LLVM.
Changed prior to commit:
https://reviews.llvm.org/D56975?vs=182699&id=189077#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56975/new/
https://reviews.llvm.org/D56975
Files:
llvm/trunk/lib/Support/Unix/Path.inc
Index: llvm/trunk/lib/Support/Unix/Path.inc
===================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc
+++ llvm/trunk/lib/Support/Unix/Path.inc
@@ -90,6 +90,11 @@
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
#endif
+#if defined(__NetBSD__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
using namespace llvm;
namespace llvm {
@@ -98,7 +103,7 @@
const file_t kInvalidFile = -1;
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \
defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || defined(__GNU__)
static int
@@ -169,7 +174,18 @@
if (realpath(exe_path, link_path))
return link_path;
}
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
+#elif defined(__NetBSD__)
+ // NB: sysctl() solution can't be used on FreeBSD since it may return
+ // a wrong path when a file is hardlinked in multiple locations.
+ // See r303285 for an earlier revert.
+
+ char exe_path[PATH_MAX];
+ int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
+ size_t len = sizeof(exe_path);
+
+ if (sysctl(mib, 4, exe_path, &len, nullptr, 0) == 0)
+ return exe_path;
+#elif defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__minix) || defined(__DragonFly__) || \
defined(__FreeBSD_kernel__) || defined(_AIX)
char exe_path[PATH_MAX];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56975.189077.patch
Type: text/x-patch
Size: 1585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190303/d7f1ac83/attachment.bin>
More information about the llvm-commits
mailing list