summaryrefslogtreecommitdiff
path: root/src/libvmon/vmon.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2024-07-23 02:02:51 -0700
committerVito Caputo <vcaputo@pengaru.com>2024-07-23 02:02:51 -0700
commit9f564cf8df6ef5fcba37082ba8013d6175955125 (patch)
treef2492e7b0d1ab82033c73d22700e04bf1b4b7c61 /src/libvmon/vmon.c
parentd113bc4f3328bd2859bf13bf4a92ce2ad668fd85 (diff)
libvmon: assume short positive reads found EOF
This avoids a bunch of pread() returning 0 EOF-finding calls. These are proc files, and actually shouldn't be getting read in a loop like this at all because it's racy to do so. With proc files you need to atomically read everything you wish to parse as one sample as an atomic unit. So this needs to be properly reworked to enlarge the buffer when a read exhausts it, throwing away what was read, then repeating the sample with the enlarged buffer. But this is tenable for now until I get around to the proper rework... just looking to reduce some sampling overheads on lower end embedded devices.
Diffstat (limited to 'src/libvmon/vmon.c')
-rw-r--r--src/libvmon/vmon.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libvmon/vmon.c b/src/libvmon/vmon.c
index 83d78c4..cace462 100644
--- a/src/libvmon/vmon.c
+++ b/src/libvmon/vmon.c
@@ -138,6 +138,12 @@ static char * load_contents_fd(vmon_t *vmon, vmon_char_array_t *array, int fd, v
memcmpcpy(&alloc[total], vmon->buf, len, changed, changed_pos);
total += len;
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf)) {
+ len = 0;
+ break;
+ }
}
array->array = alloc;
@@ -347,6 +353,10 @@ static sample_ret_t proc_sample_stat(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_
goto _out; /* this saves us the EOF read syscall */
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
_out:
@@ -430,6 +440,10 @@ static int proc_follow_children(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_follo
break;
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
/* look for children which seem to no longer exist (found by stale generation numbers) and queue them for unmonitoring, flag this as a children change too */
@@ -791,6 +805,10 @@ static sample_ret_t proc_sample_vm(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_vm
goto _out; /* this saves us the EOF read syscall */
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
_out:
@@ -848,6 +866,10 @@ static sample_ret_t proc_sample_io(vmon_t *vmon, vmon_proc_t *proc, vmon_proc_io
goto _out; /* this saves us the EOF read syscall */
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
_out:
@@ -911,6 +933,10 @@ static sample_ret_t sys_sample_stat(vmon_t *vmon, vmon_sys_stat_t **store)
goto _out; /* this saves us the EOF read syscall */
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
_out:
@@ -961,6 +987,10 @@ static sample_ret_t sys_sample_vm(vmon_t *vmon, vmon_sys_vm_t **store)
goto _out; /* this saves us the EOF read syscall */
}
}
+
+ /* assume short read found EOF */
+ if (len < sizeof(vmon->buf))
+ break;
}
_out:
© All Rights Reserved