Move PGPORT envar handling to ResetAllOptions(). Improve long options

parsing to not clobber the optarg string -- so that we can bring
SetOptsFile() up to speed.
This commit is contained in:
Peter Eisentraut 2000-07-03 20:46:10 +00:00
parent 51afb9305c
commit e2d3932e0e
5 changed files with 72 additions and 31 deletions

View File

@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pqcomm.c,v 1.98 2000/06/14 18:17:28 petere Exp $
* $Id: pqcomm.c,v 1.99 2000/07/03 20:45:57 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -41,7 +41,6 @@
* StreamServerPort - Open postmaster's server port
* StreamConnection - Create new connection with client
* StreamClose - Close a client/backend connection
* pq_getport - return the PGPORT setting
* pq_init - initialize libpq at backend startup
* pq_close - shutdown libpq at backend exit
*

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.151 2000/07/02 15:20:48 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.152 2000/07/03 20:45:58 petere Exp $
*
* NOTES
*
@ -383,9 +383,6 @@ PostmasterMain(int argc, char *argv[])
if (getenv("PGDATA"))
DataDir = strdup(getenv("PGDATA")); /* default value */
if (getenv("PGPORT"))
PostPortName = atoi(getenv("PGPORT"));
ResetAllOptions();
/*
@ -504,7 +501,6 @@ PostmasterMain(int argc, char *argv[])
strcpy(original_extraoptions, optarg);
break;
case 'p':
/* Set PGPORT by hand. */
PostPortName = atoi(optarg);
break;
case 'S':
@ -529,17 +525,16 @@ PostmasterMain(int argc, char *argv[])
break;
case '-':
{
/* A little 'long argument' simulation */
size_t equal_pos = strcspn(optarg, "=");
char *cp;
char *name, *value;
if (optarg[equal_pos] != '=')
ParseLongOption(optarg, &name, &value);
if (!value)
elog(ERROR, "--%s requires argument", optarg);
optarg[equal_pos] = '\0';
for(cp = optarg; *cp; cp++)
if (*cp == '-')
*cp = '_';
SetConfigOption(optarg, optarg + equal_pos + 1, PGC_POSTMASTER);
SetConfigOption(name, value, PGC_POSTMASTER);
free(name);
if (value)
free(value);
break;
}
default:

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.163 2000/06/29 07:35:57 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.164 2000/07/03 20:46:00 petere Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -1167,18 +1167,16 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
case '-':
{
/* A little 'long argument' simulation */
/* (copy&pasted from PostmasterMain() */
size_t equal_pos = strcspn(optarg, "=");
char *cp;
char *name, *value;
if (optarg[equal_pos] != '=')
ParseLongOption(optarg, &name, &value);
if (!value)
elog(ERROR, "--%s requires argument", optarg);
optarg[equal_pos] = '\0';
for(cp = optarg; *cp; cp++)
if (*cp == '-')
*cp = '_';
SetConfigOption(optarg, optarg + equal_pos + 1, PGC_BACKEND);
SetConfigOption(name, value, PGC_BACKEND);
free(name);
if (value)
free(value);
break;
}
@ -1408,7 +1406,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.163 $ $Date: 2000/06/29 07:35:57 $\n");
puts("$Revision: 1.164 $ $Date: 2000/07/03 20:46:00 $\n");
}
/*

View File

@ -4,7 +4,7 @@
* Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options.
*
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.4 2000/06/22 22:31:21 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.5 2000/07/03 20:46:05 petere Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
@ -354,6 +354,9 @@ ResetAllOptions(void)
}
ConfigureNamesString[i].variable = str;
}
if (getenv("PGPORT"))
PostPortName = atoi(getenv("PGPORT"));
}
@ -718,3 +721,49 @@ GetConfigOption(const char * name)
}
return NULL;
}
/*
* A little "long argument" simulation, although not quite GNU
* compliant. Takes a string of the form "some-option=some value" and
* returns name = "some_option" and value = "some value" in malloc'ed
* storage. Note that '-' is converted to '_' in the option name. If
* there is no '=' in the input string then value will be NULL.
*/
void
ParseLongOption(const char * string, char ** name, char ** value)
{
size_t equal_pos;
char *cp;
AssertArg(string);
AssertArg(name);
AssertArg(value);
equal_pos = strcspn(string, "=");
if (string[equal_pos] == '=')
{
*name = malloc(equal_pos + 1);
if (!*name)
elog(FATAL, "out of memory");
strncpy(*name, string, equal_pos);
(*name)[equal_pos] = '\0';
*value = strdup(&string[equal_pos + 1]);
if (!*value)
elog(FATAL, "out of memory");
}
else /* no equal sign in string */
{
*name = strdup(string);
if (!*name)
elog(FATAL, "out of memory");
*value = NULL;
}
for(cp = *name; *cp; cp++)
if (*cp == '-')
*cp = '_';
}

View File

@ -4,7 +4,7 @@
* External declarations pertaining to backend/utils/misc/guc.c and
* backend/utils/misc/guc-file.l
*
* $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.2 2000/06/22 22:31:24 petere Exp $
* $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.3 2000/07/03 20:46:10 petere Exp $
*/
#ifndef GUC_H
#define GUC_H
@ -51,7 +51,7 @@ void SetConfigOption(const char * name, const char * value, GucContext c
const char * GetConfigOption(const char * name);
void ProcessConfigFile(GucContext context);
void ResetAllOptions(void);
void ParseLongOption(const char * string, char ** name, char ** value);
bool set_config_option(const char * name, const char * value, GucContext context, bool DoIt);