X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprocess_runs.c;h=08963a0abe49920e51c76e455f29db36a324b1a4;hb=ee946d0d8c49f164fde0f863a5fffb646d20db27;hp=1836507aeabc866a07eb1e78d8107948d7d9bfc0;hpb=653505a3bbaad141d9fb94458e2ffffe312a8e58;p=i3%2Fi3status diff --git a/src/process_runs.c b/src/process_runs.c index 1836507..08963a0 100644 --- a/src/process_runs.c +++ b/src/process_runs.c @@ -1,4 +1,5 @@ -// vim:ts=8:sw=8:expandtab +// vim:ts=4:sw=4:expandtab +#include #include #include #include @@ -20,30 +21,30 @@ * */ bool process_runs(const char *path) { - static char pidbuf[16]; - static glob_t globbuf; - memset(pidbuf, 0, sizeof(pidbuf)); + static char pidbuf[16]; + static glob_t globbuf; + memset(pidbuf, 0, sizeof(pidbuf)); - if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) - die("glob() failed\n"); - if (globbuf.gl_pathc == 0) { - /* No glob matches, the specified path does not contain a wildcard. */ - globfree(&globbuf); - if (!slurp(path, pidbuf, sizeof(pidbuf))) - return false; - return (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM); + if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) != 0) + die("glob() failed\n"); + if (globbuf.gl_pathc == 0) { + /* No glob matches, the specified path does not contain a wildcard. */ + globfree(&globbuf); + if (!slurp(path, pidbuf, sizeof(pidbuf))) + return false; + return (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM); + } + for (size_t i = 0; i < globbuf.gl_pathc; i++) { + if (!slurp(globbuf.gl_pathv[i], pidbuf, sizeof(pidbuf))) { + globfree(&globbuf); + return false; } - for (size_t i = 0; i < globbuf.gl_pathc; i++) { - if (!slurp(globbuf.gl_pathv[i], pidbuf, sizeof(pidbuf))) { - globfree(&globbuf); - return false; - } - if (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM) { - globfree(&globbuf); - return true; - } + if (kill(strtol(pidbuf, NULL, 10), 0) == 0 || errno == EPERM) { + globfree(&globbuf); + return true; } - globfree(&globbuf); + } + globfree(&globbuf); - return false; + return false; }