diff --git a/src/main/main.c b/src/main/main.c index a913926..742327c 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -547,13 +547,8 @@ int main(int argc, char **argv) pv_remote_fini(); break; case PV_ACTION_WATCHFD: - if ((opts->watchfd_count > 0) && (NULL != opts->watchfd_fd) && (-1 == opts->watchfd_fd[0])) { - /* "Watch all file descriptors of another process" mode. */ - retcode = pv_watchpid_loop(state); - } else if ((opts->watchfd_count > 0) && (NULL != opts->watchfd_fd) && (-1 != opts->watchfd_fd[0])) { - /* "Watch a specific file descriptor of another process" mode. */ - retcode = pv_watchfd_loop(state); - } + /* "Watch file descriptor(s) of another process" mode. */ + retcode = pv_watchfd_loop(state); break; } diff --git a/src/pv/loop.c b/src/pv/loop.c index dfe1f35..b9f1327 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -591,6 +591,7 @@ int pv_main_loop(pvstate_t state) * Returns nonzero on error. * * TODO: unify this with pv_watchpid_loop. + * TODO: watch more than one fd, if watchfd.count > 1. */ int pv_watchfd_loop(pvstate_t state) { @@ -609,6 +610,11 @@ int pv_watchfd_loop(pvstate_t state) if (NULL == state->watchfd.fd) return PV_ERROREXIT_MEMORY; + /* Call pv_watchpid_loop() instead if no specific fd was given. */ + if (-1 == state->watchfd.fd[0]) { + return pv_watchpid_loop(state); + } + memset(&info, 0, sizeof(info)); info.watch_pid = state->watchfd.pid[0]; info.watch_fd = state->watchfd.fd[0];