tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / ust / fork / fork.c
CommitLineData
37bd6c8e 1/*
9d16b343
MJ
2 * Copyright (C) 2009 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
37bd6c8e 4 *
9d16b343 5 * SPDX-License-Identifier: LGPL-2.1-only
37bd6c8e 6 *
37bd6c8e
JG
7 */
8
9#include <stdio.h>
10#include <unistd.h>
11#include <sys/types.h>
b871e4b3 12#include <sys/wait.h>
37bd6c8e
JG
13#include <stdlib.h>
14
15#define TRACEPOINT_DEFINE
16#define TRACEPOINT_CREATE_PROBES
17#include "ust_tests_fork.h"
18
19int main(int argc, char **argv, char *env[])
20{
21 int result;
22
23 if (argc < 2) {
24 fprintf(stderr, "usage: fork PROG_TO_EXEC\n");
25 exit(1);
26 }
27
28 printf("parent_pid %d\n", getpid());
29 tracepoint(ust_tests_fork, before_fork, getpid());
30
31 result = fork();
32 if (result == -1) {
33 perror("fork");
34 return 1;
35 }
36 if (result == 0) {
37 char *args[] = { "fork2", NULL };
38
39 tracepoint(ust_tests_fork, after_fork_child, getpid());
40
41 result = execve(argv[1], args, env);
42 if (result == -1) {
43 perror("execve");
b871e4b3
JG
44 result = 1;
45 goto end;
37bd6c8e
JG
46 }
47 } else {
48 printf("child_pid %d\n", result);
49 tracepoint(ust_tests_fork, after_fork_parent, getpid());
b871e4b3
JG
50 if (waitpid(result, NULL, 0) < 0) {
51 perror("waitpid");
52 result = 1;
53 goto end;
54 }
37bd6c8e 55 }
b871e4b3
JG
56 result = 0;
57end:
58 return result;
37bd6c8e 59}
This page took 0.037948 seconds and 4 git commands to generate.