| 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 | #include <arpa/inet.h> |
| 18 | #include <stdlib.h> |
| 19 | |
| 20 | #define LTTNG_UST_TRACEPOINT_DEFINE |
| 21 | #include "ust_tests_hello.h" |
| 22 | |
| 23 | static |
| 24 | void inthandler(int sig __attribute__((unused))) |
| 25 | { |
| 26 | printf("in SIGUSR1 handler\n"); |
| 27 | tracepoint(ust_tests_hello, tptest_sighandler); |
| 28 | } |
| 29 | |
| 30 | static |
| 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); |
| 79 | tracepoint(ust_tests_hello, tptest, i, netint, values, |
| 80 | text, strlen(text), dbl, flt, 15); |
| 81 | //usleep(100000); |
| 82 | } |
| 83 | fprintf(stderr, " done.\n"); |
| 84 | return 0; |
| 85 | } |