From 20b6672a6d7d5531ff1db1e5af762c052bf883bf Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 25 Mar 2023 13:13:44 -0700 Subject: Set close-on-exec when opening files Signed-off-by: Alan Coopersmith --- src/maprules.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/maprules.c b/src/maprules.c index 20470f9..bd83f71 100644 --- a/src/maprules.c +++ b/src/maprules.c @@ -51,6 +51,11 @@ #include "XKBfileInt.h" #include "XKBrules.h" +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#endif #ifdef DEBUG #define PR_DEBUG(s) fprintf(stderr,s) @@ -1040,10 +1045,10 @@ XkbRF_LoadRulesByName(char *base, char *locale, XkbRF_RulesPtr rules) strcpy(buf, base); } - file = fopen(buf, "r"); + file = fopen(buf, "r" FOPEN_CLOEXEC); if ((!file) && (locale)) { /* fallback if locale was specified */ strcpy(buf, base); - file = fopen(buf, "r"); + file = fopen(buf, "r" FOPEN_CLOEXEC); } if (!file) return False; @@ -1245,11 +1250,11 @@ XkbRF_LoadDescriptionsByName(char *base, char *locale, XkbRF_RulesPtr rules) snprintf(buf, sizeof(buf), "%s.lst", base); } - file = fopen(buf, "r"); + file = fopen(buf, "r" FOPEN_CLOEXEC); if ((!file) && (locale)) { /* fallback if locale was specified */ snprintf(buf, sizeof(buf), "%s.lst", base); - file = fopen(buf, "r"); + file = fopen(buf, "r" FOPEN_CLOEXEC); } if (!file) return False; -- cgit v1.2.1