From ab08f9e0a29cfb21193fdd985db34f13bb826b71 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 31 Jul 2025 19:17:35 +0200 Subject: [PATCH] os: utils:: use xhostname() Simplify set_font_authorizations() by using xhostname(). Neither need to care about OS specifics here, nor take care of zero-terminating the hostname string - xhostname() is already doing this. Signed-off-by: Enrico Weigelt, metux IT consult --- os/utils.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/os/utils.c b/os/utils.c index 9ec93f39c..3c4fb9b7d 100644 --- a/os/utils.c +++ b/os/utils.c @@ -102,6 +102,7 @@ OR PERFORMANCE OF THIS SOFTWARE. #include "os/log_priv.h" #include "os/osdep.h" #include "os/serverlock.h" +#include "os/xhostname.h" #include "Xext/xf86bigfontsrv.h" /* XF86BigfontCleanup() */ #include "xkb/xkbsrv_priv.h" #include "dixstruct.h" @@ -796,7 +797,6 @@ set_font_authorizations(char **authorizations, int *authlen, void *client) static char *p = NULL; if (p == NULL) { - char hname[1024], *hnameptr; unsigned int len; #if defined(HAVE_GETADDRINFO) @@ -809,20 +809,23 @@ set_font_authorizations(char **authorizations, int *authlen, void *client) #endif #endif - gethostname(hname, 1024); + struct xhostname hn; + xhostname(&hn); + + char *hnameptr = NULL; #if defined(HAVE_GETADDRINFO) memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; - if (getaddrinfo(hname, NULL, &hints, &ai) == 0) { + if (getaddrinfo(hn.name, NULL, &hints, &ai) == 0) { hnameptr = ai->ai_canonname; } else { - hnameptr = hname; + hnameptr = hn.name; } #else - host = _XGethostbyname(hname, hparams); + host = _XGethostbyname(hn.name, hparams); if (host == NULL) - hnameptr = hname; + hnameptr = hn.name; else hnameptr = host->h_name; #endif