hostname: use POSIX routine to get hostname rather than reading from procfs
Ali H. Fardan raiz@firemail.cc
Sat, 08 Oct 2016 19:55:25 +0300
1 files changed,
2 insertions(+),
6 deletions(-)
jump to
M
slstatus.c
→
slstatus.c
@@ -271,14 +271,10 @@ {
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); }