summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-04-08 01:50:34 +0200
committerGravatar Nikias Bassen2009-04-08 01:50:34 +0200
commit05e6e479a0ba45a5b164e4e18fbbbb1c600554b0 (patch)
treedd37fb314be5a900d716e54f65513f300e7fe73d /main.c
parent466ff3c456383456630ce9d67abae991566c158e (diff)
downloadusbmuxd-05e6e479a0ba45a5b164e4e18fbbbb1c600554b0.tar.gz
usbmuxd-05e6e479a0ba45a5b164e4e18fbbbb1c600554b0.tar.bz2
added --exit-on-no-devices option.
Diffstat (limited to 'main.c')
-rw-r--r--main.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/main.c b/main.c
index 0af0735..8560aac 100644
--- a/main.c
+++ b/main.c
@@ -53,6 +53,7 @@ static int quit_flag = 0;
static int fsock = -1;
static int verbose = DEBUG_LEVEL;
static int foreground = 0;
+static int exit_on_no_devices = 0;
struct device_use_info {
uint32_t device_id;
@@ -869,12 +870,13 @@ static void parse_opts(int argc, char **argv)
{ "help", 0, NULL, 'h' },
{ "foreground", 0, NULL, 'f' },
{ "verbose", 0, NULL, 'v' },
+ { "exit-on-no-devices", 0, NULL, 'e' },
{ NULL, 0, NULL, 0}
};
int c;
while (1) {
- c = getopt_long(argc, argv, "hfv", longopts, (int *) 0);
+ c = getopt_long(argc, argv, "hfve", longopts, (int *) 0);
if (c == -1) {
break;
}
@@ -889,6 +891,9 @@ static void parse_opts(int argc, char **argv)
case 'v':
sock_stuff_set_verbose(++verbose);
break;
+ case 'e':
+ exit_on_no_devices = 1;
+ break;
default:
usage();
exit(2);
@@ -897,6 +902,35 @@ static void parse_opts(int argc, char **argv)
}
/**
+ * checks for attached devices
+ *
+ * @return number of devices found
+ */
+static int devices_attached()
+{
+ struct usb_bus *bus;
+ struct usb_device *dev;
+ int res = 0;
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+
+ for (bus = usb_get_busses(); bus; bus = bus->next) {
+ for (dev = bus->devices; dev; dev = dev->next) {
+ if (dev->descriptor.idVendor == 0x05ac
+ && dev->descriptor.idProduct >= 0x1290
+ && dev->descriptor.idProduct <= 0x1293)
+ {
+ res++;
+ }
+ }
+ }
+
+ return res;
+}
+
+/**
* main function. Initializes all stuff and then loops waiting in accept.
*/
int main(int argc, char **argv)
@@ -944,6 +978,13 @@ int main(int argc, char **argv)
}
}
+ if (exit_on_no_devices) {
+ if (devices_attached() <= 0) {
+ logmsg(LOG_NOTICE, "no devices attached. exiting.");
+ return 0;
+ }
+ }
+
fsock = create_unix_socket(USBMUXD_SOCKET_FILE);
if (fsock < 0) {
logmsg(LOG_ERR, "Could not create socket, exiting");