diff options
author | Björn-Egil Dahlberg <[email protected]> | 2011-09-16 16:52:00 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2011-09-16 16:52:00 +0200 |
commit | 211389b07fed7ac2bc1d7f713f0b42dc93cf615c (patch) | |
tree | 8eed3a7af224444b0512fa189caa32c7445843a0 | |
parent | a27dbff4ba4313b28bdfa132d6120e4b71d5986d (diff) | |
download | otp-211389b07fed7ac2bc1d7f713f0b42dc93cf615c.tar.gz otp-211389b07fed7ac2bc1d7f713f0b42dc93cf615c.tar.bz2 otp-211389b07fed7ac2bc1d7f713f0b42dc93cf615c.zip |
os_mon: Check results from fgets in cpu_sup
-rw-r--r-- | lib/os_mon/c_src/cpu_sup.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/os_mon/c_src/cpu_sup.c b/lib/os_mon/c_src/cpu_sup.c index fbf318c614..e3bdbd1489 100644 --- a/lib/os_mon/c_src/cpu_sup.c +++ b/lib/os_mon/c_src/cpu_sup.c @@ -191,7 +191,10 @@ int main(int argc, char** argv) { static cpu_t *read_procstat(FILE *fp, cpu_t *cpu) { char buffer[BUFFERSIZE]; - fgets(buffer, BUFFERSIZE, fp); + if (fgets(buffer, BUFFERSIZE, fp) == NULL) { + memset(cpu, 0, sizeof(cpu_t)); + return cpu; + } sscanf(buffer, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &(cpu->id), &(cpu->user), @@ -223,7 +226,11 @@ static void util_measure(unsigned int **result_vec, int *result_sz) { return; } - fgets(buffer, BUFFERSIZE, fp); /*ignore read*/ + /*ignore read*/ + if (fgets(buffer, BUFFERSIZE, fp) == NULL) { + *result_sz = 0; + return; + } rv = *result_vec; rv[0] = no_of_cpus; rv[1] = CU_VALUES; @@ -447,8 +454,12 @@ static void sendv(unsigned int data[], int ints) { } static void error(char* err_msg) { - write(FD_ERR, err_msg, strlen(err_msg)); - write(FD_ERR, "\n", 1); + /* + * if we get error here we have trouble, + * silence unnecessary warnings + */ + if(write(FD_ERR, err_msg, strlen(err_msg))); + if(write(FD_ERR, "\n", 1)); exit(-1); } |