From 8d6f3aff31e7c60b1baff013a55e34e5116abcc5 Mon Sep 17 00:00:00 2001 From: Nathan Straz Date: Mon, 14 Sep 2009 15:06:44 -0400 Subject: Handle growing files better in qacp Cache the results from the rstat packet and use that file size during the following sendfile so we don't send more than qacp is expecting. This should allow us to qacp root@host:/var/log/messages --- qarshd.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'qarshd.c') diff --git a/qarshd.c b/qarshd.c index ccfd339..345f6de 100644 --- a/qarshd.c +++ b/qarshd.c @@ -51,6 +51,11 @@ int debug = 0; struct sockaddr_in peername; int child_exitted = 0; +/* A mini cache for rstat so we can check it in pushfile */ +char *saved_path = NULL; +struct stat saved_stat; + + int setup_user(char *user, char *group) { @@ -196,22 +201,32 @@ pushfile(const char *path, int of_port) return -1; } - if (fstat(infd, &sb) < 0) { + if (strcmp(saved_path, path) == 0) { + nbytes = sendfile(outsd, infd, &offset, saved_stat.st_size); + } else if (fstat(infd, &sb) < 0) { syslog(LOG_WARNING, "Could not stat %s: %s\n", path, strerror(errno)); close(infd); close(outsd); return -1; + } else { /* fstat filled in sb */ + nbytes = sendfile(outsd, infd, &offset, sb.st_size); } - nbytes = sendfile(outsd, infd, &offset, sb.st_size); - close(infd); close(outsd); return nbytes; } +void +save_stat(const char *path, const struct stat *sb) +{ + if (saved_path) free(saved_path); + saved_path = strdup(path); + memcpy(&saved_stat, sb, sizeof saved_stat); +} + struct qa_packet * rstat(const char *path) { @@ -223,6 +238,7 @@ rstat(const char *path) } else { rp = make_qp_rstat(path, &sb); } + save_stat(path, &sb); return rp; } -- cgit