1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // fork+exec.cfa -- Check that we can use fork+exec to test parameters. |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Wed Sep 27 10:44:38 2022 |
---|
11 | // Last Modified By : |
---|
12 | // Last Modified On : |
---|
13 | // Update Count : |
---|
14 | // |
---|
15 | |
---|
16 | #include "fork+exec.hfa" |
---|
17 | |
---|
18 | int main(int argc, char * argv[]) { |
---|
19 | check_main(argv[0]); |
---|
20 | |
---|
21 | printf("arguments are:\n"); |
---|
22 | if(argc == 1) printf(" None\n"); |
---|
23 | for(int i = 1; i < argc; i++) { |
---|
24 | printf(" '%s'\n", argv[i]); |
---|
25 | } |
---|
26 | |
---|
27 | printf("Success!\n"); |
---|
28 | fflush(stdout); |
---|
29 | return 0; |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | int true_main(const char * path, char * env[]) { |
---|
35 | printf("no arg:\n"); |
---|
36 | if(pid_t child = strict_fork(); child == 0) { |
---|
37 | int ret = execle(path, path, (const char*)0p, env); |
---|
38 | if(ret < 0) { |
---|
39 | fprintf(stderr, "Execl 1 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
40 | exit(1); |
---|
41 | } |
---|
42 | } |
---|
43 | else { |
---|
44 | int status = do_wait(child); |
---|
45 | print_status(status); |
---|
46 | } |
---|
47 | |
---|
48 | printf("1 arg:\n"); |
---|
49 | if(pid_t child = strict_fork(); child == 0) { |
---|
50 | int ret = execle(path, path, "Hello World!", (const char*)0p, env); |
---|
51 | if(ret < 0) { |
---|
52 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
53 | exit(1); |
---|
54 | } |
---|
55 | } |
---|
56 | else { |
---|
57 | int status = do_wait(child); |
---|
58 | print_status(status); |
---|
59 | } |
---|
60 | |
---|
61 | printf("5 arg:\n"); |
---|
62 | if(pid_t child = strict_fork(); child == 0) { |
---|
63 | int ret = execle(path, path, "Hi,", "my", "name", "is", "Fred", (const char*)0p, env); |
---|
64 | if(ret < 0) { |
---|
65 | fprintf(stderr, "Execl 3 returned with error: %d '%s'\n", errno, strerror(errno)); |
---|
66 | exit(1); |
---|
67 | } |
---|
68 | } |
---|
69 | else { |
---|
70 | int status = do_wait(child); |
---|
71 | print_status(status); |
---|
72 | } |
---|
73 | |
---|
74 | printf("All Done!\n"); |
---|
75 | |
---|
76 | return 0; |
---|
77 | } |
---|