2008-11-29 02:03:47 +00:00
|
|
|
diff -up Python-2.6/configure.in.canonicalize Python-2.6/configure.in
|
|
|
|
--- Python-2.6/configure.in.canonicalize 2008-09-07 15:18:16.000000000 -0400
|
|
|
|
+++ Python-2.6/configure.in 2008-11-24 02:09:29.000000000 -0500
|
|
|
|
@@ -2445,7 +2445,8 @@ fi
|
|
|
|
AC_MSG_RESULT(MACHDEP_OBJS)
|
|
|
|
|
|
|
|
# checks for library functions
|
|
|
|
-AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset chown \
|
|
|
|
+AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset \
|
|
|
|
+ canonicalize_file_name chown \
|
|
|
|
clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
|
|
|
|
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
|
|
|
|
getpriority getpwent getspnam getspent getsid getwd \
|
|
|
|
diff -up Python-2.6/pyconfig.h.in.canonicalize Python-2.6/pyconfig.h.in
|
|
|
|
--- Python-2.6/pyconfig.h.in.canonicalize 2008-09-07 01:15:18.000000000 -0400
|
|
|
|
+++ Python-2.6/pyconfig.h.in 2008-11-24 02:07:11.000000000 -0500
|
|
|
|
@@ -79,6 +79,9 @@
|
|
|
|
/* Define to 1 if you have the `chflags' function. */
|
|
|
|
#undef HAVE_CHFLAGS
|
2005-09-25 20:55:14 +00:00
|
|
|
|
|
|
|
+/* Define to 1 if you have the `canonicalize_file_name' function. */
|
|
|
|
+#undef HAVE_CANONICALIZE_FILE_NAME
|
|
|
|
+
|
|
|
|
/* Define to 1 if you have the `chown' function. */
|
|
|
|
#undef HAVE_CHOWN
|
|
|
|
|
2008-11-29 02:03:47 +00:00
|
|
|
diff -up Python-2.6/Python/sysmodule.c.canonicalize Python-2.6/Python/sysmodule.c
|
|
|
|
--- Python-2.6/Python/sysmodule.c.canonicalize 2008-07-10 13:13:55.000000000 -0400
|
|
|
|
+++ Python-2.6/Python/sysmodule.c 2008-11-24 02:07:11.000000000 -0500
|
|
|
|
@@ -1524,11 +1524,13 @@ makeargvobject(int argc, char **argv)
|
2005-09-22 22:35:36 +00:00
|
|
|
void
|
|
|
|
PySys_SetArgv(int argc, char **argv)
|
|
|
|
{
|
|
|
|
+#ifndef HAVE_CANONICALIZE_FILE_NAME
|
|
|
|
#if defined(HAVE_REALPATH)
|
|
|
|
char fullpath[MAXPATHLEN];
|
|
|
|
#elif defined(MS_WINDOWS)
|
|
|
|
char fullpath[MAX_PATH];
|
|
|
|
#endif
|
|
|
|
+#endif
|
|
|
|
PyObject *av = makeargvobject(argc, argv);
|
|
|
|
PyObject *path = PySys_GetObject("path");
|
|
|
|
if (av == NULL)
|
2008-11-29 02:03:47 +00:00
|
|
|
@@ -1540,6 +1542,64 @@ PySys_SetArgv(int argc, char **argv)
|
2005-09-23 20:12:16 +00:00
|
|
|
char *p = NULL;
|
2008-11-29 02:03:47 +00:00
|
|
|
Py_ssize_t n = 0;
|
2005-09-23 20:12:16 +00:00
|
|
|
PyObject *a;
|
2005-09-22 15:11:13 +00:00
|
|
|
+#ifdef HAVE_CANONICALIZE_FILE_NAME
|
2005-09-26 22:19:21 +00:00
|
|
|
+ char *link = NULL, *argv0copy = NULL;
|
2005-09-23 20:12:16 +00:00
|
|
|
+
|
2005-09-25 20:55:14 +00:00
|
|
|
+ if (argc > 0 && argv0 != NULL) {
|
2005-09-26 22:19:21 +00:00
|
|
|
+
|
|
|
|
+ link = canonicalize_file_name(argv0);
|
2005-10-06 18:58:41 +00:00
|
|
|
+ if (link == NULL) {
|
2005-09-26 22:19:21 +00:00
|
|
|
+ link = strdup(argv0);
|
|
|
|
+ if (!link)
|
|
|
|
+ Py_FatalError("no mem for sys.argv");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (link) {
|
|
|
|
+ if (link[0] == SEP) /* Link to absolute path */
|
|
|
|
+ argv0 = link;
|
|
|
|
+ else if (strchr(link, SEP) == NULL) {
|
|
|
|
+ /* Link without path */
|
|
|
|
+ /* strdup argv0 so we can free it
|
|
|
|
+ unconditionally */
|
|
|
|
+ argv0 = strdup(argv0);
|
|
|
|
+ if (!argv0)
|
|
|
|
+ Py_FatalError("no mem for sys.argv");
|
|
|
|
+ free(link);
|
|
|
|
+ } else {
|
|
|
|
+ /* Must join(dirname(argv0), link) */
|
|
|
|
+ char *q = strrchr(argv0, SEP);
|
|
|
|
+ if (q == NULL) /* argv0 without path */
|
|
|
|
+ argv0 = link;
|
|
|
|
+ else {
|
|
|
|
+ /* Must make a copy */
|
|
|
|
+ argv0copy = calloc(
|
|
|
|
+ strlen(link) + strlen(q) +1,
|
|
|
|
+ sizeof (char));
|
|
|
|
+ if (!argv0copy)
|
|
|
|
+ Py_FatalError("no mem for sys.argv");
|
|
|
|
+ strcpy(argv0copy, argv0);
|
|
|
|
+ q = strrchr(argv0copy, SEP);
|
|
|
|
+ strcpy(argv0copy+1, link);
|
|
|
|
+ argv0 = argv0copy;
|
|
|
|
+ p = NULL;
|
|
|
|
+ free(link);
|
2005-09-25 20:55:14 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
2005-09-26 22:19:21 +00:00
|
|
|
+ }
|
|
|
|
+ if (argc > 0 && argv0 != NULL) {
|
|
|
|
+ char *q;
|
|
|
|
+ p = strrchr(argv0, SEP);
|
|
|
|
+ /* Test for alternate separator */
|
|
|
|
+ q = strrchr(p ? p : argv0, '/');
|
|
|
|
+ if (q != NULL)
|
|
|
|
+ p = q;
|
|
|
|
+ if (p != NULL) {
|
|
|
|
+ n = p + 1 - argv0;
|
|
|
|
+ if (n > 1 && p[-1] != ':')
|
|
|
|
+ n--; /* Drop trailing separator */
|
|
|
|
+ }
|
2005-09-25 20:55:14 +00:00
|
|
|
+ }
|
2005-09-22 15:11:13 +00:00
|
|
|
+#else /* ! HAVE_CANONICALIZE_FILE_NAME */
|
2005-09-23 20:12:16 +00:00
|
|
|
#ifdef HAVE_READLINK
|
|
|
|
char link[MAXPATHLEN+1];
|
|
|
|
char argv0copy[2*MAXPATHLEN+1];
|
2008-11-29 02:03:47 +00:00
|
|
|
@@ -1612,9 +1672,14 @@ PySys_SetArgv(int argc, char **argv)
|
2005-09-22 15:11:13 +00:00
|
|
|
#endif /* Unix */
|
|
|
|
}
|
|
|
|
#endif /* All others */
|
|
|
|
+#endif /* ! HAVE_CANONICALIZE_FILE_NAME */
|
|
|
|
a = PyString_FromStringAndSize(argv0, n);
|
|
|
|
if (a == NULL)
|
|
|
|
Py_FatalError("no mem for sys.path insertion");
|
|
|
|
+#ifdef HAVE_CANONICALIZE_FILE_NAME
|
2005-10-06 18:58:41 +00:00
|
|
|
+ if (argc > 0 && argv0 != NULL)
|
2005-09-25 20:55:14 +00:00
|
|
|
+ free(argv0);
|
2005-09-22 15:11:13 +00:00
|
|
|
+#endif /* HAVE_CANONICALIZE_FILE_NAME */
|
|
|
|
if (PyList_Insert(path, 0, a) < 0)
|
|
|
|
Py_FatalError("sys.path.insert(0) failed");
|
|
|
|
Py_DECREF(a);
|