summaryrefslogtreecommitdiffstats
path: root/tools/idevicesyslog.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevicesyslog.c')
-rw-r--r--tools/idevicesyslog.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 6ce6d0e..44c8246 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -28,6 +28,7 @@
28#include <libimobiledevice/libimobiledevice.h> 28#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h> 29#include <libimobiledevice/lockdown.h>
30#include <endianness.h> 30#include <endianness.h>
31#include "../src/service.h"
31 32
32static int quit_flag = 0; 33static int quit_flag = 0;
33 34
@@ -44,12 +45,10 @@ static void clean_exit(int sig)
44 45
45int main(int argc, char *argv[]) 46int main(int argc, char *argv[])
46{ 47{
47 lockdownd_client_t client = NULL;
48 idevice_t device = NULL; 48 idevice_t device = NULL;
49 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 49 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
50 int i; 50 int i;
51 const char* udid = NULL; 51 const char* udid = NULL;
52 lockdownd_service_descriptor_t service = NULL;
53 52
54 signal(SIGINT, clean_exit); 53 signal(SIGINT, clean_exit);
55 signal(SIGTERM, clean_exit); 54 signal(SIGTERM, clean_exit);
@@ -93,42 +92,27 @@ int main(int argc, char *argv[])
93 return -1; 92 return -1;
94 } 93 }
95 94
96 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &client, "idevicesyslog")) { 95 service_error_t serr = SERVICE_E_UNKNOWN_ERROR;
97 idevice_free(device); 96 service_client_t syslog = NULL;
98 return -1; 97
99 } 98 service_client_factory_start_service(device, "com.apple.syslog_relay", (void**)&syslog, "idevicesyslog", NULL, &serr);
100 99 if (serr == SERVICE_E_SUCCESS) {
101 /* start syslog_relay service and retrieve port */ 100 while (!quit_flag) {
102 ret = lockdownd_start_service(client, "com.apple.syslog_relay", &service); 101 char c;
103 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { 102 uint32_t bytes = 0;
104 lockdownd_client_free(client); 103 if (service_receive(syslog, &c, 1, &bytes) != SERVICE_E_SUCCESS) {
105 104 fprintf(stderr, "Error receiving data. Exiting...\n");
106 /* connect to socket relay messages */ 105 break;
107 idevice_connection_t conn = NULL; 106 }
108 if ((idevice_connect(device, service->port, &conn) != IDEVICE_E_SUCCESS) || !conn) { 107 if (c != 0) {
109 printf("ERROR: Could not open usbmux connection.\n"); 108 putchar(c);
110 } else { 109 fflush(stdout);
111 while (!quit_flag) {
112 char c;
113 uint32_t bytes = 0;
114 if (idevice_connection_receive(conn, &c, 1, &bytes) < 0) {
115 fprintf(stderr, "Error receiving data. Exiting...\n");
116 break;
117 }
118 if (c != 0) {
119 putchar(c);
120 fflush(stdout);
121 }
122 } 110 }
123 } 111 }
124 idevice_disconnect(conn); 112 service_client_free(syslog);
125 } else { 113 } else {
126 printf("ERROR: Could not start service com.apple.syslog_relay.\n"); 114 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
127 } 115 }
128
129 if (service)
130 lockdownd_service_descriptor_free(service);
131
132 idevice_free(device); 116 idevice_free(device);
133 117
134 return 0; 118 return 0;