From 837ff5d713c667f2ea0d111333098dad3175e9b8 Mon Sep 17 00:00:00 2001 From: Nathan Straz Date: Fri, 27 Sep 2013 11:42:39 -0400 Subject: Remove offset from data packet We really don't need this field since we always copy data sequentially. --- qacp.c | 5 +---- qarsh.c | 4 ++-- qarsh_packet.c | 9 +++------ qarsh_packet.h | 3 +-- qarshd.c | 63 ++++------------------------------------------------------ 5 files changed, 11 insertions(+), 73 deletions(-) diff --git a/qacp.c b/qacp.c index 34c0399..39fffba 100644 --- a/qacp.c +++ b/qacp.c @@ -144,7 +144,6 @@ qacp_sendonefile(const char *host, const char *srcfile, const char *destfile) struct qa_packet *qp; int fd; ssize_t nbytes; - off_t offset; struct stat sb; const int bufsize = QARSH_MAX_PACKET_SIZE/2; char buf[bufsize]; @@ -179,7 +178,6 @@ qacp_sendonefile(const char *host, const char *srcfile, const char *destfile) send_packet(qacp_fd, qp); qpfree(qp); - offset = 0; dallow = 0; complete = 0; for (;;) { @@ -233,11 +231,10 @@ qacp_sendonefile(const char *host, const char *srcfile, const char *destfile) strerror(errno)); qp = make_qp_returncode(-1, errno, strerror(errno)); } else { - qp = make_qp_data(0, offset, nbytes, buf); + qp = make_qp_data(0, nbytes, buf); if (nbytes == 0) { /* Transfer is complete */ complete = 1; } else { - offset += nbytes; dallow -= nbytes; } } diff --git a/qarsh.c b/qarsh.c index 9081ee3..bcfcf5c 100644 --- a/qarsh.c +++ b/qarsh.c @@ -251,7 +251,7 @@ run_remote_cmd(char *cmdline) if (allowed_in != -1) { /* close stdin if it is a tty */ if (stdin_isatty) { - qp = make_qp_data(0, 0, 0, NULL); + qp = make_qp_data(0, 0, NULL); ret = send_packet(qarsh_fd, qp); if (ret == -1) { fprintf(stderr, "Failed to send data packet: %s\n", strerror(errno)); @@ -304,7 +304,7 @@ run_remote_cmd(char *cmdline) if (nset && FD_ISSET(fileno(stdin), &rfds)) { nbytes = read(fileno(stdin), buf, allowed_in); if (nbytes >= 0) { - qp = make_qp_data(0, 0, nbytes, buf); + qp = make_qp_data(0, nbytes, buf); ret = send_packet(qarsh_fd, qp); if (ret == -1) { fprintf(stderr, "Failed to send data packet: %s\n", strerror(errno)); diff --git a/qarsh_packet.c b/qarsh_packet.c index 1f170f6..f657dd1 100644 --- a/qarsh_packet.c +++ b/qarsh_packet.c @@ -354,7 +354,6 @@ void parse_qp_data(char *buf, int *buflen, struct qa_packet *qp) { buf = fetch_uint8(buf, buflen, (int *)&(qp->qp_data.qp_remfd)); - buf = fetch_off_t(buf, buflen, &(qp->qp_data.qp_offset)); buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_count)); if (qp->qp_data.qp_count > *buflen) { lprintf(LOG_ERR, "Blob is larger than rest of packet, %d > %d\n", @@ -528,7 +527,6 @@ char * store_qp_data(char *buf, struct qa_packet *qp) { buf = store_uint8(buf, qp->qp_data.qp_remfd); - buf = store_off_t(buf, qp->qp_data.qp_offset); buf = store_void(buf, qp->qp_data.qp_count, qp->qp_data.qp_blob); return buf; } @@ -716,7 +714,7 @@ make_qp_rstat(const char *path, const struct stat *sb) } struct qa_packet * -make_qp_data(const int remfd, const off_t offset, const int count, void *blob) +make_qp_data(const int remfd, const int count, void *blob) { struct qa_packet *qp; qp = malloc(sizeof *qp); @@ -725,7 +723,6 @@ make_qp_data(const int remfd, const off_t offset, const int count, void *blob) qp->qp_type = QP_DATA; qp->qp_data.qp_remfd = remfd; - qp->qp_data.qp_offset = offset; qp->qp_data.qp_count = count; /* data packets are different, the blob is just a pointer which * must stick around until after the packet is sent. This is to @@ -891,8 +888,8 @@ dump_qp_rstat(struct qa_packet *qp) void dump_qp_data(struct qa_packet *qp) { - lprintf(LOG_DEBUG, "remfd: %d offset: %lld count: %d", - qp->qp_data.qp_remfd, (long long int)qp->qp_data.qp_offset, qp->qp_data.qp_count); + lprintf(LOG_DEBUG, "remfd: %d count: %d", + qp->qp_data.qp_remfd, qp->qp_data.qp_count); } void diff --git a/qarsh_packet.h b/qarsh_packet.h index 19ade47..430ff79 100644 --- a/qarsh_packet.h +++ b/qarsh_packet.h @@ -95,7 +95,6 @@ struct qp_rstat_pkt { struct qp_data_pkt { int qp_remfd; /* remote fd to write to */ - off_t qp_offset; /* offset in file for this data */ int qp_count; /* length of data buffer */ int free_blob; /* Whether qpfree should free the blob */ void *qp_blob; @@ -151,7 +150,7 @@ struct qa_packet *make_qp_kill(int sig); struct qa_packet *make_qp_recvfile(const char *path, off_t count, mode_t mode); struct qa_packet *make_qp_sendfile(const char *path); struct qa_packet *make_qp_rstat(const char *path, const struct stat *sb); -struct qa_packet *make_qp_data(const int remfd, const off_t offset, const int count, void *blob); +struct qa_packet *make_qp_data(const int remfd, const int count, void *blob); struct qa_packet *make_qp_data_allow(const int remfd, const int count); int qptostr(struct qa_packet *qp, char *qpstr, int maxsize); void qpfree(struct qa_packet *qp); diff --git a/qarshd.c b/qarshd.c index e8a5ec7..ca812cc 100644 --- a/qarshd.c +++ b/qarshd.c @@ -198,8 +198,7 @@ receive_data(struct qa_packet *qp) if (debug) syslog(LOG_DEBUG, "Transfer complete\n"); return make_qp_returncode(0, 0, "Transfer complete"); } - if (debug) syslog(LOG_DEBUG, "Data for %d, %d@%ld\n", - receivefd, qp->qp_data.qp_count, qp->qp_data.qp_offset); + if (debug) syslog(LOG_DEBUG, "Data for %d, %d\n", receivefd, qp->qp_data.qp_count); nwrote = 0; do { ret = write(receivefd, qp->qp_data.qp_blob + nwrote, qp->qp_data.qp_count - nwrote); @@ -229,60 +228,6 @@ prepare_sendfile(struct qa_packet *qp) return NULL; } -ssize_t -pushfile(const char *path) -{ - int infd; - off_t offset; - ssize_t nbytes, fsize = 0; - struct stat sb; - const int bufsize = 16384; - char buf[bufsize]; - struct qa_packet *qp; - - infd = open(path, O_RDONLY); - if (infd == -1) { - syslog(LOG_WARNING, "Could not open %s: %s\n", - path, strerror(errno)); - return -1; - } - - if (strcmp(saved_path, path)) { - if (fstat(infd, &sb) < 0) { - syslog(LOG_WARNING, "Could not stat %s: %s\n", - path, strerror(errno)); - close(infd); - return -1; - } else { - fsize = sb.st_size; - } - } else { - fsize = saved_stat.st_size; - } - if (!fsize) { - fprintf(stderr, "Unknown file size to send\n"); - close(infd); - return -1; - } - offset = 0; - do { - nbytes = read(infd, buf, bufsize); - if (nbytes < 0) { - fprintf(stderr, "read() error: %s\n", strerror(errno)); - qp = make_qp_returncode(-1, errno, strerror(errno)); - } else { - qp = make_qp_data(0, offset, nbytes, buf); - } - send_packet(qoutfd, qp); - offset += nbytes; - qpfree(qp); - } while (nbytes > 0); - - close(infd); - - return offset; -} - void save_stat(const char *path, const struct stat *sb) { @@ -465,7 +410,7 @@ handle_qarsh() if (nfd && FD_ISSET(childfds[1], &rfds)) { /* Child has something to send to stdout */ nbytes = read(childfds[1], buf, allowed_out); - qp = make_qp_data(1, 0, nbytes, buf); + qp = make_qp_data(1, nbytes, buf); send_packet(qoutfd, qp); qpfree(qp); allowed_out -= nbytes; @@ -479,7 +424,7 @@ handle_qarsh() if (nfd && FD_ISSET(childfds[2], &rfds)) { /* Child has something to send to stderr */ nbytes = read(childfds[2], buf, allowed_err); - qp = make_qp_data(2, 0, nbytes, buf); + qp = make_qp_data(2, nbytes, buf); send_packet(qoutfd, qp); qpfree(qp); allowed_err -= nbytes; @@ -577,7 +522,7 @@ handle_packets() if (nbytes == -1) { qp = make_qp_returncode(-1, errno, strerror(errno)); } else { - rp = make_qp_data(0, 0, nbytes, buf); + rp = make_qp_data(0, nbytes, buf); if (nbytes == 0) { close(sendfd); sendfd = -1; -- cgit