febcc0a067ea0224e4b53ab6f351d8a8d156b894
[lttng-tools.git] / tests / regression / tools / notification / default_pipe_size_getter.cpp
1 /*
2 * default_pipe_size_getter.c
3 *
4 * Tests suite for LTTng notification API (get default size of pipes)
5 *
6 * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * SPDX-License-Identifier: MIT
9 *
10 */
11
12 #ifndef _GNU_SOURCE
13 #define _GNU_SOURCE
14 #endif
15
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 #include <common/pipe.hpp>
22 #include <common/error.hpp>
23
24 int lttng_opt_verbose;
25 int lttng_opt_mi;
26 int lttng_opt_quiet;
27
28 #ifdef __linux__
29 /*
30 * Return the default pipe buffer size or a negative error.
31 */
32 static
33 int get_pipe_size(void)
34 {
35 int ret;
36 /*
37 * The event notifier pipes are not "special"; they are created using
38 * the lttng_pipe utility. Hence, this should be representative of a
39 * pipe created by the session daemon for event notifier messages to
40 * go through.
41 */
42 struct lttng_pipe *pipe = lttng_pipe_open(0);
43
44 if (!pipe) {
45 /* lttng_pipe_open already logs on error. */
46 ret = -1;
47 goto end;
48 }
49
50 ret = fcntl(lttng_pipe_get_writefd(pipe), F_GETPIPE_SZ);
51 if (ret < 0) {
52 PERROR("Failed to get the size of the pipe");
53 }
54
55 lttng_pipe_destroy(pipe);
56 end:
57 return ret;
58 }
59 #elif defined(__FreeBSD__)
60 static
61 int get_pipe_size(void)
62 {
63 return 65536;
64 }
65 #else
66 #error "Implement get_pipe_size() for your platform."
67 #endif
68
69 int main(void)
70 {
71 int ret;
72
73 ret = get_pipe_size();
74 if (ret < 0) {
75 return EXIT_FAILURE;
76 }
77
78 /* Print the pipe buffer size to stdout */
79 printf("%d\n", ret);
80
81 return EXIT_SUCCESS;
82 }
This page took 0.030488 seconds and 3 git commands to generate.