Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7de2dfc

Browse files
committed
Fix code that doesn't work on machines with strict alignment requirements:
must use memcpy here rather than struct assignment. In passing, rearrange some randomly-ordered declarations to be a tad less random.
1 parent 481cb5d commit 7de2dfc

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

src/backend/replication/walreceiver.c

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.9 2010/04/19 14:10:45 mha Exp $
32+
* $PostgreSQL: pgsql/src/backend/replication/walreceiver.c,v 1.10 2010/04/20 22:55:03 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -76,9 +76,15 @@ static uint32 recvOff = 0;
7676
static volatile sig_atomic_t got_SIGHUP = false;
7777
static volatile sig_atomic_t got_SIGTERM = false;
7878

79-
static void ProcessWalRcvInterrupts(void);
80-
static void EnableWalRcvImmediateExit(void);
81-
static void DisableWalRcvImmediateExit(void);
79+
/*
80+
* LogstreamResult indicates the byte positions that we have already
81+
* written/fsynced.
82+
*/
83+
static struct
84+
{
85+
XLogRecPtr Write; /* last byte + 1 written out in the standby */
86+
XLogRecPtr Flush; /* last byte + 1 flushed in the standby */
87+
} LogstreamResult;
8288

8389
/*
8490
* About SIGTERM handling:
@@ -98,6 +104,21 @@ static void DisableWalRcvImmediateExit(void);
98104
*/
99105
static volatile bool WalRcvImmediateInterruptOK = false;
100106

107+
/* Prototypes for private functions */
108+
static void ProcessWalRcvInterrupts(void);
109+
static void EnableWalRcvImmediateExit(void);
110+
static void DisableWalRcvImmediateExit(void);
111+
static void WalRcvDie(int code, Datum arg);
112+
static void XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len);
113+
static void XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr);
114+
static void XLogWalRcvFlush(void);
115+
116+
/* Signal handlers */
117+
static void WalRcvSigHupHandler(SIGNAL_ARGS);
118+
static void WalRcvShutdownHandler(SIGNAL_ARGS);
119+
static void WalRcvQuickDieHandler(SIGNAL_ARGS);
120+
121+
101122
static void
102123
ProcessWalRcvInterrupts(void)
103124
{
@@ -118,47 +139,25 @@ ProcessWalRcvInterrupts(void)
118139
}
119140

120141
static void
121-
EnableWalRcvImmediateExit()
142+
EnableWalRcvImmediateExit(void)
122143
{
123144
WalRcvImmediateInterruptOK = true;
124145
ProcessWalRcvInterrupts();
125146
}
126147

127148
static void
128-
DisableWalRcvImmediateExit()
149+
DisableWalRcvImmediateExit(void)
129150
{
130151
WalRcvImmediateInterruptOK = false;
131152
ProcessWalRcvInterrupts();
132153
}
133154

134-
/* Signal handlers */
135-
static void WalRcvSigHupHandler(SIGNAL_ARGS);
136-
static void WalRcvShutdownHandler(SIGNAL_ARGS);
137-
static void WalRcvQuickDieHandler(SIGNAL_ARGS);
138-
139-
/* Prototypes for private functions */
140-
static void WalRcvDie(int code, Datum arg);
141-
static void XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len);
142-
static void XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr);
143-
static void XLogWalRcvFlush(void);
144-
145-
/*
146-
* LogstreamResult indicates the byte positions that we have already
147-
* written/fsynced.
148-
*/
149-
static struct
150-
{
151-
XLogRecPtr Write; /* last byte + 1 written out in the standby */
152-
XLogRecPtr Flush; /* last byte + 1 flushed in the standby */
153-
} LogstreamResult;
154-
155155
/* Main entry point for walreceiver process */
156156
void
157157
WalReceiverMain(void)
158158
{
159159
char conninfo[MAXCONNINFO];
160160
XLogRecPtr startpoint;
161-
162161
/* use volatile pointer to prevent code rearrangement */
163162
volatile WalRcvData *walrcv = WalRcv;
164163

@@ -398,19 +397,21 @@ XLogWalRcvProcessMsg(unsigned char type, char *buf, Size len)
398397

399398
if (len < sizeof(XLogRecPtr))
400399
ereport(ERROR,
401-
(errmsg("invalid WAL message received from primary")));
400+
(errcode(ERRCODE_PROTOCOL_VIOLATION),
401+
errmsg_internal("invalid WAL message received from primary")));
402402

403-
recptr = *((XLogRecPtr *) buf);
403+
memcpy(&recptr, buf, sizeof(XLogRecPtr));
404404
buf += sizeof(XLogRecPtr);
405405
len -= sizeof(XLogRecPtr);
406+
406407
XLogWalRcvWrite(buf, len, recptr);
407408
break;
408409
}
409410
default:
410411
ereport(ERROR,
411412
(errcode(ERRCODE_PROTOCOL_VIOLATION),
412-
errmsg("invalid replication message type %d",
413-
type)));
413+
errmsg_internal("invalid replication message type %d",
414+
type)));
414415
}
415416
}
416417

0 commit comments

Comments
 (0)