Skip to content

Commit

Permalink
In determine_executable_name, use sysctl(3) on FreeBSD
Browse files Browse the repository at this point in the history
Just calling realpath(3) on the value of argv[0] is inadequate.

(cherry picked from commit e25db62)
  • Loading branch information
xrme committed May 14, 2017
1 parent ccead33 commit fa63981
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lisp-kernel/pmcl-kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ Boolean use_mach_exception_handling =
#include <libgen.h>
#endif

#ifdef FREEBSD
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

#if defined(FREEBSD) || defined(SOLARIS)
#include <sys/time.h>
#include <sys/resource.h>
Expand Down Expand Up @@ -1078,6 +1083,15 @@ determine_executable_name(char *argv0)
return argv0;
#endif
#ifdef FREEBSD
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
char exepath[PATH_MAX];
size_t len = sizeof(exepath);

if (sysctl(mib, 4, exepath, &len, NULL, 0) == 0) {
char *p = strndup(exepath, len);

return p;
}
return ensure_real_path(argv0);
#endif
#ifdef SOLARIS
Expand Down

0 comments on commit fa63981

Please sign in to comment.