diff options
Diffstat (limited to 'src/port/path.c')
-rw-r--r-- | src/port/path.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/port/path.c b/src/port/path.c index 8fe6d92daaf..968045cf353 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/path.c,v 1.61.2.2 2005/12/23 22:34:27 tgl Exp $ + * $PostgreSQL: pgsql/src/port/path.c,v 1.61.2.3 2006/02/01 00:32:06 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -388,7 +388,8 @@ path_is_prefix_of_path(const char *path1, const char *path2) const char * get_progname(const char *argv0) { - const char *nodir_name; + const char *nodir_name; + const char *progname; nodir_name = last_dir_separator(argv0); if (nodir_name) @@ -396,25 +397,25 @@ get_progname(const char *argv0) else nodir_name = skip_drive(argv0); -#if defined(__CYGWIN__) || defined(WIN32) - /* strip .exe suffix, regardless of case */ - if (strlen(nodir_name) > sizeof(EXE) - 1 && - pg_strcasecmp(nodir_name + strlen(nodir_name) - (sizeof(EXE) - 1), EXE) == 0) + /* + * Make a copy in case argv[0] is modified by ps_status. + * Leaks memory, but called only once. + */ + progname = strdup(nodir_name); + if (progname == NULL) { - char *progname; + fprintf(stderr, "%s: out of memory\n", nodir_name); + exit(1); /* This could exit the postmaster */ + } - progname = strdup(nodir_name); /* leaks memory, but called only once */ - if (progname == NULL) - { - fprintf(stderr, "%s: out of memory\n", nodir_name); - exit(1); /* This could exit the postmaster */ - } +#if defined(__CYGWIN__) || defined(WIN32) + /* strip ".exe" suffix, regardless of case */ + if (strlen(progname) > sizeof(EXE) - 1 && + pg_strcasecmp(progname + strlen(progname) - (sizeof(EXE) - 1), EXE) == 0) progname[strlen(progname) - (sizeof(EXE) - 1)] = '\0'; - nodir_name = progname; - } #endif - return nodir_name; + return progname; } |