Skip to content
Snippets Groups Projects
Commit 244ee0c0 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

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
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
*
*
* 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 @@
#define _(x) gettext(x)
#ifdef FRONTEND
#undef pstrdup
#define pstrdup(p) strdup(p)
#define pfree(p) free(p)
#endif
/* $PATH (or %PATH%) path separator */
#ifdef WIN32
#define PATHSEP ';'
......@@ -185,11 +179,8 @@ validate_exec(const char *path)
int
find_my_exec(const char *argv0, char *retpath)
{
char cwd[MAXPGPATH];
char *p;
char *path,
*startp,
*endp;
char cwd[MAXPGPATH], test_path[MAXPGPATH];
char *path;
if (!getcwd(cwd, MAXPGPATH))
cwd[0] = '\0';
......@@ -205,9 +196,9 @@ find_my_exec(const char *argv0, char *retpath)
* it).
*/
/* 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);
return -1;
......@@ -245,41 +236,41 @@ find_my_exec(const char *argv0, char *retpath)
* Second try: since no explicit path was supplied, the user must have
* 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 */
for (startp = path, endp = strchr(path, PATHSEP);
startp && *startp;
startp = endp + 1, endp = strchr(startp, PATHSEP))
char *startp = NULL, *endp = NULL;
do
{
if (startp == endp) /* it's a "::" */
continue;
if (endp)
*endp = '\0';
if (!startp)
startp = path;
else
startp = endp + 1;
if (is_absolute_path(startp))
snprintf(retpath, MAXPGPATH, "%s/%s", startp, argv0);
endp = strchr(startp, PATHSEP);
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
snprintf(retpath, MAXPGPATH, "%s/%s/%s", cwd, startp, argv0);
snprintf(retpath, MAXPGPATH, "%s/%s/%s", cwd, test_path, argv0);
canonicalize_path(retpath);
switch (validate_exec(retpath))
{
case 0: /* found ok */
win32_make_absolute(retpath);
pfree(path);
return 0;
case -1: /* wasn't even a candidate, keep looking */
break;
continue;
case -2: /* found but disqualified */
log_error("could not read binary \"%s\"", retpath);
pfree(path);
return -1;
continue;
}
if (!endp) /* last one */
break;
}
pfree(path);
} while (*endp);
}
log_error("could not find a \"%s\" to execute", argv0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment