summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Will Han2025-06-07 23:38:55 +0800
committerGravatar Nikias Bassen2025-06-08 03:26:08 +0200
commit4c50979bdf20d8d17281463cef7cd4c848f6d79d (patch)
tree9ffe94c8c1b1f75b2170c5d084744174156ac8ec
parent009b98206be4cd075c592ccf187d5237c7238b89 (diff)
downloadlibimobiledevice-4c50979bdf20d8d17281463cef7cd4c848f6d79d.tar.gz
libimobiledevice-4c50979bdf20d8d17281463cef7cd4c848f6d79d.tar.bz2
Add unmatch filter option to idevicesyslog.
The new -M/--unmatch option allows filtering out messages containing specific strings, complementing the existing -m/--match functionality. This provides more flexible log filtering capabilities for users.
-rw-r--r--docs/idevicesyslog.15
-rw-r--r--tools/idevicesyslog.c46
2 files changed, 49 insertions, 2 deletions
diff --git a/docs/idevicesyslog.1 b/docs/idevicesyslog.1
index 66ae2e4..ae4aff2 100644
--- a/docs/idevicesyslog.1
+++ b/docs/idevicesyslog.1
@@ -44,6 +44,11 @@ Force writing colored output, e.g. when using \f[B]\-\-output\f[].
44.B \-m, \-\-match STRING 44.B \-m, \-\-match STRING
45only print messages that contain STRING 45only print messages that contain STRING
46 46
47.SH FILTER OPTIONS
48.TP
49.B \-M, \-\-unmatch STRING
50print messages that not contain STRING
51
47This option will set a filter to only printed log messages that contain the given string. 52This option will set a filter to only printed log messages that contain the given string.
48.TP 53.TP
49.B \-t, \-\-trigger STRING 54.B \-t, \-\-trigger STRING
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index dbd7b01..f185f3a 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -58,6 +58,9 @@ static int num_pid_filters = 0;
58static char** msg_filters = NULL; 58static char** msg_filters = NULL;
59static int num_msg_filters = 0; 59static int num_msg_filters = 0;
60 60
61static char** msg_reverse_filters = NULL;
62static int num_msg_reverse_filters = 0;
63
61static char** trigger_filters = NULL; 64static char** trigger_filters = NULL;
62static int num_trigger_filters = 0; 65static int num_trigger_filters = 0;
63static char** untrigger_filters = NULL; 66static char** untrigger_filters = NULL;
@@ -217,6 +220,21 @@ static void syslog_callback(char c, void *user_data)
217 } 220 }
218 shall_print = 1; 221 shall_print = 1;
219 } 222 }
223 if (num_msg_reverse_filters > 0) {
224 int found = 0;
225 int i;
226 for (i = 0; i < num_msg_reverse_filters; i++) {
227 if (strstr(device_name_end+1, msg_reverse_filters[i])) {
228 found = 1;
229 break;
230 }
231 }
232 if (found) {
233 shall_print = 0;
234 break;
235 }
236 shall_print = 1;
237 }
220 238
221 /* process name */ 239 /* process name */
222 char* proc_name_start = p; 240 char* proc_name_start = p;
@@ -331,7 +349,7 @@ static void syslog_callback(char c, void *user_data)
331 } 349 }
332 } while (0); 350 } while (0);
333 351
334 if ((num_msg_filters == 0 && num_proc_filters == 0 && num_pid_filters == 0 && num_trigger_filters == 0 && num_untrigger_filters == 0) || shall_print) { 352 if ((num_msg_filters == 0 && num_msg_reverse_filters == 0 && num_proc_filters == 0 && num_pid_filters == 0 && num_trigger_filters == 0 && num_untrigger_filters == 0) || shall_print) {
335 fwrite(linep, 1, lp, stdout); 353 fwrite(linep, 1, lp, stdout);
336 cprintf(COLOR_RESET); 354 cprintf(COLOR_RESET);
337 fflush(stdout); 355 fflush(stdout);
@@ -487,6 +505,7 @@ static void print_usage(int argc, char **argv, int is_error)
487 "\n" 505 "\n"
488 "FILTER OPTIONS:\n" 506 "FILTER OPTIONS:\n"
489 " -m, --match STRING only print messages that contain STRING\n" 507 " -m, --match STRING only print messages that contain STRING\n"
508 " -M, --unmatch STRING print messages that not contain STRING\n"
490 " -t, --trigger STRING start logging when matching STRING\n" 509 " -t, --trigger STRING start logging when matching STRING\n"
491 " -T, --untrigger STRING stop logging when matching STRING\n" 510 " -T, --untrigger STRING stop logging when matching STRING\n"
492 " -p, --process PROCESS only print messages from matching process(es)\n" 511 " -p, --process PROCESS only print messages from matching process(es)\n"
@@ -542,7 +561,7 @@ int main(int argc, char *argv[])
542 signal(SIGPIPE, SIG_IGN); 561 signal(SIGPIPE, SIG_IGN);
543#endif 562#endif
544 563
545 while ((c = getopt_long(argc, argv, "dhu:nxt:T:m:e:p:qkKo:v", longopts, NULL)) != -1) { 564 while ((c = getopt_long(argc, argv, "dhu:nxt:T:m:M:e:p:qkKo:v", longopts, NULL)) != -1) {
546 switch (c) { 565 switch (c) {
547 case 'd': 566 case 'd':
548 idevice_set_debug_level(1); 567 idevice_set_debug_level(1);
@@ -593,6 +612,22 @@ int main(int argc, char *argv[])
593 num_msg_filters++; 612 num_msg_filters++;
594 } 613 }
595 break; 614 break;
615 case 'M':
616 if (!*optarg) {
617 fprintf(stderr, "ERROR: reverse message filter string must not be empty!\n");
618 print_usage(argc, argv, 1);
619 return 2;
620 } else {
621 char **new_msg_filters = realloc(msg_reverse_filters, sizeof(char*) * (num_msg_reverse_filters+1));
622 if (!new_msg_filters) {
623 fprintf(stderr, "ERROR: realloc() failed\n");
624 exit(EXIT_FAILURE);
625 }
626 msg_reverse_filters = new_msg_filters;
627 msg_reverse_filters[num_msg_reverse_filters] = strdup(optarg);
628 num_msg_reverse_filters++;
629 }
630 break;
596 case 't': 631 case 't':
597 if (!*optarg) { 632 if (!*optarg) {
598 fprintf(stderr, "ERROR: trigger filter string must not be empty!\n"); 633 fprintf(stderr, "ERROR: trigger filter string must not be empty!\n");
@@ -761,6 +796,13 @@ int main(int argc, char *argv[])
761 } 796 }
762 free(msg_filters); 797 free(msg_filters);
763 } 798 }
799 if (num_msg_reverse_filters > 0) {
800 int i;
801 for (i = 0; i < num_msg_reverse_filters; i++) {
802 free(msg_reverse_filters[i]);
803 }
804 free(msg_reverse_filters);
805 }
764 if (num_trigger_filters > 0) { 806 if (num_trigger_filters > 0) {
765 int i; 807 int i;
766 for (i = 0; i < num_trigger_filters; i++) { 808 for (i = 0; i < num_trigger_filters; i++) {