diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-27 16:59:38 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-27 16:59:38 +0000 |
commit | 8f5500e6bdb4d42ea9620b0f515671be7d681bf6 (patch) | |
tree | ee566993694a99187df4837355addbf633ae3372 /src/bin/pg_ctl/pg_ctl.c | |
parent | 0e3f0cbddcb6da390c1accc5fc6af4eedd33b6a2 (diff) | |
download | postgresql-8f5500e6bdb4d42ea9620b0f515671be7d681bf6.tar.gz postgresql-8f5500e6bdb4d42ea9620b0f515671be7d681bf6.zip |
Make it reasonably safe to use pg_ctl to start the postmaster from a boot-time
script.
To do this, have pg_ctl pass down its parent shell's PID in an environment
variable PG_GRANDPARENT_PID, and teach CreateLockFile() to disregard that PID
as a false match if it finds it in postmaster.pid. This allows us to cope
with one level of postgres-owned shell process even with pg_ctl in the way,
so it's just as safe as starting the postmaster directly. You still have to
be careful about how you write the initscript though.
Adjust the comments in contrib/start-scripts/ to not deprecate use of
pg_ctl. Also, fix the ROTATELOGS option in the OSX script, which was
indulging in exactly the sort of unsafe coding that renders this fix
pointless :-(. A pipe inside the "sudo" will probably result in more
than one postgres-owned process hanging around.
Diffstat (limited to 'src/bin/pg_ctl/pg_ctl.c')
-rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 40ede2c1a83..ff8f4a25523 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -4,7 +4,7 @@ * * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.111 2009/06/11 14:49:07 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.112 2009/08/27 16:59:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -672,6 +672,21 @@ do_start(void) unlimit_core_size(); #endif + /* + * If possible, tell the postmaster our parent shell's PID (see the + * comments in CreateLockFile() for motivation). Windows hasn't got + * getppid() unfortunately. + */ +#ifndef WIN32 + { + static char env_var[32]; + + snprintf(env_var, sizeof(env_var), "PG_GRANDPARENT_PID=%d", + (int) getppid()); + putenv(env_var); + } +#endif + exitcode = start_postmaster(); if (exitcode != 0) { |