Commit | Line | Data |
---|---|---|
e822f505 MD |
1 | /* |
2 | * Copyright (C) 2009 Pierre-Marc Fournier | |
3 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
a09dac63 PMF |
4 | * |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public | |
e822f505 MD |
7 | * License as published by the Free Software Foundation; version 2.1 of |
8 | * the License. | |
a09dac63 PMF |
9 | * |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
48c56fcf PMF |
20 | #include <stdio.h> |
21 | #include <unistd.h> | |
cab68136 | 22 | #include <sys/types.h> |
909bc43f | 23 | #include <stdlib.h> |
48c56fcf | 24 | |
e822f505 MD |
25 | #define TRACEPOINT_CREATE_PROBES |
26 | #include "ust_tests_fork.h" | |
48c56fcf | 27 | |
cab68136 | 28 | int main(int argc, char **argv, char *env[]) |
48c56fcf PMF |
29 | { |
30 | int result; | |
31 | ||
e822f505 | 32 | if (argc < 2) { |
cab68136 PMF |
33 | fprintf(stderr, "usage: fork PROG_TO_EXEC\n"); |
34 | exit(1); | |
35 | } | |
48c56fcf | 36 | |
cab68136 | 37 | printf("Fork test program, parent pid is %d\n", getpid()); |
e822f505 | 38 | tracepoint(ust_tests_fork_before_fork); |
36c95a5e | 39 | |
48c56fcf | 40 | result = fork(); |
e822f505 | 41 | if (result == -1) { |
48c56fcf PMF |
42 | perror("fork"); |
43 | return 1; | |
44 | } | |
e822f505 MD |
45 | if (result == 0) { |
46 | char *args[] = { "fork2", NULL }; | |
cab68136 PMF |
47 | |
48 | printf("Child pid is %d\n", getpid()); | |
49 | ||
e822f505 | 50 | tracepoint(ust_tests_fork_after_fork_child, getpid()); |
cab68136 PMF |
51 | |
52 | result = execve(argv[1], args, env); | |
e822f505 | 53 | if (result == -1) { |
cab68136 PMF |
54 | perror("execve"); |
55 | return 1; | |
56 | } | |
e822f505 MD |
57 | } else { |
58 | tracepoint(ust_tests_fork_after_fork_parent); | |
48c56fcf PMF |
59 | } |
60 | ||
61 | return 0; | |
62 | } |