]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/dyld_process_info_notify.dtest/target.c
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dyld_process_info_notify.dtest / target.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <dlfcn.h>
5 #include <signal.h>
6 #include <unistd.h>
7 #include <mach/mach.h>
8 #include <dispatch/dispatch.h>
9
10 void performDylibOperations(void) {
11 for (int i=0; i < 3; ++i) {
12 void* h = dlopen(RUN_DIR "/libfoo.dylib", 0);
13 dlclose(h);
14 }
15 fprintf(stderr, "Done (pid: %d)\n", getpid());
16 exit(0);
17 }
18
19 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
20 signal(SIGUSR1, SIG_IGN);
21 dispatch_source_t signalSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, getppid(),
22 DISPATCH_PROC_EXIT, dispatch_get_main_queue());
23 dispatch_source_set_event_handler(signalSource, ^{
24 exit(0);
25 });
26 dispatch_resume(signalSource);
27
28 if ( (argc > 1) && (strcmp(argv[1], "suspend-in-main") == 0) ) {
29 dispatch_source_t signalSourceSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL,
30 SIGUSR1, 0, dispatch_get_main_queue());
31 dispatch_source_set_event_handler(signalSourceSource, ^{
32 performDylibOperations();
33 });
34 dispatch_resume(signalSourceSource);
35 dispatch_async(dispatch_get_main_queue(), ^{
36 fprintf(stderr, "Ready (pid: %d)\n", getpid());
37 });
38 } else {
39 performDylibOperations();
40 }
41
42 dispatch_main();
43 }
44