summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/idevicesyslog.c99
1 files changed, 55 insertions, 44 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 76de128..5521736 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -2,6 +2,7 @@
2 * idevicesyslog.c 2 * idevicesyslog.c
3 * Relay the syslog of a device to stdout 3 * Relay the syslog of a device to stdout
4 * 4 *
5 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved. 6 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
@@ -29,6 +30,7 @@
29#include <signal.h> 30#include <signal.h>
30#include <stdlib.h> 31#include <stdlib.h>
31#include <unistd.h> 32#include <unistd.h>
33#include <getopt.h>
32 34
33#ifdef WIN32 35#ifdef WIN32
34#include <windows.h> 36#include <windows.h>
@@ -40,13 +42,13 @@
40 42
41static int quit_flag = 0; 43static int quit_flag = 0;
42 44
43void print_usage(int argc, char **argv);
44
45static char* udid = NULL; 45static char* udid = NULL;
46 46
47static idevice_t device = NULL; 47static idevice_t device = NULL;
48static syslog_relay_client_t syslog = NULL; 48static syslog_relay_client_t syslog = NULL;
49 49
50enum idevice_options lookup_opts = IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK;
51
50static void syslog_callback(char c, void *user_data) 52static void syslog_callback(char c, void *user_data)
51{ 53{
52 putchar(c); 54 putchar(c);
@@ -57,7 +59,7 @@ static void syslog_callback(char c, void *user_data)
57 59
58static int start_logging(void) 60static int start_logging(void)
59{ 61{
60 idevice_error_t ret = idevice_new(&device, udid); 62 idevice_error_t ret = idevice_new_with_options(&device, udid, lookup_opts);
61 if (ret != IDEVICE_E_SUCCESS) { 63 if (ret != IDEVICE_E_SUCCESS) {
62 fprintf(stderr, "Device with udid %s not found!?\n", udid); 64 fprintf(stderr, "Device with udid %s not found!?\n", udid);
63 return -1; 65 return -1;
@@ -166,9 +168,31 @@ static void clean_exit(int sig)
166 quit_flag++; 168 quit_flag++;
167} 169}
168 170
171static void print_usage(int argc, char **argv, int is_error)
172{
173 char *name = NULL;
174 name = strrchr(argv[0], '/');
175 fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
176 fprintf(is_error ? stderr : stdout,
177 "Relay syslog of a connected device.\n\n" \
178 " -u, --udid UDID target specific device by UDID\n" \
179 " -n, --network connect to network device even if available via USB\n" \
180 " -h, --help prints usage information\n" \
181 " -d, --debug enable communication debugging\n" \
182 "\n" \
183 "Homepage: <" PACKAGE_URL ">\n"
184 );
185}
186
169int main(int argc, char *argv[]) 187int main(int argc, char *argv[])
170{ 188{
171 int i; 189 int c = 0;
190 const struct option longopts[] = {
191 { "debug", no_argument, NULL, 'd' },
192 { "help", no_argument, NULL, 'h' },
193 { "udid", required_argument, NULL, 'u' },
194 { NULL, 0, NULL, 0}
195 };
172 196
173 signal(SIGINT, clean_exit); 197 signal(SIGINT, clean_exit);
174 signal(SIGTERM, clean_exit); 198 signal(SIGTERM, clean_exit);
@@ -177,35 +201,39 @@ int main(int argc, char *argv[])
177 signal(SIGPIPE, SIG_IGN); 201 signal(SIGPIPE, SIG_IGN);
178#endif 202#endif
179 203
180 /* parse cmdline args */ 204 while ((c = getopt_long(argc, argv, "dhu:n", longopts, NULL)) != -1) {
181 for (i = 1; i < argc; i++) { 205 switch (c) {
182 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { 206 case 'd':
183 idevice_set_debug_level(1); 207 idevice_set_debug_level(1);
184 continue; 208 break;
185 } 209 case 'u':
186 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { 210 if (!*optarg) {
187 i++; 211 fprintf(stderr, "ERROR: UDID must not be empty!\n");
188 if (!argv[i] || !*argv[i]) { 212 print_usage(argc, argv, 1);
189 print_usage(argc, argv); 213 return 2;
190 return 0;
191 } 214 }
192 udid = strdup(argv[i]); 215 free(udid);
193 continue; 216 udid = strdup(optarg);
194 } 217 break;
195 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { 218 case 'n':
196 print_usage(argc, argv); 219 lookup_opts |= IDEVICE_LOOKUP_PREFER_NETWORK;
197 return 0; 220 break;
198 } 221 case 'h':
199 else { 222 print_usage(argc, argv, 0);
200 print_usage(argc, argv);
201 return 0; 223 return 0;
224 default:
225 print_usage(argc, argv, 1);
226 return 2;
202 } 227 }
203 } 228 }
204 229
230 argc -= optind;
231 argv += optind;
232
205 int num = 0; 233 int num = 0;
206 char **devices = NULL; 234 idevice_info_t *devices = NULL;
207 idevice_get_device_list(&devices, &num); 235 idevice_get_device_list_extended(&devices, &num);
208 idevice_device_list_free(devices); 236 idevice_device_list_extended_free(devices);
209 if (num == 0) { 237 if (num == 0) {
210 if (!udid) { 238 if (!udid) {
211 fprintf(stderr, "No device found. Plug in a device or pass UDID with -u to wait for device to be available.\n"); 239 fprintf(stderr, "No device found. Plug in a device or pass UDID with -u to wait for device to be available.\n");
@@ -223,24 +251,7 @@ int main(int argc, char *argv[])
223 idevice_event_unsubscribe(); 251 idevice_event_unsubscribe();
224 stop_logging(); 252 stop_logging();
225 253
226 if (udid) { 254 free(udid);
227 free(udid);
228 }
229 255
230 return 0; 256 return 0;
231} 257}
232
233void print_usage(int argc, char **argv)
234{
235 char *name = NULL;
236
237 name = strrchr(argv[0], '/');
238 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
239 printf("Relay syslog of a connected device.\n\n");
240 printf(" -d, --debug\t\tenable communication debugging\n");
241 printf(" -u, --udid UDID\ttarget specific device by UDID\n");
242 printf(" -h, --help\t\tprints usage information\n");
243 printf("\n");
244 printf("Homepage: <" PACKAGE_URL ">\n");
245}
246