PostgreSQL Source Code  git master
ipc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
 
#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)
 

Typedefs

typedef void(* pg_on_exit_callback) (int code, Datum arg)
 
typedef void(* shmem_startup_hook_type) (void)
 

Functions

void proc_exit (int code) pg_attribute_noreturn()
 
void shmem_exit (int code)
 
void on_proc_exit (pg_on_exit_callback function, Datum arg)
 
void on_shmem_exit (pg_on_exit_callback function, Datum arg)
 
void before_shmem_exit (pg_on_exit_callback function, Datum arg)
 
void cancel_before_shmem_exit (pg_on_exit_callback function, Datum arg)
 
void on_exit_reset (void)
 
void CreateSharedMemoryAndSemaphores (void)
 

Variables

PGDLLIMPORT bool proc_exit_inprogress
 
PGDLLIMPORT bool shmem_exit_inprogress
 
PGDLLIMPORT shmem_startup_hook_type shmem_startup_hook
 

Macro Definition Documentation

◆ PG_END_ENSURE_ERROR_CLEANUP

#define PG_END_ENSURE_ERROR_CLEANUP (   cleanup_function,
  arg 
)
Value:
cancel_before_shmem_exit(cleanup_function, arg); \
PG_CATCH(); \
{ \
cancel_before_shmem_exit(cleanup_function, arg); \
cleanup_function (0, arg); \
PG_RE_THROW(); \
} \
PG_END_TRY(); \
} while (0)
void cancel_before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:390
void * arg

Definition at line 52 of file ipc.h.

Referenced by autoprewarm_dump_now(), btbulkdelete(), createdb(), do_pg_start_backup(), do_pg_stop_backup(), movedb(), and perform_base_backup().

◆ PG_ENSURE_ERROR_CLEANUP

#define PG_ENSURE_ERROR_CLEANUP (   cleanup_function,
  arg 
)
Value:
do { \
before_shmem_exit(cleanup_function, arg); \
PG_TRY()
void * arg

Definition at line 47 of file ipc.h.

Referenced by autoprewarm_dump_now(), btbulkdelete(), createdb(), do_pg_start_backup(), do_pg_stop_backup(), movedb(), and perform_base_backup().

Typedef Documentation

◆ pg_on_exit_callback

typedef void(* pg_on_exit_callback) (int code, Datum arg)

Definition at line 21 of file ipc.h.

◆ shmem_startup_hook_type

typedef void(* shmem_startup_hook_type) (void)

Definition at line 22 of file ipc.h.

Function Documentation

◆ before_shmem_exit()

void before_shmem_exit ( pg_on_exit_callback  function,
Datum  arg 
)

Definition at line 333 of file ipc.c.

References ONEXIT::arg, atexit_callback(), atexit_callback_setup, before_shmem_exit_index, before_shmem_exit_list, ereport, errcode(), errmsg_internal(), FATAL, ONEXIT::function, and MAX_ON_EXITS.

Referenced by ApplyLauncherMain(), AtEOXact_Namespace(), AuxiliaryProcessMain(), Exec_ListenPreCommit(), InitPostgres(), llvm_session_initialize(), LockGXact(), logicalrep_worker_attach(), MarkAsPreparing(), and pg_start_backup().

334 {
336  ereport(FATAL,
337  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
338  errmsg_internal("out of before_shmem_exit slots")));
339 
342 
344 
346  {
347  atexit(atexit_callback);
348  atexit_callback_setup = true;
349  }
350 }
#define MAX_ON_EXITS
Definition: ipc.c:71
int errcode(int sqlerrcode)
Definition: elog.c:608
pg_on_exit_callback function
Definition: ipc.c:75
static bool atexit_callback_setup
Definition: ipc.c:51
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
static int before_shmem_exit_index
Definition: ipc.c:83
Datum arg
Definition: ipc.c:76
void * arg
static struct ONEXIT before_shmem_exit_list[MAX_ON_EXITS]
Definition: ipc.c:81
static void atexit_callback(void)
Definition: ipc.c:290

◆ cancel_before_shmem_exit()

void cancel_before_shmem_exit ( pg_on_exit_callback  function,
Datum  arg 
)

