Move to kernel style SPDX license identifiers
[lttng-ust.git] / tests / compile / hello / hello.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2009 Pierre-Marc Fournier
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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 /*
18 * Work-around inet.h missing struct mmsghdr forward declaration, with
19 * triggers a warning when system files warnings are enabled.
20 */
21 struct mmsghdr;
22 #include <arpa/inet.h>
23 #include <stdlib.h>
24 #include <stdbool.h>
25
26 #define TRACEPOINT_DEFINE
27 #include "ust_tests_hello.h"
28
29 void inthandler(int sig)
30 {
31 printf("in SIGUSR1 handler\n");
32 tracepoint(ust_tests_hello, tptest_sighandler);
33 }
34
35 int init_int_handler(void)
36 {
37 int result;
38 struct sigaction act;
39
40 memset(&act, 0, sizeof(act));
41 result = sigemptyset(&act.sa_mask);
42 if (result == -1) {
43 perror("sigemptyset");
44 return -1;
45 }
46
47 act.sa_handler = inthandler;
48 act.sa_flags = SA_RESTART;
49
50 /* Only defer ourselves. Also, try to restart interrupted
51 * syscalls to disturb the traced program as little as possible.
52 */
53 result = sigaction(SIGUSR1, &act, NULL);
54 if (result == -1) {
55 perror("sigaction");
56 return -1;
57 }
58
59 return 0;
60 }
61
62 void test_inc_count(void);
63
64 int main(int argc, char **argv)
65 {
66 int i, netint;
67 long values[] = { 1, 2, 3 };
68 char text[10] = "test";
69 double dbl = 2.0;
70 float flt = 2222.0;
71 int delay = 0;
72 bool mybool = 123; /* should print "1" */
73
74 init_int_handler();
75
76 if (argc == 2)
77 delay = atoi(argv[1]);
78
79 fprintf(stderr, "Hello, World!\n");
80
81 sleep(delay);
82
83 fprintf(stderr, "Tracing... ");
84 for (i = 0; i < 1000000; i++) {
85 netint = htonl(i);
86 tracepoint(ust_tests_hello, tptest, i, netint, values,
87 text, strlen(text), dbl, flt, mybool);
88 //usleep(100000);
89 }
90 fprintf(stderr, " done.\n");
91 return 0;
92 }
This page took 0.030212 seconds and 4 git commands to generate.