tests: test uid/gid/pid/vuid/vgid/vpid trackers
[lttng-tools.git] / tests / utils / testapp / gen-kernel-test-events / gen-kernel-test-events.c
1 /*
2 * Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
3 * Copyright (C) - 2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by the
7 * Free Software Foundation; version 2.1 of the License.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <fcntl.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25
26 #include "utils.h"
27
28 #define LTTNG_MODULES_FILE "/proc/lttng-test-filter-event"
29
30 /*
31 * The process waits for the creation of a file passed as argument from an
32 * external processes to execute a syscall and exiting. This is useful for tests
33 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
34 * events generated by our test process only.
35 */
36 int main(int argc, char **argv)
37 {
38 int fd = -1, ret;
39 char *start_file, *nr_events_str;
40 ssize_t len;
41
42 if (argc != 3) {
43 fprintf(stderr, "Error: Missing argument\n");
44 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE NR_EVENTS\n",
45 argv[0]);
46 ret = -1;
47 goto end;
48 }
49
50 start_file = argv[1];
51 nr_events_str = argv[2];
52
53 /*
54 * Wait for the start_file to be created by an external process
55 * (typically the test script) before executing the syscalls.
56 */
57 ret = wait_on_file(start_file);
58 if (ret != 0) {
59 goto end;
60 }
61
62 /*
63 * Start generating events.
64 */
65 fd = open(LTTNG_MODULES_FILE, O_RDWR);
66 if (fd < 0) {
67 perror("open");
68 ret = -1;
69 goto end;
70 }
71
72 len = write(fd, nr_events_str, strlen(nr_events_str) + 1);
73 if (len != strlen(nr_events_str) + 1) {
74 perror("write");
75 ret = -1;
76 } else {
77 ret = 0;
78 }
79
80 end:
81 if (fd >= 0) {
82 int closeret = close(fd);
83 if (closeret) {
84 perror("close");
85 }
86 }
87 return ret;
88 }
This page took 0.031063 seconds and 4 git commands to generate.