From 7039b84c4fe56c88d73f43eb30fcf1372d6263ed Mon Sep 17 00:00:00 2001 From: Ryo Nakamura Date: Tue, 1 Nov 2022 00:17:05 +0900 Subject: capture retval from copy threads --- src/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 7f64dfa..4022786 100644 --- a/src/main.c +++ b/src/main.c @@ -50,6 +50,7 @@ struct mscp_thread { pthread_t tid; size_t done; /* copied bytes */ bool finished; + int ret; }; void *mscp_copy_thread(void *arg); @@ -372,8 +373,11 @@ int main(int argc, char **argv) join_out: /* waiting for threads join... */ for (n = 0; n < nr_threads; n++) - if (threads[n].tid) + if (threads[n].tid) { pthread_join(threads[n].tid, NULL); + if (threads[n].ret < 0) + ret = threads[n].ret; + } if (mtid != 0) { pthread_cancel(mtid); @@ -414,11 +418,11 @@ void *mscp_copy_thread(void *arg) if (!c) break; /* no more chunks */ - if (chunk_prepare(c, sftp) < 0) + if ((t->ret = chunk_prepare(c, sftp)) < 0) break; - if (chunk_copy(c, sftp, - m->sftp_buf_sz, m->io_buf_sz, &t->done) < 0) + if ((t->ret = chunk_copy(c, sftp, + m->sftp_buf_sz, m->io_buf_sz, &t->done)) < 0) break; } -- cgit v1.2.3