{"id":343679,"date":"2023-01-09T09:03:49","date_gmt":"2023-01-09T09:03:49","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343679"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343679","title":{"rendered":"<span>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 PostgreSQL. \u0427\u0430\u0441\u0442\u044c 2. \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0431\u044d\u043a\u044d\u043d\u0434\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e. <\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 Postgres. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043a\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/post\/704618\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a>. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0442\u0430\u043a \u0436\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/postmaster\/postmaster.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/postmaster\/postmaster.c<\/a><\/p>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043f\u043e\u0440\u043e\u0434\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043e\u0442 Postmaster \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041f\u043e \u0444\u0430\u043a\u0442\u0443, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>InitPostmasterChild() <\/em>(\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/init\/miscinit.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/utils\/init\/miscinit.c<\/a>), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0430\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/p>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0441\u0442\u0435\u043a\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u0430 \u0441\u0442\u0435\u043a\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. <\/p>\n<pre><code class=\"cpp\">\/*  * Stack base pointer -- initialized by PostmasterMain and inherited by  * subprocesses. This is not static because old versions of PL\/Java modify  * it directly. Newer versions use set_stack_base(), but we want to stay  * binary-compatible for the time being.  *\/ char   *stack_base_ptr = NULL;<\/code><\/pre>\n<p>\u041b\u044e\u0431\u043e\u0439 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0435\u043a. \u0417\u0430\u0447\u0435\u043c? \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441\u0442\u0435\u043a\u0430 \u0441\u0430\u043c\u0438\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u043a\u0441\u0442\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.\u00a0<\/p>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0435\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d \u0432 postgresql.conf: \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-resource.html#GUC-MAX-STACK-DEPTH\" rel=\"noopener noreferrer nofollow\">max_stack_depth<\/a><\/p>\n<h4>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041e\u043d\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/init\/globals.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/utils\/init\/globals.c<\/a>, \u0445\u043e\u0442\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/miscadmin.h\" rel=\"noopener noreferrer nofollow\">src\/include\/miscadmin.h<\/a> <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p><em>MyProcId<\/em> &#8212; ID \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p><em>MyStartTimestamp<\/em> &#8212; \u0448\u0442\u0430\u043c\u043f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p><em>MyStartTime<\/em> &#8212; \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Postgresql.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0440\u0443\u0433\u0430\u044f \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u044c &#8212; \u0440\u0430\u043d\u0434\u043e\u043c.\u00a0<\/p>\n<p>Postgres \u0438\u043c\u0435\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>pg_strong_random()<\/em> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/port.h\" rel=\"noopener noreferrer nofollow\">src\/include\/port.h<\/a>, \u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/port\/pg_strong_random.c\" rel=\"noopener noreferrer nofollow\">src\/port\/pg_strong_random.c<\/a><\/p>\n<pre><code class=\"cpp\">\/*  * ...  *  * Returns true on success, and false if none of the sources  * were available. NB: It is important to check the return value!  * Proceeding with key generation when no random data was available  * would lead to predictable keys and security issues.  *\/ bool pg_strong_random(void *buf, size_t len)<\/code><\/pre>\n<p>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c, \u0438\u0434\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 3 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>OpenSSL &#8212; <a href=\"https:\/\/www.openssl.org\/docs\/manmaster\/man3\/RAND_bytes.html\" rel=\"noopener noreferrer nofollow\">RAND_bytes()<\/a><\/p>\n<\/li>\n<li>\n<p>Windows &#8212; <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptgenrandom\" rel=\"noopener noreferrer nofollow\">CryptGenRandom()<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/ru.wikipedia.org\/?title=\/dev\/random_%D0%B8_\/dev\/urandom\" rel=\"noopener noreferrer nofollow\">\/dev\/urandom<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0434\u043e\u043c\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>false<\/code>. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0434 \u0441\u0430\u043c\u0438\u043c. \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0441\u0438\u0434\u0430, \u043d\u0443\u0436\u043d\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e? \u041d\u0430\u0448 PID \u0438 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430!\u00a0<\/p>\n<pre><code class=\"cpp\">unsigned int rseed;  if (!pg_strong_random(&amp;rseed, sizeof(rseed))) {     \/*      * Since PIDs and timestamps tend to change more frequently in their      * least significant bits, shift the timestamp left to allow a larger      * total number of seeds in a given time period.  Since that would      * leave only 20 bits of the timestamp that cycle every ~1 second,      * also mix in some higher bits.      *\/     rseed = ((uint64) MyProcPid) ^         ((uint64) MyStartTimestamp &lt;&lt; 12) ^         ((uint64) MyStartTimestamp >> 20); } srandom(rseed);<\/code><\/pre>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430 Postmaster \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u201c\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u043e\u201d.\u00a0\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0412 Postmaster \u0431\u044b\u043b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f <em>SIGQUIT<\/em> &#8212; \u043f\u0443\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442). \u041d\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0442\u0430\u043a \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0442\u044c &#8212; \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435, <em>SIGQUIT<\/em> \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043c\u0430\u0441\u043a\u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 (BlockSig) \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.\u00a0<\/p>\n<pre><code class=\"cpp\">\/*  * Simple signal handler for exiting quickly as if due to a crash.  *  * Normally, this would be used for handling SIGQUIT.  *\/ void SignalHandlerForCrashExit(SIGNAL_ARGS) { \/*  * We DO NOT want to run proc_exit() or atexit() callbacks -- we're here  * because shared memory may be corrupted, so we don't want to try to  * clean up our transaction.  Just nail the windows shut and get out of  * town.  The callbacks wouldn't be safe to run from a signal handler,  * anyway.  *  * Note we do _exit(2) not _exit(0).  This is to force the postmaster into  * a system reset cycle if someone sends a manual SIGQUIT to a random  * backend.  This is necessary precisely because we don't clean up our  * shared memory state.  (The \"dead man switch\" mechanism in pmsignal.c  * should ensure the postmaster sees this as a crash, too, but no harm in  * being doubly sure.)  *\/ _exit(2); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 Postmaster \u0442\u043e\u043b\u044c\u043a\u043e \u201c\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u201d: \u0435\u0441\u043b\u0438 Postmaster \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u043d\u0435\u0442 \u0437\u043e\u043c\u0431\u0438.\u00a0<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>prctl()<\/em> \u0438\u043b\u0438 <em>procctl()<\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>prctl()<\/summary>\n<div class=\"spoiler__content\">\n<p>prctl() &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430.\u00a0<\/p>\n<pre><code class=\"cpp\">#include &lt;sys\/prctl.h>  int prctl(int option, unsigned long arg2, unsigned long arg3,          unsigned long arg4, unsigned long arg5);<\/code><\/pre>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043d\u0435\u0433\u043e. <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B0%D1%82%D0%B5%D0%BC%D0%B0%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%BE%D0%BF%D1%80%D0%BE%D1%86%D0%B5%D1%81%D1%81%D0%BE%D1%80\" rel=\"noopener noreferrer nofollow\">FPU<\/a>. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 CPU, \u043b\u0438\u0431\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0414\u043b\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c prctl:<\/p>\n<pre><code class=\"cpp\">\/\/ \u042d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0431\u0435\u0437 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 prctl(PR_SET_FPEMU, PR_FPEMU_NOPRINT);  \/\/ \u041f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c SIGFPE prctl(PR_SET_FPEMU, PR_FPEMU_SIGFPE);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>procctl()<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/www.freebsd.org\/cgi\/man.cgi?query=procctl&amp;sektion=2\" rel=\"noopener noreferrer nofollow\">procctl<\/a> &#8212; \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438.<\/p>\n<pre><code class=\"cpp\">#include &lt;sys\/procctl.h>  int procctl(idtype_t idtype, id_t id, int cmd, void *data);<\/code><\/pre>\n<p>1 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442: <em>P_PID<\/em> &#8212; PID \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, <em>P_PGID<\/em> &#8212; ID \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/p>\n<p>2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; ID \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f<\/p>\n<p>3 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430<\/p>\n<p>4 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043e\u0442 \u0430\u0442\u0430\u043a\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u041e\u0421 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ASLR\" rel=\"noopener noreferrer nofollow\">ASLR<\/a>, \u043d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0435\u0432\u043d\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0442\u043e \u043d\u0435 \u0444\u0430\u043a\u0442. \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438, \u0447\u0442\u043e \u043e\u043d\u0430 \u0442\u043e\u0447\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<pre><code class=\"cpp\">\/\/ 0 \u0432 id - \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 procctl(P_PID, 0, PROC_ASLR_CTL, &amp;PROC_ASLR_FORCE_ENABLE);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>Postgres \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0430\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b Postmaster, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d:<\/p>\n<pre><code class=\"cpp\">\/*  * Signal handler to be notified if postmaster dies.  *\/ #ifdef USE_POSTMASTER_DEATH_SIGNAL volatile sig_atomic_t postmaster_possibly_dead = false;  static void postmaster_death_handler(int signo) { postmaster_possibly_dead = true; }  \/*  * The available signals depend on the OS.  SIGUSR1 and SIGUSR2 are already  * used for other things, so choose another one.  *  * Currently, we assume that we can always find a signal to use.  That  * seems like a reasonable assumption for all platforms that are modern  * enough to have a parent-death signaling mechanism.  *\/ #if defined(SIGINFO) #define POSTMASTER_DEATH_SIGNAL SIGINFO #elif defined(SIGPWR) #define POSTMASTER_DEATH_SIGNAL SIGPWR #else #error \"cannot find a signal to use for postmaster death\" #endif  #endif\/* USE_POSTMASTER_DEATH_SIGNAL *\/  void PostmasterDeathSignalInit(void) { #ifdef USE_POSTMASTER_DEATH_SIGNAL intsignum = POSTMASTER_DEATH_SIGNAL;  \/* Register our signal handler. *\/ pqsignal(signum, postmaster_death_handler);  \/* Request a signal on parent exit. *\/ #if defined(PR_SET_PDEATHSIG) if (prctl(PR_SET_PDEATHSIG, signum) &lt; 0) elog(ERROR, \"could not request parent death signal: %m\"); #elif defined(PROC_PDEATHSIG_CTL) if (procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &amp;signum) &lt; 0) elog(ERROR, \"could not request parent death signal: %m\"); #else #error \"USE_POSTMASTER_DEATH_SIGNAL set, but there is no mechanism to request the signal\" #endif  \/*  * Just in case the parent was gone already and we missed it, we'd better  * check the slow way on the first call.  *\/ postmaster_possibly_dead = true; #endif\/* USE_POSTMASTER_DEATH_SIGNAL *\/ }<\/code><\/pre>\n<h4>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MyLatch<\/h4>\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Latch, \u043d\u043e \u043e\u043d \u043d\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d.\u00a0<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430: \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0430\u0442\u0447\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u201c\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u201d.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e-\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Latch &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f MyLatch.<\/p>\n<p>Latch &#8212; \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441. \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/storage\/latch.h\" rel=\"noopener noreferrer nofollow\">src\/include\/storage\/latch.h<\/a>, \u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/storage\/ipc\/latch.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/storage\/ipc\/latch.c<\/a>.<\/p>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0437\u0430\u0441\u044b\u043f\u0430\u0442\u044c (\u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c Latch), \u043f\u043e\u043a\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 (\u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442) \u044d\u0442\u043e\u0442 Latch.<\/p>\n<p>\u042d\u0442\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">\/*  * prototypes for functions in latch.c  *\/ extern void InitializeLatchSupport(void); extern void InitLatch(Latch *latch); extern void InitSharedLatch(Latch *latch); extern void OwnLatch(Latch *latch); extern void DisownLatch(Latch *latch); extern void SetLatch(Latch *latch); extern void ResetLatch(Latch *latch); extern void ShutdownLatchSupport(void);<\/code><\/pre>\n<p>\u041b\u0443\u0447\u0448\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0410\u0422\u0414, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><em>POLL<\/em> &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 self-pipe trick<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>self-pipe trick<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u0438\u0433\u043d\u0430\u043b\u044b &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f: \u0431\u044b\u043b\u043e \u0438\u043b\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0442\u043e \u043e\u043d\u043e \u043d\u0438\u043a\u0435\u043c \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043b\u0435\u0442\u0438\u0442 \u201c\u0432 \u043d\u0438\u043a\u0443\u0434\u0430\u201d. \u0414\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d <em>self-pipe trick<\/em>.<\/p>\n<p>\u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e-\u0444\u043b\u0430\u0433 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u0440\u0438\u043d\u044f\u0442 (<em>volatile sigset_t is_signal_set<\/em>)<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0432 \u043e\u0431\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043e\u0447\u0435\u0440\u0435\u0434\u044c &#8212; \u0432\u044b\u0437\u043e\u0432 <em>fcntl(fd, FD_SETFL, O_NONBLOCK)<\/em>, fd &#8212; \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043e\u0447\u0435\u0440\u0435\u0434\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430: \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 &#8212; \u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0439\u0442 \u0432 \u043d\u0430\u0448\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0444\u043b\u0430\u0433 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 sigset_t \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d, \u0442\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u044d\u0442\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u043c\u044b \u043f\u0440\u0438\u043d\u044f\u043b\u0438. \u0410 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u0431\u044b\u043b\u043e &#8212; \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0439\u0442\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0427\u0438\u0442\u0430\u0435\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432.\u00a0<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u0444\u043b\u0430\u0433\u0430, \u0442\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <em>poll()<\/em>. \u041a\u043e\u0433\u0434\u0430 \u043e\u043d \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e, \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u044b\u043b\u0430 \u043f\u0443\u0441\u0442\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f -1 \u0438 errno \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>EINTR<\/em>, \u0438\u043d\u0430\u0447\u0435 \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0439\u0442\u044b.<\/p>\n<pre><code class=\"cpp\">void InitializeLatchSupport(void) { #if defined(WAIT_USE_SELF_PIPE) intpipefd[2];  \/\/ ...  \/*  * Set up the self-pipe that allows a signal handler to wake up the  * poll()\/epoll_wait() in WaitLatch. Make the write-end non-blocking, so  * that SetLatch won't block if the event has already been set many times  * filling the kernel buffer. Make the read-end non-blocking too, so that  * we can easily clear the pipe by reading until EAGAIN or EWOULDBLOCK.  * Also, make both FDs close-on-exec, since we surely do not want any  * child processes messing with them.  *\/ if (pipe(pipefd) &lt; 0) elog(FATAL, \"pipe() failed: %m\"); if (fcntl(pipefd[0], F_SETFL, O_NONBLOCK) == -1) elog(FATAL, \"fcntl(F_SETFL) failed on read-end of self-pipe: %m\"); if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) == -1) elog(FATAL, \"fcntl(F_SETFL) failed on write-end of self-pipe: %m\"); if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1) elog(FATAL, \"fcntl(F_SETFD) failed on read-end of self-pipe: %m\"); if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1) elog(FATAL, \"fcntl(F_SETFD) failed on write-end of self-pipe: %m\");  selfpipe_readfd = pipefd[0]; selfpipe_writefd = pipefd[1]; selfpipe_owner_pid = MyProcPid; #endif  #ifdef WAIT_USE_SIGNALFD \/\/ ... #endif  #ifdef WAIT_USE_KQUEUE \/\/ ... #endif }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ul>\n<li>\n<p><em>EPOLL<\/em> &#8212; \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0438 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 epoll()<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u0441\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043f\u043e \u0441\u0432\u043e\u0435\u0439 \u043d\u0430\u0442\u0443\u0440\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 &#8212; \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>signalfd()<\/em><\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0435, \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e <em>select()<\/em>, <em>poll()<\/em>, <em>epoll()<\/em> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u043c\u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430\u043c\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u0441 \u0441\u0438\u0433\u043d\u0430\u043b\u0430\u043c\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0434\u043b\u044f \u043d\u0435\u0433\u043e.\u00a0<\/p>\n<p>\u0418 \u0432\u043e\u0442 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0438\u0437 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 &#8212; \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0441 \u044d\u0442\u0438\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u043c \u0432 <em>epoll()<\/em>: \u0435\u0441\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0434\u0430\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u0447\u0435\u043c, \u043c\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c, \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u201c\u0444\u0430\u0439\u043b\u201d \u043d\u0435 \u043f\u0443\u0441\u0442\u043e\u0439<\/p>\n<pre><code class=\"cpp\">void InitializeLatchSupport(void) { #if defined(WAIT_USE_SELF_PIPE)   \/\/ ... #endif  #ifdef WAIT_USE_SIGNALFD sigset_tsignalfd_mask;  \/* Block SIGURG, because we'll receive it through a signalfd. *\/ sigaddset(&amp;UnBlockSig, SIGURG);  \/* Set up the signalfd to receive SIGURG notifications. *\/ sigemptyset(&amp;signalfd_mask); sigaddset(&amp;signalfd_mask, SIGURG); signal_fd = signalfd(-1, &amp;signalfd_mask, SFD_NONBLOCK | SFD_CLOEXEC); if (signal_fd &lt; 0) elog(FATAL, \"signalfd() failed\"); ReserveExternalFD(); #endif  #ifdef WAIT_USE_KQUEUE   \/\/ ... #endif }<\/code><\/pre>\n<p>* \u042d\u0442\u043e Linux-only \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<\/p>\n<\/div>\n<\/details>\n<ul>\n<li>\n<p><em>KQUEUE<\/em> &#8212; \u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, epoll() \u0434\u043b\u044f FreeBSD<\/p>\n<\/li>\n<li>\n<p><em>Windows Events<\/em> &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043b\u044f Windows, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0430\u044f Windows Events<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u044b\u0448\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439. \u041d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Windows Events \u0438 epoll &#8212; \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Windows, \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 Linux. \u041a\u0430\u043a \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439? \u041f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440!<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 latch.h, \u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0443\u0436\u0435 \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/storage\/ipc\/latch.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/storage\/ipc\/latch.c<\/a>\u00a0<\/p>\n<p>\u201c\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c\u201d \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f 2 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">\/*  * Initialize the process-local latch infrastructure.  *  * This must be called once during startup of any process that can wait on  * latches, before it issues any InitLatch() or OwnLatch() calls.  *\/ void InitializeLatchSupport(void) { #if defined(WAIT_USE_SELF_PIPE)   \/\/ ... #endif  #ifdef WAIT_USE_SIGNALFD   \/\/ ... #endif  #ifdef WAIT_USE_KQUEUE   \/\/ ... #endif }<\/code><\/pre>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0431\u043b\u043e\u043a\u0430\u0445 \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"cpp\">void ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch) { \/\/ ... #if defined(WAIT_USE_EPOLL) WaitEventAdjustEpoll(set, event, EPOLL_CTL_MOD); #elif defined(WAIT_USE_KQUEUE) WaitEventAdjustKqueue(set, event, old_events); #elif defined(WAIT_USE_POLL) WaitEventAdjustPoll(set, event); #elif defined(WAIT_USE_WIN32) WaitEventAdjustWin32(set, event); #endif }  #if defined(WAIT_USE_EPOLL) static void WaitEventAdjustEpoll(WaitEventSet *set, WaitEvent *event, int action) { \/\/ ... } #endif  #if defined(WAIT_USE_POLL) static void WaitEventAdjustPoll(WaitEventSet *set, WaitEvent *event) { \/\/ ... } #endif  #if defined(WAIT_USE_KQUEUE) static inline void WaitEventAdjustKqueueAdd(struct kevent *k_ev, int filter, int action,  WaitEvent *event) { \/\/ ... } #endif  #if defined(WAIT_USE_WIN32) static void WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event) { \/\/ ... } #endif<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u044d\u043a\u044d\u043d\u0434\u0430<\/h2>\n<h4>\u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439<\/h4>\n<p>\u041e\u0442 Postmaster \u043c\u044b \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043d\u043e \u0438 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432. \u0414\u043e\u0447\u0435\u0440\u043d\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043e\u043d\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b, \u0430 \u0441\u043e\u043a\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0431\u044d\u043a\u044d\u043d\u0434\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043b\u043e\u0433\u0433\u0435\u0440\u0430.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 \u043a\u0430\u043d\u0430\u043b\u043e\u0432: \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438. \u0412 Postmaster \u043e\u0442\u043a\u0440\u044b\u0442 \u043a\u0430\u043d\u0430\u043b \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0447\u0442\u0435\u043d\u0438\u044f, \u043d\u043e \u043b\u043e\u0433\u0433\u0435\u0440\u0443 \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0438\u0441\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043a\u0430\u043d\u0430\u043b\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0447\u0442\u0435\u043d\u0438\u044f (\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u043b\u043e\u0433\u0433\u0435\u0440)<\/p>\n<p>\u0414\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 Postmaster \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0439\u043f <code>postmaster_alive_fds<\/code>.<\/p>\n<pre><code class=\"cpp\">extern intpostmaster_alive_fds[2];  \/*  * Constants that represent which of postmaster_alive_fds is held by  * postmaster, and which is used in children to check for postmaster death.  *\/ #define POSTMASTER_FD_WATCH0\/* used in children to check for  * postmaster death *\/ #define POSTMASTER_FD_OWN1\/* kept open by postmaster only *\/<\/code><\/pre>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0441\u0442\u0430\u043b\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c, \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0430\u0439\u043f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043d\u0435\u0446 \u043f\u0430\u0439\u043f\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c.\u00a0<\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435:<\/p>\n<ul>\n<li>\n<p>\u0425\u043e\u0441\u0442 \u0438 \u043f\u043e\u0440\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/www.postgresql.org\/docs\/current\/libpq.html\" rel=\"noopener noreferrer nofollow\">libpq<\/a><\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 &#8212; \u0441\u0442\u0430\u0432\u0438\u043c DestRemote (\u043f\u0438\u0448\u0435\u043c \u0432\u0441\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443)<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u041d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u044b \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043f\u0438\u0448\u0435\u043c \u043a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c &#8212; \u043a\u043e\u043d\u0441\u043e\u043b\u044c (\u043b\u043e\u0433\u0438), \u0444\u0430\u0439\u043b (insert, update\u2026), \u0441\u0435\u0442\u044c (\u043a\u043b\u0438\u0435\u043d\u0442) \u0438\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043a\u0443\u0434\u0430 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 <em>CommandDest<\/em><\/p>\n<pre><code class=\"cpp\">\/* ----------------  *CommandDest is a simplistic means of identifying the desired  *destination.  Someday this will probably need to be improved.  *  * Note: only the values DestNone, DestDebug, DestRemote are legal for the  * global variable whereToSendOutput.   The other values may be used  * as the destination for individual commands.  * ----------------  *\/ typedef enum { DestNone,\/* results are discarded *\/ DestDebug,\/* results go to debugging output *\/ DestRemote,\/* results sent to frontend process *\/ DestRemoteExecute,\/* sent to frontend, in Execute command *\/ DestRemoteSimple,\/* sent to frontend, w\/no catalog access *\/ DestSPI,\/* results sent to SPI manager *\/ DestTuplestore,\/* results sent to Tuplestore *\/ DestIntoRel,\/* results sent to relation (SELECT INTO) *\/ DestCopyOut,\/* results sent to COPY TO code *\/ DestSQLFunction,\/* results sent to SQL-language func mgr *\/ DestTransientRel,\/* results sent to transient relation *\/ DestTupleQueue\/* results sent to tuple queue *\/ } CommandDest;<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u044d\u043a\u044d\u043d\u0434\u0430 \u043e\u043d \u0442\u043e\u0436\u0435 \u043f\u0438\u0448\u0435\u0442 \u043a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c. \u041f\u043e \u0441\u0443\u0442\u0438 &#8212; \u0441\u0438\u043d\u0433\u043b\u0442\u043e\u043d. \u0414\u043b\u044f \u043d\u0435\u0433\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>whereToSendOutput<\/code><\/p>\n<pre><code class=\"cpp\">\/* Note: whereToSendOutput is initialized for the bootstrap\/standalone case *\/ CommandDest whereToSendOutput = DestDebug;<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0417\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c<\/h4>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c, \u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u0440\u0442\u0430, \u043f\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0440\u043a\u0430\u043c, \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u044b\u0439. \u0418\u043c\u0435\u043d\u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u0434\u0435\u0431\u0430\u0433\u0435\u0440\u043e\u043c. \u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0437 postgresql.conf <a href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-developer.html#GUC-PRE-AUTH-DELAY\" rel=\"noopener noreferrer nofollow\">pre_auth_delay<\/a> &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0435\u043a\u0443\u043d\u0434 \u043f\u0440\u043e\u0441\u0442\u043e\u044f<\/p>\n<h4>\u0421\u0438\u0433\u043d\u0430\u043b\u044b \u0431\u044d\u043a\u044d\u043d\u0434\u0430<\/h4>\n<p>\u041d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0433\u0430\u0445 \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u043b\u0438 \u0432\u0441\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b Postmaster \u0438 \u0441\u043a\u0430\u0437\u0430\u043b\u0438, \u0447\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0414\u043b\u044f \u0431\u044d\u043a\u044d\u043d\u0434\u0430 &#8212; <em>SIGTERM<\/em><\/p>\n<pre><code class=\"cpp\">\/\/ ... pqsignal(SIGTERM, process_startup_packet_die); \/\/ ...  static void process_startup_packet_die(SIGNAL_ARGS) { _exit(1); }<\/code><\/pre>\n<h4>StartupPacket<\/h4>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430 &#8212; \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c.\u00a0<\/p>\n<p>\u0412\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\/\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0438\u043c\u0435\u0435\u0442 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u041f\u0440\u0438 \u0435\u0433\u043e \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f <em>SIGALRM<\/em><\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u0438\u043d\u044f\u0442\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c.\u00a0<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u0430\u043a\u0435\u0442\u0430 \u043d\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u0432\u0435\u0440\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430 \u0434\u043b\u0438\u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d &#8212; \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u0432\u0435\u0441\u044c \u043f\u0430\u043a\u0435\u0442 \u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0430\u0440\u0441\u0438\u043d\u0433<\/p>\n<ol start=\"2\">\n<li>\n<p>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u043a\u0430\u043d\u0430\u043b\u0430\u043c: SSL (TCP) \u0438\u043b\u0438 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/GSS-API\" rel=\"noopener noreferrer nofollow\">GSS-API<\/a> (UNIX)<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<pre><code class=\"cpp\">\/\/ \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 Startup \u043f\u0430\u043a\u0435\u0442\u0430 static int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)<\/code><\/pre>\n<p>2 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0431\u044b\u043b\u043e \u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>ProcessStartupPacket(myPort, false, false)<\/code> (SSL \u0438 GSS-API \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u044b), \u0430 \u0443\u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0438 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u0430 \u0436\u0435 \u0441\u0430\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<pre><code class=\"cpp\">static int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done) {     \/\/ ...    if (proto == NEGOTIATE_SSL_CODE &amp;&amp; !ssl_done) { charSSLok;  #ifdef USE_SSL \/* No SSL when disabled or on Unix sockets *\/ if (!LoadedSSL || IS_AF_UNIX(port->laddr.addr.ss_family)) SSLok = 'N'; else SSLok = 'S';\/* Support for SSL *\/ #else SSLok = 'N';\/* No support for SSL *\/ #endif  retry1: if (send(port->sock, &amp;SSLok, 1, 0) != 1) { if (errno == EINTR) goto retry1;\/* if interrupted, just retry *\/ ereport(COMMERROR, (errcode_for_socket_access(),  errmsg(\"failed to send SSL negotiation response: %m\"))); return STATUS_ERROR;\/* close the connection *\/ }  #ifdef USE_SSL if (SSLok == 'S' &amp;&amp; secure_open_server(port) == -1) return STATUS_ERROR; #endif  return ProcessStartupPacket(port, true, SSLok == 'S'); } else if (proto == NEGOTIATE_GSS_CODE &amp;&amp; !gss_done) { charGSSok = 'N';  #ifdef ENABLE_GSS \/* No GSSAPI encryption when on Unix socket *\/ if (!IS_AF_UNIX(port->laddr.addr.ss_family)) GSSok = 'G'; #endif  while (send(port->sock, &amp;GSSok, 1, 0) != 1) { if (errno == EINTR) continue; ereport(COMMERROR, (errcode_for_socket_access(),  errmsg(\"failed to send GSSAPI negotiation response: %m\"))); return STATUS_ERROR;\/* close the connection *\/ }  #ifdef ENABLE_GSS if (GSSok == 'G' &amp;&amp; secure_open_gssapi(port) == -1) return STATUS_ERROR; #endif \/\/ ... return ProcessStartupPacket(port, GSSok == 'G', true); }   \/\/ ... }<\/code><\/pre>\n<p>* \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>goto<\/code> \u043f\u0440\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 SSL, \u0430 \u0434\u043b\u044f GSS \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>while<\/code><\/p>\n<ol start=\"3\">\n<li>\n<p>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u0430\u043a\u0435\u0442\u0430 3-\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>Postgres \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0432\u043e\u0439 [\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439] \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\/\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.\u00a0<\/p>\n<p>\u041f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u0434\u043b\u044f \u0435\u0433\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u0432\u0435\u0440\u043a\u0430 \u0441\u0442\u0440\u043e\u043a \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f.  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u044d\u0442\u043e \u043d\u0430\u0447\u0430\u043b\u043e \u0446\u0438\u043a\u043b\u0430, \u0433\u0434\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0411\u0414 \u0438 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"cpp\">while (offset &lt; len) {     char   *nameptr = buf + offset;     int32valoffset;     char   *valptr;      if (*nameptr == '\\0')         break;\/* found packet terminator *\/     valoffset = offset + strlen(nameptr) + 1;     if (valoffset >= len)         break;\/* missing value, will complain below *\/     valptr = buf + valoffset;      if (strcmp(nameptr, \"database\") == 0)         port->database_name = pstrdup(valptr);     else if (strcmp(nameptr, \"user\") == 0)         port->user_name = pstrdup(valptr);     \/\/ ... }<\/code><\/pre>\n<ol start=\"4\">\n<li>\n<p>\u041f\u043e\u0441\u0442\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u0430.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0430\u043a\u0435\u0442 \u0441\u043f\u0430\u0440\u0441\u0438\u043b\u0438. \u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0411\u0414 \u043d\u0435 \u0434\u0430\u043d\u043e, \u043f\u0440\u0438\u0440\u0430\u0432\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043a \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445\/per-db \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u0441\u0435\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0411\u0414 \u0434\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e &#8212; 64<\/p>\n<\/li>\n<\/ul>\n<ol start=\"5\">\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u044b \u0432\u0441\u0435 \u0435\u0449\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442 Postmaster. \u0410 \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0442\u044c\/\u043e\u0442\u0432\u0435\u0440\u0433\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f (\u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u043b\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0442\u0430\u0440\u0442\u0430).<\/p>\n<p>\u0421\u0430\u043c\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c <em>CAC_state<\/em> (Client Accept Connection State)<\/p>\n<pre><code class=\"cpp\">typedef enum CAC_state { CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_NOTCONSISTENT, CAC_TOOMANY, CAC_SUPERUSER } CAC_state;<\/code><\/pre>\n<p>\u0421\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043d\u0438\u0445, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e <em>CAC_OK<\/em> \u0438 <em>CAC_SUPERUSER<\/em> (\u0434\u043e\u043f\u0443\u0441\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f), \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f<\/p>\n<pre><code class=\"cpp\">switch (port->canAcceptConnections) {     case CAC_STARTUP:         ereport(FATAL,                 (errcode(ERRCODE_CANNOT_CONNECT_NOW),                  errmsg(\"the database system is starting up\")));         break;     case CAC_NOTCONSISTENT:         if (EnableHotStandby)             ereport(FATAL,                     (errcode(ERRCODE_CANNOT_CONNECT_NOW),                      errmsg(\"the database system is not yet accepting connections\"),                      errdetail(\"Consistent recovery state has not been yet reached.\")));         else             ereport(FATAL,                     (errcode(ERRCODE_CANNOT_CONNECT_NOW),                      errmsg(\"the database system is not accepting connections\"),                      errdetail(\"Hot standby mode is disabled.\")));         break;     case CAC_SHUTDOWN:         ereport(FATAL,                 (errcode(ERRCODE_CANNOT_CONNECT_NOW),                  errmsg(\"the database system is shutting down\")));         break;     case CAC_RECOVERY:         ereport(FATAL,                 (errcode(ERRCODE_CANNOT_CONNECT_NOW),                  errmsg(\"the database system is in recovery mode\")));         break;     case CAC_TOOMANY:         ereport(FATAL,                 (errcode(ERRCODE_TOO_MANY_CONNECTIONS),                  errmsg(\"sorry, too many clients already\")));         break;     case CAC_SUPERUSER:         \/* OK for now, will check in InitPostgres *\/         break;     case CAC_OK:         break; }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>ereport<\/summary>\n<div class=\"spoiler__content\">\n<p>ereport() &#8212; \u043c\u0430\u043a\u0440\u043e\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/utils\/elog.h\" rel=\"noopener noreferrer nofollow\">src\/include\/utils\/elog.h<\/a>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/error\/elog.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/utils\/error\/elog.c<\/a><\/p>\n<pre><code class=\"cpp\">\/* Error level codes *\/ #define DEBUG510\/* Debugging messages, in categories of  * decreasing detail. *\/ #define DEBUG411 #define DEBUG312 #define DEBUG213 #define DEBUG114\/* used by GUC debug_* variables *\/ #define LOG15\/* Server operational messages; sent only to  * server log by default. *\/ #define LOG_SERVER_ONLY 16\/* Same as LOG for server reporting, but never  * sent to client. *\/ #define COMMERRORLOG_SERVER_ONLY \/* Client communication problems; same as  * LOG for server reporting, but never  * sent to client. *\/ #define INFO17\/* Messages specifically requested by user (eg  * VACUUM VERBOSE output); always sent to  * client regardless of client_min_messages,  * but by default not sent to server log. *\/ #define NOTICE18\/* Helpful messages to users about query  * operation; sent to client and not to server  * log by default. *\/ #define WARNING19\/* Warnings.  NOTICE is for expected messages  * like implicit sequence creation by SERIAL.  * WARNING is for unexpected messages. *\/ #define PGWARNING19\/* Must equal WARNING; see NOTE below. *\/ #define WARNING_CLIENT_ONLY20\/* Warnings to be sent to client as usual, but  * never to the server log. *\/ #define ERROR21\/* user error - abort transaction; return to  * known state *\/ #define PGERROR21\/* Must equal ERROR; see NOTE below. *\/ #define FATAL22\/* fatal error - abort process *\/ #define PANIC23\/* take down the other backends with me *\/  \/\/ ...  #define ereport(elevel, ...)\\ ereport_domain(elevel, TEXTDOMAIN, __VA_ARGS__)  #define TEXTDOMAIN NULL<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0430\u0433\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u043e\u043c\u0435\u0440 \u0443\u0440\u043e\u0432\u043d\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 <em>ERROR <\/em>(21), \u0442\u043e \u043c\u0430\u043a\u0440\u043e\u0441 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 <em>CAC_State<\/em>, \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0435 <em>CAC_OK<\/em> \u0438\u043b\u0438 <em>CAC_USERUSER, <\/em>\u0442\u043e \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>ProcessStartupPacket()<\/em> \u043c\u044b \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f, \u0442.\u043a. \u043b\u043e\u0433\u0438\u0440\u0443\u0435\u043c \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c <em>FATAL<\/em>: 22 >= 21<\/p>\n<\/div>\n<\/details>\n<h4>\u0417\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Startup \u043f\u0430\u043a\u0435\u0442\u0430 \u043c\u044b \u043d\u0430\u0432\u0435\u0441\u0438\u043b\u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0415\u0441\u043b\u0438 \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430, \u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0443\u0441\u043f\u0435\u043b\u0438 \u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 Startup \u043f\u0430\u043a\u0435\u0442\u0430 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0439 \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0443\u0442 \u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443. \u041d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c 0.<\/p>\n<p>\u0411\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0430 \u0437\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u043c\u0438 \u0430\u0434\u043c\u0438\u043d\u044b. \u0410 \u044d\u0442\u0438 \u043b\u044e\u0434\u0438 \u0447\u0430\u0449\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <em>ps<\/em>. \u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0438\u0445 \u0436\u0438\u0437\u043d\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u0437\u0430\u043c\u043e\u0440\u043e\u0447\u0438\u043b\u0438\u0441\u044c \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f &#8212; \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 &#8212; \u0440\u0430\u0437\u043d\u043e\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u0443\u0441.<\/p>\n<pre><code class=\"cpp\">set_ps_display(\"initializing\");<\/code><\/pre>\n<h4>\u0421\u0442\u0430\u0440\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0411\u0414<\/h4>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<p>\u041d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 Postmaster \u0443 \u043d\u0430\u0441 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u0431\u044b\u043b \u043e\u0431\u0449\u0438\u0439.\u00a0<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0432\u044b\u0448\u043b\u0438 \u0438\u0437 \u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 &#8212; \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0432\u043e\u0439 \u043f\u043e\u0437\u0436\u0435.<\/p>\n<pre><code class=\"cpp\">MemoryContextSwitchTo(TopMemoryContext);<\/code><\/pre>\n<h2>\u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430<\/h2>\n<p>\u041c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0431\u044d\u043a\u044d\u043d\u0434\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 argc \u0438 argv, \u043d\u043e \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f.\u00a0<\/p>\n<pre><code class=\"cpp\">\/* ----------------------------------------------------------------  * PostgresMain  *   postgres main loop -- all backends, interactive or otherwise start here  *  * argc\/argv are the command line arguments to be used.  (When being forked  * by the postmaster, these are not the original argv array of the process.)  * dbname is the name of the database to connect to, or NULL if the database  * name should be extracted from the command line arguments or defaulted.  * username is the PostgreSQL user name to be used for the session.  * ----------------------------------------------------------------  *\/ void PostgresMain(int argc, char *argv[],  const char *dbname,  const char *username)<\/code><\/pre>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/post\/701284\/\" rel=\"noopener noreferrer nofollow\">0 \u0447\u0430\u0441\u0442\u0438<\/a>, \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0438\u0437 <em>PostgesMain<\/em>, \u043c\u0438\u043d\u0443\u044f Postmaster (\u043a\u043b\u044e\u0447 <code>\u2013single<\/code>). \u0415\u0441\u043b\u0438 \u0442\u0430\u043a, \u0442\u043e \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0431\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f NULL, \u0430 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.\u00a0<\/p>\n<pre><code class=\"cpp\">else if (argc > 1 &amp;&amp; strcmp(argv[1], \"--single\") == 0) PostgresMain(argc, argv,  NULL,\/* no dbname *\/  strdup(get_user_name_or_exit(progname)));<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0411\u0414 \u0443 \u043d\u0430\u0441 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043c\u0435\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0438\u0445 \u043a\u0430\u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c argc\/argv<\/p>\n<pre><code class=\"cpp\">char   *av[2]; const intac = 1;  av[0] = \"postgres\"; av[1] = NULL;   PostgresMain(ac, av, port->database_name, port->user_name);<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0431\u044d\u043a\u044d\u043d\u0434\u0430 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u043b\u043e\u0441\u044c. <\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 &#8212; \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707950\/\"> https:\/\/habr.com\/ru\/post\/707950\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e. <\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 Postgres. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0444\u043e\u0440\u043a\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/post\/704618\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a>. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0442\u0430\u043a \u0436\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/postmaster\/postmaster.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/postmaster\/postmaster.c<\/a><\/p>\n<h2>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f<\/h2>\n<p>\u041b\u044e\u0431\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043f\u043e\u0440\u043e\u0434\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043e\u0442 Postmaster \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041f\u043e \u0444\u0430\u043a\u0442\u0443, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <em>InitPostmasterChild() <\/em>(\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/init\/miscinit.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/utils\/init\/miscinit.c<\/a>), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0430\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435<\/p>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0441\u0442\u0435\u043a\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0430\u0437\u0430 \u0441\u0442\u0435\u043a\u0430 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. <\/p>\n<pre><code class=\"cpp\">\/*  * Stack base pointer -- initialized by PostmasterMain and inherited by  * subprocesses. This is not static because old versions of PL\/Java modify  * it directly. Newer versions use set_stack_base(), but we want to stay  * binary-compatible for the time being.  *\/ char   *stack_base_ptr = NULL;<\/code><\/pre>\n<p>\u041b\u044e\u0431\u043e\u0439 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0435\u043a. \u0417\u0430\u0447\u0435\u043c? \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0441\u0442\u0435\u043a\u0430 \u0441\u0430\u043c\u0438\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u043a\u0441\u0442\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430.\u00a0<\/p>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0435\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d \u0432 postgresql.conf: \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/runtime-config-resource.html#GUC-MAX-STACK-DEPTH\" rel=\"noopener noreferrer nofollow\">max_stack_depth<\/a><\/p>\n<h4>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041e\u043d\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/utils\/init\/globals.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/utils\/init\/globals.c<\/a>, \u0445\u043e\u0442\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/miscadmin.h\" rel=\"noopener noreferrer nofollow\">src\/include\/miscadmin.h<\/a> <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p><em>MyProcId<\/em> &#8212; ID \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p><em>MyStartTimestamp<\/em> &#8212; \u0448\u0442\u0430\u043c\u043f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p><em>MyStartTime<\/em> &#8212; \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Postgresql.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0440\u0443\u0433\u0430\u044f \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u0434\u0435\u0442\u0430\u043b\u044c &#8212; \u0440\u0430\u043d\u0434\u043e\u043c.\u00a0<\/p>\n<p>Postgres \u0438\u043c\u0435\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>pg_strong_random()<\/em> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b. \u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/port.h\" rel=\"noopener noreferrer nofollow\">src\/include\/port.h<\/a>, \u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/port\/pg_strong_random.c\" rel=\"noopener noreferrer nofollow\">src\/port\/pg_strong_random.c<\/a><\/p>\n<pre><code class=\"cpp\">\/*  * ...  *  * Returns true on success, and false if none of the sources  * were available. NB: It is important to check the return value!  * Proceeding with key generation when no random data was available  * would lead to predictable keys and security issues.  *\/ bool pg_strong_random(void *buf, size_t len)<\/code><\/pre>\n<p>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c, \u0438\u0434\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 3 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u043c\u0438:<\/p>\n<ul>\n<li>\n<p>OpenSSL &#8212; <a href=\"https:\/\/www.openssl.org\/docs\/manmaster\/man3\/RAND_bytes.html\" rel=\"noopener noreferrer nofollow\">RAND_bytes()<\/a><\/p>\n<\/li>\n<li>\n<p>Windows &#8212; <a href=\"https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/api\/wincrypt\/nf-wincrypt-cryptgenrandom\" rel=\"noopener noreferrer nofollow\">CryptGenRandom()<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/ru.wikipedia.org\/?title=\/dev\/random_%D0%B8_\/dev\/urandom\" rel=\"noopener noreferrer nofollow\">\/dev\/urandom<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438\u0437 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0434\u043e\u043c\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f <code>false<\/code>. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0434 \u0441\u0430\u043c\u0438\u043c. \u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u0441\u0438\u0434\u0430, \u043d\u0443\u0436\u043d\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u0427\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e? \u041d\u0430\u0448 PID \u0438 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430!\u00a0<\/p>\n<pre><code class=\"cpp\">unsigned int rseed;  if (!pg_strong_random(&amp;rseed, sizeof(rseed))) {     \/*      * Since PIDs and timestamps tend to change more frequently in their      * least significant bits, shift the timestamp left to allow a larger      * total number of seeds in a given time period.  Since that would      * leave only 20 bits of the timestamp that cycle every ~1 second,      * also mix in some higher bits.      *\/     rseed = ((uint64) MyProcPid) ^         ((uint64) MyStartTimestamp &lt;&lt; 12) ^         ((uint64) MyStartTimestamp >> 20); } srandom(rseed);<\/code><\/pre>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432<\/h4>\n<p>\u041a\u043e\u0433\u0434\u0430 Postmaster \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u201c\u0432 \u043d\u0430\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u043e\u201d.\u00a0\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f.\u00a0<\/p>\n<p>\u0412 Postmaster \u0431\u044b\u043b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f <em>SIGQUIT<\/em> &#8212; \u043f\u0443\u0441\u0442\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442). \u041d\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0442\u0430\u043a \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0442\u044c &#8212; \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435, <em>SIGQUIT<\/em> \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u043c\u0430\u0441\u043a\u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 (BlockSig) \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.\u00a0<\/p>\n<pre><code class=\"cpp\">\/*  * Simple signal handler for exiting quickly as if due to a crash.  *  * Normally, this would be used for handling SIGQUIT.  *\/ void SignalHandlerForCrashExit(SIGNAL_ARGS) { \/*  * We DO NOT want to run proc_exit() or atexit() callbacks -- we're here  * because shared memory may be corrupted, so we don't want to try to  * clean up our transaction.  Just nail the windows shut and get out of  * town.  The callbacks wouldn't be safe to run from a signal handler,  * anyway.  *  * Note we do _exit(2) not _exit(0).  This is to force the postmaster into  * a system reset cycle if someone sends a manual SIGQUIT to a random  * backend.  This is necessary precisely because we don't clean up our  * shared memory state.  (The \"dead man switch\" mechanism in pmsignal.c  * should ensure the postmaster sees this as a crash, too, but no harm in  * being doubly sure.)  *\/ _exit(2); }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 Postmaster \u0442\u043e\u043b\u044c\u043a\u043e \u201c\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u201d: \u0435\u0441\u043b\u0438 Postmaster \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u0442\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0442\u0430\u043d\u0435\u0442 \u0437\u043e\u043c\u0431\u0438.\u00a0<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>prctl()<\/em> \u0438\u043b\u0438 <em>procctl()<\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>prctl()<\/summary>\n<div class=\"spoiler__content\">\n<p>prctl() &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430.\u00a0<\/p>\n<pre><code class=\"cpp\">#include &lt;sys\/prctl.h>  int prctl(int option, unsigned long arg2, unsigned long arg3,          unsigned long arg4, unsigned long arg5);<\/code><\/pre>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043d\u0435\u0433\u043e. <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0434 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0445\u043e\u0442\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B0%D1%82%D0%B5%D0%BC%D0%B0%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%BE%D0%BF%D1%80%D0%BE%D1%86%D0%B5%D1%81%D1%81%D0%BE%D1%80\" rel=\"noopener noreferrer nofollow\">FPU<\/a>. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442? \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0431\u043e \u044d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 CPU, \u043b\u0438\u0431\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0414\u043b\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c prctl:<\/p>\n<pre><code class=\"cpp\">\/\/ \u042d\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0431\u0435\u0437 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 prctl(PR_SET_FPEMU, PR_FPEMU_NOPRINT);  \/\/ \u041f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u043f\u043e\u0441\u044b\u043b\u0430\u0442\u044c SIGFPE prctl(PR_SET_FPEMU, PR_FPEMU_SIGFPE);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>procctl()<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/www.freebsd.org\/cgi\/man.cgi?query=procctl&amp;sektion=2\" rel=\"noopener noreferrer nofollow\">procctl<\/a> &#8212; \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438.<\/p>\n<pre><code class=\"cpp\">#include &lt;sys\/procctl.h>  int procctl(idtype_t idtype, id_t id, int cmd, void *data);<\/code><\/pre>\n<p>1 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442: <em>P_PID<\/em> &#8212; PID \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, <em>P_PGID<\/em> &#8212; ID \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/p>\n<p>2 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; ID \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f<\/p>\n<p>3 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u043a\u043e\u043c\u0430\u043d\u0434\u0430<\/p>\n<p>4 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 &#8212; \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043e\u0442 \u0430\u0442\u0430\u043a\u0438 \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u041e\u0421 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/ASLR\" rel=\"noopener noreferrer nofollow\">ASLR<\/a>, \u043d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0434\u0440\u0435\u0432\u043d\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0442\u043e \u043d\u0435 \u0444\u0430\u043a\u0442. \u0427\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438, \u0447\u0442\u043e \u043e\u043d\u0430 \u0442\u043e\u0447\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0437\u043e\u0432<\/p>\n<pre><code class=\"cpp\">\/\/ 0 \u0432 id - \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 procctl(P_PID, 0, PROC_ASLR_CTL, &amp;PROC_ASLR_FORCE_ENABLE);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>Postgres \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0430\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b Postmaster, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d:<\/p>\n<pre><code class=\"cpp\">\/*  * Signal handler to be notified if postmaster dies.  *\/ #ifdef USE_POSTMASTER_DEATH_SIGNAL volatile sig_atomic_t postmaster_possibly_dead = false;  static void postmaster_death_handler(int signo) { postmaster_possibly_dead = true; }  \/*  * The available signals depend on the OS.  SIGUSR1 and SIGUSR2 are already  * used for other things, so choose another one.  *  * Currently, we assume that we can always find a signal to use.  That  * seems like a reasonable assumption for all platforms that are modern  * enough to have a parent-death signaling mechanism.  *\/ #if defined(SIGINFO) #define POSTMASTER_DEATH_SIGNAL SIGINFO #elif defined(SIGPWR) #define POSTMASTER_DEATH_SIGNAL SIGPWR #else #error \"cannot find a signal to use for postmaster death\" #endif  #endif\/* USE_POSTMASTER_DEATH_SIGNAL *\/  void PostmasterDeathSignalInit(void) { #ifdef USE_POSTMASTER_DEATH_SIGNAL intsignum = POSTMASTER_DEATH_SIGNAL;  \/* Register our signal handler. *\/ pqsignal(signum, postmaster_death_handler);  \/* Request a signal on parent exit. *\/ #if defined(PR_SET_PDEATHSIG) if (prctl(PR_SET_PDEATHSIG, signum) &lt; 0) elog(ERROR, \"could not request parent death signal: %m\"); #elif defined(PROC_PDEATHSIG_CTL) if (procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &amp;signum) &lt; 0) elog(ERROR, \"could not request parent death signal: %m\"); #else #error \"USE_POSTMASTER_DEATH_SIGNAL set, but there is no mechanism to request the signal\" #endif  \/*  * Just in case the parent was gone already and we missed it, we'd better  * check the slow way on the first call.  *\/ postmaster_possibly_dead = true; #endif\/* USE_POSTMASTER_DEATH_SIGNAL *\/ }<\/code><\/pre>\n<h4>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f MyLatch<\/h4>\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Latch, \u043d\u043e \u043e\u043d \u043d\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d.\u00a0<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430: \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0430\u0442\u0447\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u201c\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u201d.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e-\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 Latch &#8212; \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f MyLatch.<\/p>\n<p>Latch &#8212; \u044d\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441. \u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/include\/storage\/latch.h\" rel=\"noopener noreferrer nofollow\">src\/include\/storage\/latch.h<\/a>, \u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/github.com\/postgres\/postgres\/blob\/master\/src\/backend\/storage\/ipc\/latch.c\" rel=\"noopener noreferrer nofollow\">src\/backend\/storage\/ipc\/latch.c<\/a>.<\/p>\n<p>\u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u0437\u0430\u0441\u044b\u043f\u0430\u0442\u044c (\u0437\u0430\u0445\u0432\u0430\u0442\u0438\u0442\u044c Latch), \u043f\u043e\u043a\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0435 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442 (\u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442) \u044d\u0442\u043e\u0442 Latch.<\/p>\n<p>\u042d\u0442\u043e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cpp\">\/*  * prototypes for functions in latch.c  *\/ extern void InitializeLatchSupport(void); extern void InitLatch(Latch *latch); extern void InitSharedLatch(Latch *latch); extern void OwnLatch(Latch *latch); extern void DisownLatch(Latch *latch); extern void SetLatch(Latch *latch); extern void ResetLatch(Latch *latch); extern void ShutdownLatchSupport(void);<\/code><\/pre>\n<p>\u041b\u0443\u0447\u0448\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a \u0410\u0422\u0414, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><em>POLL<\/em> &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 self-pipe trick<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>self-pipe trick<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u0438\u0433\u043d\u0430\u043b\u044b &#8212; \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f: \u0431\u044b\u043b\u043e \u0438\u043b\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u043d\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0442\u043e \u043e\u043d\u043e \u043d\u0438\u043a\u0435\u043c \u043d\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u043b\u0435\u0442\u0438\u0442 \u201c\u0432 \u043d\u0438\u043a\u0443\u0434\u0430\u201d. \u0414\u043b\u044f \u043e\u0431\u0445\u043e\u0434\u0430 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d <em>self-pipe trick<\/em>.<\/p>\n<p>\u0418\u0434\u0435\u044f \u043f\u0440\u043e\u0441\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e-\u0444\u043b\u0430\u0433 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u0440\u0438\u043d\u044f\u0442 (<em>volatile sigset_t is_signal_set<\/em>)<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0432 \u043e\u0431\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043e\u0447\u0435\u0440\u0435\u0434\u044c &#8212; \u0432\u044b\u0437\u043e\u0432 <em>fcntl(fd, FD_SETFL, O_NONBLOCK)<\/em>, fd &#8212; \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043e\u0447\u0435\u0440\u0435\u0434\u0438<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0430: \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 &#8212; \u043f\u0438\u0448\u0435\u043c \u0431\u0430\u0439\u0442 \u0432 \u043d\u0430\u0448\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0441\u0442\u0430\u0432\u0438\u043c \u0444\u043b\u0430\u0433 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u043f\u043e\u043b\u0443\u0447\u0435\u043d<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 sigset_t \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d, \u0442\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u044d\u0442\u0438\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u043c\u044b \u043f\u0440\u0438\u043d\u044f\u043b\u0438. \u0410 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0445 \u0431\u044b\u043b\u043e &#8212; \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0430\u0439\u0442\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0427\u0438\u0442\u0430\u0435\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432.\u00a0<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 \u0444\u043b\u0430\u0433\u0430, \u0442\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <em>poll()<\/em>. \u041a\u043e\u0433\u0434\u0430 \u043e\u043d \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e, \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0431\u044b\u043b\u0430 \u043f\u0443\u0441\u0442\u0430, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f -1 \u0438 errno \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>EINTR<\/em>, \u0438\u043d\u0430\u0447\u0435 \u0447\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0431\u0430\u0439\u0442\u044b.<\/p>\n<pre><code class=\"cpp\">void InitializeLatchSupport(void) { #if defined(WAIT_USE_SELF_PIPE) intpipefd[2];  \/\/ ...  \/*  * Set up the self-pipe that allows a signal handler to wake up the  * poll()\/epoll_wait() in WaitLatch. Make the write-end non-blocking, so  * that SetLatch won't block if the event has already been set many<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343679","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343679"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343679\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}