Definition at line 390 of file ipc.c.

References before_shmem_exit_index, and before_shmem_exit_list.

Referenced by pg_stop_backup_v2().

391 {
392  if (before_shmem_exit_index > 0 &&
394  == function &&
397 }
static int before_shmem_exit_index
Definition: ipc.c:83
void * arg
static struct ONEXIT before_shmem_exit_list[MAX_ON_EXITS]
Definition: ipc.c:81

◆ CreateSharedMemoryAndSemaphores()

void CreateSharedMemoryAndSemaphores ( void  )

Definition at line 94 of file ipci.c.

References add_size(), addin_request_allowed, ApplyLauncherShmemInit(), ApplyLauncherShmemSize(), AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemInit(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BackgroundWorkerShmemInit(), BackgroundWorkerShmemSize(), BTreeShmemInit(), BTreeShmemSize(), BufferShmemSize(), CheckpointerShmemInit(), CheckpointerShmemSize(), CLOGShmemInit(), CLOGShmemSize(), CommitTsShmemInit(), CommitTsShmemSize(), CreateLWLocks(), CreateSharedBackendStatus(), CreateSharedInvalidationState(), CreateSharedProcArray(), DEBUG3, dsm_postmaster_startup(), elog, hash_estimate_size(), InitBufferPool(), InitLocks(), InitPredicateLocks(), InitProcGlobal(), InitShmemAccess(), InitShmemAllocation(), InitShmemIndex(), IsUnderPostmaster, LockShmemSize(), LWLockShmemSize(), MultiXactShmemInit(), MultiXactShmemSize(), PANIC, PGReserveSemaphores(), PGSemaphoreShmemSize(), PGSharedMemoryCreate(), PMSignalShmemInit(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalSemas(), ProcGlobalShmemSize(), ProcSignalShmemInit(), ProcSignalShmemSize(), ReplicationOriginShmemInit(), ReplicationOriginShmemSize(), ReplicationSlotsShmemInit(), ReplicationSlotsShmemSize(), SHMEM_INDEX_SIZE, shmem_startup_hook, SInvalShmemSize(), SnapMgrInit(), SnapMgrShmemSize(), SpinlockSemaInit(), SpinlockSemas(), SpinlockSemaSize(), SUBTRANSShmemInit(), SUBTRANSShmemSize(), SyncScanShmemInit(), SyncScanShmemSize(), total_addin_request, TwoPhaseShmemInit(), TwoPhaseShmemSize(), WalRcvShmemInit(), WalRcvShmemSize(), WalSndShmemInit(), WalSndShmemSize(), XLOGShmemInit(), and XLOGShmemSize().

Referenced by BackendRun(), InitCommunication(), and reset_shared().

95 {
96  PGShmemHeader *shim = NULL;
97 
98  if (!IsUnderPostmaster)
99  {
100  PGShmemHeader *seghdr;
101  Size size;
102  int numSemas;
103 
104  /* Compute number of semaphores we'll need */
105  numSemas = ProcGlobalSemas();
106  numSemas += SpinlockSemas();
107 
108  /*
109  * Size of the Postgres shared-memory block is estimated via
110  * moderately-accurate estimates for the big hogs, plus 100K for the
111  * stuff that's too small to bother with estimating.
112  *
113  * We take some care during this phase to ensure that the total size
114  * request doesn't overflow size_t. If this gets through, we don't
115  * need to be so careful during the actual allocation phase.
116  */
117  size = 100000;
118  size = add_size(size, PGSemaphoreShmemSize(numSemas));
119  size = add_size(size, SpinlockSemaSize());
121  sizeof(ShmemIndexEnt)));
122  size = add_size(size, BufferShmemSize());
123  size = add_size(size, LockShmemSize());
124  size = add_size(size, PredicateLockShmemSize());
125  size = add_size(size, ProcGlobalShmemSize());
126  size = add_size(size, XLOGShmemSize());
127  size = add_size(size, CLOGShmemSize());
128  size = add_size(size, CommitTsShmemSize());
129  size = add_size(size, SUBTRANSShmemSize());
130  size = add_size(size, TwoPhaseShmemSize());
131  size = add_size(size, BackgroundWorkerShmemSize());
132  size = add_size(size, MultiXactShmemSize());
133  size = add_size(size, LWLockShmemSize());
134  size = add_size(size, ProcArrayShmemSize());
135  size = add_size(size, BackendStatusShmemSize());
136  size = add_size(size, SInvalShmemSize());
137  size = add_size(size, PMSignalShmemSize());
138  size = add_size(size, ProcSignalShmemSize());
139  size = add_size(size, CheckpointerShmemSize());
140  size = add_size(size, AutoVacuumShmemSize());
141  size = add_size(size, ReplicationSlotsShmemSize());
142  size = add_size(size, ReplicationOriginShmemSize());
143  size = add_size(size, WalSndShmemSize());
144  size = add_size(size, WalRcvShmemSize());
145  size = add_size(size, ApplyLauncherShmemSize());
146  size = add_size(size, SnapMgrShmemSize());
147  size = add_size(size, BTreeShmemSize());
148  size = add_size(size, SyncScanShmemSize());
149  size = add_size(size, AsyncShmemSize());
150 #ifdef EXEC_BACKEND
151  size = add_size(size, ShmemBackendArraySize());
152 #endif
153 
154  /* freeze the addin request size and include it */
155  addin_request_allowed = false;
156  size = add_size(size, total_addin_request);
157 
158  /* might as well round it off to a multiple of a typical page size */
159  size = add_size(size, 8192 - (size % 8192));
160 
161  elog(DEBUG3, "invoking IpcMemoryCreate(size=%zu)", size);
162 
163  /*
164  * Create the shmem segment
165  */
166  seghdr = PGSharedMemoryCreate(size, &shim);
167 
168  InitShmemAccess(seghdr);
169 
170  /*
171  * Create semaphores
172  */
173  PGReserveSemaphores(numSemas);
174 
175  /*
176  * If spinlocks are disabled, initialize emulation layer (which
177  * depends on semaphores, so the order is important here).
178  */
179 #ifndef HAVE_SPINLOCKS
181 #endif
182  }
183  else
184  {
185  /*
186  * We are reattaching to an existing shared memory segment. This
187  * should only be reached in the EXEC_BACKEND case.
188  */
189 #ifndef EXEC_BACKEND
190  elog(PANIC, "should be attached to shared memory already");
191 #endif
192  }
193 
194  /*
195  * Set up shared memory allocation mechanism
196  */
197  if (!IsUnderPostmaster)
199 
200  /*
201  * Now initialize LWLocks, which do shared memory allocation and are
202  * needed for InitShmemIndex.
203  */
204  CreateLWLocks();
205 
206  /*
207  * Set up shmem.c index hashtable
208  */
209  InitShmemIndex();
210 
211  /*
212  * Set up xlog, clog, and buffers
213  */
214  XLOGShmemInit();
215  CLOGShmemInit();
219  InitBufferPool();
220 
221  /*
222  * Set up lock manager
223  */
224  InitLocks();
225 
226  /*
227  * Set up predicate lock manager
228  */
230 
231  /*
232  * Set up process table
233  */
234  if (!IsUnderPostmaster)
235  InitProcGlobal();
240 
241  /*
242  * Set up shared-inval messaging
243  */
245 
246  /*
247  * Set up interprocess signaling mechanisms
248  */
255  WalSndShmemInit();
256  WalRcvShmemInit();
258 
259  /*
260  * Set up other modules that need some shared memory space
261  */
262  SnapMgrInit();
263  BTreeShmemInit();
265  AsyncShmemInit();
266 
267 #ifdef EXEC_BACKEND
268 
269  /*
270  * Alloc the win32 shared backend array
271  */
272  if (!IsUnderPostmaster)
273  ShmemBackendArrayAllocation();
274 #endif
275 
276  /* Initialize dynamic shared memory facilities. */
277  if (!IsUnderPostmaster)
279 
280  /*
281  * Now give loadable modules a chance to set up their shmem allocations
282  */
283  if (shmem_startup_hook)
285 }
void dsm_postmaster_startup(PGShmemHeader *shim)
Definition: dsm.c:145
Size SInvalShmemSize(void)
Definition: sinvaladt.c:203
PGShmemHeader * PGSharedMemoryCreate(Size size, PGShmemHeader **shim)
Definition: sysv_shmem.c:623
void BTreeShmemInit(void)
Definition: nbtutils.c:1987
Size PMSignalShmemSize(void)
Definition: pmsignal.c:113
Size ReplicationSlotsShmemSize(void)
Definition: slot.c:114
#define SHMEM_INDEX_SIZE
Definition: shmem.h:55
void SUBTRANSShmemInit(void)
Definition: subtrans.c:191
#define DEBUG3
Definition: elog.h:23
Size SpinlockSemaSize(void)
Definition: spin.c:39
void InitShmemAccess(void *seghdr)
Definition: shmem.c:97
void AsyncShmemInit(void)
Definition: async.c:515
void CreateSharedInvalidationState(void)
Definition: sinvaladt.c:218
Size SyncScanShmemSize(void)
Definition: syncscan.c:126
Size WalSndShmemSize(void)
Definition: walsender.c:2989
void CheckpointerShmemInit(void)
Definition: checkpointer.c:898
Size PredicateLockShmemSize(void)
Definition: predicate.c:1288
Size TwoPhaseShmemSize(void)
Definition: twophase.c:236
void ReplicationOriginShmemInit(void)
Definition: origin.c:492
void WalRcvShmemInit(void)
#define PANIC
Definition: elog.h:53
void XLOGShmemInit(void)
Definition: xlog.c:4971
Size BackgroundWorkerShmemSize(void)
Definition: bgworker.c:143
void ReplicationSlotsShmemInit(void)
Definition: slot.c:132
Size LWLockShmemSize(void)
Definition: lwlock.c:349
Size BTreeShmemSize(void)
Definition: nbtutils.c:1974
void InitProcGlobal(void)
Definition: proc.c:163
void BackgroundWorkerShmemInit(void)
Definition: bgworker.c:159
void MultiXactShmemInit(void)
Definition: multixact.c:1822
void PMSignalShmemInit(void)
Definition: pmsignal.c:128
Size XLOGShmemSize(void)
Definition: xlog.c:4930
void SpinlockSemaInit(void)
Definition: spin.c:76
bool IsUnderPostmaster
Definition: globals.c:109
Size ApplyLauncherShmemSize(void)
Definition: launcher.c:760
void InitBufferPool(void)
Definition: buf_init.c:67
void SnapMgrInit(void)
Definition: snapmgr.c:269
void InitLocks(void)
Definition: lock.c:377
Size ProcGlobalShmemSize(void)
Definition: proc.c:102
static bool addin_request_allowed
Definition: ipci.c:55
Size ProcSignalShmemSize(void)
Definition: procsignal.c:73
shmem_startup_hook_type shmem_startup_hook
Definition: ipci.c:52
Size hash_estimate_size(long num_entries, Size entrysize)
Definition: dynahash.c:732
void TwoPhaseShmemInit(void)
Definition: twophase.c:252
int SpinlockSemas(void)
Definition: spin.c:65
static Size total_addin_request
Definition: ipci.c:54
Size BackendStatusShmemSize(void)
Definition: pgstat.c:2650
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
Size AutoVacuumShmemSize(void)
Definition: autovacuum.c:3292
Size ReplicationOriginShmemSize(void)
Definition: origin.c:472
Size CheckpointerShmemSize(void)
Definition: checkpointer.c:879
Size CLOGShmemSize(void)
Definition: clog.c:692
void CreateSharedBackendStatus(void)
Definition: pgstat.c:2678
void PGReserveSemaphores(int maxSemas)
Definition: posix_sema.c:196
Size WalRcvShmemSize(void)
void CreateLWLocks(void)
Definition: lwlock.c:381
void SyncScanShmemInit(void)
Definition: syncscan.c:135
void CreateSharedProcArray(void)
Definition: procarray.c:224
Size AsyncShmemSize(void)
Definition: async.c:498
size_t Size
Definition: c.h:467
Size CommitTsShmemSize(void)
Definition: commit_ts.c:479
void ApplyLauncherShmemInit(void)
Definition: launcher.c:808
Size MultiXactShmemSize(void)
Definition: multixact.c:1805
Size LockShmemSize(void)
Definition: lock.c:3441
Size SUBTRANSShmemSize(void)
Definition: subtrans.c:185
Size BufferShmemSize(void)
Definition: buf_init.c:160
#define elog(elevel,...)
Definition: elog.h:228
void WalSndShmemInit(void)
Definition: walsender.c:3001
void CLOGShmemInit(void)
Definition: clog.c:698
Size PGSemaphoreShmemSize(int maxSemas)
Definition: posix_sema.c:165
void ProcSignalShmemInit(void)
Definition: procsignal.c:83
void InitShmemIndex(void)
Definition: shmem.c:272
void InitPredicateLocks(void)
Definition: predicate.c:1083
void AutoVacuumShmemInit(void)
Definition: autovacuum.c:3311
Size SnapMgrShmemSize(void)
Definition: snapmgr.c:253
Size ProcArrayShmemSize(void)
Definition: procarray.c:182
int ProcGlobalSemas(void)
Definition: proc.c:128
void InitShmemAllocation(void)
Definition: shmem.c:112
void CommitTsShmemInit(void)
Definition: commit_ts.c:490

◆ on_exit_reset()

void on_exit_reset ( void  )

Definition at line 409 of file ipc.c.

References before_shmem_exit_index, on_proc_exit_index, on_shmem_exit_index, and reset_on_dsm_detach().

Referenced by InitPostmasterChild().

410 {
413  on_proc_exit_index = 0;
415 }
void reset_on_dsm_detach(void)
Definition: dsm.c:1013
static int on_shmem_exit_index
Definition: ipc.c:83
static int on_proc_exit_index
Definition: ipc.c:83
static int before_shmem_exit_index
Definition: ipc.c:83

◆ on_proc_exit()

void on_proc_exit ( pg_on_exit_callback  function,
Datum  arg 
)

Definition at line 305 of file ipc.c.

References ONEXIT::arg, atexit_callback(), atexit_callback_setup, ereport, errcode(), errmsg_internal(), FATAL, ONEXIT::function, MAX_ON_EXITS, on_proc_exit_index, and on_proc_exit_list.

Referenced by CreateLockFile(), InitCatCache(), InitFileAccess(), PostgresMain(), PostmasterMain(), pq_init(), select_perl_context(), sepgsql_avc_init(), and smgrinit().

306 {
308  ereport(FATAL,
309  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
310  errmsg_internal("out of on_proc_exit slots")));
311 
314 
316 
318  {
319  atexit(atexit_callback);
320  atexit_callback_setup = true;
321  }
322 }
static struct ONEXIT on_proc_exit_list[MAX_ON_EXITS]
Definition: ipc.c:79
#define MAX_ON_EXITS
Definition: ipc.c:71
int errcode(int sqlerrcode)
Definition: elog.c:608
pg_on_exit_callback function
Definition: ipc.c:75
static bool atexit_callback_setup
Definition: ipc.c:51
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:141
static int on_proc_exit_index
Definition: ipc.c:83
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
Datum arg
Definition: ipc.c:76
void * arg
static void atexit_callback(void)
Definition: ipc.c:290

◆ on_shmem_exit()

void on_shmem_exit ( pg_on_exit_callback  function,
Datum  arg 
)

Definition at line 361 of file ipc.c.

References ONEXIT::arg, atexit_callback(), atexit_callback_setup, ereport, errcode(), errmsg_internal(), FATAL, ONEXIT::function, MAX_ON_EXITS, on_shmem_exit_index, and on_shmem_exit_list.

Referenced by autoprewarm_main(), AutoVacWorkerMain(), CreateAuxProcessResourceOwner(), dsm_postmaster_startup(), InitAuxiliaryProcess(), InitBufferPoolBackend(), InitPostgres(), InitProcess(), InitProcessPhase2(), InitWalSenderSlot(), InternalIpcMemoryCreate(), ParallelWorkerMain(), PGReserveSemaphores(), PGSharedMemoryCreate(), pgss_shmem_startup(), pgstat_initialize(), ProcSignalInit(), replorigin_session_setup(), SharedInvalBackendInit(), and WalReceiverMain().

362 {
364  ereport(FATAL,
365  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
366  errmsg_internal("out of on_shmem_exit slots")));
367 
370 
372 
374  {
375  atexit(atexit_callback);
376  atexit_callback_setup = true;
377  }
378 }
#define MAX_ON_EXITS
Definition: ipc.c:71
int errcode(int sqlerrcode)
Definition: elog.c:608
static int on_shmem_exit_index
Definition: ipc.c:83
pg_on_exit_callback function
Definition: ipc.c:75
static bool atexit_callback_setup
Definition: ipc.c:51
#define FATAL
Definition: elog.h:52
#define ereport(elevel, rest)
Definition: elog.h:141
static struct ONEXIT on_shmem_exit_list[MAX_ON_EXITS]
Definition: ipc.c:80
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
Datum arg
Definition: ipc.c:76
void * arg
static void atexit_callback(void)
Definition: ipc.c:290

◆ proc_exit()

void proc_exit ( int  code)

Definition at line 104 of file ipc.c.

References DEBUG3, elog, IsAutoVacuumWorkerProcess(), mkdir, proc_exit_prepare(), S_IRWXG, S_IRWXO, S_IRWXU, and snprintf.

Referenced by ApplyWorkerMain(), auth_failed(), AutoVacLauncherMain(), AutoVacWorkerMain(), AuxiliaryProcessMain(), BackendInitialize(), BackgroundWriterMain(), BootstrapModeMain(), CheckerModeMain(), CheckpointerMain(), errfinish(), ExitPostmaster(), HandleStartupProcInterrupts(), initialize_worker_spi(), maybe_reread_subscription(), pg_attribute_noreturn(), PostgresMain(), PreRestoreCommand(), ProcessInterrupts(), ProcessRepliesIfAny(), ProcessStandbyMessage(), RestoreArchivedFile(), StartBackgroundWorker(), StartLogicalReplication(), StartReplication(), startup_die(), StartupPacketTimeoutHandler(), StartupProcessMain(), StartupProcShutdownHandler(), StartupXLOG(), SysLoggerMain(), test_shm_mq_main(), WaitEventSetWait(), WalRcvWaitForStartPosition(), WalReceiverMain(), WalSndDone(), WalSndErrorCleanup(), and WalWriterMain().

105 {
106  /* Clean up everything that must be cleaned up */
107  proc_exit_prepare(code);
108 
109 #ifdef PROFILE_PID_DIR
110  {
111  /*
112  * If we are profiling ourself then gprof's mcleanup() is about to
113  * write out a profile to ./gmon.out. Since mcleanup() always uses a
114  * fixed file name, each backend will overwrite earlier profiles. To
115  * fix that, we create a separate subdirectory for each backend
116  * (./gprof/pid) and 'cd' to that subdirectory before we exit() - that
117  * forces mcleanup() to write each profile into its own directory. We
118  * end up with something like: $PGDATA/gprof/8829/gmon.out
119  * $PGDATA/gprof/8845/gmon.out ...
120  *
121  * To avoid undesirable disk space bloat, autovacuum workers are
122  * discriminated against: all their gmon.out files go into the same
123  * subdirectory. Without this, an installation that is "just sitting
124  * there" nonetheless eats megabytes of disk space every few seconds.
125  *
126  * Note that we do this here instead of in an on_proc_exit() callback
127  * because we want to ensure that this code executes last - we don't
128  * want to interfere with any other on_proc_exit() callback. For the
129  * same reason, we do not include it in proc_exit_prepare ... so if
130  * you are exiting in the "wrong way" you won't drop your profile in a
131  * nice place.
132  */
133  char gprofDirName[32];
134 
136  snprintf(gprofDirName, 32, "gprof/avworker");
137  else
138  snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
139 
140  /*
141  * Use mkdir() instead of MakePGDirectory() since we aren't making a
142  * PG directory here.
143  */
144  mkdir("gprof", S_IRWXU | S_IRWXG | S_IRWXO);
145  mkdir(gprofDirName, S_IRWXU | S_IRWXG | S_IRWXO);
146  chdir(gprofDirName);
147  }
148 #endif
149 
150  elog(DEBUG3, "exit(%d)", code);
151 
152  exit(code);
153 }
#define DEBUG3
Definition: elog.h:23
static void proc_exit_prepare(int code)
Definition: ipc.c:161
#define S_IRWXG
Definition: win32_port.h:281
bool IsAutoVacuumWorkerProcess(void)
Definition: autovacuum.c:3281
#define S_IRWXU
Definition: win32_port.h:269
#define elog(elevel,...)
Definition: elog.h:228
#define mkdir(a, b)
Definition: win32_port.h:58
#define snprintf
Definition: port.h:192
#define S_IRWXO
Definition: win32_port.h:293

