From 0aac6d6aacfae9b785db60cf72895c3ceb5a5250 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Fri, 17 Oct 2025 19:09:46 +0100 Subject: [PATCH] Add comments and "pid_last_seen", "fd_last_seen" structure members for proposed new logic that will hold fd info on-screen a short time after closure, to retain the progress display when a watched process exits (#81). --- src/include/pv-internal.h | 8 ++++++++ src/pv/loop.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 34384b6..07f4518 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -520,10 +520,18 @@ struct pvwatchfd_s { off_t size; /* size of whole file, 0 if unknown */ off_t position; /* position last seen at */ struct timespec start_time; /* time we started watching the fd */ + struct timespec fd_last_seen; /* time the fd was last seen open */ pid_t watch_pid; /* PID to watch */ int watch_fd; /* fd to watch */ bool displayable; /* false if not displayable */ bool unused; /* true if free for re-use */ + /* + * After the "watch_fd" is found to be closed, "fd_last_seen" stops + * being updated; when "fd_last_seen" is old enough, "unused" + * becomes true so the slot can be re-used. This allows fd + * information to be held on-screen for a short while after the fd + * is closed (#81). + */ }; typedef struct pvwatchfd_s *pvwatchfd_t; diff --git a/src/pv/loop.c b/src/pv/loop.c index cd4caf5..1b6c191 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -712,6 +712,7 @@ int pv_watchfd_loop(pvstate_t state) int fd; /* watched fd, or -1 for all */ pvwatchfd_t info_array; /* watch information for each fd */ int array_length; /* length of watch info array */ + struct timespec pid_last_seen; /* when this PID was last seen */ bool finished; /* "PID:FD": fd closed; or PID gone */ } *watching; unsigned int watch_idx; @@ -719,6 +720,26 @@ int pv_watchfd_loop(pvstate_t state) struct timespec next_update, next_remotecheck, cur_time; int prev_displayed_lines, blank_lines; + /* + * TODO: new logic: + * For each watching[] item, "pid_last_seen" stops being updated + * when the PID ceases to exist. If "fd" is >=0 then + * "pid_last_seen" is set to the newest of the "fd_last_seen" values + * of the info_array[] fd info items. When "pid_last_seen" is too + * old, "finished" becomes true so this watching[] item stops being + * displayed. + * + * In each watching[].info_array[] fd info item, once its "watch_fd" + * is closed, its "fd_last_seen" stops being updated, and once + * that's stopped updating long enough, its "unused" becomes true. + * + * All of this allows information to be held on-screen for a short + * while after the fd closes or the PID exits (#81). + */ + + /* TODO: implement the above (pid_last_seen, fd_last_seen) */ + /* TODO: check whether pid_last_seen is needed, or only fd_last_seen */ + /* If there's nothing to watch, do nothing at all. */ if (state->watchfd.count < 1) return 0;