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

Commitbf8ee6f

Browse files
committed
Fix unsafe references to errno within error messaging logic.
Various places were supposing that errno could be expected to hold stillwithin an ereport() nest or similar contexts. This isn't true necessarily,though in some cases it accidentally failed to fail depending on how thecompiler chanced to order the subexpressions. This class of thinkoexplains recent reports of odd failures on clang-built versions, typicallymissing or inappropriate HINT fields in messages.Problem identified by Christian Kruse, who also submitted the patch thiscommit is based on. (I fixed a few issues in his patch and found a coupleof additional places with the same disease.)Back-patch as appropriate to all supported branches.
1 parent56c08df commitbf8ee6f

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

‎src/backend/commands/tablespace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,14 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
770770
else
771771
{
772772
if (unlink(linkloc)<0)
773-
ereport(redo ?LOG : (errno==ENOENT ?WARNING :ERROR),
773+
{
774+
intsaved_errno=errno;
775+
776+
ereport(redo ?LOG : (saved_errno==ENOENT ?WARNING :ERROR),
774777
(errcode_for_file_access(),
775778
errmsg("could not remove symbolic link \"%s\": %m",
776779
linkloc)));
780+
}
777781
}
778782

779783
pfree(linkloc_with_version_dir);

‎src/backend/port/sysv_sema.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems)
9191

9292
if (semId<0)
9393
{
94+
intsaved_errno=errno;
95+
9496
/*
9597
* Fail quietly if error indicates a collision with existing set. One
9698
* would expect EEXIST, given that we said IPC_EXCL, but perhaps we
9799
* could get a permission violation instead? Also, EIDRM might occur
98100
* if an old set is slated for destruction but not gone yet.
99101
*/
100-
if (errno==EEXIST||errno==EACCES
102+
if (saved_errno==EEXIST||saved_errno==EACCES
101103
#ifdefEIDRM
102-
||errno==EIDRM
104+
||saved_errno==EIDRM
103105
#endif
104106
)
105107
return-1;
@@ -112,7 +114,7 @@ InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems)
112114
errdetail("Failed system call was semget(%lu, %d, 0%o).",
113115
(unsigned long)semKey,numSems,
114116
IPC_CREAT |IPC_EXCL |IPCProtection),
115-
(errno==ENOSPC) ?
117+
(saved_errno==ENOSPC) ?
116118
errhint("This error does *not* mean that you have run out of disk space. "
117119
"It occurs when either the system limit for the maximum number of "
118120
"semaphore sets (SEMMNI), or the system wide maximum number of "
@@ -136,13 +138,17 @@ IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum, int value)
136138

137139
semun.val=value;
138140
if (semctl(semId,semNum,SETVAL,semun)<0)
141+
{
142+
intsaved_errno=errno;
143+
139144
ereport(FATAL,
140145
(errmsg_internal("semctl(%d, %d, SETVAL, %d) failed: %m",
141146
semId,semNum,value),
142-
(errno==ERANGE) ?
147+
(saved_errno==ERANGE) ?
143148
errhint("You possibly need to raise your kernel's SEMVMX value to be at least "
144149
"%d. Look into the PostgreSQL documentation for details.",
145150
value) :0));
151+
}
146152
}
147153

148154
/*

‎src/backend/port/sysv_shmem.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
9696

9797
if (shmid<0)
9898
{
99+
intshmget_errno=errno;
100+
99101
/*
100102
* Fail quietly if error indicates a collision with existing segment.
101103
* One would expect EEXIST, given that we said IPC_EXCL, but perhaps
102104
* we could get a permission violation instead? Also, EIDRM might
103105
* occur if an old seg is slated for destruction but not gone yet.
104106
*/
105-
if (errno==EEXIST||errno==EACCES
107+
if (shmget_errno==EEXIST||shmget_errno==EACCES
106108
#ifdefEIDRM
107-
||errno==EIDRM
109+
||shmget_errno==EIDRM
108110
#endif
109111
)
110112
returnNULL;
@@ -118,10 +120,8 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
118120
* against SHMMIN in the preexisting-segment case, so we will not get
119121
* EINVAL a second time if there is such a segment.
120122
*/
121-
if (errno==EINVAL)
123+
if (shmget_errno==EINVAL)
122124
{
123-
intsave_errno=errno;
124-
125125
shmid=shmget(memKey,0,IPC_CREAT |IPC_EXCL |IPCProtection);
126126

127127
if (shmid<0)
@@ -147,8 +147,6 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
147147
elog(LOG,"shmctl(%d, %d, 0) failed: %m",
148148
(int)shmid,IPC_RMID);
149149
}
150-
151-
errno=save_errno;
152150
}
153151

154152
/*
@@ -160,25 +158,26 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, Size size)
160158
* it should be. SHMMNI violation is ENOSPC, per spec. Just plain
161159
* not-enough-RAM is ENOMEM.
162160
*/
161+
errno=shmget_errno;
163162
ereport(FATAL,
164163
(errmsg("could not create shared memory segment: %m"),
165164
errdetail("Failed system call was shmget(key=%lu, size=%lu, 0%o).",
166165
(unsigned long)memKey, (unsigned long)size,
167166
IPC_CREAT |IPC_EXCL |IPCProtection),
168-
(errno==EINVAL) ?
167+
(shmget_errno==EINVAL) ?
169168
errhint("This error usually means that PostgreSQL's request for a shared memory "
170169
"segment exceeded your kernel's SHMMAX parameter, or possibly that "
171170
"it is less than "
172171
"your kernel's SHMMIN parameter.\n"
173172
"The PostgreSQL documentation contains more information about shared "
174173
"memory configuration.") :0,
175-
(errno==ENOMEM) ?
174+
(shmget_errno==ENOMEM) ?
176175
errhint("This error usually means that PostgreSQL's request for a shared "
177176
"memory segment exceeded your kernel's SHMALL parameter. You might need "
178177
"to reconfigure the kernel with larger SHMALL.\n"
179178
"The PostgreSQL documentation contains more information about shared "
180179
"memory configuration.") :0,
181-
(errno==ENOSPC) ?
180+
(shmget_errno==ENOSPC) ?
182181
errhint("This error does *not* mean that you have run out of disk space. "
183182
"It occurs either if all available shared memory IDs have been taken, "
184183
"in which case you need to raise the SHMMNI parameter in your kernel, "
@@ -413,16 +412,20 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
413412
AnonymousShmem=mmap(NULL,size,PROT_READ |PROT_WRITE,PG_MMAP_FLAGS,
414413
-1,0);
415414
if (AnonymousShmem==MAP_FAILED)
415+
{
416+
intsaved_errno=errno;
417+
416418
ereport(FATAL,
417419
(errmsg("could not map anonymous shared memory: %m"),
418-
(errno==ENOMEM) ?
420+
(saved_errno==ENOMEM) ?
419421
errhint("This error usually means that PostgreSQL's request "
420422
"for a shared memory segment exceeded available memory "
421423
"or swap space. To reduce the request size (currently "
422424
"%lu bytes), reduce PostgreSQL's shared memory usage, "
423425
"perhaps by reducing shared_buffers or "
424426
"max_connections.",
425427
(unsigned long)size) :0));
428+
}
426429
AnonymousShmemSize=size;
427430

428431
/* Now we need only allocate a minimal-sized SysV shmem block. */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp