pmc: look for POLLHUP in order to work with piped input and redirection.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-25 15:45:54 +02:00
parent 9b2a6d543c
commit 8f6d2549b1
1 changed files with 13 additions and 3 deletions

16
pmc.c
View File

@ -326,7 +326,7 @@ static void usage(char *progname)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *iface_name = NULL, *progname; char *iface_name = NULL, *progname;
int c, cnt, length; int c, cnt, length, tmo = -1;
char line[1024]; char line[1024];
enum transport_type transport_type = TRANS_UDP_IPV4; enum transport_type transport_type = TRANS_UDP_IPV4;
struct ptp_message *msg; struct ptp_message *msg;
@ -404,7 +404,7 @@ int main(int argc, char *argv[])
print_set_verbose(1); print_set_verbose(1);
while (1) { while (1) {
cnt = poll(pollfd, N_FD, -1); cnt = poll(pollfd, N_FD, tmo);
if (cnt < 0) { if (cnt < 0) {
if (EINTR == errno) { if (EINTR == errno) {
continue; continue;
@ -413,7 +413,17 @@ int main(int argc, char *argv[])
return -1; return -1;
} }
} else if (!cnt) { } else if (!cnt) {
continue; break;
}
if (pollfd[0].revents & POLLHUP) {
if (tmo == -1) {
/* Wait a bit longer for outstanding replies. */
tmo = 1000;
pollfd[0].fd = -1;
pollfd[0].events = 0;
} else {
break;
}
} }
if (pollfd[0].revents & (POLLIN|POLLPRI)) { if (pollfd[0].revents & (POLLIN|POLLPRI)) {
if (!fgets(line, sizeof(line), stdin)) { if (!fgets(line, sizeof(line), stdin)) {