Commit | Line | Data |
---|---|---|
38eb8a68 FD |
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 | ||
7f530eee JR |
12 | #ifndef _GNU_SOURCE |
13 | #define _GNU_SOURCE | |
14 | #endif | |
15 | ||
28ab034a JG |
16 | #include <common/error.hpp> |
17 | #include <common/pipe.hpp> | |
18 | ||
38eb8a68 FD |
19 | #include <fcntl.h> |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
28ab034a | 22 | #include <unistd.h> |
38eb8a68 FD |
23 | |
24 | int lttng_opt_verbose; | |
25 | int lttng_opt_mi; | |
26 | int lttng_opt_quiet; | |
27 | ||
d77f0b99 | 28 | namespace { |
ccfd5162 MJ |
29 | #ifdef __linux__ |
30 | /* | |
31 | * Return the default pipe buffer size or a negative error. | |
32 | */ | |
cd9adb8b | 33 | int get_pipe_size() |
38eb8a68 FD |
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. */ | |
ccfd5162 | 46 | ret = -1; |
38eb8a68 FD |
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"); | |
38eb8a68 FD |
53 | } |
54 | ||
38eb8a68 | 55 | lttng_pipe_destroy(pipe); |
ccfd5162 | 56 | end: |
38eb8a68 FD |
57 | return ret; |
58 | } | |
ccfd5162 | 59 | #elif defined(__FreeBSD__) |
ccfd5162 MJ |
60 | int get_pipe_size(void) |
61 | { | |
62 | return 65536; | |
63 | } | |
64 | #else | |
65 | #error "Implement get_pipe_size() for your platform." | |
66 | #endif | |
d77f0b99 | 67 | } /* namespace */ |
ccfd5162 | 68 | |
cd9adb8b | 69 | int main() |
ccfd5162 MJ |
70 | { |
71 | int ret; | |
72 | ||
73 | ret = get_pipe_size(); | |
74 | if (ret < 0) { | |
75 | return EXIT_FAILURE; | |
76 | } | |
77 | ||
d77f0b99 | 78 | /* Print the pipe buffer size to stdout. */ |
ccfd5162 MJ |
79 | printf("%d\n", ret); |
80 | ||
d77f0b99 | 81 | return EXIT_SUCCESS; |
ccfd5162 | 82 | } |