mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 18:45:59 +01:00
core: remove libsystemd dependency (#5660)
* remove libsystemd dependency as per Lennart Poettering's advice: https://github.com/systemd/systemd/issues/32028#issuecomment-2031366922 * fix naming for systemd helper functions * rename vars according to code style * Nix: update meson patch --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
This commit is contained in:
parent
ea47e8c92a
commit
a945346064
7 changed files with 76 additions and 31 deletions
|
@ -192,20 +192,8 @@ endif()
|
||||||
if(NO_SYSTEMD)
|
if(NO_SYSTEMD)
|
||||||
message(STATUS "SYSTEMD support is disabled...")
|
message(STATUS "SYSTEMD support is disabled...")
|
||||||
else()
|
else()
|
||||||
message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined) checking deps...")
|
message(STATUS "SYSTEMD support is requested (NO_SYSTEMD not defined)...")
|
||||||
check_include_file("systemd/sd-daemon.h" SYSTEMDH)
|
|
||||||
if(SYSTEMDH)
|
|
||||||
pkg_check_modules(LIBSYSTEMD libsystemd)
|
|
||||||
if (LIBSYSTEMD_FOUND)
|
|
||||||
add_compile_definitions(USES_SYSTEMD)
|
add_compile_definitions(USES_SYSTEMD)
|
||||||
target_link_libraries(Hyprland "${LIBSYSTEMD_LIBRARIES}")
|
|
||||||
message(STATUS "Systemd found")
|
|
||||||
else()
|
|
||||||
message(WARNING "Systemd support requested but systemd libraries were not found")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message(WARNING "Systemd support requested but systemd headers were not found")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
|
|
@ -52,14 +52,9 @@ endif
|
||||||
|
|
||||||
backtrace_dep = cpp_compiler.find_library('execinfo', required: false)
|
backtrace_dep = cpp_compiler.find_library('execinfo', required: false)
|
||||||
epoll_dep = dependency('epoll-shim', required: false) # timerfd on BSDs
|
epoll_dep = dependency('epoll-shim', required: false) # timerfd on BSDs
|
||||||
systemd_dep = dependency('libsystemd', required: get_option('systemd'))
|
|
||||||
|
|
||||||
if get_option('systemd').enabled()
|
if get_option('systemd').enabled()
|
||||||
if systemd_dep.found()
|
|
||||||
add_project_arguments('-DUSES_SYSTEMD', language: 'cpp')
|
add_project_arguments('-DUSES_SYSTEMD', language: 'cpp')
|
||||||
else
|
|
||||||
error('Cannot enable systemd in Hyprland: libsystemd was not found')
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if get_option('legacy_renderer').enabled()
|
if get_option('legacy_renderer').enabled()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
diff --git a/meson.build b/meson.build
|
diff --git a/meson.build b/meson.build
|
||||||
index 1d2c7f9f..c5ef4e67 100644
|
index 40883073..d8f2e536 100644
|
||||||
--- a/meson.build
|
--- a/meson.build
|
||||||
+++ b/meson.build
|
+++ b/meson.build
|
||||||
@@ -33,20 +33,7 @@ if cpp_compiler.check_header('execinfo.h')
|
@@ -33,20 +33,7 @@ if cpp_compiler.check_header('execinfo.h')
|
||||||
|
@ -24,7 +24,7 @@ index 1d2c7f9f..c5ef4e67 100644
|
||||||
add_project_arguments('-DNO_XWAYLAND', language: 'cpp')
|
add_project_arguments('-DNO_XWAYLAND', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -69,8 +56,6 @@ if get_option('buildtype') == 'debug'
|
@@ -65,8 +52,6 @@ if get_option('buildtype') == 'debug'
|
||||||
add_project_arguments('-DHYPRLAND_DEBUG', language: 'cpp')
|
add_project_arguments('-DHYPRLAND_DEBUG', language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ index 1d2c7f9f..c5ef4e67 100644
|
||||||
headers = globber.stdout().strip().split('\n')
|
headers = globber.stdout().strip().split('\n')
|
||||||
foreach file : headers
|
foreach file : headers
|
||||||
diff --git a/src/meson.build b/src/meson.build
|
diff --git a/src/meson.build b/src/meson.build
|
||||||
index 45701f5f..3505cefe 100644
|
index 15c69552..327aa4fb 100644
|
||||||
--- a/src/meson.build
|
--- a/src/meson.build
|
||||||
+++ b/src/meson.build
|
+++ b/src/meson.build
|
||||||
@@ -9,7 +9,7 @@ executable('Hyprland', src,
|
@@ -9,7 +9,7 @@ executable('Hyprland', src,
|
||||||
|
@ -46,7 +46,7 @@ index 45701f5f..3505cefe 100644
|
||||||
dependency('cairo'),
|
dependency('cairo'),
|
||||||
dependency('hyprcursor'),
|
dependency('hyprcursor'),
|
||||||
dependency('hyprlang', version: '>= 0.3.2'),
|
dependency('hyprlang', version: '>= 0.3.2'),
|
||||||
@@ -17,11 +17,11 @@ executable('Hyprland', src,
|
@@ -17,10 +17,10 @@ executable('Hyprland', src,
|
||||||
dependency('egl'),
|
dependency('egl'),
|
||||||
dependency('xkbcommon'),
|
dependency('xkbcommon'),
|
||||||
dependency('libinput'),
|
dependency('libinput'),
|
||||||
|
@ -54,7 +54,6 @@ index 45701f5f..3505cefe 100644
|
||||||
+ dependency('xcb', required: get_option('xwayland')),
|
+ dependency('xcb', required: get_option('xwayland')),
|
||||||
backtrace_dep,
|
backtrace_dep,
|
||||||
epoll_dep,
|
epoll_dep,
|
||||||
systemd_dep,
|
|
||||||
- udis86,
|
- udis86,
|
||||||
+ dependency('udis86'),
|
+ dependency('udis86'),
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "debug/HyprCtl.hpp"
|
#include "debug/HyprCtl.hpp"
|
||||||
#include "debug/CrashReporter.hpp"
|
#include "debug/CrashReporter.hpp"
|
||||||
#ifdef USES_SYSTEMD
|
#ifdef USES_SYSTEMD
|
||||||
#include <systemd/sd-daemon.h> // for sd_notify
|
#include <helpers/SdDaemon.hpp> // for SdNotify
|
||||||
#endif
|
#endif
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include "helpers/VarList.hpp"
|
#include "helpers/VarList.hpp"
|
||||||
|
@ -385,8 +385,8 @@ void CCompositor::cleanup() {
|
||||||
Debug::shuttingDown = true;
|
Debug::shuttingDown = true;
|
||||||
|
|
||||||
#ifdef USES_SYSTEMD
|
#ifdef USES_SYSTEMD
|
||||||
if (sd_booted() > 0 && !envEnabled("HYPRLAND_NO_SD_NOTIFY"))
|
if (Systemd::SdBooted() > 0 && !envEnabled("HYPRLAND_NO_SD_NOTIFY"))
|
||||||
sd_notify(0, "STOPPING=1");
|
Systemd::SdNotify(0, "STOPPING=1");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// unload all remaining plugins while the compositor is
|
// unload all remaining plugins while the compositor is
|
||||||
|
@ -615,10 +615,10 @@ void CCompositor::startCompositor() {
|
||||||
g_pHyprRenderer->setCursorFromName("left_ptr");
|
g_pHyprRenderer->setCursorFromName("left_ptr");
|
||||||
|
|
||||||
#ifdef USES_SYSTEMD
|
#ifdef USES_SYSTEMD
|
||||||
if (sd_booted() > 0) {
|
if (Systemd::SdBooted() > 0) {
|
||||||
// tell systemd that we are ready so it can start other bond, following, related units
|
// tell systemd that we are ready so it can start other bond, following, related units
|
||||||
if (!envEnabled("HYPRLAND_NO_SD_NOTIFY"))
|
if (!envEnabled("HYPRLAND_NO_SD_NOTIFY"))
|
||||||
sd_notify(0, "READY=1");
|
Systemd::SdNotify(0, "READY=1");
|
||||||
} else
|
} else
|
||||||
Debug::log(LOG, "systemd integration is baked in but system itself is not booted à la systemd!");
|
Debug::log(LOG, "systemd integration is baked in but system itself is not booted à la systemd!");
|
||||||
#endif
|
#endif
|
||||||
|
|
58
src/helpers/SdDaemon.cpp
Normal file
58
src/helpers/SdDaemon.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#include "SdDaemon.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
namespace Systemd {
|
||||||
|
int SdBooted(void) {
|
||||||
|
if (!faccessat(AT_FDCWD, "/run/systemd/system/", F_OK, AT_SYMLINK_NOFOLLOW))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (errno == ENOENT)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SdNotify(int unsetEnvironment, const char* state) {
|
||||||
|
int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||||
|
if (fd == -1)
|
||||||
|
return -errno;
|
||||||
|
|
||||||
|
constexpr char envVar[] = "NOTIFY_SOCKET";
|
||||||
|
|
||||||
|
auto cleanup = [unsetEnvironment, envVar](int* fd) {
|
||||||
|
if (unsetEnvironment)
|
||||||
|
unsetenv(envVar);
|
||||||
|
close(*fd);
|
||||||
|
};
|
||||||
|
std::unique_ptr<int, decltype(cleanup)> fdCleaup(&fd, cleanup);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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)))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// arbitrary value which seems to be enough for s-d messages
|
||||||
|
size_t stateLen = strnlen(state, 128);
|
||||||
|
if (write(fd, state, stateLen) >= 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
}
|
6
src/helpers/SdDaemon.hpp
Normal file
6
src/helpers/SdDaemon.hpp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Systemd {
|
||||||
|
int SdBooted(void);
|
||||||
|
int SdNotify(int unset_environment, const char* state);
|
||||||
|
}
|
|
@ -20,7 +20,6 @@ executable('Hyprland', src,
|
||||||
xcb_dep,
|
xcb_dep,
|
||||||
backtrace_dep,
|
backtrace_dep,
|
||||||
epoll_dep,
|
epoll_dep,
|
||||||
systemd_dep,
|
|
||||||
udis86,
|
udis86,
|
||||||
|
|
||||||
dependency('pixman-1'),
|
dependency('pixman-1'),
|
||||||
|
|
Loading…
Reference in a new issue