aboutsummaryrefslogtreecommitdiff
path: root/write_or_die.c
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2006-08-31 08:42:11 +0200
committerJunio C Hamano <junkio@cox.net>2006-08-31 14:16:38 -0700
commit7cf67205ca68a157c6ffdb4e5a4ff231217c0871 (patch)
treef0b8a3170cf5abcc5e448e8d1c58ccae7bfc940c /write_or_die.c
parent2c6d22df9f8a975c88fc9a93c4db8bb0bd116b74 (diff)
downloadgit-7cf67205ca68a157c6ffdb4e5a4ff231217c0871.tar.gz
git-7cf67205ca68a157c6ffdb4e5a4ff231217c0871.tar.xz
Trace into open fd and refactor tracing code.
Now if GIT_TRACE is set to an integer value greater than 1 and lower than 10, we interpret this as an open fd value and we trace into it. Note that this behavior is not compatible with the previous one. We also trace whole messages using one write(2) call to make sure messages from processes do net get mixed up in the middle. It's now possible to run the tests like this: GIT_TRACE=9 make test 9>/var/tmp/trace.log Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'write_or_die.c')
-rw-r--r--write_or_die.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/write_or_die.c b/write_or_die.c
index ab4cb8a69..bfe4eeb64 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -18,3 +18,28 @@ void write_or_die(int fd, const void *buf, size_t count)
p += written;
}
}
+
+int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
+{
+ const char *p = buf;
+ ssize_t written;
+
+ while (count > 0) {
+ written = xwrite(fd, p, count);
+ if (written == 0) {
+ fprintf(stderr, "%s: disk full?\n", msg);
+ return 0;
+ }
+ else if (written < 0) {
+ if (errno == EPIPE)
+ exit(0);
+ fprintf(stderr, "%s: write error (%s)\n",
+ msg, strerror(errno));
+ return 0;
+ }
+ count -= written;
+ p += written;
+ }
+
+ return 1;
+}