diff options
| author | 2009-04-13 14:22:24 +0200 | |
|---|---|---|
| committer | 2009-04-13 14:22:24 +0200 | |
| commit | 9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5 (patch) | |
| tree | 5e36527dc25154182889bd42bada7590f54a9c9d /main.c | |
| parent | d6e0cb81973e99aa61c4b36e3e4a4dcd475c1e59 (diff) | |
| download | usbmuxd-9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5.tar.gz usbmuxd-9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5.tar.bz2 | |
This _should_ fix a race condition that happens when a client is about
to cleanup the stuff that is used by another client that is about to set
up a new connection. Increased timeout in sock_stuff from 10 to 20
seconds and decreased the pullbulk recv timeout from 5 to 3 seconds.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 11 |
1 files changed, 5 insertions, 6 deletions
| @@ -605,11 +605,11 @@ connect: | |||
| 605 | if (verbose >= 3) fprintf(stderr, "%s: Setting up connection to usb device #%d on port %d\n", __func__, c_req->device_id, ntohs(c_req->tcp_dport)); | 605 | if (verbose >= 3) fprintf(stderr, "%s: Setting up connection to usb device #%d on port %d\n", __func__, c_req->device_id, ntohs(c_req->tcp_dport)); |
| 606 | 606 | ||
| 607 | // find the device, and open usb connection | 607 | // find the device, and open usb connection |
| 608 | pthread_mutex_lock(&usbmux_mutex); | ||
| 608 | phone = NULL; | 609 | phone = NULL; |
| 609 | cur_dev = NULL; | 610 | cur_dev = NULL; |
| 610 | // first check if we already have an open connection | 611 | // first check if we already have an open connection |
| 611 | if (devices) { | 612 | if (devices) { |
| 612 | pthread_mutex_lock(&usbmux_mutex); | ||
| 613 | for (i = 0; i < device_count; i++) { | 613 | for (i = 0; i < device_count; i++) { |
| 614 | if (devices[i]) { | 614 | if (devices[i]) { |
| 615 | if (devices[i]->device_id == c_req->device_id) { | 615 | if (devices[i]->device_id == c_req->device_id) { |
| @@ -620,7 +620,6 @@ connect: | |||
| 620 | } | 620 | } |
| 621 | } | 621 | } |
| 622 | } | 622 | } |
| 623 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 624 | } | 623 | } |
| 625 | if (!phone) { | 624 | if (!phone) { |
| 626 | // if not found, make a new connection | 625 | // if not found, make a new connection |
| @@ -629,6 +628,7 @@ connect: | |||
| 629 | pthread_mutex_lock(&usb_mutex); | 628 | pthread_mutex_lock(&usb_mutex); |
| 630 | if (iphone_get_specific_device(0, c_req->device_id, &phone) != IPHONE_E_SUCCESS) { | 629 | if (iphone_get_specific_device(0, c_req->device_id, &phone) != IPHONE_E_SUCCESS) { |
| 631 | pthread_mutex_unlock(&usb_mutex); | 630 | pthread_mutex_unlock(&usb_mutex); |
| 631 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 632 | if (verbose >= 1) fprintf(stderr, "%s: device_id %d could not be opened\n", __func__, c_req->device_id); | 632 | if (verbose >= 1) fprintf(stderr, "%s: device_id %d could not be opened\n", __func__, c_req->device_id); |
| 633 | usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); | 633 | usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); |
| 634 | goto leave; | 634 | goto leave; |
| @@ -636,7 +636,6 @@ connect: | |||
| 636 | pthread_mutex_unlock(&usb_mutex); | 636 | pthread_mutex_unlock(&usb_mutex); |
| 637 | 637 | ||
| 638 | // create device object | 638 | // create device object |
| 639 | pthread_mutex_lock(&usbmux_mutex); | ||
| 640 | if (verbose >= 3) fprintf(stderr, "%s: add to device list\n", __func__); | 639 | if (verbose >= 3) fprintf(stderr, "%s: add to device list\n", __func__); |
| 641 | cur_dev = (struct device_info*)malloc(sizeof(struct device_info)); | 640 | cur_dev = (struct device_info*)malloc(sizeof(struct device_info)); |
| 642 | memset(cur_dev, 0, sizeof(struct device_info)); | 641 | memset(cur_dev, 0, sizeof(struct device_info)); |
| @@ -655,10 +654,10 @@ connect: | |||
| 655 | devices[device_count] = cur_dev; | 654 | devices[device_count] = cur_dev; |
| 656 | device_count++; | 655 | device_count++; |
| 657 | } | 656 | } |
| 658 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 659 | } else { | 657 | } else { |
| 660 | if (verbose >= 3) fprintf(stderr, "%s: reusing usb connection, device_id=%d\n", __func__, c_req->device_id); | 658 | if (verbose >= 3) fprintf(stderr, "%s: reusing usb connection, device_id=%d\n", __func__, c_req->device_id); |
| 661 | } | 659 | } |
| 660 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 662 | 661 | ||
| 663 | // setup connection to iPhone/iPod | 662 | // setup connection to iPhone/iPod |
| 664 | // pthread_mutex_lock(&usbmux_mutex); | 663 | // pthread_mutex_lock(&usbmux_mutex); |
| @@ -712,6 +711,7 @@ leave: | |||
| 712 | 711 | ||
| 713 | // this has to be freed only if it's not in use anymore as it closes | 712 | // this has to be freed only if it's not in use anymore as it closes |
| 714 | // the USB connection | 713 | // the USB connection |
| 714 | pthread_mutex_lock(&usbmux_mutex); | ||
| 715 | if (cur_dev) { | 715 | if (cur_dev) { |
| 716 | pthread_mutex_lock(&cur_dev->mutex); | 716 | pthread_mutex_lock(&cur_dev->mutex); |
| 717 | if (cur_dev->use_count > 1) { | 717 | if (cur_dev->use_count > 1) { |
| @@ -733,7 +733,6 @@ leave: | |||
| 733 | pthread_mutex_destroy(&cur_dev->mutex); | 733 | pthread_mutex_destroy(&cur_dev->mutex); |
| 734 | free(cur_dev); | 734 | free(cur_dev); |
| 735 | cur_dev = NULL; | 735 | cur_dev = NULL; |
| 736 | pthread_mutex_lock(&usbmux_mutex); | ||
| 737 | if (device_count > 1) { | 736 | if (device_count > 1) { |
| 738 | struct device_info **newlist; | 737 | struct device_info **newlist; |
| 739 | int j; | 738 | int j; |
| @@ -752,9 +751,9 @@ leave: | |||
| 752 | devices = NULL; | 751 | devices = NULL; |
| 753 | device_count = 0; | 752 | device_count = 0; |
| 754 | } | 753 | } |
| 755 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 756 | } | 754 | } |
| 757 | } | 755 | } |
| 756 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 758 | 757 | ||
| 759 | cdata->dead = 1; | 758 | cdata->dead = 1; |
| 760 | close(cdata->socket); | 759 | close(cdata->socket); |
