From: Bruno Haible Date: Tue, 26 May 2020 16:04:26 +0000 (+0200) Subject: mountlist: Make more robust in multithreaded applications. X-Git-Tag: v1.0~4054 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=abcd52e440c085a9fa99ec4c706780dd2e196468;p=gnulib.git mountlist: Make more robust in multithreaded applications. * lib/mountlist.c (setmntent, read_file_system_list): Pass an 'e' flag to fopen. * modules/mountlist (Depends-on): Add fopen-gnu. --- diff --git a/ChangeLog b/ChangeLog index 80bb80eaf2..be5b2a19a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-05-27 Bruno Haible + + mountlist: Make more robust in multithreaded applications. + * lib/mountlist.c (setmntent, read_file_system_list): Pass an 'e' flag + to fopen. + * modules/mountlist (Depends-on): Add fopen-gnu. + 2020-05-27 Bruno Haible sethostname: Make more robust in multithreaded applications. diff --git a/lib/mountlist.c b/lib/mountlist.c index 7abe0248ec..4cb19c87f1 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -125,7 +125,7 @@ #ifdef MOUNTED_GETMNTENT1 # if !HAVE_SETMNTENT /* Android <= 4.4 */ -# define setmntent(fp,mode) fopen (fp, mode) +# define setmntent(fp,mode) fopen (fp, mode "e") # endif # if !HAVE_ENDMNTENT /* Android <= 4.4 */ # define endmntent(fp) fclose (fp) @@ -460,7 +460,7 @@ read_file_system_list (bool need_fs_type) (and that code is in previous versions of this function), however libmount depends on libselinux which pulls in many dependencies. */ char const *mountinfo = "/proc/self/mountinfo"; - fp = fopen (mountinfo, "r"); + fp = fopen (mountinfo, "re"); if (fp != NULL) { char *line = NULL; @@ -794,7 +794,7 @@ read_file_system_list (bool need_fs_type) char *table = "/etc/mnttab"; FILE *fp; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) return NULL; @@ -852,7 +852,7 @@ read_file_system_list (bool need_fs_type) by the kernel. */ errno = 0; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) ret = errno; else @@ -924,7 +924,7 @@ read_file_system_list (bool need_fs_type) # endif errno = 0; - fp = fopen (table, "r"); + fp = fopen (table, "re"); if (fp == NULL) ret = errno; else diff --git a/modules/mountlist b/modules/mountlist index 11cf809ab2..5bb45edf64 100644 --- a/modules/mountlist +++ b/modules/mountlist @@ -8,6 +8,7 @@ m4/fstypename.m4 m4/mountlist.m4 Depends-on: +fopen-gnu getline stdbool stdint