diff options
| author | 2009-08-09 19:24:00 +0200 | |
|---|---|---|
| committer | 2009-08-09 19:24:00 +0200 | |
| commit | 98a6295df6270145c995fa651eda8a2a3a015984 (patch) | |
| tree | 123465a8fb052e2cd14d096b3bd05e511eeee2be /src | |
| parent | 0f2973702483e45a21283d74111b08bfdb95d6b4 (diff) | |
| download | usbmuxd-98a6295df6270145c995fa651eda8a2a3a015984.tar.gz usbmuxd-98a6295df6270145c995fa651eda8a2a3a015984.tar.bz2 | |
Added mutex to prevent garbled debugging output (esp. packet data)
Diffstat (limited to 'src')
| -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 {  static pthread_mutex_t usbmuxmutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t printmutex = PTHREAD_MUTEX_INITIALIZER;  static usbmux_client_t *connlist = NULL;  static int clients = 0; @@ -126,8 +127,11 @@ static void log_debug_msg(const char *format, ...)  	/* run the real fprintf */  	va_start(args, format); -	if (toto_debug) +	if (toto_debug) { +		pthread_mutex_lock(&printmutex);  		vfprintf(stderr, format, args); +		pthread_mutex_unlock(&printmutex); +	}  	va_end(args);  #endif @@ -433,10 +437,12 @@ static int send_to_device(usbmux_device_t device, char *data, int datalen)  	int bytes = 0;  if (toto_debug > 0) { +	pthread_mutex_lock(&printmutex);  	printf("===============================\n%s: trying to send\n",  		   __func__);  	print_buffer(data, datalen);  	printf("===============================\n"); +	pthread_mutex_unlock(&printmutex);  }  	do { @@ -486,10 +492,12 @@ if (toto_debug > 0) {  	if (bytes > 0) {  		if (toto_debug > 0) { +			pthread_mutex_lock(&printmutex);  			printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");  			printf("%s: sent to device\n", __func__);  			print_buffer(data, bytes);  			printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); +			pthread_mutex_unlock(&printmutex);  		}  	}  	return bytes; @@ -534,10 +542,12 @@ static int recv_from_device_timeout(usbmux_device_t device, char *data,  	}  	if (bytes > 0) {  		if (toto_debug > 0) { +			pthread_mutex_lock(&printmutex);  			printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");  			printf("%s: received from device:\n", __func__);  			print_buffer(data, bytes);  			printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); +			pthread_mutex_unlock(&printmutex);  		}  	} | 
