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