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

Commitc95ede4

Browse files
committed
In count_usable_fds(), duplicate stderr not stdin.
We had a complaint that the postmaster fails to start if the invokingprogram closes stdin. That happens because count_usable_fds expectsto be able to dup(0), and if it can't, we conclude there are no freeFDs and go belly-up. So far as I can find, though, there is no otherplace in the server that touches stdin, and it's not unreasonable toexpect that a daemon wouldn't use that file.As a simple improvement, let's dup FD 2 (stderr) instead. Unlike stdin,it *is* reasonable for us to expect that stderr be open; even if we areconfigured not to touch it, common libraries such as libc might try towrite error messages there.Per gripe from Mario Emmenlauer. Given the lack of previous complaints,I'm not excited about pushing this into stable branches, but it seemsOK to squeeze it into v14.Discussion:https://postgr.es/m/48bafc63-c30f-3962-2ded-f2e985d93e86@emmenlauer.de
1 parentce773f2 commitc95ede4

File tree

1 file changed

+5
-3
lines changed
  • src/backend/storage/file

1 file changed

+5
-3
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,9 @@ InitTemporaryFileAccess(void)
934934
* of already_open will give the right answer. In practice, max_to_probe
935935
* of a couple of dozen should be enough to ensure good results.
936936
*
937-
* We assume stdin (FD 0) is available for dup'ing
937+
* We assume stderr (FD 2) is available for dup'ing. While the calling
938+
* script could theoretically close that, it would be a really bad idea,
939+
* since then one risks loss of error messages from, e.g., libc.
938940
*/
939941
staticvoid
940942
count_usable_fds(intmax_to_probe,int*usable_fds,int*already_open)
@@ -978,12 +980,12 @@ count_usable_fds(int max_to_probe, int *usable_fds, int *already_open)
978980
break;
979981
#endif
980982

981-
thisfd=dup(0);
983+
thisfd=dup(2);
982984
if (thisfd<0)
983985
{
984986
/* Expect EMFILE or ENFILE, else it's fishy */
985987
if (errno!=EMFILE&&errno!=ENFILE)
986-
elog(WARNING,"dup(0) failed after %d successes: %m",used);
988+
elog(WARNING,"duplicating stderr file descriptor failed after %d successes: %m",used);
987989
break;
988990
}
989991

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp