Skip to content

Commit 2409210

Browse files
authored
Merge pull request #466 from giuseppe/use-CLOEXEC
src: open all files with O_CLOEXEC
2 parents cfb141f + f269c2f commit 2409210

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/cgroup.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ static int write_oom_files()
323323
ninfo("OOM received");
324324
if (opt_persist_path) {
325325
_cleanup_free_ char *ctr_oom_file_path = g_build_filename(opt_persist_path, "oom", NULL);
326-
_cleanup_close_ int ctr_oom_fd = open(ctr_oom_file_path, O_CREAT, 0666);
326+
_cleanup_close_ int ctr_oom_fd = open(ctr_oom_file_path, O_CREAT | O_CLOEXEC, 0666);
327327
if (ctr_oom_fd < 0) {
328328
nwarn("Failed to write oom file");
329329
}
330330
}
331-
_cleanup_close_ int oom_fd = open("oom", O_CREAT, 0666);
331+
_cleanup_close_ int oom_fd = open("oom", O_CREAT | O_CLOEXEC, 0666);
332332
if (oom_fd < 0) {
333333
nwarn("Failed to write oom file");
334334
}

src/conn_sock.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static char *setup_socket(int *fd, const char *path)
179179
if (dname == NULL)
180180
pexitf("Cannot get dirname for %s", csname);
181181

182-
sfd = open(dname, O_CREAT | O_PATH, 0600);
182+
sfd = open(dname, O_CREAT | O_PATH | O_CLOEXEC, 0600);
183183
if (sfd < 0)
184184
pexit("Failed to create file for console-socket");
185185

@@ -271,7 +271,7 @@ static char *bind_unix_socket(char *socket_relative_name, int sock_type, mode_t
271271
* the corresponding entry in `/proc/self/fd` to act as the path to base_path, then we use the socket_relative_name
272272
* to actually refer to the file where the socket will be created below.
273273
*/
274-
_cleanup_close_ int parent_dir_fd = open(parent_dir, O_PATH);
274+
_cleanup_close_ int parent_dir_fd = open(parent_dir, O_PATH | O_CLOEXEC);
275275
if (parent_dir_fd < 0)
276276
pexitf("failed to open socket path parent dir %s", parent_dir);
277277

src/oom.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define _GNU_SOURCE
2+
13
#include "oom.h"
24
#include "utils.h"
35

@@ -11,7 +13,7 @@ static void write_oom_adjust(int oom_score, int *old_value)
1113
{
1214
#ifdef __linux__
1315
char fmt_oom_score[16];
14-
int oom_score_fd = open("/proc/self/oom_score_adj", O_RDWR);
16+
int oom_score_fd = open("/proc/self/oom_score_adj", O_RDWR | O_CLOEXEC);
1517
if (oom_score_fd < 0) {
1618
ndebugf("failed to open /proc/self/oom_score_adj: %s\n", strerror(errno));
1719
return;

0 commit comments

Comments
 (0)