dyld-750.5.tar.gz
[apple/dyld.git] / testing / nocr / nocr.cpp
1 #include <errno.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <mach/mach.h>
6
7 #include "test_support.h"
8
9 extern const char** environ;
10
11 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
12 if ( argc < 2 ) {
13 fprintf(stderr, "usage: nocr prog args...\n");
14 return EXIT_FAILURE;
15 }
16
17 _process process;
18 process.set_executable_path(argv[1]);
19 process.set_args(&argv[2]);
20 process.set_env(environ);
21 process.set_crash_handler(^(task_t task) {
22 exit(0);
23 });
24 process.set_exit_handler(^(pid_t pid) {
25 int status = 0;
26 (void)waitpid(pid, &status, 0);
27
28 // Only call exit if the child exited normally, otherwise keep running to consume the crash
29 if (WIFEXITED(status)) {
30 exit(0);
31 }
32 });
33 process.launch();
34 dispatch_main();
35 }