From: Yoga Ramalingam Date: Wed, 12 Nov 2014 21:07:15 +0000 (-0500) Subject: collectdctl command hangs on AIX and returns error 0 on Solaris. X-Git-Tag: collectd-5.3.2~17^2~2 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=993900f43c19c3836a6a4e89268ffb6d17d0fce0;p=collectd.git collectdctl command hangs on AIX and returns error 0 on Solaris. Summary: Problem: collectdctl command hangs on AIX and returns error 0 on Solaris. Root cause - client (collectdctl) and server (collectd daemon) are using fprintf to communicate using Unix domain socket, Since fprintf buffers, command sent by client did not reach server, since client does not get the response, it closes the socket which forces the client to flush the command, now server receives the command, when responding, it gets socket error because the client already closed the socket. Solution: Added flush after all fprintf calls. Test Plan: Tested collectdctl on AIX and SunOS for listval, getval commands Reviewers: skhajamo Reviewed By: skhajamo CC: arcyd Differential Revision: https://all.phab.dev.bloomberg.com/D155584 --- diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 726f25d4..49a4d879 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -258,6 +258,7 @@ static int lcc_send (lcc_connection_t *c, const char *command) /* {{{ */ lcc_set_errno (c, errno); return (-1); } + fflush(c->fh); return (0); } /* }}} int lcc_send */ diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c index 3584f3b7..c35aeb04 100644 --- a/src/utils_cmd_flush.c +++ b/src/utils_cmd_flush.c @@ -32,7 +32,8 @@ WARNING ("handle_flush: failed to write to socket #%i: %s", \ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ return -1; \ - } + } \ + fflush(fh); static int add_to_array (char ***array, int *array_num, char *value) { diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c index ce3e28e0..9de66df3 100644 --- a/src/utils_cmd_getval.c +++ b/src/utils_cmd_getval.c @@ -32,7 +32,8 @@ WARNING ("handle_getval: failed to write to socket #%i: %s", \ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ return -1; \ - } + } \ + fflush(fh); int handle_getval (FILE *fh, char *buffer) { diff --git a/src/utils_cmd_listval.c b/src/utils_cmd_listval.c index ef66af56..864e5f44 100644 --- a/src/utils_cmd_listval.c +++ b/src/utils_cmd_listval.c @@ -44,7 +44,8 @@ WARNING ("handle_listval: failed to write to socket #%i: %s", \ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ free_everything_and_return (-1); \ - } + } \ + fflush(fh); int handle_listval (FILE *fh, char *buffer) { diff --git a/src/utils_cmd_putnotif.c b/src/utils_cmd_putnotif.c index d3cf3834..d09eeb3e 100644 --- a/src/utils_cmd_putnotif.c +++ b/src/utils_cmd_putnotif.c @@ -31,7 +31,8 @@ WARNING ("handle_putnotif: failed to write to socket #%i: %s", \ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ return -1; \ - } + } \ + fflush(fh); static int set_option_severity (notification_t *n, const char *value) { diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index 4cbc2f1d..d579b6e8 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -31,7 +31,8 @@ WARNING ("handle_putval: failed to write to socket #%i: %s", \ fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \ return -1; \ - } + } \ + fflush(fh); static int dispatch_values (const data_set_t *ds, value_list_t *vl, FILE *fh, char *buffer)