Commit | Line | Data |
---|---|---|
246e1625 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
246e1625 | 3 | * |
c0c0989a MJ |
4 | * Copyright (C) 2009 Pierre-Marc Fournier |
5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
246e1625 MD |
6 | */ |
7 | ||
8 | #include <stdio.h> | |
9 | #include <unistd.h> | |
10 | #include <sys/mman.h> | |
11 | #include <stdarg.h> | |
12 | #include <sys/types.h> | |
13 | #include <sys/stat.h> | |
14 | #include <fcntl.h> | |
15 | #include <signal.h> | |
16 | #include <string.h> | |
17 | #include <arpa/inet.h> | |
18 | #include <stdlib.h> | |
19 | ||
88c7c4ea | 20 | #define LTTNG_UST_TRACEPOINT_DEFINE |
246e1625 MD |
21 | #include "ust_tests_hello.h" |
22 | ||
4b4a1337 | 23 | static |
2208d8b5 | 24 | void inthandler(int sig __attribute__((unused))) |
246e1625 MD |
25 | { |
26 | printf("in SIGUSR1 handler\n"); | |
cbc06a3b | 27 | lttng_ust_tracepoint(ust_tests_hello, tptest_sighandler); |
246e1625 MD |
28 | } |
29 | ||
4b4a1337 | 30 | static |
246e1625 MD |
31 | int init_int_handler(void) |
32 | { | |
33 | int result; | |
34 | struct sigaction act; | |
35 | ||
36 | memset(&act, 0, sizeof(act)); | |
37 | result = sigemptyset(&act.sa_mask); | |
38 | if (result == -1) { | |
39 | perror("sigemptyset"); | |
40 | return -1; | |
41 | } | |
42 | ||
43 | act.sa_handler = inthandler; | |
44 | act.sa_flags = SA_RESTART; | |
45 | ||
46 | /* Only defer ourselves. Also, try to restart interrupted | |
47 | * syscalls to disturb the traced program as little as possible. | |
48 | */ | |
49 | result = sigaction(SIGUSR1, &act, NULL); | |
50 | if (result == -1) { | |
51 | perror("sigaction"); | |
52 | return -1; | |
53 | } | |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
58 | int main(int argc, char **argv) | |
59 | { | |
60 | int i, netint; | |
61 | long values[] = { 1, 2, 3 }; | |
62 | char text[10] = "test"; | |
63 | double dbl = 2.0; | |
64 | float flt = 2222.0; | |
65 | int delay = 0; | |
66 | ||
67 | init_int_handler(); | |
68 | ||
69 | if (argc == 2) | |
70 | delay = atoi(argv[1]); | |
71 | ||
72 | fprintf(stderr, "Hello, World!\n"); | |
73 | ||
74 | sleep(delay); | |
75 | ||
76 | fprintf(stderr, "Tracing... "); | |
77 | for (i = 0; i < 1000000; i++) { | |
78 | netint = htonl(i); | |
cbc06a3b | 79 | lttng_ust_tracepoint(ust_tests_hello, tptest, i, netint, values, |
246e1625 | 80 | text, strlen(text), dbl, flt); |
246e1625 MD |
81 | } |
82 | fprintf(stderr, " done.\n"); | |
83 | return 0; | |
84 | } |