>From acdcd9f872f5338f901a9019627953dcb5e8d95f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 26 May 2020 18:00:04 +0200 Subject: [PATCH 6/8] sethostname: Make more robust in multithreaded applications. * lib/sethostname.c (sethostname): Pass an 'e' flag to fopen. * modules/sethostname (Depends-on): Add fopen-gnu. --- ChangeLog | 6 ++++++ lib/sethostname.c | 2 +- modules/sethostname | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 893d080..162b861 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-05-26 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-26 Bruno Haible + readutmp: Make more robust in multithreaded applications. * lib/readutmp.c (read_utmp): Pass an 'e' flag to fopen. * modules/readutmp (Depends-on): Add fopen-gnu. diff --git a/lib/sethostname.c b/lib/sethostname.c index 87b3af9..1be69be 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 f3c0d13..92b4a2b 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 -- 2.7.4