mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 07:26:15 +01:00
Use "e" mode flag in fopen () calls for race-free setting of the close-on-exec flag
All Unix CRTs examined: glibc, musl, BSDs, Apple libc, Android bionic ignore unknown fopen () mode flags, so this flag can be added unconditionally for Unix builds. Only Windows CRT is intolerant of these, so the single case in g_dbus_address_connect () where the fopen () call is shared between Unix and Windows needs appropriate platform-specific handling. Skipped the call sites in libcharset and xdgmime copylibs.
This commit is contained in:
parent
3f2e18b07c
commit
0e7bf99ec2
@ -53,6 +53,12 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#define FO_CLOEXEC ""
|
||||
#else
|
||||
#define FO_CLOEXEC "e"
|
||||
#endif
|
||||
|
||||
#include "glibintl.h"
|
||||
|
||||
/**
|
||||
@ -711,7 +717,7 @@ g_dbus_address_connect (const gchar *address_entry,
|
||||
int errsv;
|
||||
|
||||
/* be careful to read only 16 bytes - we also check that the file is only 16 bytes long */
|
||||
f = fopen (nonce_file, "rb");
|
||||
f = fopen (nonce_file, "rb" FO_CLOEXEC);
|
||||
errsv = errno;
|
||||
if (f == NULL)
|
||||
{
|
||||
|
@ -3166,7 +3166,7 @@ _resolve_dev_root (void)
|
||||
/* see if device with similar major:minor as /dev/root is mention
|
||||
* in /etc/mtab (it usually is)
|
||||
*/
|
||||
f = fopen ("/etc/mtab", "r");
|
||||
f = fopen ("/etc/mtab", "re");
|
||||
if (f != NULL)
|
||||
{
|
||||
struct mntent *entp;
|
||||
|
@ -446,7 +446,7 @@ read_aliases (const gchar *file,
|
||||
FILE *fp;
|
||||
char buf[256];
|
||||
|
||||
fp = fopen (file,"r");
|
||||
fp = fopen (file, "re");
|
||||
if (!fp)
|
||||
return;
|
||||
while (fgets (buf, 256, fp))
|
||||
|
Loading…
Reference in New Issue
Block a user