summaryrefslogtreecommitdiffstats
path: root/qarshd.c
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-09-09 10:05:44 -0500
committerNathan Straz <nstraz@redhat.com>2013-09-11 17:51:52 -0400
commitf9e8d1c326353fc527fc5c6fee78797f9fe6e96c (patch)
treea53a927647177570d758d806d3bebca42195b60e /qarshd.c
parentea6e0450c85776ee4a578be239b87309fdc1142c (diff)
downloadqarsh-f9e8d1c326353fc527fc5c6fee78797f9fe6e96c.tar.gz
qarsh-f9e8d1c326353fc527fc5c6fee78797f9fe6e96c.tar.xz
qarsh-f9e8d1c326353fc527fc5c6fee78797f9fe6e96c.zip
Fix up stdin handling
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) {