summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2009-09-14 15:06:44 -0400
committerNathan Straz <nstraz@redhat.com>2009-09-14 15:06:44 -0400
commit8d6f3aff31e7c60b1baff013a55e34e5116abcc5 (patch)
tree6c2472e42f70f1971413559a93fba4511980fad8
parentf2328f0f062ce649d1464413521499ef5ef135c1 (diff)
downloadqarsh-8d6f3aff31e7c60b1baff013a55e34e5116abcc5.tar.gz
qarsh-8d6f3aff31e7c60b1baff013a55e34e5116abcc5.tar.xz
qarsh-8d6f3aff31e7c60b1baff013a55e34e5116abcc5.zip
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
-rw-r--r--qarshd.c22
1 files changed, 19 insertions, 3 deletions
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;
}