Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cmake/compile_definitions/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,24 @@ if(X11_FOUND)
"${CMAKE_SOURCE_DIR}/src/platform/linux/x11grab.cpp")
endif()

# GIO
pkg_check_modules(GIO gio-2.0 gio-unix-2.0 REQUIRED)
if(GIO_FOUND)
include_directories(SYSTEM ${GIO_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBRARIES ${GIO_LIBRARIES})
endif()

# XDG portal
if(${SUNSHINE_ENABLE_PORTAL})
pkg_check_modules(GIO gio-2.0 gio-unix-2.0 REQUIRED)
pkg_check_modules(PIPEWIRE libpipewire-0.3 REQUIRED)
else()
set(GIO_FOUND OFF)
set(PIPEWIRE_FOUND OFF)
endif()
if(PIPEWIRE_FOUND)

if(PIPEWIRE_FOUND AND GIO_FOUND)
add_compile_definitions(SUNSHINE_BUILD_PORTAL)
include_directories(SYSTEM ${GIO_INCLUDE_DIRS} ${PIPEWIRE_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBRARIES ${GIO_LIBRARIES} ${PIPEWIRE_LIBRARIES})
include_directories(SYSTEM ${PIPEWIRE_INCLUDE_DIRS})
list(APPEND PLATFORM_LIBRARIES ${PIPEWIRE_LIBRARIES})
list(APPEND PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/linux/portalgrab.cpp")
endif()
Expand Down
67 changes: 66 additions & 1 deletion src/platform/linux/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
// platform includes
#include <arpa/inet.h>
#include <dlfcn.h>
#include <gio/gio.h> // For RTKit
#include <ifaddrs.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <pwd.h>
#include <sys/resource.h> // For setpriority
#include <sys/socket.h>

#ifdef __FreeBSD__
#include <net/if_dl.h> // For sockaddr_dl, LLADDR, and AF_LINK
#include <sys/syscall.h> // For syscall: SYS_thr_self
#include <sys/thr.h> // For thr_self
#endif

// lib includes
Expand Down Expand Up @@ -324,7 +328,68 @@
}

void adjust_thread_priority(thread_priority_e priority) {
// Unimplemented
#if defined(__FreeBSD__)
pid_t tid = syscall(SYS_thr_self);
#else
pid_t tid = syscall(SYS_gettid);
#endif
bool success = false;
int32_t linux_nice;

using enum thread_priority_e;
switch (priority) {
case low:
linux_nice = 10;
break;
case normal:
linux_nice = 0;
break;
case high:
linux_nice = -10;
break;
case critical:
linux_nice = -15;
break;
default:
BOOST_LOG(debug) << "Unknown thread priority: "sv << std::to_underlying(priority);
return;
}

g_autoptr(GError) err = nullptr;
GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);

if (conn) {
g_dbus_connection_call_sync(
conn,
"org.freedesktop.RealtimeKit1",
"/org/freedesktop/RealtimeKit1",
"org.freedesktop.RealtimeKit1",
"MakeThreadHighPriority",
g_variant_new("(ti)", (guint64) tid, linux_nice),
nullptr,
G_DBUS_CALL_FLAGS_NONE,
-1,
nullptr,
&err
);

if (!err) {
success = true;
BOOST_LOG(debug) << "RTKit: Successfully set priority to "sv << linux_nice;
} else {
BOOST_LOG(debug) << "RTKit: Could not set priority: "sv << err->message;
g_clear_error(&err);
}
}

if (!success) {
// This will run on FreeBSD OR Linux if RTKit failed/was missing
if (setpriority(PRIO_PROCESS, 0, linux_nice) == -1) {
BOOST_LOG(warning) << "setpriority failed for nice "sv << linux_nice << ": "sv << strerror(errno);
} else {
BOOST_LOG(debug) << "setpriority success for nice "sv << linux_nice;
}
}
}

void set_thread_name(const std::string &name) {
Expand All @@ -344,7 +409,7 @@
}

void restart_on_exit() {
char executable[PATH_MAX];

Check warning on line 412 in src/platform/linux/misc.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::string" instead of a C-style char array.

See more on https://sonarcloud.io/project/issues?id=LizardByte_Sunshine&issues=AZ0TQJ_9ynbVXazXkPo7&open=AZ0TQJ_9ynbVXazXkPo7&pullRequest=4885
ssize_t len = readlink("/proc/self/exe", executable, PATH_MAX - 1);
if (len == -1) {
BOOST_LOG(fatal) << "readlink() failed: "sv << errno;
Expand Down
Loading