Commit | Line | Data |
---|---|---|
ba5e8d0a | 1 | /* |
9d16b343 MJ |
2 | * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com> |
3 | * Copyright (C) 2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
ba5e8d0a | 4 | * |
9d16b343 | 5 | * SPDX-License-Identifier: LGPL-2.1-only |
ba5e8d0a | 6 | * |
ba5e8d0a MD |
7 | */ |
8 | ||
9 | #include <fcntl.h> | |
10 | #include <stdio.h> | |
11 | #include <string.h> | |
12 | #include <sys/stat.h> | |
13 | #include <sys/types.h> | |
14 | #include <unistd.h> | |
15 | ||
16 | #include "utils.h" | |
17 | ||
18 | #define LTTNG_MODULES_FILE "/proc/lttng-test-filter-event" | |
19 | ||
20 | /* | |
21 | * The process waits for the creation of a file passed as argument from an | |
22 | * external processes to execute a syscall and exiting. This is useful for tests | |
23 | * in combinaison with LTTng's PID tracker feature where we can trace the kernel | |
24 | * events generated by our test process only. | |
25 | */ | |
26 | int main(int argc, char **argv) | |
27 | { | |
28 | int fd = -1, ret; | |
29 | char *start_file, *nr_events_str; | |
30 | ssize_t len; | |
31 | ||
32 | if (argc != 3) { | |
33 | fprintf(stderr, "Error: Missing argument\n"); | |
34 | fprintf(stderr, "USAGE: %s PATH_WAIT_FILE NR_EVENTS\n", | |
35 | argv[0]); | |
36 | ret = -1; | |
37 | goto end; | |
38 | } | |
39 | ||
40 | start_file = argv[1]; | |
41 | nr_events_str = argv[2]; | |
42 | ||
43 | /* | |
44 | * Wait for the start_file to be created by an external process | |
45 | * (typically the test script) before executing the syscalls. | |
46 | */ | |
47 | ret = wait_on_file(start_file); | |
48 | if (ret != 0) { | |
49 | goto end; | |
50 | } | |
51 | ||
52 | /* | |
53 | * Start generating events. | |
54 | */ | |
55 | fd = open(LTTNG_MODULES_FILE, O_RDWR); | |
56 | if (fd < 0) { | |
57 | perror("open"); | |
58 | ret = -1; | |
59 | goto end; | |
60 | } | |
61 | ||
62 | len = write(fd, nr_events_str, strlen(nr_events_str) + 1); | |
63 | if (len != strlen(nr_events_str) + 1) { | |
64 | perror("write"); | |
65 | ret = -1; | |
66 | } else { | |
67 | ret = 0; | |
68 | } | |
69 | ||
70 | end: | |
71 | if (fd >= 0) { | |
72 | int closeret = close(fd); | |
73 | if (closeret) { | |
74 | perror("close"); | |
75 | } | |
76 | } | |
77 | return ret; | |
78 | } |