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

Commit21aa47d

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 parent18db215 commit21aa47d

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
@@ -591,6 +591,36 @@ PostmasterMain(int argc, char *argv[])
591591
/* Initialize paths to installation files */
592592
getInstallationPaths(argv[0]);
593593

594+
/*
595+
* Set up signal handlers for the postmaster process.
596+
*
597+
* CAUTION: when changing this list, check for side-effects on the signal
598+
* handling setup of child processes. See tcop/postgres.c,
599+
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
600+
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
601+
* postmaster/syslogger.c, postmaster/bgworker.c and
602+
* postmaster/checkpointer.c.
603+
*/
604+
pqinitmask();
605+
PG_SETMASK(&BlockSig);
606+
607+
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
608+
* children do same */
609+
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
610+
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
611+
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
612+
pqsignal(SIGALRM,SIG_IGN);/* ignored */
613+
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
614+
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
615+
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
616+
pqsignal(SIGCHLD,reaper);/* handle child termination */
617+
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
618+
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
619+
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
620+
#ifdefSIGXFSZ
621+
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
622+
#endif
623+
594624
/*
595625
* Options setup
596626
*/
@@ -1139,36 +1169,6 @@ PostmasterMain(int argc, char *argv[])
11391169
on_proc_exit(unlink_external_pid_file,0);
11401170
}
11411171

1142-
/*
1143-
* Set up signal handlers for the postmaster process.
1144-
*
1145-
* CAUTION: when changing this list, check for side-effects on the signal
1146-
* handling setup of child processes. See tcop/postgres.c,
1147-
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
1148-
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
1149-
* postmaster/syslogger.c, postmaster/bgworker.c and
1150-
* postmaster/checkpointer.c.
1151-
*/
1152-
pqinitmask();
1153-
PG_SETMASK(&BlockSig);
1154-
1155-
pqsignal(SIGHUP,SIGHUP_handler);/* reread config file and have
1156-
* children do same */
1157-
pqsignal(SIGINT,pmdie);/* send SIGTERM and shut down */
1158-
pqsignal(SIGQUIT,pmdie);/* send SIGQUIT and die */
1159-
pqsignal(SIGTERM,pmdie);/* wait for children and shut down */
1160-
pqsignal(SIGALRM,SIG_IGN);/* ignored */
1161-
pqsignal(SIGPIPE,SIG_IGN);/* ignored */
1162-
pqsignal(SIGUSR1,sigusr1_handler);/* message from child process */
1163-
pqsignal(SIGUSR2,dummy_handler);/* unused, reserve for children */
1164-
pqsignal(SIGCHLD,reaper);/* handle child termination */
1165-
pqsignal(SIGTTIN,SIG_IGN);/* ignored */
1166-
pqsignal(SIGTTOU,SIG_IGN);/* ignored */
1167-
/* ignore SIGXFSZ, so that ulimit violations work like disk full */
1168-
#ifdefSIGXFSZ
1169-
pqsignal(SIGXFSZ,SIG_IGN);/* ignored */
1170-
#endif
1171-
11721172
/*
11731173
* If enabled, start up syslogger collection subprocess
11741174
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp