diff --git a/Makefile b/Makefile index fccbeb80..a0abaec0 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ static: $(MAKE) git-vars bin/conmon PKG_CONFIG='$(PKG_CONFIG) --static' CFLAGS='-static' LDFLAGS='$(LDFLAGS) -s -w -static' LIBS='$(LIBS)' bin/conmon: $(OBJS) | bin - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -o $@ -c $< diff --git a/src/conn_sock.c b/src/conn_sock.c index 4ffa5783..3a09eba6 100644 --- a/src/conn_sock.c +++ b/src/conn_sock.c @@ -180,8 +180,7 @@ static gboolean read_conn_sock(struct conn_sock_s *sock) /* Not everything was written to stdin, let's wait for the fd to be ready. */ if (sock->remaining) - g_unix_fd_add(masterfd_stdin, G_IO_OUT, masterfd_write_cb, NULL); - + schedule_master_stdin_write(); return G_SOURCE_CONTINUE; } @@ -240,7 +239,7 @@ static void write_to_masterfd_stdin(gpointer data, gpointer user_data) static void sock_try_write_to_masterfd_stdin(struct conn_sock_s *sock) { - if (!sock->remaining) + if (!sock->remaining || masterfd_stdin < 0) return; ssize_t w = write(masterfd_stdin, sock->buf + sock->off, sock->remaining); @@ -264,3 +263,8 @@ static gboolean masterfd_write_cb(G_GNUC_UNUSED int fd, G_GNUC_UNUSED GIOConditi return G_SOURCE_CONTINUE; return G_SOURCE_REMOVE; } + +void schedule_master_stdin_write() +{ + g_unix_fd_add(masterfd_stdin, G_IO_OUT, masterfd_write_cb, NULL); +} diff --git a/src/conn_sock.h b/src/conn_sock.h index cf876e70..24286f78 100644 --- a/src/conn_sock.h +++ b/src/conn_sock.h @@ -18,5 +18,6 @@ struct conn_sock_s { char *setup_console_socket(void); char *setup_attach_socket(void); void conn_sock_shutdown(struct conn_sock_s *sock, int how); +void schedule_master_stdin_write(); #endif // CONN_SOCK_H diff --git a/src/ctrl.c b/src/ctrl.c index 48f0f0cd..5075d1a0 100644 --- a/src/ctrl.c +++ b/src/ctrl.c @@ -5,6 +5,7 @@ #include "globals.h" #include "config.h" #include "ctr_logging.h" +#include "conn_sock.h" #include "cmsg.h" #include "cli.h" // opt_bundle_path @@ -59,6 +60,10 @@ gboolean terminal_accept_cb(int fd, G_GNUC_UNUSED GIOCondition condition, G_GNUC masterfd_stdin = console.fd; masterfd_stdout = console.fd; + /* Now that we have a fd to the tty, make sure we handle any pending data + * that was already buffered. */ + schedule_master_stdin_write(); + /* now that we've set masterfd_stdout, we can register the ctrl_winsz_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 */