Tcl Source Code

Check-in [fbc6fd24c0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Getting better; now possibly with autoconf magic! Comments too.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-1224888
Files: files | file ages | folders
SHA1: fbc6fd24c0b5ab7f29502abba2e92a30a3814dc5
User & Date: dkf 2011-10-13 12:34:04
Context
2011-10-13
21:04
Ugh; Tcl_DStringInit in wrong place... check-in: a6843c662e user: dkf tags: bug-1224888
12:34
Getting better; now possibly with autoconf magic! Comments too. check-in: fbc6fd24c0 user: dkf tags: bug-1224888
12:16
A little more resilience. check-in: 9856078e30 user: dkf tags: bug-1224888
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to unix/configure.in.

126
127
128
129
130
131
132

133
134
135
136
137
138
139
# define USEGETWD even if the posix getcwd exists. Add a test ?

AC_REPLACE_FUNCS(opendir strstr strtol strtoll strtoull tmpnam waitpid)
AC_CHECK_FUNC(strerror, , [AC_DEFINE(NO_STRERROR)])
AC_CHECK_FUNC(getwd, , [AC_DEFINE(NO_GETWD)])
AC_CHECK_FUNC(wait3, , [AC_DEFINE(NO_WAIT3)])
AC_CHECK_FUNC(uname, , [AC_DEFINE(NO_UNAME)])


if test "`uname -s`" = "Darwin" && test "${TCL_THREADS}" = 1 && \
	test "`uname -r | awk -F. '{print [$]1}'`" -lt 7; then
    # prior to Darwin 7, realpath is not threadsafe, so don't
    # use it when threads are enabled, c.f. bug # 711232
    ac_cv_func_realpath=no
fi







>







126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# define USEGETWD even if the posix getcwd exists. Add a test ?

AC_REPLACE_FUNCS(opendir strstr strtol strtoll strtoull tmpnam waitpid)
AC_CHECK_FUNC(strerror, , [AC_DEFINE(NO_STRERROR)])
AC_CHECK_FUNC(getwd, , [AC_DEFINE(NO_GETWD)])
AC_CHECK_FUNC(wait3, , [AC_DEFINE(NO_WAIT3)])
AC_CHECK_FUNC(uname, , [AC_DEFINE(NO_UNAME)])
AC_CHECK_FUNC(dladdr, , [AC_DEFINE(NO_DLADDR)])

if test "`uname -s`" = "Darwin" && test "${TCL_THREADS}" = 1 && \
	test "`uname -r | awk -F. '{print [$]1}'`" -lt 7; then
    # prior to Darwin 7, realpath is not threadsafe, so don't
    # use it when threads are enabled, c.f. bug # 711232
    ac_cv_func_realpath=no
fi

Changes to unix/tclUnixFile.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tclInt.h"
#include "tclPort.h"
#ifndef NO_DLFCN_H
#include <dlfcn.h>
#endif

static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types);


/*







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tclInt.h"
#include "tclPort.h"
#if !defined(NO_DLADDR) && !defined(NO_DLFCN_H)
#include <dlfcn.h>
#endif

static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types);


/*
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74











75


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    CONST char *argv0;		/* The value of the application's argv[0]
				 * (native). */
{
    CONST char *name, *p;
    Tcl_StatBuf statBuf;
    int length;
    Tcl_DString buffer, nameString;
#ifndef DJGPP
    int i;

    static CONST char *exepaths[] = {
      "/proc/self/exe", "/proc/%lu/exe", "/proc/%lu/file",
      "/proc/%lu/object/a.out"
    };
    char buf1[PATH_MAX+1], buf2[128];
#endif
#ifndef NO_DLFCN_H
    Dl_info dlinfoBuffer;
    void *sym;
#endif

    if (argv0 == NULL) {
	return NULL;
    }
    if (tclNativeExecutableName != NULL) {
	return tclNativeExecutableName;
    }












#ifndef DJGPP


    for (i=0 ; i<sizeof(exepaths)/sizeof(*exepaths) ; i++) {
	sprintf(buf2,exepaths[i],(unsigned long)getpid());
	if (readlink(buf2,buf1,PATH_MAX) > 0 && buf1[0] == '/') {
	    name = buf1;
	    goto gotName;
	}
    }
#endif
#ifndef NO_DLFCN_H
    sym = dlsym(RTLD_DEFAULT, "main");
    if (sym == NULL) {
	sym = dlsym(RTLD_DEFAULT, "_main");
    }
    if (sym != NULL && dladdr(sym, &dlinfoBuffer)
	    && dlinfoBuffer.dli_fname[0] == '/') {
	name = dlinfoBuffer.dli_fname;







|

>

|
<

|

|











>
>
>
>
>
>
>
>
>
>
>
|
>
>

|
|





|







48
49
50
51
52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    CONST char *argv0;		/* The value of the application's argv[0]
				 * (native). */
{
    CONST char *name, *p;
    Tcl_StatBuf statBuf;
    int length;
    Tcl_DString buffer, nameString;
#if !defined(__APPLE__) && !defined(DJGPP)
    int i;
    unsigned long pid;
    static CONST char *exepaths[] = {
	"/proc/%lu/exe", "/proc/%lu/file", "/proc/%lu/object/a.out"

    };
    char buf1[PATH_MAX+1], buf2[64];
#endif
#if !defined(NO_DLADDR) && !defined(NO_DLFCN_H)
    Dl_info dlinfoBuffer;
    void *sym;
#endif

    if (argv0 == NULL) {
	return NULL;
    }
    if (tclNativeExecutableName != NULL) {
	return tclNativeExecutableName;
    }

    /*
     * The executable name is sometimes available to us directly, which is
     * useful because it's not always there in argv[0]; that's a value that is
     * set by the code that invoked this process and it sometimes lies.  [Bug
     * 1224888]
     *
     * Our options for independently determining it are to scrape it out of
     * /proc (if that's mounted, and we have readlink(2)) or to pick the
     * information out of the dynamic loader (assuming we're using a
     * compatible one and it supports the relevant - common - extension).
     */

#if !defined(__APPLE__) && !defined(DJGPP)
    pid = getpid();
    for (i=0 ; i<sizeof(exepaths)/sizeof(*exepaths) ; i++) {
	sprintf(buf2, exepaths[i], pid);
	if (readlink(buf2, buf1, PATH_MAX) > 0 && buf1[0] == '/') {
	    name = buf1;
	    goto gotName;
	}
    }
#endif
#if !defined(NO_DLADDR) && !defined(NO_DLFCN_H)
    sym = dlsym(RTLD_DEFAULT, "main");
    if (sym == NULL) {
	sym = dlsym(RTLD_DEFAULT, "_main");
    }
    if (sym != NULL && dladdr(sym, &dlinfoBuffer)
	    && dlinfoBuffer.dli_fname[0] == '/') {
	name = dlinfoBuffer.dli_fname;