From: Sebastian Harl Date: Thu, 1 May 2008 23:14:32 +0000 (+0200) Subject: collectd-nagios: Open two different I/O streams for reading and writing. X-Git-Tag: collectd-4.4.0~6 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=42815bcf65f8c6b7eeb915ef88dab7d11dd8eede;p=collectd.git 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 --- 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)