From f93fc2736c86b616e26040a6962b09b9e9fdd5d1 Mon Sep 17 00:00:00 2001 From: Rafal Mielniczuk Date: Sat, 19 Oct 2013 15:19:19 +0200 Subject: [PATCH] weston-launch: close input fds in deactivate request If we don't do that, open fds get accumulated in weston-launch process, which leads to hang, when the system limit of open fds is exceeded --- src/weston-launch.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/weston-launch.c b/src/weston-launch.c index e5301c7..697a511 100644 --- a/src/weston-launch.c +++ b/src/weston-launch.c @@ -81,6 +81,9 @@ struct weston_launch { pid_t child; int verbose; char *new_user; + + int input_fds[256]; + int input_fds_count; }; union cmsg_data { unsigned char b[4]; int fd; }; @@ -304,6 +307,10 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len) goto err0; } + if (major(s.st_rdev) == INPUT_MAJOR) { + wl->input_fds[wl->input_fds_count++] = fd; + } + err0: memset(&nmsg, 0, sizeof nmsg); nmsg.msg_iov = &iov; @@ -406,6 +413,16 @@ quit(struct weston_launch *wl, int status) exit(status); } +static void +close_input_fds(struct weston_launch *wl) +{ + int i; + for (i = 0; i < wl->input_fds_count; ++i) { + close(wl->input_fds[i]); + } + wl->input_fds_count = 0; +} + static int handle_signal(struct weston_launch *wl) { @@ -444,6 +461,7 @@ handle_signal(struct weston_launch *wl) break; case SIGUSR1: send_reply(wl, WESTON_LAUNCHER_DEACTIVATE); + close_input_fds(wl); drmDropMaster(wl->drm_fd); ioctl(wl->tty, VT_RELDISP, 1); break; @@ -685,6 +703,8 @@ main(int argc, char *argv[]) if (setup_signals(&wl) < 0) exit(EXIT_FAILURE); + wl.input_fds_count = 0; + wl.child = fork(); if (wl.child == -1) { error(1, errno, "fork failed"); -- 1.8.4.1