[collectd] [PATCH] collectd-nagios: Open two different I/O streams for reading and writing.

Sebastian Harl sh at tokkee.org
Fri May 2 01:14:32 CEST 2008


Full-duplex standard I/O streams are not really supported on sockets.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/collectd-nagios.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index 63effd5..f4dff5b 100644
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
@@ -142,7 +142,7 @@ static int get_values (int *ret_values_num, double **ret_values,
 	struct sockaddr_un sa;
 	int status;
 	int fd;
-	FILE *fh;
+	FILE *fh_in, *fh_out;
 	char buffer[4096];
 
 	int values_num;
@@ -172,8 +172,8 @@ static int get_values (int *ret_values_num, double **ret_values,
 		return (-1);
 	}
 
-	fh = fdopen (fd, "r+");
-	if (fh == NULL)
+	fh_in = fdopen (fd, "r");
+	if (fh_in == NULL)
 	{
 		fprintf (stderr, "fdopen failed: %s\n",
 				strerror (errno));
@@ -181,17 +181,28 @@ static int get_values (int *ret_values_num, double **ret_values,
 		return (-1);
 	}
 
-	fprintf (fh, "GETVAL %s/%s\n", hostname_g, value_string_g);
-	fflush (fh);
+	fh_out = fdopen (fd, "w");
+	if (fh_out == NULL)
+	{
+		fprintf (stderr, "fdopen failed: %s\n",
+				strerror (errno));
+		fclose (fh_in);
+		return (-1);
+	}
+
+	fprintf (fh_out, "GETVAL %s/%s\n", hostname_g, value_string_g);
+	fflush (fh_out);
 
-	if (fgets (buffer, sizeof (buffer), fh) == NULL)
+	if (fgets (buffer, sizeof (buffer), fh_in) == NULL)
 	{
 		fprintf (stderr, "fgets failed: %s\n",
 				strerror (errno));
-		close (fd);
+		fclose (fh_in);
+		fclose (fh_out);
 		return (-1);
 	}
-	close (fd); fd = -1;
+	fclose (fh_in); fh_in = NULL; fd = -1;
+	fclose (fh_out); fh_out = NULL;
 
 	values_num = atoi (buffer);
 	if (values_num < 1)
-- 
1.5.5.1.79.g57cf

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080502/68036469/attachment.pgp 


More information about the collectd mailing list