remsim-client: Fix the -k/ --keep-running option

When introducing asynchronous USB support in Change-Id
Ic18690b3c2cbc5e99de0665c0b68b7555433b3cd, we accidentially
broke the --keep-running behavior, where even a disappearing USB
device will not terminate the remsim-client process.

Change-Id: I19cca9f7953d61058a36856b2fc4c97a3b93e15d
diff --git a/src/client/simtrace2-remsim_client.c b/src/client/simtrace2-remsim_client.c
index ac78dd4..1af3274 100644
--- a/src/client/simtrace2-remsim_client.c
+++ b/src/client/simtrace2-remsim_client.c
@@ -96,6 +96,9 @@
 void __thread *talloc_asn1_ctx;
 int asn_debug;
 
+/* should we leave main loop processing? */
+bool g_leave_main = false;
+
 __attribute__((unused)) static int gsmtap_send_sim(const uint8_t *apdu, unsigned int len)
 {
 	struct gsmtap_hdr *gh;
@@ -152,10 +155,11 @@
 		break;
 	case LIBUSB_TRANSFER_NO_DEVICE:
 		fprintf(stderr, "USB device disappeared\n");
-		exit(23);
+		g_leave_main = true;
 		break;
 	default:
-		osmo_panic("USB OUT transfer failed, status=%u\n", xfer->status);
+		fprintf(stderr, "USB OUT transfer failed, status=%u\n", xfer->status);
+		g_leave_main = true;
 		break;
 	}
 
@@ -577,10 +581,11 @@
 		break;
 	case LIBUSB_TRANSFER_NO_DEVICE:
 		fprintf(stderr, "USB device disappeared\n");
-		exit(23);
+		g_leave_main = true;
 		break;
 	default:
-		osmo_panic("USB IN transfer failed, status=%u\n", xfer->status);
+		fprintf(stderr, "USB IN transfer failed, status=%u\n", xfer->status);
+		g_leave_main = true;
 		break;
 	}
 
@@ -627,10 +632,11 @@
 		break;
 	case LIBUSB_TRANSFER_NO_DEVICE:
 		fprintf(stderr, "USB device disappeared\n");
-		exit(23);
+		g_leave_main = true;
 		break;
 	default:
-		osmo_panic("USB IRQ transfer failed, status=%u\n", xfer->status);
+		fprintf(stderr, "USB IRQ transfer failed, status=%u\n", xfer->status);
+		g_leave_main = true;
 		break;
 	}
 
@@ -1092,9 +1098,10 @@
 	allocate_and_submit_irq(ci);
 	allocate_and_submit_in(ci);
 
-	while (1) {
+	while (!g_leave_main) {
 		osmo_select_main(false);
 	}
+	g_leave_main = false;
 
 	libusb_release_interface(transp->usb_devh, 0);