Skip to content

Commit ae1ba51

Browse files
committed
Merge pull request #2 from DanyL/feature/multi_process_filtering
Added support for multi process filtering
2 parents 8ebbdb9 + 0719dcf commit ae1ba51

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

main.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
static CFMutableDictionaryRef liveConnections;
1414
static int debug;
1515
static CFStringRef requiredDeviceId;
16-
static char *requiredProcessName;
16+
static char *requiredProcessNames;
1717
static regex_t *requiredRegex;
1818
static void (*printMessage)(int fd, const char *, size_t);
1919
static void (*printSeparator)(int fd);
@@ -75,7 +75,8 @@ static unsigned char should_print_message(const char *buffer, size_t length)
7575
find_space_offsets(buffer, length, space_offsets);
7676

7777
// Check whether process name matches the one passed to -p option and filter if needed
78-
if (requiredProcessName != NULL) {
78+
if (requiredProcessNames != NULL) {
79+
char *currentProcessName;
7980
int nameLength = space_offsets[1] - space_offsets[0]; //This size includes the NULL terminator.
8081

8182
char *processName = malloc(nameLength);
@@ -86,8 +87,15 @@ static unsigned char should_print_message(const char *buffer, size_t length)
8687
if (processName[i] == '[')
8788
processName[i] = '\0';
8889

89-
if (strcmp(processName, requiredProcessName) != 0)
90-
should_print = 0;
90+
currentProcessName = strtok(strdup(requiredProcessNames), ", ");
91+
while (currentProcessName != NULL) {
92+
should_print = (strcmp(processName, currentProcessName) == 0);
93+
94+
if (should_print)
95+
break;
96+
97+
currentProcessName = strtok(NULL, ", ");
98+
}
9199

92100
free(processName);
93101
}
@@ -321,7 +329,7 @@ static void color_separator(int fd)
321329
int main (int argc, char * const argv[])
322330
{
323331
if ((argc == 2) && (strcmp(argv[1], "--help") == 0)) {
324-
fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\t\tInclude connect/disconnect messages in standard out\n -u <udid>\t\t\tShow only logs from a specific device\n -p <process name>\t\tShow only logs from a specific process\n -r <regular expression>\tFilter messages by regular expression.\n -x\t\t\t\tDisable tty coloring in Xcode (unless XcodeColors intalled).\n\nControl-C to disconnect\nMail bug reports and suggestions to <ryan.petrich@medialets.com>\n", argv[0]);
332+
fprintf(stderr, "Usage: %s [options]\nOptions:\n -d\t\t\t\tInclude connect/disconnect messages in standard out\n -u <udid>\t\t\tShow only logs from a specific device\n -p <\"process name, process name\">\t\tShow only logs from a specific process\n -r <regular expression>\tFilter messages by regular expression.\n -x\t\t\t\tDisable tty coloring in Xcode (unless XcodeColors intalled).\n\nControl-C to disconnect\nMail bug reports and suggestions to <ryan.petrich@medialets.com>\n", argv[0]);
325333
return 1;
326334
}
327335
int c;
@@ -351,10 +359,10 @@ int main (int argc, char * const argv[])
351359
requiredDeviceId = CFStringCreateWithCString(kCFAllocatorDefault, optarg, kCFStringEncodingASCII);
352360
break;
353361
case 'p':
354-
requiredProcessName = malloc(strlen(optarg) + 1);
355-
requiredProcessName[strlen(optarg)] = '\0';
362+
requiredProcessNames = malloc(strlen(optarg) + 1);
363+
requiredProcessNames[strlen(optarg)] = '\0';
356364

357-
strcpy(requiredProcessName, optarg);
365+
strcpy(requiredProcessNames, optarg);
358366
break;
359367
case 'r':
360368
requiredRegex = malloc(sizeof(regex_t));

0 commit comments

Comments
 (0)