From cd5de2fe5d97f40565758461e89321827c5252ab Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Sun, 10 Nov 2024 12:42:34 +0100 Subject: [PATCH] nvttest: Return error if anything fails --- nvttest/nvttest.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nvttest/nvttest.c b/nvttest/nvttest.c index 80368c0..fecbf3e 100644 --- a/nvttest/nvttest.c +++ b/nvttest/nvttest.c @@ -42,6 +42,7 @@ typedef struct { typedef struct { pthread_t thr; topts_t opts; + int errors; } thr_t; @@ -68,6 +69,7 @@ static void *_worker(void *arg) if (fd < 0) { nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev); + thr->errors++; break; } @@ -76,12 +78,14 @@ static void *_worker(void *arg) if (err != 0) { nvt_log(LOG_ERR, "ioctl(TCGETS) failed: %m\n"); + thr->errors++; break; } err = ioctl(fd, TCSETS, &ios); if (err != 0) { nvt_log(LOG_ERR, "ioctl(TCSETS) failed: %m\n"); + thr->errors++; break; } close(fd); @@ -98,6 +102,7 @@ static void *_worker(void *arg) if (fd < 0) { nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev); + thr->errors++; break; } @@ -108,11 +113,13 @@ static void *_worker(void *arg) if (nw < 0) { nvt_log(LOG_ERR, "write failed: %m\n"); + thr->errors++; break; } if (nw < len) { nvt_log(LOG_ERR, "write short: %u/%u\n", nw, len); + thr->errors++; break; } } @@ -128,7 +135,7 @@ static void *_worker(void *arg) int main(int argc, char **argv) { - int err; + int err, errors; int opt; int ithr, nthr; thr_t *threads, *thr; @@ -179,7 +186,7 @@ int main(int argc, char **argv) topts.nthread = nthr; - threads = malloc(nthr * sizeof(thr_t)); + threads = calloc(nthr, sizeof(thr_t)); for (ithr = 0; ithr < nthr; ithr++) { @@ -197,14 +204,17 @@ int main(int argc, char **argv) } } + errors = 0; for (ithr = 0; ithr < nthr; ithr++) { thr = &threads[ithr]; if (thr->thr == 0) break; pthread_join(thr->thr, NULL); - nvt_log(LOG_INFO, "Joined worker thread %d/%d\n", ithr + 1, nthr); + errors += thr->errors; + nvt_log(LOG_INFO, "Joined worker thread %d/%d (err=%d)\n", + ithr + 1, nthr, thr->errors); } - return 0; + return errors ? 1 : 0; }