From dbad7cd7353e3c5555f78599151a75cde522af37 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 4 May 2018 06:17:15 -0700 Subject: bugfix: correcly obtain self path on Solaris. * configure: Add detection for getexecname. * sysif.c (getcwd_wrap): Change static function to external. * sysif.h (getcwd_wrap): Declared. * txr.c (get_self_path): New implementation for Solaris using getexecname, which requires us to prepend the current directory name if the result is a relative path. --- configure | 18 ++++++++++++++++++ sysif.c | 2 +- sysif.h | 3 +++ txr.c | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 3e42ddc2..bd84ad42 100755 --- a/configure +++ b/configure @@ -2973,6 +2973,24 @@ else printf "no\n" fi +printf "Checking for getexecname ... " +cat > conftest.c < + +int main(void) +{ + const char *rp = getexecname(); + return 0; +} +! + +if conftest ; then + printf "yes\n" + printf "#define HAVE_GETEXECNAME 1\n" >> config.h +else + printf "no\n" +fi + # # Dependent variables # diff --git a/sysif.c b/sysif.c index 057560df..8111d4f5 100644 --- a/sysif.c +++ b/sysif.c @@ -335,7 +335,7 @@ static val chdir_wrap(val path) return t; } -static val getcwd_wrap(void) +val getcwd_wrap(void) { size_t guess = 256; diff --git a/sysif.h b/sysif.h index a9c13cd5..bae55147 100644 --- a/sysif.h +++ b/sysif.h @@ -69,4 +69,7 @@ INLINE void repress_privilege(void) { } INLINE void drop_privilege(void) { } INLINE void simulate_setuid_setgid(val open_script) { } #endif +#if HAVE_UNISTD_H +val getcwd_wrap(void); +#endif void sysif_init(void); diff --git a/txr.c b/txr.c index 428a0ff0..197f6515 100644 --- a/txr.c +++ b/txr.c @@ -243,6 +243,14 @@ static val get_self_path(void) return nil; return string_utf8(self); } +#elif HAVE_GETEXECNAME +static val get_self_path(void) +{ + val execname = string_utf8(getexecname()); + if (car(execname) == chr('/')) + return execname; + return format(nil, lit("~a/~a"), getcwd_wrap(), execname, nao); +} #else static val get_self_path(void) { -- cgit v1.2.3