Make create_file function static in gen-ust-tracef.c
[lttng-tools.git] / tests / utils / testapp / gen-ust-tracef / gen-ust-tracef.c
CommitLineData
b02dcdb8 1/*
9d16b343
MJ
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b02dcdb8 4 *
9d16b343 5 * SPDX-License-Identifier: LGPL-2.1-only
b02dcdb8 6 *
b02dcdb8
MD
7 */
8
70dac0d7 9#define _LGPL_SOURCE
b02dcdb8
MD
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>
95983a02 22#include "signal-helper.h"
b02dcdb8
MD
23
24const char *str = "test string";
25
6c641879 26static
b02dcdb8
MD
27void 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
42int 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
95983a02
JG
49 if (set_signal_handler()) {
50 return 1;
51 }
52
b02dcdb8
MD
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);
95983a02
JG
77 if (should_quit) {
78 break;
79 }
b02dcdb8
MD
80 }
81
82 return 0;
83}
This page took 0.050282 seconds and 5 git commands to generate.