mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 14:45:58 +01:00
Make libcap optional.
This commit is contained in:
parent
5c211e6195
commit
dd40a42a99
4 changed files with 30 additions and 5 deletions
|
@ -50,7 +50,7 @@ find_package(GBM REQUIRED)
|
||||||
find_package(LibInput REQUIRED)
|
find_package(LibInput REQUIRED)
|
||||||
find_package(XKBCommon REQUIRED)
|
find_package(XKBCommon REQUIRED)
|
||||||
find_package(Udev REQUIRED)
|
find_package(Udev REQUIRED)
|
||||||
find_package(Libcap REQUIRED)
|
find_package(Libcap)
|
||||||
find_package(Systemd)
|
find_package(Systemd)
|
||||||
|
|
||||||
include(Wayland)
|
include(Wayland)
|
||||||
|
|
|
@ -18,6 +18,7 @@ Install dependencies:
|
||||||
* libinput
|
* libinput
|
||||||
* udev
|
* udev
|
||||||
* systemd (optional, for logind support)
|
* systemd (optional, for logind support)
|
||||||
|
* libcap (optional, for capability support)
|
||||||
* asciidoc (optional, for man pages)
|
* asciidoc (optional, for man pages)
|
||||||
|
|
||||||
Run these commands:
|
Run these commands:
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
include_directories(
|
include_directories(
|
||||||
${WAYLAND_INCLUDE_DIR}
|
${WAYLAND_INCLUDE_DIR}
|
||||||
${DRM_INCLUDE_DIRS}
|
${DRM_INCLUDE_DIRS}
|
||||||
${Libcap_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(sources
|
set(sources
|
||||||
|
@ -12,7 +11,6 @@ set(sources
|
||||||
set(libs
|
set(libs
|
||||||
wlr-util
|
wlr-util
|
||||||
${WAYLAND_LIBRARIES}
|
${WAYLAND_LIBRARIES}
|
||||||
${Libcap_LIBRARIES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (SYSTEMD_FOUND)
|
if (SYSTEMD_FOUND)
|
||||||
|
@ -24,5 +22,13 @@ if (SYSTEMD_FOUND)
|
||||||
list(APPEND libs ${SYSTEMD_LIBRARIES})
|
list(APPEND libs ${SYSTEMD_LIBRARIES})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (Libcap_FOUND)
|
||||||
|
add_definitions(${Libcap_DEFINITIONS})
|
||||||
|
include_directories(${Libcap_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
add_definitions(-DHAS_LIBCAP)
|
||||||
|
list(APPEND libs ${Libcap_LIBRARIES})
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_library(wlr-session ${sources})
|
add_library(wlr-session ${sources})
|
||||||
target_link_libraries(wlr-session ${libs})
|
target_link_libraries(wlr-session ${libs})
|
||||||
|
|
|
@ -321,17 +321,35 @@ static void communicate(int sock) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_session *direct_session_start(struct wl_display *disp) {
|
#ifdef HAS_LIBCAP
|
||||||
|
static bool have_permissions(void) {
|
||||||
cap_t cap = cap_get_proc();
|
cap_t cap = cap_get_proc();
|
||||||
cap_flag_value_t val;
|
cap_flag_value_t val;
|
||||||
|
|
||||||
if (!cap || cap_get_flag(cap, CAP_SYS_ADMIN, CAP_PERMITTED, &val) || val != CAP_SET) {
|
if (!cap || cap_get_flag(cap, CAP_SYS_ADMIN, CAP_PERMITTED, &val) || val != CAP_SET) {
|
||||||
wlr_log(L_ERROR, "Do not have CAP_SYS_ADMIN; cannot become DRM master");
|
wlr_log(L_ERROR, "Do not have CAP_SYS_ADMIN; cannot become DRM master");
|
||||||
cap_free(cap);
|
cap_free(cap);
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cap_free(cap);
|
cap_free(cap);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static bool have_permissions(void) {
|
||||||
|
if (geteuid() != 0) {
|
||||||
|
wlr_log(L_ERROR, "Do not have root privileges; cannot become DRM master");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static struct wlr_session *direct_session_start(struct wl_display *disp) {
|
||||||
|
if (!have_permissions()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int sock[2];
|
int sock[2];
|
||||||
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sock) < 0) {
|
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sock) < 0) {
|
||||||
|
|
Loading…
Reference in a new issue