From 592782336ebb56fa31148f8c8b29c797c82185e9 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 15 Feb 2014 19:15:58 +0100 Subject: preflight: create preflight worker as detached thread and handle errors --- src/preflight.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/preflight.c b/src/preflight.c index 5c4474a..88e6700 100644 --- a/src/preflight.c +++ b/src/preflight.c @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include @@ -343,7 +344,17 @@ void preflight_worker_device_add(struct device_info* info) memcpy(infocopy, info, sizeof(struct device_info)); pthread_t th; - pthread_create(&th, NULL, preflight_worker_handle_device_add, infocopy); + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + int perr = pthread_create(&th, &attr, preflight_worker_handle_device_add, infocopy); + if (perr != 0) { + free(infocopy); + usbmuxd_log(LL_ERROR, "ERROR: failed to start preflight worker thread for device %s: %s (%d). Invoking client_device_add() directly but things might not work as expected.", info->serial, strerror(perr), perr); + client_device_add(info); + } #else client_device_add(info); #endif -- cgit v1.1-32-gdbae