- Notifications
You must be signed in to change notification settings - Fork28
Commit3e51725
committed
Avoid depending on non-POSIX behavior of fcntl(2).
The POSIX standard does not say that the success return value forfcntl(F_SETFD) and fcntl(F_SETFL) is zero; it says only that it's not -1.We had several calls that were making the stronger assumption. Adjustthem to test specifically for -1 for strict spec compliance.The standard further leaves open the possibility that the O_NONBLOCKflag bit is not the only active one in F_SETFL's argument. Formally,therefore, one ought to get the current flags with F_GETFL and storethem back with only the O_NONBLOCK bit changed when trying to changethe nonblock state. In port/noblock.c, we were doing the full pushupin pg_set_block but not in pg_set_noblock, which is just weird. Makeboth of them do it properly, since they have little business makingany assumptions about the socket they're handed. The other placeswhere we're issuing F_SETFL are working with FDs we just got frompipe(2), so it's reasonable to assume the FDs' properties are alldefault, so I didn't bother adding F_GETFL steps there.Also, while pg_set_block deserves some points for trying to do thingsright, somebody had decided that it'd be even better to cast fcntl'sthird argument to "long". Which is completely loony, because POSIXclearly says the third argument for an F_SETFL call is "int".Given the lack of field complaints, these missteps apparently are notof significance on any common platforms. But they're still wrong,so back-patch to all supported branches.Discussion:https://postgr.es/m/30882.1492800880@sss.pgh.pa.us1 parent68e61ee commit3e51725
File tree
4 files changed
+25
-8
lines changed- src
- backend
- postmaster
- storage/ipc
- bin/pg_test_fsync
- port
4 files changed
+25
-8
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6263 | 6263 |
| |
6264 | 6264 |
| |
6265 | 6265 |
| |
6266 |
| - | |
| 6266 | + | |
6267 | 6267 |
| |
6268 | 6268 |
| |
6269 | 6269 |
| |
| |||
6272 | 6272 |
| |
6273 | 6273 |
| |
6274 | 6274 |
| |
6275 |
| - | |
| 6275 | + | |
6276 | 6276 |
| |
6277 | 6277 |
| |
6278 | 6278 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
169 | 169 |
| |
170 | 170 |
| |
171 | 171 |
| |
172 |
| - | |
| 172 | + | |
173 | 173 |
| |
174 |
| - | |
| 174 | + | |
175 | 175 |
| |
176 | 176 |
| |
177 | 177 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
| 10 | + | |
10 | 11 |
| |
11 | 12 |
| |
12 | 13 |
| |
|
Lines changed: 20 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
4 |
| - | |
| 4 | + | |
5 | 5 |
| |
6 | 6 |
| |
7 | 7 |
| |
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 |
| |
21 | 25 |
| |
22 | 26 |
| |
23 | 27 |
| |
24 |
| - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
25 | 36 |
| |
26 | 37 |
| |
27 | 38 |
| |
| |||
30 | 41 |
| |
31 | 42 |
| |
32 | 43 |
| |
33 |
| - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
34 | 48 |
| |
35 | 49 |
| |
36 | 50 |
| |
37 | 51 |
| |
38 | 52 |
| |
39 | 53 |
| |
40 | 54 |
| |
41 |
| - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
42 | 58 |
| |
43 | 59 |
| |
44 | 60 |
| |
|
0 commit comments
Comments
(0)