From 0bf882489848c7f19eb602e286d760c709685251 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 19 Apr 2014 21:02:47 +0300 Subject: [PATCH] Use select when reading mount command output If pmount ends up using FUSE to do the actual mounting, the filesystem driver process inherits the output capture pipe. In this case the write end of the pipe stays open and read can block indefinitely. Instead of relying on read to return eof, call waitpid if select indicates no data available. --- main.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 609db22..916c2e2 100644 --- a/main.c +++ b/main.c @@ -566,22 +566,32 @@ void row_activated(GtkTreeView *list, GtkTreePath *path, GtkTreeViewColumn *colu char buf[1024]; int pos = 0; int status; + fd_set fds; + struct timeval timeout; close(pipe_fd[1]); + FD_ZERO(&fds); + FD_SET(pipe_fd[0], &fds); + timeout.tv_sec = 0; + timeout.tv_usec = 200000; while(1) { - int len; + if(select(pipe_fd[0]+1, &fds, NULL, NULL, &timeout)) + { + int len; - len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1); - if(len<=0) + len = read(pipe_fd[0], buf+pos, sizeof(buf)-pos-1); + if(len<=0) + break; + pos += len; + } + else if(waitpid(pid, &status, 0)) break; - pos += len; } buf[pos] = 0; - waitpid(pid, &status, 0); if(!WIFEXITED(status) || WEXITSTATUS(status)) { GtkWidget *dialog; -- 2.45.2