Use HOST_NAME_MAX instead of hardcoding the maximum hostname length

This commit is contained in:
Guillaume Meunier
2023-11-24 12:05:23 +01:00
parent d74512bebb
commit a1d8aef1d6
3 changed files with 12 additions and 8 deletions
+5 -1
View File
@@ -16,6 +16,7 @@ include(FetchContent)
include(ExternalProject) include(ExternalProject)
option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON) option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(WIVRN_USE_SYSTEMD "Use systemd" ON)
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF) option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
option(WIVRN_BUILD_CLIENT "Build WiVRn client" ON) option(WIVRN_BUILD_CLIENT "Build WiVRn client" ON)
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON) option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
@@ -54,7 +55,10 @@ 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) if (WIVRN_USE_SYSTEMD)
pkg_check_modules(SYSTEMD REQUIRED IMPORTED_TARGET systemd)
endif()
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)
+1 -1
View File
@@ -100,7 +100,7 @@ if(X264_FOUND)
target_link_libraries(wivrn-server PRIVATE PkgConfig::X264) target_link_libraries(wivrn-server PRIVATE PkgConfig::X264)
endif() endif()
if(SYSTEMD_FOUND) if(WIVRN_USE_SYSTEMD)
target_sources(wivrn-server PRIVATE hostname-sd.cpp) target_sources(wivrn-server PRIVATE hostname-sd.cpp)
target_link_libraries(wivrn-server PRIVATE PkgConfig::SYSTEMD) target_link_libraries(wivrn-server PRIVATE PkgConfig::SYSTEMD)
else() else()
+6 -6
View File
@@ -1,13 +1,13 @@
#include "hostname.h" #include "hostname.h"
#include <string> #include <string>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
std::string hostname() std::string hostname()
{ {
char buf[256]; char buf[HOST_NAME_MAX];
int code = gethostname(buf, 256); int code = gethostname(buf, HOST_NAME_MAX);
if (code == 0) if (code == 0)
return std::string(buf); return buf;
return "unknown"; return "unknown";
} }