aboutsummaryrefslogtreecommitdiffstats
path: root/lib/os_mon/c_src/cpu_sup.c
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2011-09-19 19:26:54 +0200
committerMicael Karlberg <[email protected]>2011-09-19 19:26:54 +0200
commit7c730a573a7e239f41bc619b024a675667767428 (patch)
tree1265ca1ddae47b094af21f669d0526c9c1b074dd /lib/os_mon/c_src/cpu_sup.c
parent13fcdd5c954ddbb8ac9401d73f8e77423fbd976c (diff)
parente84f232326b2800ca806c867b2bfbe3652d423cb (diff)
downloadotp-7c730a573a7e239f41bc619b024a675667767428.tar.gz
otp-7c730a573a7e239f41bc619b024a675667767428.tar.bz2
otp-7c730a573a7e239f41bc619b024a675667767428.zip
Merge branch 'dev' of super:otp into bmk/inets/inets571_integration
Diffstat (limited to 'lib/os_mon/c_src/cpu_sup.c')
-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);
}