mirror of
https://github.com/pikami/slstatus.git
synced 2024-11-27 13:55:41 +00:00
hostname: use POSIX routine to get hostname rather than reading from procfs
This commit is contained in:
parent
fb440d8f62
commit
4339c8330a
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user