aboutsummaryrefslogtreecommitdiffstats
path: root/lib/os_mon/c_src
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2011-09-19 09:42:28 +0200
committerBjörn-Egil Dahlberg <[email protected]>2011-09-19 09:42:28 +0200
commit2d13b9580f405541e46491743702eaaedf3f6e91 (patch)
tree41582dd49f44ee1f2ab92a207bd48e40533ba773 /lib/os_mon/c_src
parent9d1b6de75122c940333fe86b931771cc6f2d67e2 (diff)
parent2c79dee4b4f2a0a692cdf28399fc069eca18f07a (diff)
downloadotp-2d13b9580f405541e46491743702eaaedf3f6e91.tar.gz
otp-2d13b9580f405541e46491743702eaaedf3f6e91.tar.bz2
otp-2d13b9580f405541e46491743702eaaedf3f6e91.zip
Merge branch 'egil/fix-compiler-warning/OTP-9542' into dev
* egil/fix-compiler-warning/OTP-9542: 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/c_src')
-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);
}