Skip to content

Commit

Permalink
Merge pull request #71 from haircommander/stdout-wait-ctrl
Browse files Browse the repository at this point in the history
set masterfd_stdout before regsitering ctrl_cb
  • Loading branch information
vrothberg authored Sep 13, 2019
2 parents 4d36cb6 + 9e1e1ff commit 35437e4
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 35437e4

Please sign in to comment.