[Lldb-commits] [PATCH] D29089: Switch HostInfoNetBSD::GetProgramFileSpec to sysctl(7)

Kamil Rytarowski via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 24 09:59:02 PST 2017


krytarowski created this revision.
krytarowski added a project: LLDB.

Remove dependency on the proc (/proc) filesystem, which is optional.

KERN_PROC_PATHNAME is available in NetBSD-current and will land NetBSD 8.0.
Older stable versions of NetBSD will not be supported.

Sponsored by <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D29089

Files:
  source/Host/netbsd/HostInfoNetBSD.cpp


Index: source/Host/netbsd/HostInfoNetBSD.cpp
===================================================================
--- source/Host/netbsd/HostInfoNetBSD.cpp
+++ source/Host/netbsd/HostInfoNetBSD.cpp
@@ -85,15 +85,15 @@
   static FileSpec g_program_filespec;
 
   if (!g_program_filespec) {
-    ssize_t len;
-    static char buf[PATH_MAX];
-    char name[PATH_MAX];
-
-    ::snprintf(name, PATH_MAX, "/proc/%d/exe", ::getpid());
-    len = ::readlink(name, buf, PATH_MAX - 1);
-    if (len != -1) {
-      buf[len] = '\0';
-      g_program_filespec.SetFile(buf, false);
+    static const int name[] = {
+        CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
+    };
+    char path[MAXPATHLEN];
+    size_t len;
+
+    len = sizeof(path);
+    if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1) {
+        g_program_filespec.SetFile(path, false);
     }
   }
   return g_program_filespec;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29089.85600.patch
Type: text/x-patch
Size: 904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170124/b418f349/attachment-0001.bin>


More information about the lldb-commits mailing list