Zdenek Kotala píše v út 31. 03. 2009 v 21:25 +0200: > Another possibility is to rewrite postgres(and pg_resetxlog) to use > getopt_long() instead of getopt().
Attached patch rewrites postgres to use getopt_long instead of getopt. Patch also removes configure part for Solaris related to getopt. Zdenek
diff -Nrc pgsql_getopt.2ecfaec29a72/configure.in pgsql_getopt/configure.in *** pgsql_getopt.2ecfaec29a72/configure.in 2009-04-05 23:12:35.718886756 +0200 --- pgsql_getopt/configure.in 2009-04-05 23:12:35.761770812 +0200 *************** *** 1276,1287 **** AC_LIBOBJ(getopt_long) fi - # Solaris' getopt() doesn't do what we want for long options, so always use - # our version on that platform. - if test "$PORTNAME" = "solaris"; then - AC_LIBOBJ(getopt) - fi - # Win32 support if test "$PORTNAME" = "win32"; then AC_REPLACE_FUNCS(gettimeofday) --- 1276,1281 ---- diff -Nrc pgsql_getopt.2ecfaec29a72/src/backend/bootstrap/bootstrap.c pgsql_getopt/src/backend/bootstrap/bootstrap.c *** pgsql_getopt.2ecfaec29a72/src/backend/bootstrap/bootstrap.c 2009-04-05 23:12:35.723955129 +0200 --- pgsql_getopt/src/backend/bootstrap/bootstrap.c 2009-04-05 23:12:35.762270558 +0200 *************** *** 17,25 **** #include <time.h> #include <unistd.h> #include <signal.h> ! #ifdef HAVE_GETOPT_H ! #include <getopt.h> ! #endif #include "access/genam.h" #include "access/heapam.h" --- 17,23 ---- #include <time.h> #include <unistd.h> #include <signal.h> ! #include "getopt_long.h" #include "access/genam.h" #include "access/heapam.h" *************** *** 38,43 **** --- 36,42 ---- #include "tcop/tcopprot.h" #include "utils/builtins.h" #include "utils/fmgroids.h" + #include "utils/guc.h" #include "utils/memutils.h" #include "utils/ps_status.h" #include "utils/tqual.h" *************** *** 208,213 **** --- 207,214 ---- int flag; AuxProcType auxType = CheckerProcess; char *userDoption = NULL; + struct option *optlist; + int optindex; /* * initialize globals *************** *** 247,253 **** argc--; } ! while ((flag = getopt(argc, argv, "B:c:d:D:Fr:x:-:")) != -1) { switch (flag) { --- 248,256 ---- argc--; } ! optlist = GetLongOptionList(); ! ! while ((flag = getopt_long(argc, argv, "B:c:d:D:Fr:x:", optlist, &optindex)) != -1) { switch (flag) { *************** *** 280,286 **** auxType = atoi(optarg); break; case 'c': - case '-': { char *name, *value; --- 283,288 ---- *************** *** 288,293 **** --- 290,296 ---- ParseLongOption(optarg, &name, &value); if (!value) { + free(optlist); if (flag == '-') ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), *************** *** 306,311 **** --- 309,317 ---- free(value); break; } + case 1 : + SetConfigOption(optlist[optindex].name, optarg, PGC_POSTMASTER, PGC_S_ARGV); + break; default: write_stderr("Try \"%s --help\" for more information.\n", progname); *************** *** 313,318 **** --- 319,325 ---- break; } } + free(optlist); if (argc != optind) { diff -Nrc pgsql_getopt.2ecfaec29a72/src/backend/postmaster/postmaster.c pgsql_getopt/src/backend/postmaster/postmaster.c *** pgsql_getopt.2ecfaec29a72/src/backend/postmaster/postmaster.c 2009-04-05 23:12:35.729964754 +0200 --- pgsql_getopt/src/backend/postmaster/postmaster.c 2009-04-05 23:12:35.762704640 +0200 *************** *** 83,92 **** #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif ! ! #ifdef HAVE_GETOPT_H ! #include <getopt.h> ! #endif #ifdef USE_BONJOUR #include <DNSServiceDiscovery/DNSServiceDiscovery.h> --- 83,89 ---- #ifdef HAVE_SYS_SELECT_H #include <sys/select.h> #endif ! #include "getopt_long.h" #ifdef USE_BONJOUR #include <DNSServiceDiscovery/DNSServiceDiscovery.h> *************** *** 116,121 **** --- 113,119 ---- #include "tcop/tcopprot.h" #include "utils/builtins.h" #include "utils/datetime.h" + #include "utils/guc.h" #include "utils/memutils.h" #include "utils/ps_status.h" *************** *** 463,468 **** --- 461,468 ---- int status; char *userDoption = NULL; int i; + struct option *optlist; + int optindex; MyProcPid = PostmasterPid = getpid(); *************** *** 506,517 **** opterr = 1; /* * Parse command-line options. CAUTION: keep this in sync with * tcop/postgres.c (the option sets should not conflict) and with the * common help() function in main/main.c. */ ! while ((opt = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1) { switch (opt) { --- 506,518 ---- opterr = 1; + optlist = GetLongOptionList(); /* * Parse command-line options. CAUTION: keep this in sync with * tcop/postgres.c (the option sets should not conflict) and with the * common help() function in main/main.c. */ ! while ((opt = getopt_long(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:", optlist, &optindex )) != -1) { switch (opt) { *************** *** 644,650 **** break; case 'c': - case '-': { char *name, *value; --- 645,650 ---- *************** *** 671,676 **** --- 671,680 ---- break; } + case 1: + SetConfigOption(optlist[optindex].name, optarg, PGC_POSTMASTER, PGC_S_ARGV); + break; + default: write_stderr("Try \"%s --help\" for more information.\n", progname); *************** *** 678,683 **** --- 682,689 ---- } } + free(optlist); + /* * Postmaster accepts no non-option switch arguments. */ diff -Nrc pgsql_getopt.2ecfaec29a72/src/backend/tcop/postgres.c pgsql_getopt/src/backend/tcop/postgres.c *** pgsql_getopt.2ecfaec29a72/src/backend/tcop/postgres.c 2009-04-05 23:12:35.739820636 +0200 --- pgsql_getopt/src/backend/tcop/postgres.c 2009-04-05 23:12:35.763135706 +0200 *************** *** 31,39 **** #include <sys/time.h> #include <sys/resource.h> #endif ! #ifdef HAVE_GETOPT_H ! #include <getopt.h> ! #endif #ifndef HAVE_GETRUSAGE #include "rusagestub.h" --- 31,37 ---- #include <sys/time.h> #include <sys/resource.h> #endif ! #include "getopt_long.h" #ifndef HAVE_GETRUSAGE #include "rusagestub.h" *************** *** 69,74 **** --- 67,73 ---- #include "utils/memutils.h" #include "utils/ps_status.h" #include "utils/snapmgr.h" + #include "utils/guc.h" #include "mb/pg_wchar.h" *************** *** 2859,2864 **** --- 2858,2865 ---- StringInfoData input_message; sigjmp_buf local_sigjmp_buf; volatile bool send_ready_for_query = true; + struct option *optlist; + int optindex; #define PendingConfigOption(name,val) \ (guc_names = lappend(guc_names, pstrdup(name)), \ *************** *** 2940,2946 **** * postmaster/postmaster.c (the option sets should not conflict) and with * the common help() function in main/main.c. */ ! while ((flag = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:y:-:")) != -1) { switch (flag) { --- 2941,2949 ---- * postmaster/postmaster.c (the option sets should not conflict) and with * the common help() function in main/main.c. */ ! optlist = GetLongOptionList(); ! ! while ((flag = getopt_long(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:y:", optlist, &optindex)) != -1) { switch (flag) { *************** *** 3074,3080 **** SetConfigOption("post_auth_delay", optarg, ctx, gucsource); break; - case 'y': /* --- 3077,3082 ---- *************** *** 3092,3098 **** break; case 'c': - case '-': { char *name, *value; --- 3094,3099 ---- *************** *** 3100,3105 **** --- 3101,3107 ---- ParseLongOption(optarg, &name, &value); if (!value) { + free(optlist); if (flag == '-') ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), *************** *** 3126,3136 **** --- 3128,3150 ---- break; } + case 1: + /* + * If a SUSET option, must postpone evaluation, unless we + * are still reading secure switches. + */ + if (ctx == PGC_BACKEND && IsSuperuserConfigOption(optlist[optindex].name)) + PendingConfigOption(optlist[optindex].name, optarg); + else + SetConfigOption(optlist[optindex].name, optarg, ctx, gucsource); + break; + default: errs++; break; } } + free(optlist); /* * Process any additional GUC variable settings passed in startup packet. diff -Nrc pgsql_getopt.2ecfaec29a72/src/backend/utils/misc/guc.c pgsql_getopt/src/backend/utils/misc/guc.c *** pgsql_getopt.2ecfaec29a72/src/backend/utils/misc/guc.c 2009-04-05 23:12:35.758577351 +0200 --- pgsql_getopt/src/backend/utils/misc/guc.c 2009-04-05 23:12:35.763797096 +0200 *************** *** 26,31 **** --- 26,33 ---- #include <syslog.h> #endif + #include "getopt_long.h" + #include "access/gin.h" #include "access/transam.h" #include "access/twophase.h" *************** *** 6872,6877 **** --- 6874,6904 ---- #endif /* EXEC_BACKEND */ + struct option * + GetLongOptionList() + { + struct option *opt; + struct config_generic *conf; + int i; + int numOpts; + + numOpts = GetNumConfigOptions(); + + opt = malloc( sizeof(struct option) * (numOpts + 1) ); + + for (i = 0; i < numOpts; i++) + { + conf = guc_variables[i]; + opt[i].name = conf->name; + opt[i].has_arg = TRUE; + opt[i].flag = NULL; + opt[i].val = 1; + } + + memset( &opt[numOpts], 0, sizeof(struct option) ); + return opt; + } + /* * A little "long argument" simulation, although not quite GNU * compliant. Takes a string of the form "some-option=some value" and diff -Nrc pgsql_getopt.2ecfaec29a72/src/include/utils/guc.h pgsql_getopt/src/include/utils/guc.h *** pgsql_getopt.2ecfaec29a72/src/include/utils/guc.h 2009-04-05 23:12:35.759983257 +0200 --- pgsql_getopt/src/include/utils/guc.h 2009-04-05 23:12:35.764155507 +0200 *************** *** 256,261 **** --- 256,262 ---- extern int NewGUCNestLevel(void); extern void AtEOXact_GUC(bool isCommit, int nestLevel); extern void BeginReportingGUCOptions(void); + extern struct option *GetLongOptionList(); extern void ParseLongOption(const char *string, char **name, char **value); extern bool parse_int(const char *value, int *result, int flags, const char **hintmsg);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers