-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netbsd does not have KERN_PROC_PATHNAME but /proc/self/exe #16
Conversation
Hello @marcIhm 👋 I don't really know NetBSD 😐 @jbeich Can you please chime in and tell us what you think about the proposed changes? As far as I can tell, you made the judgment call to assume NetBSD has Thanks in advance 🙏 |
lldb @marcIhm, can you try the following instead? diff --git a/src/whereami.c b/src/whereami.c
index 7441823..a43e975 100644
--- a/src/whereami.c
+++ b/src/whereami.c
@@ -576,17 +576,21 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
char buffer1[PATH_MAX];
char buffer2[PATH_MAX];
char* path = buffer1;
char* resolved = NULL;
int length = -1;
for (;;)
{
+#if defined(__NetBSD__)
+ int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
+#else
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+#endif
size_t size = sizeof(buffer1);
if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0)
break;
resolved = realpath(path, buffer2);
if (!resolved)
break; |
NetBSD 6.x reached EOL a few months ago but NetBSD 7.x is still supported and lacks diff --git a/src/whereami.c b/src/whereami.c
index 7441823..cda4e8d 100644
--- a/src/whereami.c
+++ b/src/whereami.c
@@ -7,16 +7,22 @@
#if !defined(WHEREAMI_H)
#include <whereami.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
+#if defined(__DragonFly__) || defined(__FreeBSD__) || \
+ defined(__FreeBSD_kernel__) || defined(__NetBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC)
#include <stdlib.h>
#endif
#if !defined(WAI_MALLOC)
#define WAI_MALLOC(size) malloc(size)
#endif
@@ -153,17 +159,17 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
#endif
{
length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length);
}
return length;
}
-#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun)
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || (defined(__NetBSD__) && !defined(KERN_PROC_PATHNAME))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#include <linux/limits.h>
#else
#include <limits.h>
@@ -555,38 +561,39 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
}
break;
}
return length;
}
-#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
- defined(__FreeBSD_kernel__) || defined(__NetBSD__)
+#elif defined(KERN_PROC_PATHNAME)
#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
#include <dlfcn.h>
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer1[PATH_MAX];
char buffer2[PATH_MAX];
char* path = buffer1;
char* resolved = NULL;
int length = -1;
for (;;)
{
+#if defined(__NetBSD__)
+ int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
+#else
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+#endif
size_t size = sizeof(buffer1);
if (sysctl(mib, (u_int)(sizeof(mib) / sizeof(mib[0])), path, &size, NULL, 0) != 0)
break;
resolved = realpath(path, buffer2);
if (!resolved)
break; |
7.0 will get EOL probably soon as we are planning to release -9 earlier |
Does inspecting |
The patch provided by Jan works for my netBSD 8 box like a charm; updated my pull request accordingly. |
Well I vastly prefer your initial patch that inspects This makes the code clearer than interspersing |
Reverted to the initial Version :-) |
/proc is deprecated, please never use it except as a fallback for old versions of NetBSD (but at this point we can ignore them) |
Okay, thanx to Kamils comment we are back at the Changes proposed by Jan. Seems like sometimes you just Need some ifdefs :-) |
Time to iron things out! My understanding is that the current code in
To avoid scattering the platform detection If we really want to support NetBSD 7.0 or help packagers, we could alter line 161 to force the inspection of
What do you think? If we all agree, for this PR to merge:
Oh and happy new year 2019! 🎉 |
Yes, woule be great for me ! So it would be Jans first and simpler proposal without support for NetBSD 7 and earlier. (And Jan should be the author of Course !) |
- assume NetBSD >= 8.0 - for NetBSD < 8.0, define WAI_USE_PROC_SELF_EXE
@marcIhm I squashed and pushed to your |
Just compiled and started yabasic on NetBSD 8: No Problems ! |
Thanks for improving |
Hi, thanx for your library !
(I am using it for my own project yabasic)
Found it is not working out of the box on netbsd but a simple modification helps.
Tested for netbsd 8.0
Thanx for merging (if you do …) !