Commit 244ee0c0 authored by Bruce Momjian's avatar Bruce Momjian

Remove pstrdup() call from exec.c because DLLIMPORT flag on

CurrentMemoryContext caused compile problems.

Recode to not make a copy of the PATH but copy parts out into MAXPGPATH
variables.
parent fcbc95b9
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/port/exec.c,v 1.14 2004/05/24 20:23:50 momjian Exp $ * $PostgreSQL: pgsql/src/port/exec.c,v 1.15 2004/05/24 22:35:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,12 +28,6 @@ ...@@ -28,12 +28,6 @@
#define _(x) gettext(x) #define _(x) gettext(x)
#ifdef FRONTEND
#undef pstrdup
#define pstrdup(p) strdup(p)
#define pfree(p) free(p)
#endif
/* $PATH (or %PATH%) path separator */ /* $PATH (or %PATH%) path separator */
#ifdef WIN32 #ifdef WIN32
#define PATHSEP ';' #define PATHSEP ';'
...@@ -185,11 +179,8 @@ validate_exec(const char *path) ...@@ -185,11 +179,8 @@ validate_exec(const char *path)
int int
find_my_exec(const char *argv0, char *retpath) find_my_exec(const char *argv0, char *retpath)
{ {
char cwd[MAXPGPATH]; char cwd[MAXPGPATH], test_path[MAXPGPATH];
char *p; char *path;
char *path,
*startp,
*endp;
if (!getcwd(cwd, MAXPGPATH)) if (!getcwd(cwd, MAXPGPATH))
cwd[0] = '\0'; cwd[0] = '\0';
...@@ -205,9 +196,9 @@ find_my_exec(const char *argv0, char *retpath) ...@@ -205,9 +196,9 @@ find_my_exec(const char *argv0, char *retpath)
* it). * it).
*/ */
/* Does argv0 have a separator? */ /* Does argv0 have a separator? */
if ((p = last_path_separator(argv0))) if ((path = last_path_separator(argv0)))
{ {
if (*++p == '\0') if (*++path == '\0')
{ {
log_error("argv[0] ends with a path separator \"%s\"", argv0); log_error("argv[0] ends with a path separator \"%s\"", argv0);
return -1; return -1;
...@@ -245,41 +236,41 @@ find_my_exec(const char *argv0, char *retpath) ...@@ -245,41 +236,41 @@ find_my_exec(const char *argv0, char *retpath)
* Second try: since no explicit path was supplied, the user must have * Second try: since no explicit path was supplied, the user must have
* been relying on PATH. We'll use the same PATH. * been relying on PATH. We'll use the same PATH.
*/ */
if ((p = getenv("PATH")) && *p) if ((path = getenv("PATH")) && *path)
{ {
path = pstrdup(p); /* make a modifiable copy */ char *startp = NULL, *endp = NULL;
for (startp = path, endp = strchr(path, PATHSEP);
startp && *startp; do
startp = endp + 1, endp = strchr(startp, PATHSEP))
{ {
if (startp == endp) /* it's a "::" */ if (!startp)
continue; startp = path;
if (endp) else
*endp = '\0'; startp = endp + 1;
if (is_absolute_path(startp)) endp = strchr(startp, PATHSEP);
snprintf(retpath, MAXPGPATH, "%s/%s", startp, argv0); if (!endp)
endp = startp + strlen(startp); /* point to end */
StrNCpy(test_path, startp, Min(endp - startp + 1, MAXPGPATH));
if (is_absolute_path(test_path))
snprintf(retpath, MAXPGPATH, "%s/%s", test_path, argv0);
else else
snprintf(retpath, MAXPGPATH, "%s/%s/%s", cwd, startp, argv0); snprintf(retpath, MAXPGPATH, "%s/%s/%s", cwd, test_path, argv0);
canonicalize_path(retpath); canonicalize_path(retpath);
switch (validate_exec(retpath)) switch (validate_exec(retpath))
{ {
case 0: /* found ok */ case 0: /* found ok */
win32_make_absolute(retpath); win32_make_absolute(retpath);
pfree(path);
return 0; return 0;
case -1: /* wasn't even a candidate, keep looking */ case -1: /* wasn't even a candidate, keep looking */
break; continue;
case -2: /* found but disqualified */ case -2: /* found but disqualified */
log_error("could not read binary \"%s\"", retpath); log_error("could not read binary \"%s\"", retpath);
pfree(path); continue;
return -1;
} }
if (!endp) /* last one */ } while (*endp);
break;
}
pfree(path);
} }
log_error("could not find a \"%s\" to execute", argv0); log_error("could not find a \"%s\" to execute", argv0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment