Skip to content

Commit

Permalink
set masterfd_stdout before regsitering ctrl_cb
Browse files Browse the repository at this point in the history
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 <pehunt@redhat.com>
  • Loading branch information
haircommander committed Sep 12, 2019
1 parent 4d36cb6 commit 9e1e1ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e1e1ff

Please sign in to comment.