Use O_CLOEXEC in {g_,}open () calls for race-free setting of the close-on-exec flag

The remaining call sites are either Windows-only, between fork () and
exec () or in xdgmime copylib.

Hope I haven't missed any site.
This commit is contained in:
Maciej S. Szmigiero
2023-02-19 16:22:22 +01:00
committed by Philip Withnall
parent 0f5d274871
commit 3f2e18b07c
10 changed files with 56 additions and 24 deletions

View File

@@ -32,6 +32,10 @@
#include <fcntl.h>
#include <string.h>
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
#include <glib-object.h>
#include <glib/gfileutils.h>
#include <gio/gfilemonitor.h>
@@ -583,7 +587,7 @@ _kqsub_start_watching (kqueue_sub *sub)
struct stat st;
struct kevent ev;
sub->fd = open (sub->filename, O_KQFLAG);
sub->fd = open (sub->filename, O_KQFLAG | O_CLOEXEC);
if (sub->fd == -1)
return FALSE;