aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-04-01 21:58:24 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-04-01 21:58:24 +0200
commitfc93ed97cd02e7c737a3fdcd93faa6c866ab2d7a (patch)
tree00d469ad2ab13f99be34649b6d647fdec3dc642e
parent0ae2e72d391f63d4721aed691773a05c50381c12 (diff)
downloadburstdog-fc93ed97cd02e7c737a3fdcd93faa6c866ab2d7a.tar.xz
fix fd-caching being completely broken
-rw-r--r--watchdog.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/watchdog.c b/watchdog.c
index 806fbcc..0e2d91b 100644
--- a/watchdog.c
+++ b/watchdog.c
@@ -146,12 +146,10 @@ int main(int argc, char **argv)
for (size_t i = 0; i < num_pids; i++) {
struct process *oldproc = NULL;
if (num_samples > 1) {
- while (oldproc_idx < oldprocs->num && oldprocs->arr[oldproc_idx].pid < pids[i]) {
- close(oldprocs->arr[oldproc_idx].fd);
- oldproc_idx++;
- }
+ while (oldproc_idx < oldprocs->num && oldprocs->arr[oldproc_idx].pid < pids[i])
+ close(oldprocs->arr[oldproc_idx++].fd);
if (oldproc_idx < oldprocs->num && oldprocs->arr[oldproc_idx].pid == pids[i])
- oldproc = &oldprocs->arr[oldproc_idx];
+ oldproc = &oldprocs->arr[oldproc_idx++];
}
int statfd;
@@ -167,7 +165,6 @@ int main(int argc, char **argv)
}
ssize_t n_read = pread(statfd, statbuffer, BUFSIZ-1, 0);
- close(statfd);
if (n_read == -1) {
close(statfd);
continue;
@@ -184,6 +181,7 @@ int main(int argc, char **argv)
struct process *proc = &procs->arr[procs->num++];
proc->pid = pids[i];
+ proc->fd = statfd;
proc->time[0] = atoi(utime) + atoi(stime);
if (oldproc) {
@@ -217,10 +215,8 @@ int main(int argc, char **argv)
}
}
- while (oldproc_idx < oldprocs->num) {
- close(oldprocs->arr[oldproc_idx].fd);
- oldproc_idx++;
- }
+ while (oldproc_idx < oldprocs->num)
+ close(oldprocs->arr[oldproc_idx++].fd);
struct process_tab *tmp = oldprocs;
oldprocs = procs;