| 1 | /* |
| 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 3 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: LGPL-2.1-only |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #define _LGPL_SOURCE |
| 10 | #include <assert.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <stdarg.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <sys/mman.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <lttng/tracef.h> |
| 22 | #include "signal-helper.h" |
| 23 | |
| 24 | const char *str = "test string"; |
| 25 | |
| 26 | static |
| 27 | void create_file(const char *path) |
| 28 | { |
| 29 | int ret; |
| 30 | |
| 31 | assert(path); |
| 32 | |
| 33 | ret = creat(path, S_IRWXU); |
| 34 | if (ret < 0) { |
| 35 | fprintf(stderr, "Failed to create file %s\n", path); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | (void) close(ret); |
| 40 | } |
| 41 | |
| 42 | int main(int argc, char **argv) |
| 43 | { |
| 44 | int i; |
| 45 | unsigned int nr_iter = 100; |
| 46 | useconds_t nr_usec = 0; |
| 47 | char *tmp_file_path = NULL; |
| 48 | |
| 49 | if (set_signal_handler()) { |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | if (argc >= 2) { |
| 54 | nr_iter = atoi(argv[1]); |
| 55 | } |
| 56 | |
| 57 | if (argc >= 3) { |
| 58 | /* By default, don't wait unless user specifies. */ |
| 59 | nr_usec = atoi(argv[2]); |
| 60 | } |
| 61 | |
| 62 | if (argc >= 4) { |
| 63 | tmp_file_path = argv[3]; |
| 64 | } |
| 65 | |
| 66 | for (i = 0; i < nr_iter; i++) { |
| 67 | tracef("Test message %d with string \"%s\"", i, str); |
| 68 | |
| 69 | /* |
| 70 | * First loop we create the file if asked to indicate |
| 71 | * that at least one tracepoint has been hit. |
| 72 | */ |
| 73 | if (i == 0 && tmp_file_path) { |
| 74 | create_file(tmp_file_path); |
| 75 | } |
| 76 | usleep(nr_usec); |
| 77 | if (should_quit) { |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |