2006-12-19 00:17:32 +01:00
|
|
|
--- proc/readproc.c
|
2012-06-04 16:22:08 +02:00
|
|
|
+++ proc/readproc.c 2012-06-01 15:00:43.848010122 +0000
|
|
|
|
@@ -527,7 +527,7 @@ static int file2str(const char *director
|
2006-12-19 00:17:32 +01:00
|
|
|
int fd, num_read;
|
|
|
|
|
|
|
|
sprintf(filename, "%s/%s", directory, what);
|
|
|
|
- fd = open(filename, O_RDONLY, 0);
|
|
|
|
+ fd = open(filename, O_RDONLY, O_NOATIME);
|
|
|
|
if(unlikely(fd==-1)) return -1;
|
|
|
|
num_read = read(fd, ret, cap - 1);
|
|
|
|
close(fd);
|
2012-06-04 16:22:08 +02:00
|
|
|
@@ -538,41 +538,42 @@ static int file2str(const char *director
|
2006-12-19 00:17:32 +01:00
|
|
|
|
|
|
|
static char** file2strvec(const char* directory, const char* what) {
|
|
|
|
char buf[2048]; /* read buf bytes at a time */
|
|
|
|
- char *p, *rbuf = 0, *endbuf, **q, **ret;
|
|
|
|
- int fd, tot = 0, n, c, end_of_file = 0;
|
2007-01-12 19:23:43 +01:00
|
|
|
- int align;
|
2006-12-19 00:17:32 +01:00
|
|
|
+ char *p, *rbuf = (char*)0, *endbuf, **q, **ret;
|
2007-01-12 19:23:43 +01:00
|
|
|
+ int fd, c;
|
|
|
|
+ ssize_t n, align, tot = 0;
|
2006-12-19 00:17:32 +01:00
|
|
|
|
|
|
|
sprintf(buf, "%s/%s", directory, what);
|
|
|
|
- fd = open(buf, O_RDONLY, 0);
|
|
|
|
+ fd = open(buf, O_RDONLY, O_NOATIME);
|
|
|
|
if(fd==-1) return NULL;
|
|
|
|
|
|
|
|
/* read whole file into a memory buffer, allocating as we go */
|
2012-06-04 16:22:08 +02:00
|
|
|
- while ((n = read(fd, buf, sizeof buf - 1)) >= 0) {
|
2006-12-19 00:17:32 +01:00
|
|
|
- if (n < (int)(sizeof buf - 1))
|
|
|
|
- end_of_file = 1;
|
2012-06-04 16:22:08 +02:00
|
|
|
- if (n == 0 && rbuf == 0) {
|
|
|
|
- close(fd);
|
2006-12-19 00:17:32 +01:00
|
|
|
- return NULL; /* process died between our open and read */
|
2012-06-04 16:22:08 +02:00
|
|
|
- }
|
2007-01-12 19:23:43 +01:00
|
|
|
+ do {
|
|
|
|
+ n = read(fd, buf, sizeof(buf) - 1);
|
2006-12-19 00:17:32 +01:00
|
|
|
if (n < 0) {
|
2007-01-12 19:23:43 +01:00
|
|
|
- if (rbuf)
|
|
|
|
- free(rbuf);
|
2012-06-04 16:22:08 +02:00
|
|
|
- close(fd);
|
2007-01-12 19:23:43 +01:00
|
|
|
- return NULL; /* read error */
|
|
|
|
+ tot = 0;
|
|
|
|
+ break; /* read error! */
|
2006-12-19 00:17:32 +01:00
|
|
|
+ }
|
|
|
|
+ if (n == 0) {
|
|
|
|
+ if(rbuf == (char*)0)
|
2007-01-12 19:23:43 +01:00
|
|
|
+ tot = 0; /* process died between our open and read */
|
2006-12-19 00:17:32 +01:00
|
|
|
+ break; /* we're done */
|
|
|
|
}
|
2012-06-04 16:22:08 +02:00
|
|
|
- if (end_of_file && (n == 0 || buf[n-1]))/* last read char not null */
|
2006-12-19 00:17:32 +01:00
|
|
|
- buf[n++] = '\0'; /* so append null-terminator */
|
|
|
|
rbuf = xrealloc(rbuf, tot + n); /* allocate more memory */
|
|
|
|
memcpy(rbuf + tot, buf, n); /* copy buffer into it */
|
|
|
|
tot += n; /* increment total byte ctr */
|
|
|
|
- if (end_of_file)
|
|
|
|
- break;
|
2007-01-12 19:23:43 +01:00
|
|
|
- }
|
2012-06-04 16:22:08 +02:00
|
|
|
+ } while (n >= (sizeof(buf) - 1));
|
2007-01-12 19:23:43 +01:00
|
|
|
+
|
2006-12-19 00:17:32 +01:00
|
|
|
close(fd);
|
|
|
|
- if (n <= 0 && !end_of_file) {
|
2007-01-12 19:23:43 +01:00
|
|
|
+
|
2006-12-19 00:17:32 +01:00
|
|
|
+ if (tot == 0) {
|
2012-06-04 16:22:08 +02:00
|
|
|
if (rbuf) free(rbuf);
|
|
|
|
- return NULL; /* read error */
|
|
|
|
+ return NULL; /* read error */
|
|
|
|
+ }
|
2007-01-12 19:23:43 +01:00
|
|
|
+ if (rbuf[tot-1]) { /* last read char not null */
|
|
|
|
+ rbuf = xrealloc(rbuf, tot + 1); /* allocate more memory */
|
|
|
|
+ rbuf[tot++] = '\0'; /* and append null-terminator */
|
2012-06-04 16:22:08 +02:00
|
|
|
}
|
2007-01-12 19:23:43 +01:00
|
|
|
+
|
2006-12-19 00:17:32 +01:00
|
|
|
endbuf = rbuf + tot; /* count space for pointers */
|
|
|
|
align = (sizeof(char*)-1) - ((tot + sizeof(char*)-1) & (sizeof(char*)-1));
|
2012-06-04 16:22:08 +02:00
|
|
|
for (c = 0, p = rbuf; p < endbuf; p++) {
|
|
|
|
@@ -605,7 +606,7 @@ static int read_unvectored(char *restric
|
2006-12-19 00:17:32 +01:00
|
|
|
unsigned n = 0;
|
2012-06-04 16:22:08 +02:00
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "%s/%s", whom, what);
|
|
|
|
- fd = open(path, O_RDONLY);
|
|
|
|
+ fd = open(path, O_RDONLY, O_NOATIME);
|
2006-12-19 00:17:32 +01:00
|
|
|
if(fd==-1) return 0;
|
2012-06-04 16:22:08 +02:00
|
|
|
|
2006-12-19 00:17:32 +01:00
|
|
|
for(;;){
|