On Mon, Jan 28, 2013 at 09:46:32AM -0500, Peter Eisentraut wrote: > On 1/26/13 4:44 PM, Aaron W. Swenson wrote: > > You are right. Had I read a little further down, it seems that the > > exit status should actually be 7. > > 7 is OK for "not running", but what should we use when the server is not > in standby mode? Using the idempotent argument that we are discussing > for the stop action, promoting a server that is not a standby should be > a noop and exit successfully. Not sure if that is what we want, though.
I looked at all the LSB return codes listed here and mapped them to pg_ctl error situations: https://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html Patch attached. I did not touch the start/stop return codes. -- Bruce Momjian <br...@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. +
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c new file mode 100644 index 9045e00..7982340 *** a/src/bin/pg_ctl/pg_ctl.c --- b/src/bin/pg_ctl/pg_ctl.c *************** get_pgpid(void) *** 252,258 **** { write_stderr(_("%s: could not open PID file \"%s\": %s\n"), progname, pid_file, strerror(errno)); ! exit(1); } } if (fscanf(pidf, "%ld", &pid) != 1) --- 252,258 ---- { write_stderr(_("%s: could not open PID file \"%s\": %s\n"), progname, pid_file, strerror(errno)); ! exit(6); } } if (fscanf(pidf, "%ld", &pid) != 1) *************** get_pgpid(void) *** 264,270 **** else write_stderr(_("%s: invalid data in PID file \"%s\"\n"), progname, pid_file); ! exit(1); } fclose(pidf); return (pgpid_t) pid; --- 264,270 ---- else write_stderr(_("%s: invalid data in PID file \"%s\"\n"), progname, pid_file); ! exit(6); } fclose(pidf); return (pgpid_t) pid; *************** read_post_opts(void) *** 668,680 **** if (optlines == NULL) { write_stderr(_("%s: could not read file \"%s\"\n"), progname, postopts_file); ! exit(1); } else if (optlines[0] == NULL || optlines[1] != NULL) { write_stderr(_("%s: option file \"%s\" must have exactly one line\n"), progname, postopts_file); ! exit(1); } else { --- 668,680 ---- if (optlines == NULL) { write_stderr(_("%s: could not read file \"%s\"\n"), progname, postopts_file); ! exit(6); } else if (optlines[0] == NULL || optlines[1] != NULL) { write_stderr(_("%s: option file \"%s\" must have exactly one line\n"), progname, postopts_file); ! exit(6); } else { *************** find_other_exec_or_die(const char *argv0 *** 730,736 **** "but was not the same version as %s.\n" "Check your installation.\n"), target, full_path, progname); ! exit(1); } return found_path; --- 730,736 ---- "but was not the same version as %s.\n" "Check your installation.\n"), target, full_path, progname); ! exit(5); } return found_path; *************** do_start(void) *** 813,819 **** { write_stderr(_("%s: could not start server: exit code was %d\n"), progname, exitcode); ! exit(1); } if (do_wait) --- 813,819 ---- { write_stderr(_("%s: could not start server: exit code was %d\n"), progname, exitcode); ! exit(7); } if (do_wait) *************** do_start(void) *** 835,847 **** write_stderr(_("%s: could not start server\n" "Examine the log output.\n"), progname); ! exit(1); break; case PQPING_NO_ATTEMPT: print_msg(_(" failed\n")); write_stderr(_("%s: could not wait for server because of misconfiguration\n"), progname); ! exit(1); } } else --- 835,847 ---- write_stderr(_("%s: could not start server\n" "Examine the log output.\n"), progname); ! exit(7); break; case PQPING_NO_ATTEMPT: print_msg(_(" failed\n")); write_stderr(_("%s: could not wait for server because of misconfiguration\n"), progname); ! exit(6); } } else *************** do_status(void) *** 1203,1212 **** printf(_("%s: no server running\n"), progname); /* ! * The Linux Standard Base Core Specification 3.1 says this should return ! * '3' ! * http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-ge ! * neric/iniscrptact.html */ exit(3); } --- 1203,1210 ---- printf(_("%s: no server running\n"), progname); /* ! * The Linux Standard Base Core Specification 3.1 says this should return '3' ! * https://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html */ exit(3); } *************** pgwin32_CommandLine(bool registration) *** 1253,1259 **** if (ret != 0) { write_stderr(_("%s: could not find own program executable\n"), progname); ! exit(1); } } else --- 1251,1257 ---- if (ret != 0) { write_stderr(_("%s: could not find own program executable\n"), progname); ! exit(5); } } else *************** pgwin32_CommandLine(bool registration) *** 1263,1269 **** if (ret != 0) { write_stderr(_("%s: could not find postgres program executable\n"), progname); ! exit(1); } } --- 1261,1267 ---- if (ret != 0) { write_stderr(_("%s: could not find postgres program executable\n"), progname); ! exit(5); } } *************** set_mode(char *modeopt) *** 1848,1854 **** { write_stderr(_("%s: unrecognized shutdown mode \"%s\"\n"), progname, modeopt); do_advice(); ! exit(1); } } --- 1846,1852 ---- { write_stderr(_("%s: unrecognized shutdown mode \"%s\"\n"), progname, modeopt); do_advice(); ! exit(2); } } *************** set_sig(char *signame) *** 1880,1886 **** { write_stderr(_("%s: unrecognized signal name \"%s\"\n"), progname, signame); do_advice(); ! exit(1); } } --- 1878,1884 ---- { write_stderr(_("%s: unrecognized signal name \"%s\"\n"), progname, signame); do_advice(); ! exit(2); } } *************** set_starttype(char *starttypeopt) *** 1897,1903 **** { write_stderr(_("%s: unrecognized start type \"%s\"\n"), progname, starttypeopt); do_advice(); ! exit(1); } } #endif --- 1895,1901 ---- { write_stderr(_("%s: unrecognized start type \"%s\"\n"), progname, starttypeopt); do_advice(); ! exit(2); } } #endif *************** main(int argc, char **argv) *** 2026,2032 **** "(unprivileged) user that will\n" "own the server process.\n"), progname); ! exit(1); } #endif --- 2024,2030 ---- "(unprivileged) user that will\n" "own the server process.\n"), progname); ! exit(4); } #endif *************** main(int argc, char **argv) *** 2094,2100 **** #else write_stderr(_("%s: -S option not supported on this platform\n"), progname); ! exit(1); #endif break; case 't': --- 2092,2098 ---- #else write_stderr(_("%s: -S option not supported on this platform\n"), progname); ! exit(3); #endif break; case 't': *************** main(int argc, char **argv) *** 2125,2131 **** default: /* getopt_long already issued a suitable error message */ do_advice(); ! exit(1); } } --- 2123,2129 ---- default: /* getopt_long already issued a suitable error message */ do_advice(); ! exit(2); } } *************** main(int argc, char **argv) *** 2136,2142 **** { write_stderr(_("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]); do_advice(); ! exit(1); } if (strcmp(argv[optind], "init") == 0 --- 2134,2140 ---- { write_stderr(_("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]); do_advice(); ! exit(2); } if (strcmp(argv[optind], "init") == 0 *************** main(int argc, char **argv) *** 2160,2166 **** { write_stderr(_("%s: missing arguments for kill mode\n"), progname); do_advice(); ! exit(1); } ctl_command = KILL_COMMAND; set_sig(argv[++optind]); --- 2158,2164 ---- { write_stderr(_("%s: missing arguments for kill mode\n"), progname); do_advice(); ! exit(2); } ctl_command = KILL_COMMAND; set_sig(argv[++optind]); *************** main(int argc, char **argv) *** 2178,2184 **** { write_stderr(_("%s: unrecognized operation mode \"%s\"\n"), progname, argv[optind]); do_advice(); ! exit(1); } optind++; } --- 2176,2182 ---- { write_stderr(_("%s: unrecognized operation mode \"%s\"\n"), progname, argv[optind]); do_advice(); ! exit(2); } optind++; } *************** main(int argc, char **argv) *** 2188,2194 **** { write_stderr(_("%s: no operation specified\n"), progname); do_advice(); ! exit(1); } /* Note we put any -D switch into the env var above */ --- 2186,2192 ---- { write_stderr(_("%s: no operation specified\n"), progname); do_advice(); ! exit(2); } /* Note we put any -D switch into the env var above */ *************** main(int argc, char **argv) *** 2210,2216 **** write_stderr(_("%s: no database directory specified and environment variable PGDATA unset\n"), progname); do_advice(); ! exit(1); } if (!wait_set) --- 2208,2214 ---- write_stderr(_("%s: no database directory specified and environment variable PGDATA unset\n"), progname); do_advice(); ! exit(2); } if (!wait_set)
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers