mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Ensure BackgroundWorker struct contents are well-defined.
Coverity complained because bgw.bgw_extra wasn't being filled in by ApplyLauncherRegister(). The most future-proof fix is to memset the whole BackgroundWorker struct to zeroes. While at it, let's apply the same coding rule to other places that set up BackgroundWorker structs; four out of five had the same or related issues.
This commit is contained in:
@ -435,6 +435,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
|
|||||||
oldcontext = MemoryContextSwitchTo(TopTransactionContext);
|
oldcontext = MemoryContextSwitchTo(TopTransactionContext);
|
||||||
|
|
||||||
/* Configure a worker. */
|
/* Configure a worker. */
|
||||||
|
memset(&worker, 0, sizeof(worker));
|
||||||
snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
|
snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
|
||||||
MyProcPid);
|
MyProcPid);
|
||||||
worker.bgw_flags =
|
worker.bgw_flags =
|
||||||
@ -446,7 +447,6 @@ LaunchParallelWorkers(ParallelContext *pcxt)
|
|||||||
sprintf(worker.bgw_function_name, "ParallelWorkerMain");
|
sprintf(worker.bgw_function_name, "ParallelWorkerMain");
|
||||||
worker.bgw_main_arg = UInt32GetDatum(dsm_segment_handle(pcxt->seg));
|
worker.bgw_main_arg = UInt32GetDatum(dsm_segment_handle(pcxt->seg));
|
||||||
worker.bgw_notify_pid = MyProcPid;
|
worker.bgw_notify_pid = MyProcPid;
|
||||||
memset(&worker.bgw_extra, 0, BGW_EXTRALEN);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start workers.
|
* Start workers.
|
||||||
|
@ -291,6 +291,7 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
|
|||||||
LWLockRelease(LogicalRepWorkerLock);
|
LWLockRelease(LogicalRepWorkerLock);
|
||||||
|
|
||||||
/* Register the new dynamic worker. */
|
/* Register the new dynamic worker. */
|
||||||
|
memset(&bgw, 0, sizeof(bgw));
|
||||||
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
||||||
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
||||||
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
||||||
@ -560,6 +561,10 @@ ApplyLauncherShmemSize(void)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ApplyLauncherRegister
|
||||||
|
* Register a background worker running the logical replication launcher.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
ApplyLauncherRegister(void)
|
ApplyLauncherRegister(void)
|
||||||
{
|
{
|
||||||
@ -568,6 +573,7 @@ ApplyLauncherRegister(void)
|
|||||||
if (max_logical_replication_workers == 0)
|
if (max_logical_replication_workers == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
memset(&bgw, 0, sizeof(bgw));
|
||||||
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
bgw.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
||||||
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
||||||
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
||||||
|
@ -213,6 +213,7 @@ setup_background_workers(int nworkers, dsm_segment *seg)
|
|||||||
PointerGetDatum(wstate));
|
PointerGetDatum(wstate));
|
||||||
|
|
||||||
/* Configure a worker. */
|
/* Configure a worker. */
|
||||||
|
memset(&worker, 0, sizeof(worker));
|
||||||
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
|
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
|
||||||
worker.bgw_start_time = BgWorkerStart_ConsistentState;
|
worker.bgw_start_time = BgWorkerStart_ConsistentState;
|
||||||
worker.bgw_restart_time = BGW_NEVER_RESTART;
|
worker.bgw_restart_time = BGW_NEVER_RESTART;
|
||||||
|
@ -343,6 +343,7 @@ _PG_init(void)
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* set up common data for all our workers */
|
/* set up common data for all our workers */
|
||||||
|
memset(&worker, 0, sizeof(worker));
|
||||||
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
||||||
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
||||||
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
||||||
@ -375,6 +376,7 @@ worker_spi_launch(PG_FUNCTION_ARGS)
|
|||||||
BgwHandleStatus status;
|
BgwHandleStatus status;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
memset(&worker, 0, sizeof(worker));
|
||||||
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
|
||||||
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
BGWORKER_BACKEND_DATABASE_CONNECTION;
|
||||||
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
|
||||||
|
Reference in New Issue
Block a user