Commit | Line | Data |
---|---|---|
030312cf FD |
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 | #define _LGPL_SOURCE | |
19 | ||
20 | #include <fcntl.h> | |
21 | #include <stdio.h> | |
22 | #include <sys/syscall.h> | |
23 | #include <unistd.h> | |
24 | ||
25 | #include "utils.h" | |
26 | ||
27 | #define MAX_LEN 16 | |
28 | /* | |
29 | * The process waits for the creation of a file passed as argument from an | |
30 | * external processes to execute a syscall and exiting. This is useful for tests | |
31 | * in combinaison with LTTng's PID tracker feature where we can trace the kernel | |
32 | * events generated by our test process only. | |
33 | */ | |
34 | int main(int argc, char **argv) | |
35 | { | |
c8e51d15 | 36 | int fd, ret; |
030312cf FD |
37 | char buf[MAX_LEN]; |
38 | char *start_file; | |
39 | ||
40 | if (argc != 2) { | |
41 | fprintf(stderr, "Error: Missing argument\n"); | |
42 | fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]); | |
43 | ret = -1; | |
44 | goto error; | |
45 | } | |
46 | ||
47 | start_file = argv[1]; | |
48 | ||
49 | /* | |
50 | * Wait for the start_file to be created by an external process | |
51 | * (typically the test script) before executing the syscalls. | |
52 | */ | |
53 | ret = wait_on_file(start_file); | |
54 | if (ret != 0) { | |
55 | goto error; | |
56 | } | |
57 | ||
58 | /* | |
59 | * Start generating syscalls. We use syscall(2) to prevent libc to change | |
60 | * the underlying syscall. e.g. calling openat(2) instead of open(2). | |
61 | */ | |
62 | fd = syscall(SYS_open, "/proc/cpuinfo", O_RDONLY); | |
63 | if (fd < 0) { | |
64 | perror("open"); | |
65 | ret = -1; | |
66 | goto error; | |
67 | } | |
68 | ||
69 | ret = syscall(SYS_read, fd, buf, MAX_LEN); | |
70 | if (ret < 0) { | |
71 | perror("read"); | |
72 | ret = -1; | |
73 | goto error; | |
74 | } | |
75 | ||
76 | ret = syscall(SYS_close, fd); | |
77 | if (ret == -1) { | |
78 | perror("close"); | |
79 | ret = -1; | |
80 | goto error; | |
81 | } | |
82 | ||
83 | error: | |
84 | return ret; | |
85 | } |