* 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 $
*
*-------------------------------------------------------------------------
*/
* 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
*
*
*
* 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
*
if (getenv("PGDATA"))
DataDir = strdup(getenv("PGDATA")); /* default value */
- if (getenv("PGPORT"))
- PostPortName = atoi(getenv("PGPORT"));
-
ResetAllOptions();
/*
strcpy(original_extraoptions, optarg);
break;
case 'p':
- /* Set PGPORT by hand. */
PostPortName = atoi(optarg);
break;
case 'S':
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:
*
*
* 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
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;
}
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");
}
/*
* 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>.
}
ConfigureNamesString[i].variable = str;
}
+
+ if (getenv("PGPORT"))
+ PostPortName = atoi(getenv("PGPORT"));
}
}
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 = '_';
+}
* 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
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);