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

Commit093d3da

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 parentcb11f4d commit093d3da

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,35 @@ PostmasterMain(int argc, char *argv[])
514514
/* Initialize paths to installation files */
515515
getInstallationPaths(argv[0]);
516516

517+
/*
518+
* Set up signal handlers for the postmaster process.
519+
*
520+
* CAUTION: when changing this list, check for side-effects on the signal
521+
* handling setup of child processes. See tcop/postgres.c,
522+
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
523+
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c, and
524+
* postmaster/syslogger.c.
525+
*/
526+
pqinitmask();
527+
PG_SETMASK(&BlockSig);
528+
529+
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
530+
* children do same */
531+
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
532+
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
533+
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
534+
pqsignal(SIGALRM,SIG_IGN);/* ignored */
535+
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
536+
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
537+
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
538+
pqsignal(SIGCHLD,reaper);/* handle child termination */
539+
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
540+
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
541+
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
542+
#ifdefSIGXFSZ
543+
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
544+
#endif
545+
517546
/*
518547
* Options setup
519548
*/
@@ -1031,35 +1060,6 @@ PostmasterMain(int argc, char *argv[])
10311060
progname,external_pid_file,strerror(errno));
10321061
}
10331062

1034-
/*
1035-
* Set up signal handlers for the postmaster process.
1036-
*
1037-
* CAUTION: when changing this list, check for side-effects on the signal
1038-
* handling setup of child processes. See tcop/postgres.c,
1039-
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
1040-
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c, and
1041-
* postmaster/syslogger.c.
1042-
*/
1043-
pqinitmask();
1044-
PG_SETMASK(&BlockSig);
1045-
1046-
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
1047-
* children do same */
1048-
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
1049-
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
1050-
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
1051-
pqsignal(SIGALRM,SIG_IGN);/* ignored */
1052-
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
1053-
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
1054-
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
1055-
pqsignal(SIGCHLD,reaper);/* handle child termination */
1056-
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
1057-
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
1058-
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
1059-
#ifdefSIGXFSZ
1060-
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
1061-
#endif
1062-
10631063
/*
10641064
* If enabled, start up syslogger collection subprocess
10651065
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp