diff options
| author | 2009-08-09 19:24:00 +0200 | |
|---|---|---|
| committer | 2009-08-09 19:24:00 +0200 | |
| commit | 98a6295df6270145c995fa651eda8a2a3a015984 (patch) | |
| tree | 123465a8fb052e2cd14d096b3bd05e511eeee2be | |
| parent | 0f2973702483e45a21283d74111b08bfdb95d6b4 (diff) | |
| download | usbmuxd-98a6295df6270145c995fa651eda8a2a3a015984.tar.gz usbmuxd-98a6295df6270145c995fa651eda8a2a3a015984.tar.bz2 | |
Added mutex to prevent garbled debugging output (esp. packet data)
| -rw-r--r-- | src/usbmux.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/usbmux.c b/src/usbmux.c index 20c1298..c5e38dd 100644 --- a/src/usbmux.c +++ b/src/usbmux.c | |||
| @@ -106,6 +106,7 @@ struct usbmux_client_int { | |||
| 106 | 106 | ||
| 107 | 107 | ||
| 108 | static pthread_mutex_t usbmuxmutex = PTHREAD_MUTEX_INITIALIZER; | 108 | static pthread_mutex_t usbmuxmutex = PTHREAD_MUTEX_INITIALIZER; |
| 109 | static pthread_mutex_t printmutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 109 | static usbmux_client_t *connlist = NULL; | 110 | static usbmux_client_t *connlist = NULL; |
| 110 | static int clients = 0; | 111 | static int clients = 0; |
| 111 | 112 | ||
| @@ -126,8 +127,11 @@ static void log_debug_msg(const char *format, ...) | |||
| 126 | /* run the real fprintf */ | 127 | /* run the real fprintf */ |
| 127 | va_start(args, format); | 128 | va_start(args, format); |
| 128 | 129 | ||
| 129 | if (toto_debug) | 130 | if (toto_debug) { |
| 131 | pthread_mutex_lock(&printmutex); | ||
| 130 | vfprintf(stderr, format, args); | 132 | vfprintf(stderr, format, args); |
| 133 | pthread_mutex_unlock(&printmutex); | ||
| 134 | } | ||
| 131 | 135 | ||
| 132 | va_end(args); | 136 | va_end(args); |
| 133 | #endif | 137 | #endif |
| @@ -433,10 +437,12 @@ static int send_to_device(usbmux_device_t device, char *data, int datalen) | |||
| 433 | int bytes = 0; | 437 | int bytes = 0; |
| 434 | 438 | ||
| 435 | if (toto_debug > 0) { | 439 | if (toto_debug > 0) { |
| 440 | pthread_mutex_lock(&printmutex); | ||
| 436 | printf("===============================\n%s: trying to send\n", | 441 | printf("===============================\n%s: trying to send\n", |
| 437 | __func__); | 442 | __func__); |
| 438 | print_buffer(data, datalen); | 443 | print_buffer(data, datalen); |
| 439 | printf("===============================\n"); | 444 | printf("===============================\n"); |
| 445 | pthread_mutex_unlock(&printmutex); | ||
| 440 | } | 446 | } |
| 441 | 447 | ||
| 442 | do { | 448 | do { |
| @@ -486,10 +492,12 @@ if (toto_debug > 0) { | |||
| 486 | 492 | ||
| 487 | if (bytes > 0) { | 493 | if (bytes > 0) { |
| 488 | if (toto_debug > 0) { | 494 | if (toto_debug > 0) { |
| 495 | pthread_mutex_lock(&printmutex); | ||
| 489 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); | 496 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); |
| 490 | printf("%s: sent to device\n", __func__); | 497 | printf("%s: sent to device\n", __func__); |
| 491 | print_buffer(data, bytes); | 498 | print_buffer(data, bytes); |
| 492 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); | 499 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); |
| 500 | pthread_mutex_unlock(&printmutex); | ||
| 493 | } | 501 | } |
| 494 | } | 502 | } |
| 495 | return bytes; | 503 | return bytes; |
| @@ -534,10 +542,12 @@ static int recv_from_device_timeout(usbmux_device_t device, char *data, | |||
| 534 | } | 542 | } |
| 535 | if (bytes > 0) { | 543 | if (bytes > 0) { |
| 536 | if (toto_debug > 0) { | 544 | if (toto_debug > 0) { |
| 545 | pthread_mutex_lock(&printmutex); | ||
| 537 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); | 546 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); |
| 538 | printf("%s: received from device:\n", __func__); | 547 | printf("%s: received from device:\n", __func__); |
| 539 | print_buffer(data, bytes); | 548 | print_buffer(data, bytes); |
| 540 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); | 549 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); |
| 550 | pthread_mutex_unlock(&printmutex); | ||
| 541 | } | 551 | } |
| 542 | } | 552 | } |
| 543 | 553 | ||
