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