From 42815bcf65f8c6b7eeb915ef88dab7d11dd8eede Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 2 May 2008 01:14:32 +0200 Subject: [PATCH] collectd-nagios: Open two different I/O streams for reading and writing. Full-duplex standard I/O streams are not really supported on sockets. Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- src/collectd-nagios.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index 63effd55..f4dff5bb 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) -- 2.11.0