picom: get max hostname length with sysconf()

For FreeBSD compatibility, which doesn't define HOST_NAME_MAX.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-10-25 03:13:03 +00:00
parent 02daff8bc8
commit 27d59dbb30
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 7 additions and 2 deletions

View File

@ -18,6 +18,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <xcb/composite.h>
#include <xcb/damage.h>
#include <xcb/glx.h>
@ -972,8 +973,10 @@ static int register_cm(session_t *ps) {
// Set WM_CLIENT_MACHINE. As per EWMH, because we set _NET_WM_PID, we must also
// set WM_CLIENT_MACHINE.
{
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, sizeof(hostname)) == 0) {
const auto hostname_max = (unsigned long)sysconf(_SC_HOST_NAME_MAX);
char *hostname = malloc(hostname_max);
if (gethostname(hostname, hostname_max) == 0) {
e = xcb_request_check(
ps->c, xcb_change_property_checked(
ps->c, XCB_PROP_MODE_REPLACE, ps->reg_win,
@ -987,6 +990,8 @@ static int register_cm(session_t *ps) {
} else {
log_error_errno("Failed to get hostname");
}
free(hostname);
}
// Set _NET_WM_PID