Skip to content

Commit ff0b706

Browse files
committed
Fix random breakage in exec.c for platforms where strdup is a macro.
1 parent 79c3bf4 commit ff0b706

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/include/port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.36 2004/05/21 05:08:03 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.37 2004/05/21 16:06:22 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -60,7 +60,7 @@ extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
6060

6161
/* Portable way to find binaries */
6262
extern int find_my_exec(const char *argv0, char *retpath);
63-
extern int find_other_exec(const char *argv0, char const *target,
63+
extern int find_other_exec(const char *argv0, const char *target,
6464
const char *versionstr, char *retpath);
6565
#if defined(__CYGWIN__) || defined(WIN32)
6666
#define EXE ".exe"

src/port/exec.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/port/exec.c,v 1.12 2004/05/20 15:38:11 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.13 2004/05/21 16:06:23 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#ifndef FRONTEND
1616
#include "postgres.h"
17-
#define malloc(l) palloc(l)
18-
#define free(p) pfree(p)
19-
#define strdup(p) pstrdup(p)
2017
#else
2118
#include "postgres_fe.h"
2219
#endif
2320

2421
#include <grp.h>
2522
#include <pwd.h>
2623
#include <sys/stat.h>
24+
#include <sys/wait.h>
2725
#include <unistd.h>
2826

29-
#include <sys/wait.h>
27+
#include "miscadmin.h"
3028

31-
#define _(x) gettext((x))
29+
#define _(x) gettext(x)
3230

33-
#include "miscadmin.h"
31+
#ifdef FRONTEND
32+
#undef pstrdup
33+
#define pstrdup(p) strdup(p)
34+
#define pfree(p) free(p)
35+
#endif
3436

3537
/* $PATH (or %PATH%) path separator */
3638
#ifdef WIN32
@@ -58,8 +60,10 @@
5860
#define log_error(str, param) fprintf(stderr, (str), (param))
5961
#endif
6062

63+
6164
static void win32_make_absolute(char *path);
6265

66+
6367
/*
6468
* validate_exec -- validate "path" as an executable file
6569
*
@@ -243,7 +247,7 @@ find_my_exec(const char *argv0, char *retpath)
243247
*/
244248
if ((p = getenv("PATH")) && *p)
245249
{
246-
path = strdup(p); /* make a modifiable copy */
250+
path = pstrdup(p); /* make a modifiable copy */
247251
for (startp = path, endp = strchr(path, PATHSEP);
248252
startp && *startp;
249253
startp = endp + 1, endp = strchr(startp, PATHSEP))
@@ -263,19 +267,19 @@ find_my_exec(const char *argv0, char *retpath)
263267
{
264268
case 0: /* found ok */
265269
win32_make_absolute(retpath);
266-
free(path);
270+
pfree(path);
267271
return 0;
268272
case -1: /* wasn't even a candidate, keep looking */
269273
break;
270274
case -2: /* found but disqualified */
271275
log_error("could not read binary \"%s\"", retpath);
272-
free(path);
276+
pfree(path);
273277
return -1;
274278
}
275279
if (!endp) /* last one */
276280
break;
277281
}
278-
free(path);
282+
pfree(path);
279283
}
280284

281285
log_error("could not find a \"%s\" to execute", argv0);
@@ -296,8 +300,9 @@ find_my_exec(const char *argv0, char *retpath)
296300
* Find our binary directory, then make sure the "target" executable
297301
* is the proper version.
298302
*/
299-
int find_other_exec(const char *argv0, char const *target,
300-
const char *versionstr, char *retpath)
303+
int
304+
find_other_exec(const char *argv0, const char *target,
305+
const char *versionstr, char *retpath)
301306
{
302307
char cmd[MAXPGPATH];
303308
char line[100];
@@ -380,8 +385,6 @@ pclose_check(FILE *stream)
380385
/*
381386
* Windows doesn't like relative paths to executables (other things work fine)
382387
* so we call its builtin function to expand them. Elsewhere this is a NOOP
383-
*
384-
* Returns malloc'ed memory.
385388
*/
386389
static void
387390
win32_make_absolute(char *path)
@@ -391,14 +394,11 @@ win32_make_absolute(char *path)
391394

392395
if (_fullpath(abspath, path, MAXPGPATH) == NULL)
393396
{
394-
log_error("Win32 path expansion failed: %s", strerror(errno));
397+
log_error("Win32 path expansion failed: %s", strerror(errno));
395398
StrNCpy(abspath, path, MAXPGPATH);
396399
}
397400
canonicalize_path(abspath);
398401

399402
StrNCpy(path, abspath, MAXPGPATH);
400403
#endif
401-
return;
402404
}
403-
404-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy