[collectd] [PATCH 4/4] use read_file_contents() in processes plugin

Michał Mirosław mirq-linux at rere.qmqm.pl
Sat Jun 21 22:21:56 CEST 2008


src/processes.c: use read_file_contents()

Signed-off-by: Michał Mirosław <mirq-linux at rere.qmqm.pl>

diff --git a/src/processes.c b/src/processes.c
--- 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)



More information about the collectd mailing list