aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-03-01 01:16:01 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-03-01 01:16:01 +0100
commita2e4641865f5b1478c4243767abd208772a303b3 (patch)
treeeb0f2af4416bdda5e0a785785ab66301d3bd0a96 /src/blogc-make
parent7c24a0a338a4bfe57690d586f59c9dc40ecd01ed (diff)
downloadblogc-a2e4641865f5b1478c4243767abd208772a303b3.tar.gz
blogc-a2e4641865f5b1478c4243767abd208772a303b3.tar.bz2
blogc-a2e4641865f5b1478c4243767abd208772a303b3.zip
make: support freebsd properly. drop solaris
Diffstat (limited to 'src/blogc-make')
-rw-r--r--src/blogc-make/exec.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index de37536..2fc46d8 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -14,6 +14,13 @@
#include <sys/wait.h>
#include <errno.h>
#include <libgen.h>
+
+#ifdef __FreeBSD__
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#include "../common/error.h"
#include "../common/file.h"
#include "../common/utils.h"
@@ -33,12 +40,24 @@ bm_exec_find_binary(const char *bin, const char *env)
// second try: same dir as current exec
char *path = realpath("/proc/self/exe", NULL); // Linux
+#ifdef __FreeBSD__
if (path == NULL) {
- path = realpath("/proc/curproc/file", NULL); // FreeBSD
+ path = realpath("/proc/curproc/file", NULL); // FreeBSD with /proc
if (path == NULL) {
- path = realpath("/proc/self/path/a.out", NULL); // Solaris
+ // FreeBSD without /proc (default for 11.0)
+ int name[4];
+ name[0] = CTL_KERN;
+ name[1] = KERN_PROC;
+ name[2] = KERN_PROC_PATHNAME;
+ name[3] = -1;
+ char buf[PATH_MAX];
+ size_t buf_len = sizeof(buf);
+ if (-1 != sysctl(name, 4, buf, &buf_len, NULL, 0)) {
+ path = bc_strdup_printf("%.*s", buf_len, buf);
+ }
}
}
+#endif
if (path != NULL) {
char *dir = bc_strdup(dirname(path));
free(path);