From: Michał Mirosław Date: Sat, 21 Jun 2008 20:21:56 +0000 (+0200) Subject: processes plugin: Use read_file_contents(). X-Git-Tag: collectd-4.5.0~109 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ce140b198884909f060dcdf5bfb7fac8799f50ea;p=collectd.git processes plugin: Use read_file_contents(). src/processes.c: use read_file_contents() Signed-off-by: Michał Mirosław Signed-off-by: Florian Forster --- diff --git a/src/processes.c b/src/processes.c index 54596723..c0d667d3 100644 --- a/src/processes.c +++ b/src/processes.c @@ -644,7 +644,6 @@ int ps_read_process (int pid, procstat_t *ps, char *state) { char filename[64]; char buffer[1024]; - FILE *fh; char *fields[64]; char fields_len; @@ -663,16 +662,10 @@ int ps_read_process (int pid, procstat_t *ps, char *state) ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid); - if ((fh = fopen (filename, "r")) == NULL) + i = read_file_contents (filename, buffer, sizeof(buffer) - 1); + if (i <= 0) return (-1); - - if (fgets (buffer, 1024, fh) == NULL) - { - fclose (fh); - return (-1); - } - - fclose (fh); + buffer[i] = 0; fields_len = strsplit (buffer, fields, 64); if (fields_len < 24)