Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / tests / regression / tools / notification / default_pipe_size_getter.cpp
... / ...
CommitLineData
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 <common/error.hpp>
17#include <common/pipe.hpp>
18
19#include <fcntl.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <unistd.h>
23
24int lttng_opt_verbose;
25int lttng_opt_mi;
26int lttng_opt_quiet;
27
28namespace {
29#ifdef __linux__
30/*
31 * Return the default pipe buffer size or a negative error.
32 */
33int get_pipe_size()
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);
56end:
57 return ret;
58}
59#elif defined(__FreeBSD__)
60int get_pipe_size(void)
61{
62 return 65536;
63}
64#else
65#error "Implement get_pipe_size() for your platform."
66#endif
67} /* namespace */
68
69int main()
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.02424 seconds and 5 git commands to generate.