Tests: triggers: Add kprobe event rule condition kernel tests
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events / gen-syscall-events.c
CommitLineData
030312cf 1/*
9d16b343 2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
030312cf 3 *
9d16b343 4 * SPDX-License-Identifier: LGPL-2.1-only
030312cf 5 *
030312cf
FD
6 */
7
030312cf
FD
8#include <fcntl.h>
9#include <stdio.h>
10#include <sys/syscall.h>
11#include <unistd.h>
12
13#include "utils.h"
14
15#define MAX_LEN 16
16/*
17 * The process waits for the creation of a file passed as argument from an
18 * external processes to execute a syscall and exiting. This is useful for tests
19 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
20 * events generated by our test process only.
21 */
22int main(int argc, char **argv)
23{
c8e51d15 24 int fd, ret;
030312cf
FD
25 char buf[MAX_LEN];
26 char *start_file;
27
28 if (argc != 2) {
29 fprintf(stderr, "Error: Missing argument\n");
30 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
31 ret = -1;
32 goto error;
33 }
34
35 start_file = argv[1];
36
37 /*
38 * Wait for the start_file to be created by an external process
39 * (typically the test script) before executing the syscalls.
40 */
41 ret = wait_on_file(start_file);
42 if (ret != 0) {
43 goto error;
44 }
45
46 /*
47 * Start generating syscalls. We use syscall(2) to prevent libc to change
48 * the underlying syscall. e.g. calling openat(2) instead of open(2).
49 */
8192bd8f 50 fd = syscall(SYS_openat, AT_FDCWD, "/proc/cpuinfo", O_RDONLY);
030312cf
FD
51 if (fd < 0) {
52 perror("open");
53 ret = -1;
54 goto error;
55 }
56
57 ret = syscall(SYS_read, fd, buf, MAX_LEN);
58 if (ret < 0) {
59 perror("read");
60 ret = -1;
61 goto error;
62 }
63
64 ret = syscall(SYS_close, fd);
65 if (ret == -1) {
66 perror("close");
67 ret = -1;
68 goto error;
69 }
70
71error:
72 return ret;
73}
This page took 0.044821 seconds and 4 git commands to generate.