hostname: use POSIX routine to get hostname rather than reading from procfs
authorAli H. Fardan <raiz@firemail.cc>
Sat, 8 Oct 2016 16:55:25 +0000 (19:55 +0300)
committerAli H. Fardan <raiz@firemail.cc>
Sat, 8 Oct 2016 16:55:25 +0000 (19:55 +0300)
slstatus.c

index ba7f95a2a8b439955430753a1f5e1a7ca716b543..641730515d9953b56a33973426ba0d448ff4d80f 100644 (file)
@@ -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);
 }