From: Aaron Marcher Date: Wed, 12 Oct 2016 20:01:46 +0000 (+0200) Subject: Merge pull request #23 from R41z/master X-Git-Url: https://git.xinqibao.xyz/slstatus.git/commitdiff_plain/97c745e10e3f0710db4b2c84340171f915f2f6c6?hp=39fa14916b8a7432ebef574c6739cafc0bc2ed2f Merge pull request #23 from R41z/master get rid of unused variable (silly gcc did not report that error) --- diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 63a71c9..7a61847 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,3 +7,4 @@ Thanks you very much for your great help! - [pfannkuckengesicht](https://github.com/pfannkuchengesicht) - [sahne](https://github.com/sahne) - [Ali H. Fardan](http://raiz.duckdns.org) +- [Quentin Rameau](https://fifth.space) diff --git a/slstatus.c b/slstatus.c index 3d9712f..d442776 100644 --- a/slstatus.c +++ b/slstatus.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -271,7 +272,7 @@ hostname(void) char buf[HOST_NAME_MAX]; if (gethostname(buf, sizeof(buf)) == -1) { - warn(1, "hostname"); + warn("hostname"); return smprintf(UNKNOWN_STR); } @@ -400,17 +401,19 @@ static char * run_command(const char *cmd) { FILE *fp; - char buf[64] = "n/a"; + char buf[1024] = "n/a"; fp = popen(cmd, "r"); if (fp == NULL) { warn("Failed to get command output for %s", cmd); return smprintf(UNKNOWN_STR); } - fgets(buf, sizeof(buf), fp); - buf[sizeof(buf)-1] = '\0'; + fgets(buf, sizeof(buf)-1, fp); pclose(fp); + buf[strlen(buf)] = '\0'; + strtok(buf, "\n"); + return smprintf("%s", buf); } @@ -497,9 +500,9 @@ vol_perc(const char *card) snd_mixer_close(handle); if (max == 0) - return smprintf("%d%%", 0); + return smprintf("0%%"); else - return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); + return smprintf("%lu%%", ((uint_fast16_t)(vol * 100) / max)); } static char * @@ -619,8 +622,8 @@ main(int argc, char *argv[]) if (dflag && oflag) { usage(); } - if (dflag) { - (void)daemon(1, 1); + if (dflag && daemon(1, 1) < 0) { + err(1, "daemon"); } memset(&act, 0, sizeof(act)); @@ -632,6 +635,8 @@ main(int argc, char *argv[]) dpy = XOpenDisplay(NULL); } + setlocale(LC_ALL, ""); + while (!done) { status_string[0] = '\0';