From 9fc82fc82e7248a598b8c8bedd86cecb3c10d1e9 Mon Sep 17 00:00:00 2001 From: Nate Straz Date: Thu, 16 Nov 2006 04:17:02 +0000 Subject: Use off_t instead of size_t so we can transfer files larger than 2GB. I changed all formats from %zd to %lld, but this adds a lot of warnings because off_t isn't the same as long long int to the compiler. I don't know if there is a way to avoid the warnings on all platforms. --- Makefile | 2 +- qacp.c | 2 +- qarsh_packet.c | 12 ++++++------ qarsh_packet.h | 4 ++-- qarshd.c | 19 ++++++++++--------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 7d9427b..aae72f2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: clean clobber uninstall -CFLAGS := -Wall -g -I/usr/include/libxml2 +CFLAGS := -Wall -g -I/usr/include/libxml2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE COMMON := qarsh_packet.c sockutil.c diff --git a/qacp.c b/qacp.c index c9d76d7..b2b9286 100644 --- a/qacp.c +++ b/qacp.c @@ -282,7 +282,7 @@ qacp_recvonefile(const char *host, const char *srcfile, const char *destfile) if (nleft != 0) { unlink(destfile); fprintf(stderr, "Short file transfer of %s, " - "%zd bytes lost, wanted %ld\n", srcfile, nleft, + "%lld bytes lost, wanted %lld\n", srcfile, nleft, rstatp->qp_st_size); } diff --git a/qarsh_packet.c b/qarsh_packet.c index 6e70e79..f3f6ebb 100644 --- a/qarsh_packet.c +++ b/qarsh_packet.c @@ -277,7 +277,7 @@ parse_qp_recvfile(xmlXPathContextPtr ctxt, struct qa_packet *qp) free(s); s = get_xpath_string(ctxt, "param[@name='count']"); - qp->qp_recvfile.qp_count = atoi(s); + qp->qp_recvfile.qp_count = atoll(s); free(s); s = get_xpath_string(ctxt, "param[@name='mode']"); @@ -496,7 +496,7 @@ void string_qp_recvfile(xmlNodePtr node, struct qa_packet *qp) snprintf(tmpstr, 32, "%d", qp->qp_recvfile.qp_if_port); xmlAddChild(node, make_param("if_port", tmpstr)); - snprintf(tmpstr, 32, "%zd", qp->qp_recvfile.qp_count); + snprintf(tmpstr, 32, "%lld", qp->qp_recvfile.qp_count); xmlAddChild(node, make_param("count", tmpstr)); snprintf(tmpstr, 32, "%d", qp->qp_recvfile.qp_mode); @@ -523,7 +523,7 @@ void string_qp_rstat(xmlNodePtr node, struct qa_packet *qp) xmlAddChild(node, make_param("st_uid", tmpstr)); snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_gid); xmlAddChild(node, make_param("st_gid", tmpstr)); - snprintf(tmpstr, 32, "%ld", qp->qp_rstat.qp_st_size); + snprintf(tmpstr, 32, "%lld", qp->qp_rstat.qp_st_size); xmlAddChild(node, make_param("st_size", tmpstr)); } @@ -669,7 +669,7 @@ make_qp_kill(int sig) } struct qa_packet * -make_qp_recvfile(const char *path, int if_port, size_t count, mode_t mode) +make_qp_recvfile(const char *path, int if_port, off_t count, mode_t mode) { struct qa_packet *qp; qp = malloc(sizeof *qp); @@ -831,7 +831,7 @@ dump_qp_recvfile(struct qa_packet *qp) { printf("\tpath: %s\n", qp->qp_recvfile.qp_path); printf("\tif_port: %d\n", qp->qp_recvfile.qp_if_port); - printf("\tcount: %zd\n", qp->qp_recvfile.qp_count); + printf("\tcount: %lld\n", qp->qp_recvfile.qp_count); printf("\tmode: %o\n", qp->qp_recvfile.qp_mode); } @@ -849,7 +849,7 @@ dump_qp_rstat(struct qa_packet *qp) printf("\tst_mode: %o\n", qp->qp_rstat.qp_st_mode); printf("\tst_uid: %d\n", qp->qp_rstat.qp_st_uid); printf("\tst_gid: %d\n", qp->qp_rstat.qp_st_gid); - printf("\tst_size: %ld\n", qp->qp_rstat.qp_st_size); + printf("\tst_size: %lld\n", qp->qp_rstat.qp_st_size); } void diff --git a/qarsh_packet.h b/qarsh_packet.h index e854bd5..2ed50f4 100644 --- a/qarsh_packet.h +++ b/qarsh_packet.h @@ -80,7 +80,7 @@ struct qp_recvfile_pkt { char *qp_path; mode_t qp_mode; int qp_if_port; - size_t qp_count; + off_t qp_count; }; struct qp_sendfile_pkt { @@ -137,7 +137,7 @@ struct qa_packet *make_qp_runcmd(char *cmdline, int p_in, int p_out, int p_err); struct qa_packet *make_qp_cmdexit(pid_t pid, int status); struct qa_packet *make_qp_setuser(char *user, char *group); struct qa_packet *make_qp_kill(int sig); -struct qa_packet *make_qp_recvfile(const char *path, int if_port, size_t count, mode_t mode); +struct qa_packet *make_qp_recvfile(const char *path, int if_port, off_t count, mode_t mode); struct qa_packet *make_qp_sendfile(const char *path, int of_port); struct qa_packet *make_qp_rstat(const char *path, const struct stat *sb); char *qptostr(struct qa_packet *qp, char **qpstr, int *qpsize); diff --git a/qarshd.c b/qarshd.c index 9f9bba8..a961086 100644 --- a/qarshd.c +++ b/qarshd.c @@ -112,15 +112,15 @@ run_cmd(const char *cmd, int p_in, int p_out, int p_err) return pid; } -ssize_t -recvfile(const char *path, int if_port, size_t count, mode_t mode) +off_t +recvfile(const char *path, int if_port, off_t count, mode_t mode) { int sd; int ofd; char buf[BUFSIZ]; - ssize_t nread; - ssize_t nwrote; - ssize_t nleft; + off_t nread; + off_t nwrote; + off_t nleft; /* Read count bytes from ifd (sd after we connect), * write into file @ path @@ -156,7 +156,7 @@ recvfile(const char *path, int if_port, size_t count, mode_t mode) if (nleft != 0) { unlink(path); syslog(LOG_WARNING, "Short file transfer in recvfile(), " - "%zd bytes lost, wanted %zd\n", nleft, count); + "%lld bytes lost, wanted %lld\n", nleft, count); } close(sd); @@ -232,7 +232,7 @@ handle_packets(int infd) pid_t child_pid = 0; int child_status; - ssize_t nbytes; + off_t nbytes; sigemptyset(&sigmask); sigaddset(&sigmask, SIGCHLD); @@ -271,6 +271,7 @@ handle_packets(int infd) syslog(LOG_DEBUG, "That's enough\n"); break; } + dump_qp(qp); switch (qp->qp_type) { case QP_KILL: if (child_pid) { @@ -298,7 +299,7 @@ handle_packets(int infd) break; case QP_RECVFILE: syslog(LOG_INFO, "Got a QP_RECVFILE with path = %s, " - "ifd = %d, count = %zd, mode = %o\n", + "ifd = %d, count = %lld, mode = %o\n", qp->qp_recvfile.qp_path, qp->qp_recvfile.qp_if_port, qp->qp_recvfile.qp_count, @@ -311,7 +312,7 @@ handle_packets(int infd) rp = make_qp_returncode(-1, errno, strerror(errno)); } else if (nbytes < qp->qp_recvfile.qp_count) { char tmpstr[512]; - sprintf(tmpstr, "Excpected %zd, wrote %zd\n", + sprintf(tmpstr, "Excpected %lld, wrote %lld\n", qp->qp_recvfile.qp_count, nbytes); rp = make_qp_returncode(-1, 0, tmpstr); } else { -- cgit