Index: kitsh/buildsrc/kitsh-0.0/configure.ac ================================================================== --- kitsh/buildsrc/kitsh-0.0/configure.ac +++ kitsh/buildsrc/kitsh-0.0/configure.ac @@ -41,11 +41,11 @@ AC_CHECK_FUNCS(Tcl_GetEncodingNameFromEnvironment Tcl_SetSystemEncoding) LIBS="${SAVE_LIBS}" dnl Check for optional headers AC_HEADER_STDC -AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(unistd.h string.h strings.h) dnl Check for optional system calls AC_CHECK_FUNCS(readlink) dnl Check for acceptable dladdr so we can find ourselves on Solaris Index: kitsh/buildsrc/kitsh-0.0/kitInit.c ================================================================== --- kitsh/buildsrc/kitsh-0.0/kitInit.c +++ kitsh/buildsrc/kitsh-0.0/kitInit.c @@ -34,10 +34,16 @@ #include "tclInt.h" #ifdef HAVE_UNISTD_H # include #endif +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif /* For dladdr() and Dl_info */ #ifdef HAVE_DLFCN_H # include #endif @@ -204,28 +210,37 @@ int len = 0; Tcl_Obj *execNameObj; Tcl_Obj *lobjv[1]; #ifdef HAVE_READLINK ssize_t readlink_ret; - char procpath[4096]; char exe_buf[4096]; - int snprintf_ret; #endif /* HAVE_READLINK */ #ifdef HAVE_ACCEPTABLE_DLADDR Dl_info syminfo; int dladdr_ret; #endif /* HAVE_ACCEPTABLE_DLADDR */ #ifdef HAVE_READLINK if (Tcl_GetNameOfExecutable() == NULL) { - snprintf_ret = snprintf(procpath, sizeof(procpath), "/proc/%lu/exe", (unsigned long) getpid()); - if (snprintf_ret < sizeof(procpath)) { - readlink_ret = readlink(procpath, exe_buf, sizeof(exe_buf) - 1); + readlink_ret = readlink("/proc/self/exe", exe_buf, sizeof(exe_buf) - 1); + + if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) { + exe_buf[readlink_ret] = '\0'; + + SetExecName(interp, exe_buf); + + return; + } + } + + if (Tcl_GetNameOfExecutable() == NULL) { + readlink_ret = readlink("/proc/curproc/file", exe_buf, sizeof(exe_buf) - 1); + + if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) { + exe_buf[readlink_ret] = '\0'; - if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) { - exe_buf[readlink_ret] = '\0'; - + if (strcmp(exe_buf, "unknown") != 0) { SetExecName(interp, exe_buf); return; } }