summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Ben Wagner2020-02-06 14:20:44 -0500
committerGravatar Nikias Bassen2022-03-29 11:59:43 +0200
commitdd52f8ffc25032dd1ec5fb6a39e97a7c3a848d10 (patch)
treea84540bc0f1b82853ff7942128f5d5e9982af5de
parent94ed8c464dee51191f16b5758f090e920fb4d3e1 (diff)
downloadlibimobiledevice-dd52f8ffc25032dd1ec5fb6a39e97a7c3a848d10.tar.gz
libimobiledevice-dd52f8ffc25032dd1ec5fb6a39e97a7c3a848d10.tar.bz2
idevicedebug: Process "Wxx" response as "exited with code xx"
-rw-r--r--tools/idevicedebug.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c
index a9ef5c6..7b49a46 100644
--- a/tools/idevicedebug.c
+++ b/tools/idevicedebug.c
@@ -108,7 +108,7 @@ static instproxy_error_t instproxy_client_get_object_by_key_from_info_dictionary
108 return INSTPROXY_E_SUCCESS; 108 return INSTPROXY_E_SUCCESS;
109} 109}
110 110
111static debugserver_error_t debugserver_client_handle_response(debugserver_client_t client, char** response, int send_reply) 111static debugserver_error_t debugserver_client_handle_response(debugserver_client_t client, char** response, int send_reply, int* exit_status)
112{ 112{
113 debugserver_error_t dres = DEBUGSERVER_E_SUCCESS; 113 debugserver_error_t dres = DEBUGSERVER_E_SUCCESS;
114 debugserver_command_t command = NULL; 114 debugserver_command_t command = NULL;
@@ -149,12 +149,24 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
149 149
150 dres = DEBUGSERVER_E_UNKNOWN_ERROR; 150 dres = DEBUGSERVER_E_UNKNOWN_ERROR;
151 } else if (r[0] == 'E' || r[0] == 'W') { 151 } else if (r[0] == 'E' || r[0] == 'W') {
152 printf("%s: %s\n", (r[0] == 'E' ? "ERROR": "WARNING") , r + 1); 152 debugserver_decode_string(r + 1, strlen(r) - 1, &o);
153 153 /* dogben: 'W' + byte seems to mean "process exited with this status." */
154 if (r[0] == 'W' && strlen(o) == 1) {
155 printf("Exit status: %u\n", o[0]);
156 if (exit_status != NULL) {
157 *exit_status = o[0];
158 }
159 } else {
160 printf("%s: %s\n", (r[0] == 'E' ? "ERROR": "WARNING") , o);
161 }
162 if (o != NULL) {
163 free(o);
164 o = NULL;
165 }
154 free(*response); 166 free(*response);
155 *response = NULL; 167 *response = NULL;
156 168
157 if (!send_reply) 169 if (!send_reply || (exit_status != NULL && *exit_status >= 0))
158 return dres; 170 return dres;
159 171
160 /* send reply */ 172 /* send reply */
@@ -229,6 +241,7 @@ int main(int argc, char *argv[])
229 char* response = NULL; 241 char* response = NULL;
230 debugserver_command_t command = NULL; 242 debugserver_command_t command = NULL;
231 debugserver_error_t dres = DEBUGSERVER_E_UNKNOWN_ERROR; 243 debugserver_error_t dres = DEBUGSERVER_E_UNKNOWN_ERROR;
244 int exit_status = -1;
232 245
233 /* map signals */ 246 /* map signals */
234 signal(SIGINT, on_signal); 247 signal(SIGINT, on_signal);
@@ -376,7 +389,7 @@ int main(int argc, char *argv[])
376 command = NULL; 389 command = NULL;
377 if (response) { 390 if (response) {
378 if (strncmp(response, "OK", 2)) { 391 if (strncmp(response, "OK", 2)) {
379 debugserver_client_handle_response(debugserver_client, &response, 0); 392 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
380 goto cleanup; 393 goto cleanup;
381 } 394 }
382 free(response); 395 free(response);
@@ -394,7 +407,7 @@ int main(int argc, char *argv[])
394 command = NULL; 407 command = NULL;
395 if (response) { 408 if (response) {
396 if (strncmp(response, "OK", 2)) { 409 if (strncmp(response, "OK", 2)) {
397 debugserver_client_handle_response(debugserver_client, &response, 0); 410 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
398 goto cleanup; 411 goto cleanup;
399 } 412 }
400 free(response); 413 free(response);
@@ -410,7 +423,7 @@ int main(int argc, char *argv[])
410 command = NULL; 423 command = NULL;
411 if (response) { 424 if (response) {
412 if (strncmp(response, "OK", 2)) { 425 if (strncmp(response, "OK", 2)) {
413 debugserver_client_handle_response(debugserver_client, &response, 0); 426 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
414 goto cleanup; 427 goto cleanup;
415 } 428 }
416 free(response); 429 free(response);
@@ -451,7 +464,7 @@ int main(int argc, char *argv[])
451 command = NULL; 464 command = NULL;
452 if (response) { 465 if (response) {
453 if (strncmp(response, "OK", 2)) { 466 if (strncmp(response, "OK", 2)) {
454 debugserver_client_handle_response(debugserver_client, &response, 0); 467 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
455 goto cleanup; 468 goto cleanup;
456 } 469 }
457 free(response); 470 free(response);
@@ -477,7 +490,7 @@ int main(int argc, char *argv[])
477 command = NULL; 490 command = NULL;
478 if (response) { 491 if (response) {
479 if (strncmp(response, "OK", 2)) { 492 if (strncmp(response, "OK", 2)) {
480 debugserver_client_handle_response(debugserver_client, &response, 0); 493 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
481 goto cleanup; 494 goto cleanup;
482 } 495 }
483 free(response); 496 free(response);
@@ -502,9 +515,12 @@ int main(int argc, char *argv[])
502 if (response) { 515 if (response) {
503 log_debug("response: %s", response); 516 log_debug("response: %s", response);
504 if (strncmp(response, "OK", 2)) { 517 if (strncmp(response, "OK", 2)) {
505 dres = debugserver_client_handle_response(debugserver_client, &response, 1); 518 dres = debugserver_client_handle_response(debugserver_client, &response, 1, &exit_status);
506 } 519 }
507 } 520 }
521 if (exit_status > 0) {
522 goto cleanup;
523 }
508 524
509 sleep(1); 525 sleep(1);
510 } 526 }
@@ -517,7 +533,7 @@ int main(int argc, char *argv[])
517 command = NULL; 533 command = NULL;
518 if (response) { 534 if (response) {
519 if (strncmp(response, "OK", 2)) { 535 if (strncmp(response, "OK", 2)) {
520 debugserver_client_handle_response(debugserver_client, &response, 0); 536 debugserver_client_handle_response(debugserver_client, &response, 0, NULL);
521 goto cleanup; 537 goto cleanup;
522 } 538 }
523 free(response); 539 free(response);
@@ -552,5 +568,9 @@ cleanup:
552 if (device) 568 if (device)
553 idevice_free(device); 569 idevice_free(device);
554 570
555 return res; 571 if (exit_status > 0) {
572 return exit_status;
573 } else {
574 return res;
575 }
556} 576}