MCPcopy Create free account
hub / github.com/apache/kvrocks / SupervisedSystemd

Function SupervisedSystemd

src/cli/daemon_util.h:46–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46inline bool SupervisedSystemd() {
47 const char *notify_socket = getenv("NOTIFY_SOCKET");
48 if (!notify_socket) {
49 WARN("systemd supervision requested, but NOTIFY_SOCKET not found");
50 return false;
51 }
52
53 auto fd = UniqueFD(socket(AF_UNIX, SOCK_DGRAM, 0));
54 if (!fd) {
55 WARN("Cannot connect to systemd socket {}", notify_socket);
56 return false;
57 }
58
59 sockaddr_un su = {};
60 su.sun_family = AF_UNIX;
61 strncpy(su.sun_path, notify_socket, sizeof(su.sun_path) - 1);
62 su.sun_path[sizeof(su.sun_path) - 1] = '\0';
63 if (notify_socket[0] == '@') su.sun_path[0] = '\0';
64
65 iovec iov = {};
66 std::string ready = "READY=1";
67 iov.iov_base = ready.data();
68 iov.iov_len = ready.size();
69
70 msghdr hdr = {};
71 hdr.msg_name = &su;
72 hdr.msg_namelen = offsetof(sockaddr_un, sun_path) + strlen(su.sun_path);
73 hdr.msg_iov = &iov;
74 hdr.msg_iovlen = 1;
75
76 int sendto_flags = 0;
77 unsetenv("NOTIFY_SOCKET");
78#ifdef HAVE_MSG_NOSIGNAL
79 sendto_flags |= MSG_NOSIGNAL;
80#endif
81 if (sendmsg(*fd, &hdr, sendto_flags) < 0) {
82 WARN("Cannot send notification to systemd");
83 return false;
84 }
85 return true;
86}
87
88inline bool IsSupervisedMode(SupervisedMode mode) {
89 if (mode == kSupervisedAutoDetect) {

Callers 1

IsSupervisedModeFunction · 0.85

Calls 1

UniqueFDClass · 0.85

Tested by

no test coverage detected