aboutsummaryrefslogtreecommitdiffstats
path: root/lib/os_mon
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2011-09-19 09:42:57 +0200
committerBjörn-Egil Dahlberg <[email protected]>2011-09-19 09:42:57 +0200
commit87288e173f09d573460a06d98466f84cba8f4b5c (patch)
tree2e0949deb7bc6c27e58feb870458dc1583cd4e07 /lib/os_mon
parentadbad8f580825761238c647e181a07678f07d361 (diff)
parent2d13b9580f405541e46491743702eaaedf3f6e91 (diff)
downloadotp-87288e173f09d573460a06d98466f84cba8f4b5c.tar.gz
otp-87288e173f09d573460a06d98466f84cba8f4b5c.tar.bz2
otp-87288e173f09d573460a06d98466f84cba8f4b5c.zip
Merge branch 'dev' into major
* dev: gs: Update to modern type guards in examples os_mon: Check results from fgets in cpu_sup erts: Remove compiler warning in sys.c
Diffstat (limited to 'lib/os_mon')
-rw-r--r--lib/os_mon/c_src/cpu_sup.c19
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);
}