summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2017-10-03 14:58:25 +0200
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2017-10-03 14:58:25 +0200
commitb24f15f86de48a5f1dd499c8af4d16c696b2c656 (patch)
tree2719db16fa0f28c0ad897abee14f1a9c672343ad
parentd149aa762c05ba904e77f8cf27da7ad821f5ecd0 (diff)
Fix coding rules violations in walreceiver.c
1. Since commit b1a9bad9e744 we had pstrdup() inside a spinlock-protected critical section; reported by Andreas Seltenreich. Turn those into strlcpy() to stack-allocated variables instead. Backpatch to 9.6. 2. Since commit 9ed551e0a4fd we had a pfree() uselessly inside a spinlock-protected critical section. Tom Lane noticed in code review. Move down. Backpatch to 9.6. 3. Since commit 64233902d22b we had GetCurrentTimestamp() (a kernel call) inside a spinlock-protected critical section. Tom Lane noticed in code review. Move it up. Backpatch to 9.2. 4. Since commit 1bb2558046cc we did elog(PANIC) while holding spinlock. Tom Lane noticed in code review. Release spinlock before dying. Backpatch to 9.2. Discussion: https://postgr.es/m/87h8vhtgj2.fsf@ansel.ydns.eu
-rw-r--r--src/backend/replication/walreceiver.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 0158ae06826..5f181d118da 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -195,6 +195,7 @@ WalReceiverMain(void)
/* use volatile pointer to prevent code rearrangement */
volatile WalRcvData *walrcv = WalRcv;
TimestampTz last_recv_timestamp;
+ TimestampTz now;
bool ping_sent;
/*
@@ -203,6 +204,8 @@ WalReceiverMain(void)
*/
Assert(walrcv != NULL);
+ now = GetCurrentTimestamp();
+
/*
* Mark walreceiver as running in shared memory.
*
@@ -233,6 +236,7 @@ WalReceiverMain(void)
case WALRCV_RESTARTING:
default:
/* Shouldn't happen */
+ SpinLockRelease(&walrcv->mutex);
elog(PANIC, "walreceiver still running according to shared memory state");
}
/* Advertise our PID so that the startup process can kill us */
@@ -245,7 +249,8 @@ WalReceiverMain(void)
startpointTLI = walrcv->receiveStartTLI;
/* Initialise to a sanish value */
- walrcv->lastMsgSendTime = walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = GetCurrentTimestamp();
+ walrcv->lastMsgSendTime =
+ walrcv->lastMsgReceiptTime = walrcv->latestWalEndTime = now;
SpinLockRelease(&walrcv->mutex);