From b1ffacddfc2f558ad150d05a79318b7e58c572b2 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 12 May 2004 13:38:49 +0000 Subject: [PATCH] Rename find_my_binary/find_other_binary to find_my_exec/find_other_exec(). Remove passing of progname to these functions as they can find that out from argv[0], which they already have. Make get_progname return const char *, and update all progname variables to be const char *. --- src/backend/postmaster/postmaster.c | 10 +++++----- src/backend/tcop/postgres.c | 6 +++--- src/bin/initdb/initdb.c | 6 +++--- src/bin/pg_controldata/pg_controldata.c | 4 ++-- src/bin/pg_dump/pg_dumpall.c | 6 +++--- src/bin/pg_resetxlog/pg_resetxlog.c | 4 ++-- src/bin/psql/settings.h | 4 ++-- src/bin/psql/tab-complete.c | 4 ++-- src/bin/scripts/clusterdb.c | 4 ++-- src/bin/scripts/createdb.c | 4 ++-- src/bin/scripts/createlang.c | 4 ++-- src/bin/scripts/createuser.c | 4 ++-- src/bin/scripts/dropdb.c | 4 ++-- src/bin/scripts/droplang.c | 4 ++-- src/bin/scripts/dropuser.c | 4 ++-- src/bin/scripts/vacuumdb.c | 4 ++-- src/include/port.h | 9 ++++----- src/interfaces/ecpg/preproc/ecpg.c | 4 ++-- src/port/exec.c | 11 ++++++----- src/port/path.c | 6 +++--- 20 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index d2c7104174..bd18373920 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.384 2004/05/12 03:48:42 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.385 2004/05/12 13:38:39 momjian Exp $ * * NOTES * @@ -172,7 +172,7 @@ int MaxBackends; int ReservedBackends; -static char *progname = NULL; +static const char *progname = NULL; /* The socket(s) we're listening to. */ #define MAXLISTEN 10 @@ -412,7 +412,7 @@ PostmasterMain(int argc, char *argv[]) *original_extraoptions = '\0'; - progname = argv[0]; + progname = get_progname(argv[0]); IsPostmasterEnvironment = true; @@ -692,7 +692,7 @@ PostmasterMain(int argc, char *argv[]) /* * On some systems our dynloader code needs the executable's pathname. */ - if (find_my_binary(pg_pathname, argv[0], "postgres") < 0) + if (find_my_exec(pg_pathname, argv[0]) < 0) ereport(FATAL, (errmsg("%s: could not locate postgres executable", progname))); @@ -3222,7 +3222,7 @@ CreateOptsFile(int argc, char *argv[]) FILE *fp; int i; - if (find_my_binary(fullprogname, argv[0], "postmaster") < 0) + if (find_my_exec(fullprogname, argv[0]) < 0) { elog(LOG, "could not locate postmaster"); return false; diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index caeef3cd57..4c006f00b8 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.403 2004/05/11 21:57:14 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.404 2004/05/12 13:38:40 momjian Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -2083,7 +2083,7 @@ assign_max_stack_depth(int newval, bool doit, GucSource source) static void -usage(char *progname) +usage(const char *progname) { printf(gettext("%s is the PostgreSQL stand-alone backend. It is not\nintended to be used by normal users.\n\n"), progname); @@ -2649,7 +2649,7 @@ PostgresMain(int argc, char *argv[], const char *username) * On some systems our dynloader code needs the executable's * pathname. (If under postmaster, this was done already.) */ - if (find_my_binary(pg_pathname, argv[0], "postgres") < 0) + if (find_my_exec(pg_pathname, argv[0]) < 0) ereport(FATAL, (errmsg("%s: could not locate postgres executable", argv[0]))); diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index fa8bf28da8..c7ebb60f03 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -39,7 +39,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.27 2004/05/11 21:57:14 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.28 2004/05/12 13:38:42 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ bool show_setting = false; /* internal vars */ -char *progname; +const char *progname; char *postgres; char *encodingid = "0"; char *bki_file; @@ -1932,7 +1932,7 @@ main(int argc, char *argv[]) sprintf(pgdenv, "PGDATA=%s", pg_data); putenv(pgdenv); - if ((ret = find_other_binary(backendbin, argv[0], progname, "postgres", + if ((ret = find_other_exec(backendbin, argv[0], "postgres", PG_VERSIONSTR)) < 0) { if (ret == -1) diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c index 4342d1e10a..86b4d557d9 100644 --- a/src/bin/pg_controldata/pg_controldata.c +++ b/src/bin/pg_controldata/pg_controldata.c @@ -6,7 +6,7 @@ * copyright (c) Oliver Elphick , 2001; * licence: BSD * - * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.14 2004/03/22 15:34:22 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.15 2004/05/12 13:38:43 momjian Exp $ */ #include "postgres.h" @@ -75,7 +75,7 @@ main(int argc, char *argv[]) char ckpttime_str[128]; char sysident_str[32]; char *strftime_fmt = "%c"; - char *progname; + const char *progname; setlocale(LC_ALL, ""); #ifdef ENABLE_NLS diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 0817cabfb9..cac837865e 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.31 2004/05/11 21:57:14 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.32 2004/05/12 13:38:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ int optreset; #define PG_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n" -static char *progname; +static const char *progname; static void help(void); @@ -123,7 +123,7 @@ main(int argc, char *argv[]) } } - if ((ret = find_other_binary(pg_dump_bin, argv[0], progname, "pg_dump", + if ((ret = find_other_exec(pg_dump_bin, argv[0], "pg_dump", PG_VERSIONSTR)) < 0) { if (ret == -1) diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 80281e8ef7..8c57f71011 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.17 2004/03/22 16:46:28 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.18 2004/05/12 13:38:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -75,7 +75,7 @@ static ControlFileData ControlFile; /* pg_control values */ static uint32 newXlogId, newXlogSeg; /* ID/Segment of new XLOG segment */ static bool guessed = false; /* T if we had to guess at any values */ -static char *progname; +static const char *progname; static bool ReadControlFile(void); static void GuessControlValues(void); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index e28383b16b..d8766b045a 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.17 2004/03/21 22:29:11 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.18 2004/05/12 13:38:45 momjian Exp $ */ #ifndef SETTINGS_H #define SETTINGS_H @@ -42,7 +42,7 @@ typedef struct _psqlSettings * loop */ bool cur_cmd_interactive; - char *progname; /* in case you renamed psql */ + const char *progname; /* in case you renamed psql */ char *inputfile; /* for error reporting */ unsigned lineno; /* also for error reporting */ diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index f2b2d0902b..2eb2f19f09 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.105 2004/05/07 00:24:58 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.106 2004/05/12 13:38:46 momjian Exp $ */ /*---------------------------------------------------------------------- @@ -428,7 +428,7 @@ static char *dequote_file_name(char *text, char quote_char); void initialize_readline(void) { - rl_readline_name = pset.progname; + rl_readline_name = (char *)pset.progname; rl_attempted_completion_function = (void *) psql_completion; rl_basic_word_break_characters = "\t\n@$><=;|&{( "; diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 6518e010b7..0fcab8ec6d 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 2002-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.5 2004/01/01 19:27:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.6 2004/05/12 13:38:46 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,7 +43,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index 005c942cca..8ee5fdca65 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.7 2004/01/01 19:27:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.8 2004/05/12 13:38:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -37,7 +37,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c index 64e257bc2f..f75e9e07cd 100644 --- a/src/bin/scripts/createlang.c +++ b/src/bin/scripts/createlang.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.8 2004/03/19 18:58:07 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.9 2004/05/12 13:38:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 12c1aabb5d..2a262ecb39 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.9 2004/01/09 00:15:11 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.10 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index 91ad090f42..5b8540e4c3 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.8 2004/01/01 19:27:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.9 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c index 43f57115f5..63fe0f7c32 100644 --- a/src/bin/scripts/droplang.c +++ b/src/bin/scripts/droplang.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.7 2004/03/19 18:58:07 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.8 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,7 +34,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index b0dc5a7d7c..352f913a06 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.7 2004/01/01 19:27:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.8 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index cc9d8be139..ae64f34ab9 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.5 2004/01/01 19:27:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.6 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -48,7 +48,7 @@ main(int argc, char *argv[]) {NULL, 0, NULL, 0} }; - char *progname; + const char *progname; int optindex; int c; diff --git a/src/include/port.h b/src/include/port.h index 177c82f8c4..a037ac1f5f 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/port.h,v 1.29 2004/05/11 21:57:15 momjian Exp $ + * $PostgreSQL: pgsql/src/include/port.h,v 1.30 2004/05/12 13:38:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -25,12 +25,11 @@ extern bool is_absolute_path(const char *filename); extern char *first_path_separator(const char *filename); extern char *last_path_separator(const char *filename); extern void canonicalize_path(char *path); -extern char *get_progname(char *argv0); +extern const char *get_progname(const char *argv0); /* Portable way to find binaries */ -extern int find_my_binary(char *full_path, const char *argv0, - const char *binary_name); -extern int find_other_binary(char *retpath, const char *argv0, const char *progname, +extern int find_my_exec(char *full_path, const char *argv0); +extern int find_other_exec(char *retpath, const char *argv0, char const *target, const char *versionstr); #if defined(__CYGWIN__) || defined(WIN32) diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 5629f2b944..40edf0ecc4 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.85 2004/01/28 20:43:03 tgl Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.86 2004/05/12 13:38:48 momjian Exp $ */ /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */ /* (C) Michael Meskes Feb 5th, 1998 */ @@ -119,7 +119,7 @@ main(int argc, char *const argv[]) verbose = false, out_option = 0; struct _include_path *ip; - char *progname; + const char *progname; progname = get_progname(argv[0]); diff --git a/src/port/exec.c b/src/port/exec.c index 27e66cc0c8..2ea6531c8e 100644 --- a/src/port/exec.c +++ b/src/port/exec.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/exec.c,v 1.1 2004/05/11 21:57:15 momjian Exp $ + * $PostgreSQL: pgsql/src/port/exec.c,v 1.2 2004/05/12 13:38:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -165,7 +165,7 @@ validate_exec(char *path) } /* - * find_my_binary -- find an absolute path to a valid executable + * find_my_exec -- find an absolute path to a valid executable * * The reason we have to work so hard to find an absolute path is that * on some platforms we can't do dynamic loading unless we know the @@ -177,13 +177,14 @@ validate_exec(char *path) * non-threaded binaries, not in library routines. */ int -find_my_binary(char *full_path, const char *argv0, const char *binary_name) +find_my_exec(char *full_path, const char *argv0) { char buf[MAXPGPATH + 2]; char *p; char *path, *startp, *endp; + const char *binary_name = get_progname(argv0); /* * First try: use the binary that's located in the @@ -273,14 +274,14 @@ find_my_binary(char *full_path, const char *argv0, const char *binary_name) * Find our binary directory, then make sure the "target" executable * is the proper version. */ -int find_other_binary(char *retpath, const char *argv0, const char *progname, +int find_other_exec(char *retpath, const char *argv0, char const *target, const char *versionstr) { char cmd[MAXPGPATH]; char line[100]; FILE *pgver; - if (find_my_binary(retpath, argv0, progname) < 0) + if (find_my_exec(retpath, argv0) < 0) return -1; /* Trim off program name and keep just directory */ diff --git a/src/port/path.c b/src/port/path.c index 965d63ea33..5d102a90c2 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/path.c,v 1.6 2004/05/11 21:57:15 momjian Exp $ + * $PostgreSQL: pgsql/src/port/path.c,v 1.7 2004/05/12 13:38:49 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -113,8 +113,8 @@ canonicalize_path(char *path) /* * Extracts the actual name of the program as called. */ -char * -get_progname(char *argv0) +const char * +get_progname(const char *argv0) { if (!last_path_separator(argv0)) return argv0;