From 8bbeee11734d3ba8e2cf15d19cb3c302f8bfdbf2 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:51:18 +0100 Subject: core: Add clang-tidy (#8664) This adds a .clang-tidy file for us. It's not a strict requirement to be compliant, but I tuned it to be alright. --- src/helpers/SdDaemon.cpp | 77 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'src/helpers/SdDaemon.cpp') diff --git a/src/helpers/SdDaemon.cpp b/src/helpers/SdDaemon.cpp index 80944794..018165c0 100644 --- a/src/helpers/SdDaemon.cpp +++ b/src/helpers/SdDaemon.cpp @@ -4,59 +4,56 @@ #include #include -#include +#include #include #include -#include -#include +#include #include -namespace Systemd { - int SdBooted(void) { - if (!faccessat(AT_FDCWD, "/run/systemd/system/", F_OK, AT_SYMLINK_NOFOLLOW)) - return true; +int NSystemd::sdBooted() { + if (!faccessat(AT_FDCWD, "/run/systemd/system/", F_OK, AT_SYMLINK_NOFOLLOW)) + return true; - if (errno == ENOENT) - return false; + if (errno == ENOENT) + return false; - return -errno; - } + return -errno; +} - int SdNotify(int unsetEnvironment, const char* state) { - int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (fd < 0) - return -errno; +int NSystemd::sdNotify(int unsetEnvironment, const char* state) { + int fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (fd < 0) + return -errno; - constexpr char envVar[] = "NOTIFY_SOCKET"; + constexpr char envVar[] = "NOTIFY_SOCKET"; - auto cleanup = [unsetEnvironment, envVar](int* fd) { - if (unsetEnvironment) - unsetenv(envVar); - close(*fd); - }; - std::unique_ptr fdCleaup(&fd, cleanup); + auto cleanup = [unsetEnvironment, envVar](const int* fd) { + if (unsetEnvironment) + unsetenv(envVar); + close(*fd); + }; + std::unique_ptr fdCleaup(&fd, cleanup); - const char* addr = getenv(envVar); - if (!addr) - return 0; + const char* addr = getenv(envVar); + if (!addr) + return 0; - // address length must be at most this; see man 7 unix - size_t addrLen = strnlen(addr, 107); + // address length must be at most this; see man 7 unix + size_t addrLen = strnlen(addr, 107); - struct sockaddr_un unixAddr; - unixAddr.sun_family = AF_UNIX; - strncpy(unixAddr.sun_path, addr, addrLen); - if (unixAddr.sun_path[0] == '@') - unixAddr.sun_path[0] = '\0'; + struct sockaddr_un unixAddr; + unixAddr.sun_family = AF_UNIX; + strncpy(unixAddr.sun_path, addr, addrLen); + if (unixAddr.sun_path[0] == '@') + unixAddr.sun_path[0] = '\0'; - if (connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)) < 0) - return -errno; + if (connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)) < 0) + return -errno; - // arbitrary value which seems to be enough for s-d messages - ssize_t stateLen = strnlen(state, 128); - if (write(fd, state, stateLen) == stateLen) - return 1; + // arbitrary value which seems to be enough for s-d messages + ssize_t stateLen = strnlen(state, 128); + if (write(fd, state, stateLen) == stateLen) + return 1; - return -errno; - } + return -errno; } -- cgit v1.2.3