From 2f2c8205d841a98649e9697ad5ba8cfe430ffaa7 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 9 Jul 2017 22:12:50 +1200 Subject: Moved IPC to its own file. --- include/session/direct-ipc.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 include/session/direct-ipc.h (limited to 'include/session/direct-ipc.h') diff --git a/include/session/direct-ipc.h b/include/session/direct-ipc.h new file mode 100644 index 00000000..a8d9469d --- /dev/null +++ b/include/session/direct-ipc.h @@ -0,0 +1,12 @@ +#ifndef SESSION_DIRECT_IPC +#define SESSION_DIRECT_IPC + +#include + +int direct_ipc_open(int sock, const char *path); +void direct_ipc_setmaster(int sock); +void direct_ipc_dropmaster(int sock); +void direct_ipc_finish(int sock, pid_t pid); +int direct_ipc_start(pid_t *pid_out); + +#endif -- cgit v1.2.3 From 3779ef802ddf89067e1588077ed8c72b4674565a Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 9 Jul 2017 22:23:54 +1200 Subject: Stop remembering the drm fd in child. --- include/session/direct-ipc.h | 4 ++-- session/direct-ipc.c | 26 ++++++++++---------------- session/direct.c | 6 +++--- 3 files changed, 15 insertions(+), 21 deletions(-) (limited to 'include/session/direct-ipc.h') diff --git a/include/session/direct-ipc.h b/include/session/direct-ipc.h index a8d9469d..96504f04 100644 --- a/include/session/direct-ipc.h +++ b/include/session/direct-ipc.h @@ -4,8 +4,8 @@ #include int direct_ipc_open(int sock, const char *path); -void direct_ipc_setmaster(int sock); -void direct_ipc_dropmaster(int sock); +void direct_ipc_setmaster(int sock, int fd); +void direct_ipc_dropmaster(int sock, int fd); void direct_ipc_finish(int sock, pid_t pid); int direct_ipc_start(pid_t *pid_out); diff --git a/session/direct-ipc.c b/session/direct-ipc.c index ef8de68c..fbbde02a 100644 --- a/session/direct-ipc.c +++ b/session/direct-ipc.c @@ -116,7 +116,7 @@ static void communicate(int sock) { int drm_fd = -1; bool running = true; - while (running && recv_msg(sock, NULL, &msg, sizeof(msg)) >= 0) { + while (running && recv_msg(sock, &drm_fd, &msg, sizeof(msg)) >= 0) { switch (msg.type) { case MSG_OPEN: errno = 0; @@ -140,29 +140,24 @@ static void communicate(int sock) { goto error; } - if (maj == DRM_MAJOR) { - if (drmSetMaster(fd)) { - ret = errno; - } else { - drm_fd = fd; - } + if (maj == DRM_MAJOR && drmSetMaster(fd)) { + ret = errno; } error: send_msg(sock, ret ? -1 : fd, &ret, sizeof(ret)); - - if (fd != drm_fd) { - close(fd); - } + close(fd); break; case MSG_SETMASTER: drmSetMaster(drm_fd); + close(drm_fd); send_msg(sock, -1, NULL, 0); break; case MSG_DROPMASTER: drmDropMaster(drm_fd); + close(drm_fd); send_msg(sock, -1, NULL, 0); break; @@ -173,7 +168,6 @@ error: } } - close(drm_fd); close(sock); } @@ -189,17 +183,17 @@ int direct_ipc_open(int sock, const char *path) { return err ? -err : fd; } -void direct_ipc_setmaster(int sock) { +void direct_ipc_setmaster(int sock, int fd) { struct msg msg = { .type = MSG_SETMASTER }; - send_msg(sock, -1, &msg, sizeof(msg)); + send_msg(sock, fd, &msg, sizeof(msg)); recv_msg(sock, NULL, NULL, 0); } -void direct_ipc_dropmaster(int sock) { +void direct_ipc_dropmaster(int sock, int fd) { struct msg msg = { .type = MSG_DROPMASTER }; - send_msg(sock, -1, &msg, sizeof(msg)); + send_msg(sock, fd, &msg, sizeof(msg)); recv_msg(sock, NULL, NULL, 0); } diff --git a/session/direct.c b/session/direct.c index 23ce1ee1..1247663b 100644 --- a/session/direct.c +++ b/session/direct.c @@ -65,7 +65,7 @@ static void direct_session_close(struct wlr_session *base, int fd) { } if (major(st.st_rdev) == DRM_MAJOR) { - direct_ipc_dropmaster(session->sock); + direct_ipc_dropmaster(session->sock, session->base.drm_fd); session->base.drm_fd = -1; } else if (major(st.st_rdev) == INPUT_MAJOR) { ioctl(fd, EVIOCREVOKE, 0); @@ -109,11 +109,11 @@ static int vt_handler(int signo, void *data) { if (session->base.active) { session->base.active = false; wl_signal_emit(&session->base.session_signal, session); - direct_ipc_dropmaster(session->sock); + direct_ipc_dropmaster(session->sock, session->base.drm_fd); ioctl(session->tty_fd, VT_RELDISP, 1); } else { ioctl(session->tty_fd, VT_RELDISP, VT_ACKACQ); - direct_ipc_setmaster(session->sock); + direct_ipc_setmaster(session->sock, session->base.drm_fd); session->base.active = true; wl_signal_emit(&session->base.session_signal, session); } -- cgit v1.2.3