From fb440d8f622142c11e98e4799b7adceb33cd23b0 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 8 Oct 2016 19:50:53 +0300 Subject: [PATCH 1/2] vol_perc: return zero if the value of max is set to zero --- slstatus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slstatus.c b/slstatus.c index f6e8339..ba7f95a 100644 --- a/slstatus.c +++ b/slstatus.c @@ -501,7 +501,10 @@ vol_perc(const char *card) snd_mixer_selem_id_free(s_elem); snd_mixer_close(handle); - return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); + if (max == 0) + return smprintf("%d%%", 0); + else + return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); } static char * From 4339c8330a3a9ac2a4000201a286cdda3808b4f6 Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Sat, 8 Oct 2016 19:55:25 +0300 Subject: [PATCH 2/2] hostname: use POSIX routine to get hostname rather than reading from procfs --- slstatus.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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); }