Fix random breakage in exec.c for platforms where strdup is a macro.

This commit is contained in:
Tom Lane 2004-05-21 16:06:23 +00:00
parent 79c3bf4984
commit ff0b706b13
2 changed files with 22 additions and 22 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/port.h,v 1.36 2004/05/21 05:08:03 tgl Exp $ * $PostgreSQL: pgsql/src/include/port.h,v 1.37 2004/05/21 16:06:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -60,7 +60,7 @@ extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
/* Portable way to find binaries */ /* Portable way to find binaries */
extern int find_my_exec(const char *argv0, char *retpath); extern int find_my_exec(const char *argv0, char *retpath);
extern int find_other_exec(const char *argv0, char const *target, extern int find_other_exec(const char *argv0, const char *target,
const char *versionstr, char *retpath); const char *versionstr, char *retpath);
#if defined(__CYGWIN__) || defined(WIN32) #if defined(__CYGWIN__) || defined(WIN32)
#define EXE ".exe" #define EXE ".exe"

View File

@ -7,16 +7,13 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/port/exec.c,v 1.12 2004/05/20 15:38:11 momjian Exp $ * $PostgreSQL: pgsql/src/port/exec.c,v 1.13 2004/05/21 16:06:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef FRONTEND #ifndef FRONTEND
#include "postgres.h" #include "postgres.h"
#define malloc(l) palloc(l)
#define free(p) pfree(p)
#define strdup(p) pstrdup(p)
#else #else
#include "postgres_fe.h" #include "postgres_fe.h"
#endif #endif
@ -24,14 +21,19 @@
#include <grp.h> #include <grp.h>
#include <pwd.h> #include <pwd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#define _(x) gettext((x))
#include "miscadmin.h" #include "miscadmin.h"
#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 ';'
@ -58,8 +60,10 @@
#define log_error(str, param) fprintf(stderr, (str), (param)) #define log_error(str, param) fprintf(stderr, (str), (param))
#endif #endif
static void win32_make_absolute(char *path); static void win32_make_absolute(char *path);
/* /*
* validate_exec -- validate "path" as an executable file * validate_exec -- validate "path" as an executable file
* *
@ -243,7 +247,7 @@ find_my_exec(const char *argv0, char *retpath)
*/ */
if ((p = getenv("PATH")) && *p) if ((p = getenv("PATH")) && *p)
{ {
path = strdup(p); /* make a modifiable copy */ path = pstrdup(p); /* make a modifiable copy */
for (startp = path, endp = strchr(path, PATHSEP); for (startp = path, endp = strchr(path, PATHSEP);
startp && *startp; startp && *startp;
startp = endp + 1, endp = strchr(startp, PATHSEP)) startp = endp + 1, endp = strchr(startp, PATHSEP))
@ -263,19 +267,19 @@ find_my_exec(const char *argv0, char *retpath)
{ {
case 0: /* found ok */ case 0: /* found ok */
win32_make_absolute(retpath); win32_make_absolute(retpath);
free(path); 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; break;
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);
free(path); pfree(path);
return -1; return -1;
} }
if (!endp) /* last one */ if (!endp) /* last one */
break; break;
} }
free(path); pfree(path);
} }
log_error("could not find a \"%s\" to execute", argv0); log_error("could not find a \"%s\" to execute", argv0);
@ -296,8 +300,9 @@ find_my_exec(const char *argv0, char *retpath)
* Find our binary directory, then make sure the "target" executable * Find our binary directory, then make sure the "target" executable
* is the proper version. * is the proper version.
*/ */
int find_other_exec(const char *argv0, char const *target, int
const char *versionstr, char *retpath) find_other_exec(const char *argv0, const char *target,
const char *versionstr, char *retpath)
{ {
char cmd[MAXPGPATH]; char cmd[MAXPGPATH];
char line[100]; char line[100];
@ -380,8 +385,6 @@ pclose_check(FILE *stream)
/* /*
* Windows doesn't like relative paths to executables (other things work fine) * Windows doesn't like relative paths to executables (other things work fine)
* so we call its builtin function to expand them. Elsewhere this is a NOOP * so we call its builtin function to expand them. Elsewhere this is a NOOP
*
* Returns malloc'ed memory.
*/ */
static void static void
win32_make_absolute(char *path) win32_make_absolute(char *path)
@ -391,14 +394,11 @@ win32_make_absolute(char *path)
if (_fullpath(abspath, path, MAXPGPATH) == NULL) if (_fullpath(abspath, path, MAXPGPATH) == NULL)
{ {
log_error("Win32 path expansion failed: %s", strerror(errno)); log_error("Win32 path expansion failed: %s", strerror(errno));
StrNCpy(abspath, path, MAXPGPATH); StrNCpy(abspath, path, MAXPGPATH);
} }
canonicalize_path(abspath); canonicalize_path(abspath);
StrNCpy(path, abspath, MAXPGPATH); StrNCpy(path, abspath, MAXPGPATH);
#endif #endif
return;
} }