From 9e1e1ffc5488ee8ff53057a855f1bd5343895695 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Thu, 12 Sep 2019 15:59:20 -0400 Subject: [PATCH] set masterfd_stdout before regsitering ctrl_cb exec with conmon ran into issues because the manager attempted to resize the window before stdout was configured. Thus, we got the ctrl_cb from the caller, but had no where to send the ioctl. Fix this by registering the callback after we set stdout. Signed-off-by: Peter Hunt --- src/conmon.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/conmon.c b/src/conmon.c index a14a1ff1..ff5f7124 100644 --- a/src/conmon.c +++ b/src/conmon.c @@ -676,7 +676,7 @@ static void resize_winsz(int height, int width) ws.ws_col = width; ret = ioctl(masterfd_stdout, TIOCSWINSZ, &ws); if (ret == -1) { - nwarn("Failed to set process pty terminal size"); + pwarn("Failed to set process pty terminal size"); } } @@ -795,6 +795,11 @@ static gboolean terminal_accept_cb(int fd, G_GNUC_UNUSED GIOCondition condition, masterfd_stdin = console.fd; masterfd_stdout = console.fd; + /* now that we've set masterfd_stdout, we can register the ctrl_cb + * if we didn't set it here, we'd risk attempting to run ioctl on + * a negative fd, and fail to resize the window */ + g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); + /* Clean up everything */ close(connfd); @@ -988,7 +993,6 @@ static int setup_terminal_control_fifo() int dummyfd = open(ctl_fifo_path, O_WRONLY | O_CLOEXEC); if (dummyfd == -1) pexit("Failed to open dummy writer for fifo"); - g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); ninfof("terminal_ctrl_fd: %d", terminal_ctrl_fd); return dummyfd; @@ -1315,6 +1319,11 @@ int main(int argc, char *argv[]) masterfd_stdout = fds[0]; slavefd_stdout = fds[1]; + + /* now that we've set masterfd_stdout, we can register the ctrl_cb + * if we didn't set it here, we'd risk attempting to run ioctl on + * a negative fd, and fail to resize the window */ + g_unix_fd_add(terminal_ctrl_fd, G_IO_IN, ctrl_cb, NULL); } /* We always create a stderr pipe, because that way we can capture