From 0b2f9ec3978d1018289c1c90da9d028205e0c726 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Wed, 24 Sep 2025 22:11:44 +0100 Subject: [PATCH] Only call pv_watchfd_loop() from main, so that eventually pv_watchpid_loop() can be removed and multiple "-d" values supported (#12). --- src/main/main.c | 9 ++------- src/pv/loop.c | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) 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];