Package: reprepro
Version: 5.3.0-1.1
Severity: important
Tags: patch
X-Debbugs-Cc: none, Hilko Bengen <ben...@debian.org>

Dear Maintainer,

when used with --endhook, reprepro fails to output anything if standard
output is a pipe. Here's a minimal reproducer:

,----
| $ mkdir -p r/conf
| $ cat > r/conf/distributions <<EOF
| Codename: sid
| Architectures: amd64 source
| Components: main
| EOF
| $ reprepro -b r includedsc sid hello_2.10-2.dsc
| Exporting indices...
| $ reprepro -b r list sid
| sid|main|source: hello 2.10-2
| $ reprepro -b r list sid | cat
| sid|main|source: hello 2.10-2
| $ reprepro -b r --endhook /bin/true list sid | cat
| $
`----

Apparently stdio buffers are not flushed before exec()ing the endhook
program. The attached patch fixes this.

Cheers,
-Hilko
>From 14c3140374e3cf815bda060d5e4e668484b92791 Mon Sep 17 00:00:00 2001
From: Hilko Bengen <ben...@debian.org>
Date: Wed, 10 Feb 2021 01:47:23 +0100
Subject: [PATCH] Flush stdout, stderr before calling endhook

---
 main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/main.c b/main.c
index 31aa5cf..d6ee80d 100644
--- a/main.c
+++ b/main.c
@@ -4906,6 +4906,8 @@ static inline int callendhook(int status, char *argv[]) {
 	if (snprintf(exitcode, 4, "%u", ((unsigned int)status)&255U) > 3)
 		memcpy(exitcode, "255", 4);
 	sethookenvironment(causingfile, NULL, NULL, exitcode);
+        fflush(stdout);
+        fflush(stderr);
 	argv[0] = endhook,
 	(void)execv(endhook, argv);
 	fprintf(stderr, "Error executing '%s': %s\n", endhook,
-- 
2.30.0

Reply via email to