MySQL 8.4.3
Source Code Documentation
sd_notify.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#include <sstream>
25
26// build with -DWITH_SYSTEMD_DEBUG=1 as needed!
27namespace sysd {
28void notify_connect();
29void notify();
30
31template <typename T, typename... Ts>
32inline void notify(T, Ts...);
33
34/**
35 Class wrapping the "globals" as static members so that they can only
36 be accessed from the friend-declared notify functions.
37 */
39 static int socket;
40 static std::stringstream fmt;
41
42 NotifyGlobals() = delete;
43
44 friend void notify_connect();
45 friend void notify();
46 template <typename T, typename... Ts>
47 friend void notify(T t, Ts... ts);
48};
49
50/**
51 Takes a variable number of arguments of different type and formats
52 them on NotifyGlobals::fmt, and sends result to notification socket.
53
54 @param t current argument to format
55 @param ts remaining args parameter pack for recursive call
56*/
57template <typename T, typename... Ts>
58inline void notify(T t [[maybe_unused]], Ts... ts [[maybe_unused]]) {
59#ifndef _WIN32
60#ifndef WITH_SYSTEMD_DEBUG
61 if (NotifyGlobals::socket == -1) {
62 return;
63 }
64#endif /* WITH_SYSTEMD_DEBUG */
66 notify(ts...);
67#endif /* not defined _WIN32 */
68}
69} // namespace sysd
Class wrapping the "globals" as static members so that they can only be accessed from the friend-decl...
Definition: sd_notify.h:38
static int socket
File descriptor for the systemd notification socket file.
Definition: sd_notify.h:39
static std::stringstream fmt
Stringstream for formatting notification messages.
Definition: sd_notify.h:40
friend void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:116
friend void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:63
Definition: sd_notify.cc:52
void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:63
void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:116