mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-04-09 08:21:23 -04:00
cage: set CLOEXEC on the file descriptors
As mentioned by @emersion: By default, pipe creates FDs without the CLOEXEC flag set, which means they will be leaked to any other child process spawned. Would be nice to set the CLOEXEC flag to prevent the leak.
This commit is contained in:
parent
96218dc95f
commit
7f919a5198
1 changed files with 24 additions and 0 deletions
24
cage.c
24
cage.c
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -67,6 +68,25 @@ sigchld_handler(int fd, uint32_t mask, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
set_cloexec(int fd)
|
||||||
|
{
|
||||||
|
int flags = fcntl(fd, F_GETFD);
|
||||||
|
|
||||||
|
if (flags == -1) {
|
||||||
|
wlr_log(WLR_ERROR, "Unable to set the CLOEXEC flag: fnctl failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = flags | FD_CLOEXEC;
|
||||||
|
if (fcntl(fd, F_SETFD, flags) == -1) {
|
||||||
|
wlr_log(WLR_ERROR, "Unable to set the CLOEXEC flag: fnctl failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
spawn_primary_client(struct wl_display *display, char *argv[], pid_t *pid_out, struct wl_event_source **sigchld_source)
|
spawn_primary_client(struct wl_display *display, char *argv[], pid_t *pid_out, struct wl_event_source **sigchld_source)
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +110,10 @@ spawn_primary_client(struct wl_display *display, char *argv[], pid_t *pid_out, s
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!set_cloexec(fd[0]) || !set_cloexec(fd[1])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Close write, we only need read in Cage. */
|
/* Close write, we only need read in Cage. */
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue