Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d8117e

Browse files
committed
Block signals earlier during postmaster startup.
Formerly, we set up the postmaster's signal handling only when we wereabout to start launching subprocesses. This is a bad idea though, asit means that for example a SIGINT arriving before that will kill thepostmaster instantly, perhaps leaving lockfiles, socket files, sharedmemory, etc laying about. We'd rather that such a signal caused orderlypostmaster termination including releasing of those resources. A simplefix is to move the PostmasterMain stanza that initializes signal handlingto an earlier point, before we've created any such resources. Then, anearly-arriving signal will be blocked until we're ready to deal with itin the usual way. (The only part that really needs to be moved up isblocking of signals, but it seems best to keep the signal handlerinstallation calls together with that; for one thing this ensures thekernel won't drop any signals we wished to get. The handlers won't getinvoked in any case until we unblock signals in ServerLoop.)Per a report from MauMau. He proposed changing the way "pg_ctl stop"works to deal with this, but that'd just be masking one symptom notfixing the core issue.It's been like this since forever, so back-patch to all supported branches.
1 parentffbba6e commit5d8117e

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,36 @@ PostmasterMain(int argc, char *argv[])
561561
/* Initialize paths to installation files */
562562
getInstallationPaths(argv[0]);
563563

564+
/*
565+
* Set up signal handlers for the postmaster process.
566+
*
567+
* CAUTION: when changing this list, check for side-effects on the signal
568+
* handling setup of child processes. See tcop/postgres.c,
569+
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
570+
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
571+
* postmaster/syslogger.c, postmaster/bgworker.c and
572+
* postmaster/checkpointer.c.
573+
*/
574+
pqinitmask();
575+
PG_SETMASK(&BlockSig);
576+
577+
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
578+
* children do same */
579+
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
580+
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
581+
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
582+
pqsignal(SIGALRM,SIG_IGN);/* ignored */
583+
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
584+
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
585+
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
586+
pqsignal(SIGCHLD,reaper);/* handle child termination */
587+
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
588+
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
589+
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
590+
#ifdefSIGXFSZ
591+
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
592+
#endif
593+
564594
/*
565595
* Options setup
566596
*/
@@ -1108,36 +1138,6 @@ PostmasterMain(int argc, char *argv[])
11081138
on_proc_exit(unlink_external_pid_file,0);
11091139
}
11101140

1111-
/*
1112-
* Set up signal handlers for the postmaster process.
1113-
*
1114-
* CAUTION: when changing this list, check for side-effects on the signal
1115-
* handling setup of child processes. See tcop/postgres.c,
1116-
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
1117-
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
1118-
* postmaster/syslogger.c, postmaster/bgworker.c and
1119-
* postmaster/checkpointer.c.
1120-
*/
1121-
pqinitmask();
1122-
PG_SETMASK(&BlockSig);
1123-
1124-
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
1125-
* children do same */
1126-
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
1127-
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
1128-
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
1129-
pqsignal(SIGALRM,SIG_IGN);/* ignored */
1130-
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
1131-
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
1132-
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
1133-
pqsignal(SIGCHLD,reaper);/* handle child termination */
1134-
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
1135-
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
1136-
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
1137-
#ifdefSIGXFSZ
1138-
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
1139-
#endif
1140-
11411141
/*
11421142
* If enabled, start up syslogger collection subprocess
11431143
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp