From: Bruno Haible Date: Tue, 26 May 2020 16:00:04 +0000 (+0200) Subject: sethostname: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4055 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=939b0c71b4275d340514387c871e29cf8f20006f;p=gnulib.git sethostname: Make more robust in multithreaded applications. * lib/sethostname.c (sethostname): Pass an 'e' flag to fopen. * modules/sethostname (Depends-on): Add fopen-gnu. --- diff --git a/ChangeLog b/ChangeLog index 8f89928f4f..80bb80eaf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-05-27 Bruno Haible + + sethostname: Make more robust in multithreaded applications. + * lib/sethostname.c (sethostname): Pass an 'e' flag to fopen. + * modules/sethostname (Depends-on): Add fopen-gnu. + 2020-05-27 Bruno Haible readutmp: Make more robust in multithreaded applications. diff --git a/lib/sethostname.c b/lib/sethostname.c index 87b3af958b..1be69beabb 100644 --- a/lib/sethostname.c +++ b/lib/sethostname.c @@ -52,7 +52,7 @@ sethostname (const char *name, size_t len) these are appropriate for us to set, even if they may match the situation, during failed open/write/close operations, so we leave errno alone and rely on what the system sets up. */ - hostf = fopen ("/etc/hostname.file", "w"); + hostf = fopen ("/etc/hostname.file", "we"); if (hostf == NULL) r = -1; else diff --git a/modules/sethostname b/modules/sethostname index f3c0d134b5..92b4a2b98f 100644 --- a/modules/sethostname +++ b/modules/sethostname @@ -9,6 +9,7 @@ m4/gethostname.m4 Depends-on: unistd errno [test $HAVE_SETHOSTNAME = 0] +fopen-gnu [test $HAVE_SETHOSTNAME = 0] configure.ac: gl_FUNC_SETHOSTNAME