diff options
| -rw-r--r-- | main.c | 43 |
1 files changed, 42 insertions, 1 deletions
| @@ -53,6 +53,7 @@ static int quit_flag = 0; | |||
| 53 | static int fsock = -1; | 53 | static int fsock = -1; |
| 54 | static int verbose = DEBUG_LEVEL; | 54 | static int verbose = DEBUG_LEVEL; |
| 55 | static int foreground = 0; | 55 | static int foreground = 0; |
| 56 | static int exit_on_no_devices = 0; | ||
| 56 | 57 | ||
| 57 | struct device_use_info { | 58 | struct device_use_info { |
| 58 | uint32_t device_id; | 59 | uint32_t device_id; |
| @@ -869,12 +870,13 @@ static void parse_opts(int argc, char **argv) | |||
| 869 | { "help", 0, NULL, 'h' }, | 870 | { "help", 0, NULL, 'h' }, |
| 870 | { "foreground", 0, NULL, 'f' }, | 871 | { "foreground", 0, NULL, 'f' }, |
| 871 | { "verbose", 0, NULL, 'v' }, | 872 | { "verbose", 0, NULL, 'v' }, |
| 873 | { "exit-on-no-devices", 0, NULL, 'e' }, | ||
| 872 | { NULL, 0, NULL, 0} | 874 | { NULL, 0, NULL, 0} |
| 873 | }; | 875 | }; |
| 874 | int c; | 876 | int c; |
| 875 | 877 | ||
| 876 | while (1) { | 878 | while (1) { |
| 877 | c = getopt_long(argc, argv, "hfv", longopts, (int *) 0); | 879 | c = getopt_long(argc, argv, "hfve", longopts, (int *) 0); |
| 878 | if (c == -1) { | 880 | if (c == -1) { |
| 879 | break; | 881 | break; |
| 880 | } | 882 | } |
| @@ -889,6 +891,9 @@ static void parse_opts(int argc, char **argv) | |||
| 889 | case 'v': | 891 | case 'v': |
| 890 | sock_stuff_set_verbose(++verbose); | 892 | sock_stuff_set_verbose(++verbose); |
| 891 | break; | 893 | break; |
| 894 | case 'e': | ||
| 895 | exit_on_no_devices = 1; | ||
| 896 | break; | ||
| 892 | default: | 897 | default: |
| 893 | usage(); | 898 | usage(); |
| 894 | exit(2); | 899 | exit(2); |
| @@ -897,6 +902,35 @@ static void parse_opts(int argc, char **argv) | |||
| 897 | } | 902 | } |
| 898 | 903 | ||
| 899 | /** | 904 | /** |
| 905 | * checks for attached devices | ||
| 906 | * | ||
| 907 | * @return number of devices found | ||
| 908 | */ | ||
| 909 | static int devices_attached() | ||
| 910 | { | ||
| 911 | struct usb_bus *bus; | ||
| 912 | struct usb_device *dev; | ||
| 913 | int res = 0; | ||
| 914 | |||
| 915 | usb_init(); | ||
| 916 | usb_find_busses(); | ||
| 917 | usb_find_devices(); | ||
| 918 | |||
| 919 | for (bus = usb_get_busses(); bus; bus = bus->next) { | ||
| 920 | for (dev = bus->devices; dev; dev = dev->next) { | ||
| 921 | if (dev->descriptor.idVendor == 0x05ac | ||
| 922 | && dev->descriptor.idProduct >= 0x1290 | ||
| 923 | && dev->descriptor.idProduct <= 0x1293) | ||
| 924 | { | ||
| 925 | res++; | ||
| 926 | } | ||
| 927 | } | ||
| 928 | } | ||
| 929 | |||
| 930 | return res; | ||
| 931 | } | ||
| 932 | |||
| 933 | /** | ||
| 900 | * main function. Initializes all stuff and then loops waiting in accept. | 934 | * main function. Initializes all stuff and then loops waiting in accept. |
| 901 | */ | 935 | */ |
| 902 | int main(int argc, char **argv) | 936 | int main(int argc, char **argv) |
| @@ -944,6 +978,13 @@ int main(int argc, char **argv) | |||
| 944 | } | 978 | } |
| 945 | } | 979 | } |
| 946 | 980 | ||
| 981 | if (exit_on_no_devices) { | ||
| 982 | if (devices_attached() <= 0) { | ||
| 983 | logmsg(LOG_NOTICE, "no devices attached. exiting."); | ||
| 984 | return 0; | ||
| 985 | } | ||
| 986 | } | ||
| 987 | |||
| 947 | fsock = create_unix_socket(USBMUXD_SOCKET_FILE); | 988 | fsock = create_unix_socket(USBMUXD_SOCKET_FILE); |
| 948 | if (fsock < 0) { | 989 | if (fsock < 0) { |
| 949 | logmsg(LOG_ERR, "Could not create socket, exiting"); | 990 | logmsg(LOG_ERR, "Could not create socket, exiting"); |
