MySQL  8.0.16
Source Code Documentation
sd_notify.h
Go to the documentation of this file.
1 /* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
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 namespace sysd {
26 void notify_connect();
27 void notify();
28 
29 template <typename T, typename... Ts>
30 inline void notify(T t, Ts... ts);
31 
32 /**
33  Class wrapping the "globals" as static members so that they can only
34  be accessed from the friend-declared notify functions.
35  */
37  static int socket;
38  static std::stringstream fmt;
39 
40  NotifyGlobals() = delete;
41 
42  friend void notify_connect();
43  friend void notify();
44  template <typename T, typename... Ts>
45  friend void notify(T t, Ts... ts);
46 };
47 
48 /**
49  Takes a variable number of arguments of different type and formats
50  them on NotifyGlobals::fmt, and sends result to notification socket.
51 
52  @param t current argument to format
53  @param ts remaining args parameter pack for recursive call
54 */
55 template <typename T, typename... Ts>
56 inline void notify(T t, Ts... ts) {
57 #ifndef _WIN32
58  if (NotifyGlobals::socket == -1) {
59  return;
60  }
62  notify(ts...);
63 #endif /* not defined _WIN32 */
64 }
65 } // namespace sysd
Class wrapping the "globals" as static members so that they can only be accessed from the friend-decl...
Definition: sd_notify.h:36
void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:103
static std::stringstream fmt
Stringstream for formatting notification messages.
Definition: sd_notify.h:38
t
Definition: dbug_analyze.cc:147
Definition: sd_notify.cc:51
friend void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:62
static int socket
File descriptor for the systemd notification socket file.
Definition: sd_notify.h:37
void notify_connect()
Looks for the name of the socket file in the environment variable NOTIFY_SOCKET.
Definition: sd_notify.cc:62
friend void notify()
Recursion terminator overload for varargs template function.
Definition: sd_notify.cc:103