neko (1.8.1-6) kfreebsd-executable-path.diff

Summary

 vm/main.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

    
download this patch

Patch contents

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: neko/vm/main.c
===================================================================
--- neko.orig/vm/main.c	2010-02-13 18:49:43.000000000 +0100
+++ neko/vm/main.c	2010-02-15 20:54:47.000000000 +0100
@@ -30,6 +30,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();
@@ -57,10 +60,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("_");