]> Savannah Git Hosting - gnulib.git/commitdiff
sethostname: Make more robust in multithreaded applications.
authorBruno Haible <bruno@clisp.org>
Tue, 26 May 2020 16:00:04 +0000 (18:00 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 27 May 2020 17:30:46 +0000 (19:30 +0200)
* lib/sethostname.c (sethostname): Pass an 'e' flag to fopen.
* modules/sethostname (Depends-on): Add fopen-gnu.

ChangeLog
lib/sethostname.c
modules/sethostname

index 8f89928f4f19ce48f43a45aed6a62bf5648d5a10..80bb80eaf2c235a69c12fc5c4b22c321d0677062 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-27  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        readutmp: Make more robust in multithreaded applications.
index 87b3af958b88425d742f4d6bccd64fa03679af47..1be69beabbcb56a2f194db3f257f3c5580f0402f 100644 (file)
@@ -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
index f3c0d134b519c9244260247cb047c0ff48dbf642..92b4a2b98fbf1394dc7bbffb65d900c14be45197 100644 (file)
@@ -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