Use pretty hostnames only when systemd is supported. (#5)
This commit is contained in:
@@ -51,6 +51,7 @@ if (WIVRN_BUILD_SERVER)
|
|||||||
message(FATAL_ERROR "No encoder found")
|
message(FATAL_ERROR "No encoder found")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
pkg_check_modules(SYSTEMD IMPORTED_TARGET systemd)
|
||||||
pkg_check_modules(AVAHI IMPORTED_TARGET avahi-client)
|
pkg_check_modules(AVAHI IMPORTED_TARGET avahi-client)
|
||||||
pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
|
pkg_check_modules(libpulse IMPORTED_TARGET libpulse)
|
||||||
find_package(Eigen3 REQUIRED)
|
find_package(Eigen3 REQUIRED)
|
||||||
|
|||||||
@@ -93,6 +93,12 @@ if(X264_FOUND)
|
|||||||
target_link_libraries(wivrn-server PRIVATE PkgConfig::X264)
|
target_link_libraries(wivrn-server PRIVATE PkgConfig::X264)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(SYSTEMD_FOUND)
|
||||||
|
target_sources(wivrn-server PRIVATE hostname-sd.cpp)
|
||||||
|
target_link_libraries(wivrn-server PRIVATE PkgConfig::SYSTEMD)
|
||||||
|
else()
|
||||||
|
target_sources(wivrn-server PRIVATE hostname.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(CompileGLSL)
|
include(CompileGLSL)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#include "hostname.h"
|
||||||
|
#include <systemd/sd-bus.h>
|
||||||
|
|
||||||
|
std::string hostname()
|
||||||
|
{
|
||||||
|
sd_bus * bus;
|
||||||
|
if (sd_bus_default_system(&bus) < 0)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
for (auto property: {"PrettyHostname", "StaticHostname", "Hostname"})
|
||||||
|
{
|
||||||
|
char * hostname = nullptr;
|
||||||
|
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
|
|
||||||
|
if (sd_bus_get_property_string(bus, "org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1", property, &error, &hostname) < 0)
|
||||||
|
{
|
||||||
|
sd_bus_error_free(&error);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sd_bus_error_free(&error);
|
||||||
|
if (hostname && strcmp(hostname, ""))
|
||||||
|
{
|
||||||
|
std::string s = hostname;
|
||||||
|
free(hostname);
|
||||||
|
sd_bus_unref(bus);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sd_bus_unref(bus);
|
||||||
|
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -1,5 +1,4 @@
|
|||||||
#include "hostname.h"
|
#include "hostname.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -11,3 +10,4 @@ std::string hostname()
|
|||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user