MySQL 8.0.30
Source Code Documentation
sd_notify.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#include <sstream>
24
25// build with -DWITH_SYSTEMD_DEBUG=1 as needed!
26namespace sysd {
27void notify_connect();
28void notify();
29
30template <typename T, typename... Ts>
31inline void notify(T t, Ts... ts);
32
33/**
34 Class wrapping the "globals" as static members so that they can only
35 be accessed from the friend-declared notify functions.
36 */
38 static int socket;
39 static std::stringstream fmt;
40
41 NotifyGlobals() = delete;
42
43 friend void notify_connect();
44 friend void notify();
45 template <typename T, typename... Ts>
46 friend void notify(T t, Ts... ts);
47};
48
49/**
50 Takes a variable number of arguments of different type and formats
51 them on NotifyGlobals::fmt, and sends result to notification socket.
52
53 @param t current argument to format
54 @param ts remaining args parameter pack for recursive call
55*/
56template <typename T, typename... Ts>
57inline void notify(T t, Ts... ts) {
58#ifndef _WIN32
59#ifndef WITH_SYSTEMD_DEBUG
60 if (NotifyGlobals::socket == -1) {
61 return;
62 }
63#endif /* WITH_SYSTEMD_DEBUG */
65 notify(ts...);
66#endif /* not defined _WIN32 */
67}
68} // namespace sysd
Class wrapping the "globals" as static members so that they can only be accessed from the friend-decl...
Definition: sd_notify.h:37
static int socket
File descriptor for the systemd notification socket file.
Definition: sd_notify.h:38
static std::stringstream fmt
Stringstream for formatting notification messages.
Definition: sd_notify.h:39
friend void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:115
friend void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:62
Definition: sd_notify.cc:51
void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:62
void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:115