From 3812a302cefcccbeb9bc46ed5c55710eb4c0512e Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 28 Apr 2021 19:28:14 -0700 Subject: encode_cache: handle pthread_create() errors switch to using rmdThread() and handle errors previously pthread_create() errors were completely unnoticed --- src/rmd.c | 6 ++++-- src/rmd_encode_cache.c | 17 +++++++++++++---- src/rmd_encode_cache.h | 2 +- src/rmd_rescue.c | 5 +++-- 4 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/rmd.c b/src/rmd.c index b3a1af2..9fe2867 100644 --- a/src/rmd.c +++ b/src/rmd.c @@ -158,8 +158,10 @@ int main(int argc, char **argv) //encode and then cleanup cache if (!pdata.args.encOnTheFly && !pdata.args.no_encode) { - if (!pdata.aborted) - rmdEncodeCache(&pdata); + if (!pdata.aborted) { + if (rmdEncodeCache(&pdata)) + return 1; + } fprintf(stderr, "Cleanning up cache...\n"); if (rmdPurgeCache(pdata.cache_data, !pdata.args.nosound)) diff --git a/src/rmd_encode_cache.c b/src/rmd_encode_cache.c index e2bf85d..2d778be 100644 --- a/src/rmd_encode_cache.c +++ b/src/rmd_encode_cache.c @@ -30,6 +30,7 @@ #include "rmd_flush_to_ogg.h" #include "rmd_init_encoder.h" #include "rmd_load_cache.h" +#include "rmd_threads.h" #include "rmd_types.h" #include @@ -38,8 +39,7 @@ #include - -void rmdEncodeCache(ProgData *pdata) +int rmdEncodeCache(ProgData *pdata) { pthread_t flush_to_ogg_t, load_cache_t; @@ -61,13 +61,22 @@ void rmdEncodeCache(ProgData *pdata) pdata->sound_buffer = pdata->sound_buffer->next; } } - pthread_create(&flush_to_ogg_t, NULL, (void *)rmdFlushToOgg, (void *)pdata); + + if (rmdThread(&flush_to_ogg_t, rmdFlushToOgg, pdata)) { + fprintf(stderr, "Error creating rmdFlushToOgg thread!!!\n"); + return 1; + } //start loading image and audio - pthread_create(&load_cache_t, NULL, (void *)rmdLoadCache, (void *)pdata); + if (rmdThread(&load_cache_t, rmdLoadCache, pdata)) { + fprintf(stderr, "Error creating rmdLoadCache thread!!!\n"); + return 1; + } //join and finish pthread_join(load_cache_t, NULL); fprintf(stderr, "Encoding finished!\nWait a moment please...\n"); pthread_join(flush_to_ogg_t, NULL); + + return 0; } diff --git a/src/rmd_encode_cache.h b/src/rmd_encode_cache.h index 4c37f97..f1078c1 100644 --- a/src/rmd_encode_cache.h +++ b/src/rmd_encode_cache.h @@ -35,7 +35,7 @@ * ogg stream. * \param pdata ProgData struct containing all program data */ -void rmdEncodeCache(ProgData *pdata); +int rmdEncodeCache(ProgData *pdata); #endif diff --git a/src/rmd_rescue.c b/src/rmd_rescue.c index 73ae7d4..ac224dd 100644 --- a/src/rmd_rescue.c +++ b/src/rmd_rescue.c @@ -114,8 +114,9 @@ int rmdRescue(const char *path) rmdRegisterCallbacks(&pdata); fprintf(stderr, "Restoring %s!!!\n", path); - - rmdEncodeCache(&pdata); + + if (rmdEncodeCache(&pdata)) + return 1; fprintf(stderr, "Done!!!\n"); fprintf(stderr, "Goodbye!\n"); -- cgit v1.2.3