mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
conmux: Handle EOF from conmux
If conmux goes away, e.g. by someone invoking ~$quit, the read() from the conmux fd will continously return 0, which is not discarded as an error, but sent as a console output message to the client, continuously. Quit bad when this happens, instead. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
9
bad.c
9
bad.c
@@ -228,6 +228,13 @@ void watch_add_readfd(int fd, int (*cb)(int, void*), void *data)
|
||||
list_add(&read_watches, &w->node);
|
||||
}
|
||||
|
||||
static bool quit_invoked;
|
||||
|
||||
void watch_quit(void)
|
||||
{
|
||||
quit_invoked = true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct watch *w;
|
||||
@@ -243,7 +250,7 @@ int main(int argc, char **argv)
|
||||
flags = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
for (;;) {
|
||||
while (!quit_invoked) {
|
||||
nfds = 0;
|
||||
|
||||
list_for_each_entry(w, &read_watches, node) {
|
||||
|
||||
13
conmux.c
13
conmux.c
@@ -215,10 +215,15 @@ static int conmux_data(int fd, void *data)
|
||||
if (n < 0)
|
||||
return n;
|
||||
|
||||
hdr.type = MSG_CONSOLE;
|
||||
hdr.len = n;
|
||||
write(STDOUT_FILENO, &hdr, sizeof(hdr));
|
||||
write(STDOUT_FILENO, buf, n);
|
||||
if (!n) {
|
||||
fprintf(stderr, "Received EOF from conmux\n");
|
||||
watch_quit();
|
||||
} else {
|
||||
hdr.type = MSG_CONSOLE;
|
||||
hdr.len = n;
|
||||
write(STDOUT_FILENO, &hdr, sizeof(hdr));
|
||||
write(STDOUT_FILENO, buf, n);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user