From a17f4139da738fbd55f8085fdb9952e9662e51a4 Mon Sep 17 00:00:00 2001 From: Tuomas Jaakola Date: Sun, 18 Feb 2018 22:53:33 +0200 Subject: [PATCH] wait child process to terminate --- bmd-streamer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bmd-streamer.c b/bmd-streamer.c index 2d8be80..a626b9a 100644 --- a/bmd-streamer.c +++ b/bmd-streamer.c @@ -1364,7 +1364,7 @@ int main(int argc, char **argv) libusb_context *ctx; libusb_hotplug_callback_handle cbhandle; const char *msg = NULL; - int i, r, ec = 0, opt, optindex; + int i, r, ec = 0, opt, optindex, status; signal(SIGCHLD, reapchildren); signal(SIGTERM, dostop); @@ -1453,6 +1453,9 @@ int main(int argc, char **argv) libusb_handle_events(ctx); error: + // wait child process to terminate + while (waitpid(-1, &status, 0) != -1 || errno != ECHILD); + if (msg) dlog(LOG_ERR, "failed to %s: %s", msg, libusb_error_name(r)); if (ctx)