◆ shmem_exit()

void shmem_exit ( int  code)

Definition at line 224 of file ipc.c.

References ONEXIT::arg, before_shmem_exit_index, before_shmem_exit_list, DEBUG3, dsm_backend_shutdown(), elog, ONEXIT::function, on_shmem_exit_index, on_shmem_exit_list, and shmem_exit_inprogress.

Referenced by PostmasterStateMachine(), and proc_exit_prepare().

225 {
226  shmem_exit_inprogress = true;
227 
228  /*
229  * Call before_shmem_exit callbacks.
230  *
231  * These should be things that need most of the system to still be up and
232  * working, such as cleanup of temp relations, which requires catalog
233  * access; or things that need to be completed because later cleanup steps
234  * depend on them, such as releasing lwlocks.
235  */
236  elog(DEBUG3, "shmem_exit(%d): %d before_shmem_exit callbacks to make",
238  while (--before_shmem_exit_index >= 0)
242 
243  /*
244  * Call dynamic shared memory callbacks.
245  *
246  * These serve the same purpose as late callbacks, but for dynamic shared
247  * memory segments rather than the main shared memory segment.
248  * dsm_backend_shutdown() has the same kind of progressive logic we use
249  * for the main shared memory segment; namely, it unregisters each
250  * callback before invoking it, so that we don't get stuck in an infinite
251  * loop if one of those callbacks itself throws an ERROR or FATAL.
252  *
253  * Note that explicitly calling this function here is quite different from
254  * registering it as an on_shmem_exit callback for precisely this reason:
255  * if one dynamic shared memory callback errors out, the remaining
256  * callbacks will still be invoked. Thus, hard-coding this call puts it
257  * equal footing with callbacks for the main shared memory segment.
258  */
260 
261  /*
262  * Call on_shmem_exit callbacks.
263  *
264  * These are generally releasing low-level shared memory resources. In
265  * some cases, this is a backstop against the possibility that the early
266  * callbacks might themselves fail, leading to re-entry to this routine;
267  * in other cases, it's cleanup that only happens at process exit.
268  */
269  elog(DEBUG3, "shmem_exit(%d): %d on_shmem_exit callbacks to make",
270  code, on_shmem_exit_index);
271  while (--on_shmem_exit_index >= 0)
275 
276  shmem_exit_inprogress = false;
277 }
#define DEBUG3
Definition: elog.h:23
static int on_shmem_exit_index
Definition: ipc.c:83
pg_on_exit_callback function
Definition: ipc.c:75
void dsm_backend_shutdown(void)
Definition: dsm.c:618
static struct ONEXIT on_shmem_exit_list[MAX_ON_EXITS]
Definition: ipc.c:80
static int before_shmem_exit_index
Definition: ipc.c:83
bool shmem_exit_inprogress
Definition: ipc.c:45
#define elog(elevel,...)
Definition: elog.h:228
void * arg
static struct ONEXIT before_shmem_exit_list[MAX_ON_EXITS]
Definition: ipc.c:81

Variable Documentation

◆ proc_exit_inprogress

◆ shmem_exit_inprogress

PGDLLIMPORT bool shmem_exit_inprogress

Definition at line 45 of file ipc.c.

Referenced by AtAbort_Portals(), and shmem_exit().

◆ shmem_startup_hook

Definition at line 52 of file ipci.c.

Referenced by _PG_fini(), _PG_init(), and CreateSharedMemoryAndSemaphores().