diff options
author | Michael Stapelberg <michael+x200@stapelberg.de> | 2008-10-07 11:22:35 +0200 |
---|---|---|
committer | Michael Stapelberg <michael+x200@stapelberg.de> | 2008-10-07 11:22:35 +0200 |
commit | e94e25208936ab8f6ab684b1b229bc29073b955d (patch) | |
tree | 3cc37c0b59377b91b5461b0ef594b77e04083e46 /wmiistatus.c | |
parent | e31a85eb3b9d331d73254ceb2d6156cc8e66c40a (diff) |
Strip all non-digit characters from pidbuf
This is needed for dhclient's pidfile, as it contains a newline
Diffstat (limited to 'wmiistatus.c')
-rw-r--r-- | wmiistatus.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/wmiistatus.c b/wmiistatus.c index 00aa487..bdb1e6a 100644 --- a/wmiistatus.c +++ b/wmiistatus.c @@ -246,7 +246,9 @@ static char *get_eth_info() { */ static bool process_runs(const char *path) { char pidbuf[512], - procbuf[512]; + procbuf[512], + *walk; + int n; static glob_t globbuf; struct stat statbuf; @@ -257,8 +259,15 @@ static bool process_runs(const char *path) { globfree(&globbuf); if (fd < 0) return false; - read(fd, pidbuf, sizeof(pidbuf)); + n = read(fd, pidbuf, sizeof(pidbuf)); + if (n > 0) + pidbuf[n] = '\0'; close(fd); + for (walk = pidbuf; *walk != '\0'; walk++) + if (!isdigit((int)(*walk))) { + *walk = '\0'; + break; + } sprintf(procbuf, "/proc/%s", pidbuf); return (stat(procbuf, &statbuf) >= 0); } |