summaryrefslogtreecommitdiffstats
path: root/qarshd.c
diff options
context:
space:
mode:
Diffstat (limited to 'qarshd.c')
-rw-r--r--qarshd.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/qarshd.c b/qarshd.c
index 915098c..7f0f944 100644
--- a/qarshd.c
+++ b/qarshd.c
@@ -283,9 +283,10 @@ handle_qarsh()
int child_status;
struct qa_packet *qp = NULL, *rp = NULL;
int allowed_out = 0, allowed_err = 0; /* number of bytes we can send to client */
- char buf[4096], buf_in[4096];
- int eof_in = 0;
- int z_in = 0;
+ char buf[4096]; /* short term buffer for stdout and stderr */
+ char buf_in[4096]; /* long term buffer for stdin */
+ int z_in = 0; /* Number of bytes in stdin buffer */
+ int eof_in = 0; /* Have we seen EOF on stdin yet? */
int nbytes;
sigemptyset(&sigmask);
@@ -367,9 +368,20 @@ handle_qarsh()
qp->qp_data.qp_remfd, qp->qp_data.qp_count, QARSHD_BUFSIZE - z_in);
break;
}
- if (qp->qp_data.qp_count == 0) eof_in = 1;
- memcpy(buf_in+z_in, qp->qp_data.qp_blob, qp->qp_data.qp_count);
- z_in += qp->qp_data.qp_count;
+ if (eof_in) {
+ syslog(LOG_ERR, "Received data on stdin after EOF\n");
+ break;
+ }
+ if (qp->qp_data.qp_count == 0) {
+ eof_in = 1;
+ if (z_in == 0) {
+ close(childfds[0]);
+ childfds[0] = -1;
+ }
+ } else {
+ memcpy(buf_in+z_in, qp->qp_data.qp_blob, qp->qp_data.qp_count);
+ z_in += qp->qp_data.qp_count;
+ }
break;
case QP_DALLOW:
if (qp->qp_dallow.qp_remfd == 1) {