nvttest: Return error if anything fails
This commit is contained in:
+14
-4
@@ -42,6 +42,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_t thr;
|
pthread_t thr;
|
||||||
topts_t opts;
|
topts_t opts;
|
||||||
|
int errors;
|
||||||
} thr_t;
|
} thr_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,6 +69,7 @@ static void *_worker(void *arg)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,12 +78,14 @@ static void *_worker(void *arg)
|
|||||||
if (err != 0)
|
if (err != 0)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "ioctl(TCGETS) failed: %m\n");
|
nvt_log(LOG_ERR, "ioctl(TCGETS) failed: %m\n");
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
err = ioctl(fd, TCSETS, &ios);
|
err = ioctl(fd, TCSETS, &ios);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "ioctl(TCSETS) failed: %m\n");
|
nvt_log(LOG_ERR, "ioctl(TCSETS) failed: %m\n");
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -98,6 +102,7 @@ static void *_worker(void *arg)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,11 +113,13 @@ static void *_worker(void *arg)
|
|||||||
if (nw < 0)
|
if (nw < 0)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "write failed: %m\n");
|
nvt_log(LOG_ERR, "write failed: %m\n");
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nw < len)
|
if (nw < len)
|
||||||
{
|
{
|
||||||
nvt_log(LOG_ERR, "write short: %u/%u\n", nw, len);
|
nvt_log(LOG_ERR, "write short: %u/%u\n", nw, len);
|
||||||
|
thr->errors++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +135,7 @@ static void *_worker(void *arg)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int err;
|
int err, errors;
|
||||||
int opt;
|
int opt;
|
||||||
int ithr, nthr;
|
int ithr, nthr;
|
||||||
thr_t *threads, *thr;
|
thr_t *threads, *thr;
|
||||||
@@ -179,7 +186,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
topts.nthread = nthr;
|
topts.nthread = nthr;
|
||||||
|
|
||||||
threads = malloc(nthr * sizeof(thr_t));
|
threads = calloc(nthr, sizeof(thr_t));
|
||||||
|
|
||||||
for (ithr = 0; ithr < nthr; ithr++)
|
for (ithr = 0; ithr < nthr; ithr++)
|
||||||
{
|
{
|
||||||
@@ -197,14 +204,17 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errors = 0;
|
||||||
for (ithr = 0; ithr < nthr; ithr++)
|
for (ithr = 0; ithr < nthr; ithr++)
|
||||||
{
|
{
|
||||||
thr = &threads[ithr];
|
thr = &threads[ithr];
|
||||||
if (thr->thr == 0)
|
if (thr->thr == 0)
|
||||||
break;
|
break;
|
||||||
pthread_join(thr->thr, NULL);
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user