diff options
| author | 2025-06-14 03:01:02 +0200 | |
|---|---|---|
| committer | 2025-06-14 03:01:02 +0200 | |
| commit | 34b170f03ab97b7c9ab6cf009cd8da280c6db97c (patch) | |
| tree | d04de2f33c932071c3d8ac64938a2ee8489a3e06 | |
| parent | 8d048f454e623957dc42379565bb1ae247b3093f (diff) | |
| download | libimobiledevice-34b170f03ab97b7c9ab6cf009cd8da280c6db97c.tar.gz libimobiledevice-34b170f03ab97b7c9ab6cf009cd8da280c6db97c.tar.bz2 | |
idevicesyslog: Use ostrace's pid filter if possible
| -rw-r--r-- | tools/idevicesyslog.c | 84 |
1 files changed, 79 insertions, 5 deletions
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c index 67eaf69..830b76a 100644 --- a/tools/idevicesyslog.c +++ b/tools/idevicesyslog.c | |||
| @@ -542,12 +542,69 @@ static void ostrace_syslog_callback(const void* buf, size_t len, void* user_data | |||
| 542 | } | 542 | } |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | static plist_t get_pid_list() | ||
| 546 | { | ||
| 547 | plist_t list = NULL; | ||
| 548 | ostrace_client_t ostrace_tmp = NULL; | ||
| 549 | ostrace_client_start_service(device, &ostrace_tmp, TOOL_NAME); | ||
| 550 | if (ostrace_tmp) { | ||
| 551 | ostrace_get_pid_list(ostrace_tmp, &list); | ||
| 552 | ostrace_client_free(ostrace_tmp); | ||
| 553 | } | ||
| 554 | return list; | ||
| 555 | } | ||
| 556 | |||
| 557 | static int pid_valid(int pid) | ||
| 558 | { | ||
| 559 | plist_t list = get_pid_list(); | ||
| 560 | if (!list) return 0; | ||
| 561 | char valbuf[16]; | ||
| 562 | snprintf(valbuf, 16, "%d", pid); | ||
| 563 | return (plist_dict_get_item(list, valbuf)) ? 1 : 0; | ||
| 564 | } | ||
| 565 | |||
| 566 | static int pid_for_proc(const char* procname) | ||
| 567 | { | ||
| 568 | int result = -1; | ||
| 569 | plist_t list = get_pid_list(); | ||
| 570 | if (!list) { | ||
| 571 | return result; | ||
| 572 | } | ||
| 573 | plist_dict_iter iter = NULL; | ||
| 574 | plist_dict_new_iter(list, &iter); | ||
| 575 | if (iter) { | ||
| 576 | plist_t node = NULL; | ||
| 577 | do { | ||
| 578 | char* key = NULL; | ||
| 579 | node = NULL; | ||
| 580 | plist_dict_next_item(list, iter, &key, &node); | ||
| 581 | if (!key) { | ||
| 582 | break; | ||
| 583 | } | ||
| 584 | if (PLIST_IS_DICT(node)) { | ||
| 585 | plist_t pname = plist_dict_get_item(node, "ProcessName"); | ||
| 586 | if (PLIST_IS_STRING(pname)) { | ||
| 587 | if (!strcmp(plist_get_string_ptr(pname, NULL), procname)) { | ||
| 588 | result = (int)strtol(key, NULL, 10); | ||
| 589 | } | ||
| 590 | } | ||
| 591 | } | ||
| 592 | free(key); | ||
| 593 | } while (node); | ||
| 594 | plist_mem_free(iter); | ||
| 595 | } | ||
| 596 | plist_free(list); | ||
| 597 | return result; | ||
| 598 | } | ||
| 599 | |||
| 545 | static int connect_service(int ostrace_required) | 600 | static int connect_service(int ostrace_required) |
| 546 | { | 601 | { |
| 547 | idevice_error_t ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX); | 602 | if (!device) { |
| 548 | if (ret != IDEVICE_E_SUCCESS) { | 603 | idevice_error_t ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX); |
| 549 | fprintf(stderr, "Device with udid %s not found!?\n", udid); | 604 | if (ret != IDEVICE_E_SUCCESS) { |
| 550 | return -1; | 605 | fprintf(stderr, "Device with udid %s not found!?\n", udid); |
| 606 | return -1; | ||
| 607 | } | ||
| 551 | } | 608 | } |
| 552 | 609 | ||
| 553 | lockdownd_client_t lockdown = NULL; | 610 | lockdownd_client_t lockdown = NULL; |
| @@ -628,7 +685,24 @@ static int start_logging(void) | |||
| 628 | 685 | ||
| 629 | /* start capturing syslog */ | 686 | /* start capturing syslog */ |
| 630 | if (ostrace) { | 687 | if (ostrace) { |
| 631 | ostrace_error_t serr = ostrace_start_activity(ostrace, NULL, ostrace_syslog_callback, NULL); | 688 | plist_t options = plist_new_dict(); |
| 689 | if (num_proc_filters == 0 && num_pid_filters == 1 && !proc_filter_excluding) { | ||
| 690 | if (pid_filters[0] > 0) { | ||
| 691 | if (!pid_valid(pid_filters[0])) { | ||
| 692 | fprintf(stderr, "NOTE: A process with pid doesn't exists!\n"); | ||
| 693 | } | ||
| 694 | } | ||
| 695 | plist_dict_set_item(options, "Pid", plist_new_int(pid_filters[0])); | ||
| 696 | } else if (num_proc_filters == 1 && num_pid_filters == 0 && !proc_filter_excluding) { | ||
| 697 | int pid = pid_for_proc(proc_filters[0]); | ||
| 698 | if (!strcmp(proc_filters[0], "kernel")) { | ||
| 699 | pid = 0; | ||
| 700 | } | ||
| 701 | if (pid >= 0) { | ||
| 702 | plist_dict_set_item(options, "Pid", plist_new_int(pid)); | ||
| 703 | } | ||
| 704 | } | ||
| 705 | ostrace_error_t serr = ostrace_start_activity(ostrace, options, ostrace_syslog_callback, NULL); | ||
| 632 | if (serr != OSTRACE_E_SUCCESS) { | 706 | if (serr != OSTRACE_E_SUCCESS) { |
| 633 | fprintf(stderr, "ERROR: Unable to start capturing syslog.\n"); | 707 | fprintf(stderr, "ERROR: Unable to start capturing syslog.\n"); |
| 634 | ostrace_client_free(ostrace); | 708 | ostrace_client_free(ostrace); |
