diff options
| author | 2013-05-23 14:15:40 +0200 | |
|---|---|---|
| committer | 2013-05-23 14:15:40 +0200 | |
| commit | abad8cbf298a09627eda4a53024907cef92aa01f (patch) | |
| tree | ddd1cbeacbb2b8bed9b50d197c5aab111a9fb618 | |
| parent | 06d2399461182e0c0c113fb473902e204117641e (diff) | |
| download | libimobiledevice-abad8cbf298a09627eda4a53024907cef92aa01f.tar.gz libimobiledevice-abad8cbf298a09627eda4a53024907cef92aa01f.tar.bz2 | |
idevicesyslog: Switch code to new syslog_relay service interface
| -rw-r--r-- | tools/Makefile.am | 2 | ||||
| -rw-r--r-- | tools/idevicesyslog.c | 74 |
2 files changed, 26 insertions, 50 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index fe9b1fa..fe0ec5d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -18,7 +18,7 @@ idevicepair_LDADD = $(top_srcdir)/common/libinternalcommon.la ../src/libimobiled | |||
| 18 | idevicesyslog_SOURCES = idevicesyslog.c | 18 | idevicesyslog_SOURCES = idevicesyslog.c |
| 19 | idevicesyslog_CFLAGS = $(AM_CFLAGS) | 19 | idevicesyslog_CFLAGS = $(AM_CFLAGS) |
| 20 | idevicesyslog_LDFLAGS = $(AM_LDFLAGS) | 20 | idevicesyslog_LDFLAGS = $(AM_LDFLAGS) |
| 21 | idevicesyslog_LDADD = $(top_srcdir)/common/libinternalcommon.la ../src/libimobiledevice.la | 21 | idevicesyslog_LDADD = ../src/libimobiledevice.la |
| 22 | 22 | ||
| 23 | idevice_id_SOURCES = idevice_id.c | 23 | idevice_id_SOURCES = idevice_id.c |
| 24 | idevice_id_CFLAGS = $(AM_CFLAGS) | 24 | idevice_id_CFLAGS = $(AM_CFLAGS) |
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c index 3dd2257..6836191 100644 --- a/tools/idevicesyslog.c +++ b/tools/idevicesyslog.c | |||
| @@ -33,9 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | #include <libimobiledevice/libimobiledevice.h> | 34 | #include <libimobiledevice/libimobiledevice.h> |
| 35 | #include <libimobiledevice/lockdown.h> | 35 | #include <libimobiledevice/lockdown.h> |
| 36 | 36 | #include <libimobiledevice/syslog_relay.h> | |
| 37 | #include "src/service.h" | ||
| 38 | #include "common/thread.h" | ||
| 39 | 37 | ||
| 40 | static int quit_flag = 0; | 38 | static int quit_flag = 0; |
| 41 | 39 | ||
| @@ -44,36 +42,11 @@ void print_usage(int argc, char **argv); | |||
| 44 | static char* udid = NULL; | 42 | static char* udid = NULL; |
| 45 | 43 | ||
| 46 | static idevice_t device = NULL; | 44 | static idevice_t device = NULL; |
| 47 | static service_client_t syslog = NULL; | 45 | static syslog_relay_client_t syslog = NULL; |
| 48 | |||
| 49 | thread_t worker = NULL; | ||
| 50 | |||
| 51 | static int logging = 0; | ||
| 52 | 46 | ||
| 53 | static void *syslog_worker(void *arg) | 47 | static void syslog_callback(char c, void *user_data) |
| 54 | { | 48 | { |
| 55 | service_error_t ret = SERVICE_E_UNKNOWN_ERROR; | 49 | putchar(c); |
| 56 | |||
| 57 | fprintf(stdout, "[connected]\n"); | ||
| 58 | fflush(stdout); | ||
| 59 | |||
| 60 | logging = 1; | ||
| 61 | |||
| 62 | while (logging) { | ||
| 63 | char c; | ||
| 64 | uint32_t bytes = 0; | ||
| 65 | ret = service_receive_with_timeout(syslog, &c, 1, &bytes, 0); | ||
| 66 | if (ret < 0 || (bytes != 1)) { | ||
| 67 | printf("\n[connection interrupted]\n"); | ||
| 68 | fflush(stdout); | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | if(c != 0) { | ||
| 72 | putchar(c); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | return NULL; | ||
| 77 | } | 50 | } |
| 78 | 51 | ||
| 79 | static int start_logging() | 52 | static int start_logging() |
| @@ -85,36 +58,39 @@ static int start_logging() | |||
| 85 | } | 58 | } |
| 86 | 59 | ||
| 87 | /* start and connect to syslog_relay service */ | 60 | /* start and connect to syslog_relay service */ |
| 88 | service_error_t serr = SERVICE_E_UNKNOWN_ERROR; | 61 | syslog_relay_error_t serr = SYSLOG_RELAY_E_UNKNOWN_ERROR; |
| 89 | service_client_factory_start_service(device, "com.apple.syslog_relay", (void**)&syslog, "idevicesyslog", NULL, &serr); | 62 | serr = syslog_relay_client_start_service(device, &syslog, "idevicesyslog"); |
| 90 | if (serr != SERVICE_E_SUCCESS) { | 63 | if (serr != SYSLOG_RELAY_E_SUCCESS) { |
| 91 | fprintf(stderr, "ERROR: Could not start service com.apple.syslog_relay.\n"); | 64 | fprintf(stderr, "ERROR: Could not start service com.apple.syslog_relay.\n"); |
| 92 | idevice_free(device); | 65 | idevice_free(device); |
| 93 | device = NULL; | 66 | device = NULL; |
| 94 | return -1; | 67 | return -1; |
| 95 | } | 68 | } |
| 96 | 69 | ||
| 97 | /* start worker thread */ | 70 | /* start capturing syslog */ |
| 98 | logging = 1; | 71 | serr = syslog_relay_start_capture(syslog, syslog_callback, NULL); |
| 99 | if (thread_create(&worker, syslog_worker, NULL) != 0) { | 72 | if (serr != SYSLOG_RELAY_E_SUCCESS) { |
| 100 | logging = 0; | 73 | fprintf(stderr, "ERROR: Unable tot start capturing syslog.\n"); |
| 74 | syslog_relay_client_free(syslog); | ||
| 75 | syslog = NULL; | ||
| 76 | idevice_free(device); | ||
| 77 | device = NULL; | ||
| 101 | return -1; | 78 | return -1; |
| 102 | } | 79 | } |
| 80 | |||
| 81 | fprintf(stdout, "[connected]\n"); | ||
| 82 | fflush(stdout); | ||
| 83 | |||
| 103 | return 0; | 84 | return 0; |
| 104 | } | 85 | } |
| 105 | 86 | ||
| 106 | static void stop_logging() | 87 | static void stop_logging() |
| 107 | { | 88 | { |
| 108 | if (logging) { | 89 | fflush(stdout); |
| 109 | /* notify thread to finish */ | ||
| 110 | logging = 0; | ||
| 111 | if (syslog) { | ||
| 112 | service_client_free(syslog); | ||
| 113 | syslog = NULL; | ||
| 114 | } | ||
| 115 | 90 | ||
| 116 | /* wait for thread to complete */ | 91 | if (syslog) { |
| 117 | thread_join(worker); | 92 | syslog_relay_client_free(syslog); |
| 93 | syslog = NULL; | ||
| 118 | } | 94 | } |
| 119 | 95 | ||
| 120 | if (device) { | 96 | if (device) { |
| @@ -126,7 +102,7 @@ static void stop_logging() | |||
| 126 | static void device_event_cb(const idevice_event_t* event, void* userdata) | 102 | static void device_event_cb(const idevice_event_t* event, void* userdata) |
| 127 | { | 103 | { |
| 128 | if (event->event == IDEVICE_DEVICE_ADD) { | 104 | if (event->event == IDEVICE_DEVICE_ADD) { |
| 129 | if (!logging) { | 105 | if (!syslog) { |
| 130 | if (!udid) { | 106 | if (!udid) { |
| 131 | udid = strdup(event->udid); | 107 | udid = strdup(event->udid); |
| 132 | } | 108 | } |
| @@ -137,7 +113,7 @@ static void device_event_cb(const idevice_event_t* event, void* userdata) | |||
| 137 | } | 113 | } |
| 138 | } | 114 | } |
| 139 | } else if (event->event == IDEVICE_DEVICE_REMOVE) { | 115 | } else if (event->event == IDEVICE_DEVICE_REMOVE) { |
| 140 | if (logging && (strcmp(udid, event->udid) == 0)) { | 116 | if (syslog && (strcmp(udid, event->udid) == 0)) { |
| 141 | stop_logging(); | 117 | stop_logging(); |
| 142 | } | 118 | } |
| 143 | } | 119 | } |
