From: Ali H. Fardan Date: Sat, 8 Oct 2016 16:55:25 +0000 (+0300) Subject: hostname: use POSIX routine to get hostname rather than reading from procfs X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=4339c8330a3a9ac2a4000201a286cdda3808b4f6;p=suckless%2Fslstatus.git hostname: use POSIX routine to get hostname rather than reading from procfs --- diff --git a/slstatus.c b/slstatus.c index ba7f95a..6417305 100644 --- a/slstatus.c +++ b/slstatus.c @@ -271,14 +271,10 @@ hostname(void) char buf[HOST_NAME_MAX]; FILE *fp; - fp = fopen("/proc/sys/kernel/hostname", "r"); - if (fp == NULL) { - warn("Failed to open file /proc/sys/kernel/hostname"); + if (gethostname(buf, sizeof(buf)) == -1) { + warn(1, "hostname"); return smprintf(UNKNOWN_STR); } - fgets(buf, sizeof(buf), fp); - buf[strlen(buf)-1] = '\0'; - fclose(fp); return smprintf("%s", buf); }