Package: neko / 2.0.0-3

kfreebsd-executable-path.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Description: Make executable_path() work on kFreeBSD
 Fix for finding executable_path() on kFreeBSD, which only seemed to
 work when invoked from bash, thanks to Roman Neuhauser.
Author: Jens Peter Secher <jps@debian.org>
Forwarded: no
Last-Update: 2010-02-13

Index: b/vm/main.c
===================================================================
--- a/vm/main.c
+++ b/vm/main.c
@@ -35,6 +35,9 @@
 #ifdef NEKO_POSIX
 #	include <signal.h>
 #endif
+#if defined(__FreeBSD_kernel__) || defined (__FreeBSD__)
+#	include <sys/sysctl.h>
+#endif
 
 #ifdef NEKO_STANDALONE
 	extern void neko_standalone_init();
@@ -62,10 +65,24 @@
 	if ( _NSGetExecutablePath(path, &path_len) )
 		return NULL;
 	return path;
+#elif defined(__FreeBSD_kernel__) || defined (__FreeBSD__)
+	int mib[4];
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_PROC;
+	mib[2] = KERN_PROC_PATHNAME;
+	mib[3] = -1;
+	static char path[1024];
+	size_t length = sizeof(path);
+	sysctl(mib, 4, path, &length, NULL, 0);
+	if( length < 0 || length >= 1024 ) {
+		return NULL;
+	}
+	path[length] = '\0';
+	return path;
 #else
-	static char path[200];
+	static char path[1024];
 	int length = readlink("/proc/self/exe", path, sizeof(path));
-	if( length < 0 || length >= 200 ) {
+	if( length < 0 || length >= 1024 ) {
 		char *p = getenv("   "); // for upx
 		if( p == NULL )
 			p = getenv("_");