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