diff options
author | Ali H. Fardan <raiz@firemail.cc> | 2016-10-08 19:55:25 +0300 |
---|---|---|
committer | Ali H. Fardan <raiz@firemail.cc> | 2016-10-08 19:55:25 +0300 |
commit | 4339c8330a3a9ac2a4000201a286cdda3808b4f6 (patch) | |
tree | 7682621299bd9d35dea516882208b1b36487b629 /slstatus.c | |
parent | fb440d8f622142c11e98e4799b7adceb33cd23b0 (diff) |
hostname: use POSIX routine to get hostname rather than reading from procfs
Diffstat (limited to 'slstatus.c')
-rw-r--r-- | slstatus.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -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); } |