From 20eefd15cf9a9ff60b8f60828cf1c00a025fcec9 Mon Sep 17 00:00:00 2001 From: Lu Yong Date: Mon, 15 Jun 2015 17:15:16 +0800 Subject: [PATCH] filter process with POSIX Extended Regular Expressions --- main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index da11003..77cb6b5 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include #include #include "MobileDevice.h" +#include typedef struct { service_conn_t connection; @@ -13,6 +14,7 @@ static CFMutableDictionaryRef liveConnections; static int debug; static CFStringRef requiredDeviceId; static char requiredProcessName[256]; +static regex_t requiredProcessNamePattern; static void (*printMessage)(int fd, const char *, size_t); static void (*printSeparator)(int fd); @@ -61,7 +63,7 @@ static unsigned char should_print_message(const char *buffer, size_t length) if (processName[i]=='[') processName[i]='\0'; - if (strcmp(processName, requiredProcessName)!=0) + if (regexec(&requiredProcessNamePattern, processName, 0, NULL, 0)) return 0; } @@ -303,6 +305,10 @@ int main (int argc, char * const argv[]) break; case 'p': strcpy(requiredProcessName, optarg); + if (regcomp(&requiredProcessNamePattern, requiredProcessName, REG_EXTENDED)) { + fprintf(stderr, "Could not compile regex\n"); + return 1; + } break; case '?': if (optopt == 'u')