summaryrefslogtreecommitdiffstats
path: root/qarsh/qarsh.c
diff options
context:
space:
mode:
Diffstat (limited to 'qarsh/qarsh.c')
-rw-r--r--qarsh/qarsh.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/qarsh/qarsh.c b/qarsh/qarsh.c
index 0c90568..20e7023 100644
--- a/qarsh/qarsh.c
+++ b/qarsh/qarsh.c
@@ -63,8 +63,8 @@ int
run_remote_cmd(char *cmdline)
{
struct qa_packet *qp;
- char *packetbuf;
- int packetsize;
+ char *buf;
+ int bufsize;
int rc;
int p_in, p_out, p_err; /* Port numbers */
int l_in, l_out, l_err; /* listening sockets */
@@ -83,10 +83,8 @@ run_remote_cmd(char *cmdline)
qp = make_qp_runcmd(cmdline, p_in, p_out, p_err);
qp->qp_seq = 1;
- packetbuf = qptostr(qp, &packetbuf, &packetsize);
+ send_packet(qarsh_fd, qp);
qpfree(qp);
- write(qarsh_fd, packetbuf, packetsize);
- free(packetbuf);
/* Get the stdin, stdout, and stderr connections up before we do work */
FD_ZERO(&readfds);
@@ -146,20 +144,20 @@ run_remote_cmd(char *cmdline)
if (fcntl(fileno(stdin), F_SETFL, O_NONBLOCK) != 0) {
fprintf(stderr, "fcntl stdin O_NONBLOCK failed, %d: %s\n", errno, strerror(errno));
}
- packetbuf = malloc(1024);
- memset(packetbuf, 0, 1024);
+ buf = malloc(1024);
+ memset(buf, 0, 1024);
for (;;) {
testfds = readfds;
- memset(packetbuf, 0, 1024);
+ memset(buf, 0, 1024);
nset = select(FD_SETSIZE, &testfds, NULL, NULL, NULL);
if (FD_ISSET(fileno(stdin), &testfds)) {
do {
- packetsize = read(fileno(stdin), packetbuf, 1024);
- write(c_in, packetbuf, packetsize);
- } while (packetsize == 1024);
- if (packetsize == 0) {
+ bufsize = read(fileno(stdin), buf, 1024);
+ write(c_in, buf, bufsize);
+ } while (bufsize == 1024);
+ if (bufsize == 0) {
FD_CLR(fileno(stdin), &readfds);
close(c_in);
c_in = 0;
@@ -167,10 +165,10 @@ run_remote_cmd(char *cmdline)
}
if (c_out && FD_ISSET(c_out, &testfds)) {
do {
- packetsize = read(c_out, packetbuf, 1024);
- write(fileno(stdout), packetbuf, packetsize);
- } while (packetsize == 1024);
- if (packetsize == 0) {
+ bufsize = read(c_out, buf, 1024);
+ write(fileno(stdout), buf, bufsize);
+ } while (bufsize == 1024);
+ if (bufsize == 0) {
FD_CLR(c_out, &readfds);
close(c_out);
c_out = 0;
@@ -178,22 +176,17 @@ run_remote_cmd(char *cmdline)
}
if (c_err && FD_ISSET(c_err, &testfds)) {
do {
- packetsize = read(c_err, packetbuf, 1024);
- write(fileno(stderr), packetbuf, packetsize);
- } while (packetsize == 1024);
- if (packetsize == 0) {
+ bufsize = read(c_err, buf, 1024);
+ write(fileno(stderr), buf, bufsize);
+ } while (bufsize == 1024);
+ if (bufsize == 0) {
FD_CLR(c_err, &readfds);
close(c_err);
c_err = 0;
}
}
if (FD_ISSET(qarsh_fd, &testfds)) {
- packetsize = read(qarsh_fd, packetbuf, 1024);
- if (packetsize == 0) {
- qp = NULL;
- break;
- }
- qp = parse_packets(packetbuf, packetsize);
+ qp = recv_packet(qarsh_fd);
/* dump_qp(qp); */
if (qp && qp->qp_type == QP_CMDEXIT) {
@@ -206,7 +199,7 @@ run_remote_cmd(char *cmdline)
if (c_err) close(c_err);
if (qp == NULL) {
fprintf(stderr, "Remote command exited with unknown state\n");
- free(packetbuf);
+ free(buf);
return 127;
}
if (WIFSIGNALED(qp->qp_cmdexit.qp_status)) {
@@ -215,7 +208,7 @@ run_remote_cmd(char *cmdline)
rc = WEXITSTATUS(qp->qp_cmdexit.qp_status);
}
qpfree(qp);
- free(packetbuf);
+ free(buf);
return rc;
}