Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7de2dfc

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 lessrandom.
1 parent481cb5d commit7de2dfc

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
staticvolatilesig_atomic_tgot_SIGHUP= false;
7777
staticvolatilesig_atomic_tgot_SIGTERM= false;
7878

79-
staticvoidProcessWalRcvInterrupts(void);
80-
staticvoidEnableWalRcvImmediateExit(void);
81-
staticvoidDisableWalRcvImmediateExit(void);
79+
/*
80+
* LogstreamResult indicates the byte positions that we have already
81+
* written/fsynced.
82+
*/
83+
staticstruct
84+
{
85+
XLogRecPtrWrite;/* last byte + 1 written out in the standby */
86+
XLogRecPtrFlush;/* 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
staticvolatileboolWalRcvImmediateInterruptOK= false;
100106

107+
/* Prototypes for private functions */
108+
staticvoidProcessWalRcvInterrupts(void);
109+
staticvoidEnableWalRcvImmediateExit(void);
110+
staticvoidDisableWalRcvImmediateExit(void);
111+
staticvoidWalRcvDie(intcode,Datumarg);
112+
staticvoidXLogWalRcvProcessMsg(unsignedchartype,char*buf,Sizelen);
113+
staticvoidXLogWalRcvWrite(char*buf,Sizenbytes,XLogRecPtrrecptr);
114+
staticvoidXLogWalRcvFlush(void);
115+
116+
/* Signal handlers */
117+
staticvoidWalRcvSigHupHandler(SIGNAL_ARGS);
118+
staticvoidWalRcvShutdownHandler(SIGNAL_ARGS);
119+
staticvoidWalRcvQuickDieHandler(SIGNAL_ARGS);
120+
121+
101122
staticvoid
102123
ProcessWalRcvInterrupts(void)
103124
{
@@ -118,47 +139,25 @@ ProcessWalRcvInterrupts(void)
118139
}
119140

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

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

134-
/* Signal handlers */
135-
staticvoidWalRcvSigHupHandler(SIGNAL_ARGS);
136-
staticvoidWalRcvShutdownHandler(SIGNAL_ARGS);
137-
staticvoidWalRcvQuickDieHandler(SIGNAL_ARGS);
138-
139-
/* Prototypes for private functions */
140-
staticvoidWalRcvDie(intcode,Datumarg);
141-
staticvoidXLogWalRcvProcessMsg(unsignedchartype,char*buf,Sizelen);
142-
staticvoidXLogWalRcvWrite(char*buf,Sizenbytes,XLogRecPtrrecptr);
143-
staticvoidXLogWalRcvFlush(void);
144-
145-
/*
146-
* LogstreamResult indicates the byte positions that we have already
147-
* written/fsynced.
148-
*/
149-
staticstruct
150-
{
151-
XLogRecPtrWrite;/* last byte + 1 written out in the standby */
152-
XLogRecPtrFlush;/* last byte + 1 flushed in the standby */
153-
}LogstreamResult;
154-
155155
/* Main entry point for walreceiver process */
156156
void
157157
WalReceiverMain(void)
158158
{
159159
charconninfo[MAXCONNINFO];
160160
XLogRecPtrstartpoint;
161-
162161
/* use volatile pointer to prevent code rearrangement */
163162
volatileWalRcvData*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)

[8]ページ先頭

©2009-2025 Movatter.jp