Diff

Differences From Artifact [534a43d0fd]:

To Artifact [4d11547632]:


    32     32   #endif /* MB_TASKMODAL */
    33     33   
    34     34   #include "tclInt.h"
    35     35   
    36     36   #ifdef HAVE_UNISTD_H
    37     37   #  include <unistd.h>
    38     38   #endif
           39  +#ifdef HAVE_STRING_H
           40  +#  include <string.h>
           41  +#endif
           42  +#ifdef HAVE_STRINGS_H
           43  +#  include <strings.h>
           44  +#endif
    39     45   
    40     46   /* For dladdr() and Dl_info */
    41     47   #ifdef HAVE_DLFCN_H
    42     48   #  include <dlfcn.h>
    43     49   #endif
    44     50   
    45     51   #if defined(HAVE_TCL_GETENCODINGNAMEFROMENVIRONMENT) && defined(HAVE_TCL_SETSYSTEMENCODING)
................................................................................
   202    208   
   203    209   static void FindAndSetExecName(Tcl_Interp *interp) {
   204    210   	int len = 0;
   205    211   	Tcl_Obj *execNameObj;
   206    212   	Tcl_Obj *lobjv[1];
   207    213   #ifdef HAVE_READLINK
   208    214   	ssize_t readlink_ret;
   209         -	char procpath[4096];
   210    215   	char exe_buf[4096];
   211         -	int snprintf_ret;
   212    216   #endif /* HAVE_READLINK */
   213    217   #ifdef HAVE_ACCEPTABLE_DLADDR
   214    218   	Dl_info syminfo;
   215    219   	int dladdr_ret;
   216    220   #endif /* HAVE_ACCEPTABLE_DLADDR */ 
   217    221   
   218    222   #ifdef HAVE_READLINK
   219    223   	if (Tcl_GetNameOfExecutable() == NULL) {
   220         -		snprintf_ret = snprintf(procpath, sizeof(procpath), "/proc/%lu/exe", (unsigned long) getpid());
   221         -		if (snprintf_ret < sizeof(procpath)) {
   222         -			readlink_ret = readlink(procpath, exe_buf, sizeof(exe_buf) - 1);
          224  +		readlink_ret = readlink("/proc/self/exe", exe_buf, sizeof(exe_buf) - 1);
   223    225   
   224         -			if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) {
   225         -				exe_buf[readlink_ret] = '\0';
          226  +		if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) {
          227  +			exe_buf[readlink_ret] = '\0';
   226    228   
          229  +			SetExecName(interp, exe_buf);
          230  +
          231  +			return;
          232  +		}
          233  +	}
          234  +
          235  +	if (Tcl_GetNameOfExecutable() == NULL) {
          236  +		readlink_ret = readlink("/proc/curproc/file", exe_buf, sizeof(exe_buf) - 1);
          237  +
          238  +		if (readlink_ret > 0 && readlink_ret < (sizeof(exe_buf) - 1)) {
          239  +			exe_buf[readlink_ret] = '\0';
          240  +
          241  +			if (strcmp(exe_buf, "unknown") != 0) {
   227    242   				SetExecName(interp, exe_buf);
   228    243   
   229    244   				return;
   230    245   			}
   231    246   		}
   232    247   	}
   233    248   #endif /* HAVE_READLINK */