zdtm: cleanup thread-bomb test error handling and printing

1) Let's do test_init earlier so that max_nr test_msg is now visible in
thread-bomb.out.

2) Also lets check errors from malloc and pthread_...  functions, print
messages about their errors and do proper deallocation at least.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov 2021-01-20 11:12:51 +03:00 committed by Andrei Vagin
parent 9807413c39
commit af1103ff2f

View file

@ -18,17 +18,31 @@ static const size_t stack_size = 64 * 1024;
static void *thread_fn(void *arg)
{
pthread_t t, p, *self;
int err;
if (arg) {
p = *(pthread_t *)arg;
pthread_join(p, NULL);
err = pthread_join(p, NULL);
free(arg);
if (err) {
pr_err("pthread_join(): %d\n", err);
return NULL;
}
}
self = malloc(sizeof(*self));
if (!self) {
pr_perror("malloc()");
return NULL;
}
*self = pthread_self();
pthread_create(&t, &attr, thread_fn, self);
err = pthread_create(&t, &attr, thread_fn, self);
if (err) {
pr_err("pthread_create(): %d\n", err);
free(self);
}
return NULL;
}
@ -38,6 +52,8 @@ int main(int argc, char **argv)
char *val;
int err;
test_init(argc, argv);
err = pthread_attr_init(&attr);
if (err) {
pr_err("pthread_attr_init(): %d\n", err);
@ -56,8 +72,6 @@ int main(int argc, char **argv)
test_msg("%d\n", max_nr);
test_init(argc, argv);
for (i = 0; i < max_nr; i++) {
pthread_t p;
err = pthread_create(&p, &attr, thread_fn, NULL);