threads / patch / 64756

patchhttp-backend: write newlines to stderr when responding with errors

Subject: [PATCH] http-backend: write newlines to stderr when responding with errors

## tl;dr

4 messages between Jan 8, 2026 and Jan 12, 2026. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

KJ Tsanaktsidis· Jan 8, 2026, 22:59 UTC · lore
From: KJ Tsanaktsidis <kjtsanaktsidis@groq.com>

The not_found and forbidden methods currently do not write a newline to stderr after the error message. This means that if git-http-backend is invoked through something like fcgiwrap, and the stderr of that fcgiwrap process is sent to a logging daemon (e.g. journald), the error messages of several git-http-backend invocations will just get strung together, e.g.

> Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'

I think it's git-http-backend's responsibility to format these messages properly, rather than it being fcgiwrap's job to notice that the script didn't terminate stderr with a newline and do so itself.

Signed-off-by: KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>
---
 http-backend.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Show changes to http-backend.c +6 −2
diff --git a/http-backend.c b/http-backend.c
index 52f0483dd3..bda8bb91e1 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -143,8 +143,10 @@ static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
 	end_headers(hdr);
 
 	va_start(params, err);
-	if (err && *err)
+	if (err && *err) {
 		vfprintf(stderr, err, params);
+		fprintf(stderr, "\n");
+	}
 	va_end(params);
 	exit(0);
 }
@@ -159,8 +161,10 @@ static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
 	end_headers(hdr);
 
 	va_start(params, err);
-	if (err && *err)
+	if (err && *err) {
 		vfprintf(stderr, err, params);
+		fprintf(stderr, "\n");
+	}
 	va_end(params);
 	exit(0);
 }
-- 
2.51.2
Junio C Hamano· Jan 11, 2026, 18:25 UTC · re: KJ Tsanaktsidis · lore

Re: [PATCH] http-backend: write newlines to stderr when responding with errors

KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au> writes:
Show 14 quoted lines
> From: KJ Tsanaktsidis <kjtsanaktsidis@groq.com>
>
> The not_found and forbidden methods currently do not write a newline to
> stderr after the error message. This means that if git-http-backend is
> invoked through something like fcgiwrap, and the stderr of that fcgiwrap
> process is sent to a logging daemon (e.g. journald), the error messages
> of several git-http-backend invocations will just get strung together,
> e.g.
>
>> Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'
>
> I think it's git-http-backend's responsibility to format these messages
> properly, rather than it being fcgiwrap's job to notice that the script
> didn't terminate stderr with a newline and do so itself.

Now another question is which between the callers and these two helper functions is responsible to ensure that the message terminates with LF. As these functions can be called only once, I think letting them add LF makes sense (if they can be called twice or more, we can imagine that a caller may find it useful to make two calls to produce a single log entry by ending only the later call with LF, but such a use-case clearly cannot be supported with these NORETURN functions). So I think this design makes sense.

Show 17 quoted lines
> Signed-off-by: KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>
> ---
>  http-backend.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/http-backend.c b/http-backend.c
> index 52f0483dd3..bda8bb91e1 100644
> --- a/http-backend.c
> +++ b/http-backend.c
> @@ -143,8 +143,10 @@ static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
>  	end_headers(hdr);
>  
>  	va_start(params, err);
> -	if (err && *err)
> +	if (err && *err) {
>  		vfprintf(stderr, err, params);
> +		fprintf(stderr, "\n");

Somehow it feels overly heavyweight to call fprintf() just to send a single literal byte to the standard error stream. putc('\n', stderr) perhaps? The same comment forr the other hunk.

Show 16 quoted lines
> +	}
>  	va_end(params);
>  	exit(0);
>  }
> @@ -159,8 +161,10 @@ static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
>  	end_headers(hdr);
>  
>  	va_start(params, err);
> -	if (err && *err)
> +	if (err && *err) {
>  		vfprintf(stderr, err, params);
> +		fprintf(stderr, "\n");
> +	}
>  	va_end(params);
>  	exit(0);
>  }
KJ Tsanaktsidis· Jan 12, 2026, 01:44 UTC · re: Junio C Hamano · lore

[PATCH v2] http-backend: write newlines to stderr when responding with errors

The not_found and forbidden methods currently do not write a newline to stderr after the error message. This means that if git-http-backend is invoked through something like fcgiwrap, and the stderr of that fcgiwrap process is sent to a logging daemon (e.g. journald), the error messages of several git-http-backend invocations will just get strung together, e.g.

> Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'Not a git repository: '/var/lib/git/foo.git'

I think it's git-http-backend's responsibility to format these messages properly, rather than it being fcgiwrap's job to notice that the script didn't terminate stderr with a newline and do so itself.

Signed-off-by: KJ Tsanaktsidis <kj@kjtsanaktsidis.id.au>
---
 http-backend.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Show changes to http-backend.c +6 −2
diff --git a/http-backend.c b/http-backend.c
index 52f0483dd3..8c810cfcbd 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -143,8 +143,10 @@ static NORETURN void not_found(struct strbuf *hdr, const char *err, ...)
 	end_headers(hdr);
 
 	va_start(params, err);
-	if (err && *err)
+	if (err && *err) {
 		vfprintf(stderr, err, params);
+		putc('\n', stderr);
+	}
 	va_end(params);
 	exit(0);
 }
@@ -159,8 +161,10 @@ static NORETURN void forbidden(struct strbuf *hdr, const char *err, ...)
 	end_headers(hdr);
 
 	va_start(params, err);
-	if (err && *err)
+	if (err && *err) {
 		vfprintf(stderr, err, params);
+		putc('\n', stderr);
+	}
 	va_end(params);
 	exit(0);
 }
-- 
2.51.2
KJ Tsanaktsidis· Jan 12, 2026, 01:47 UTC · re: Junio C Hamano · lore

Re: [PATCH] http-backend: write newlines to stderr when responding with errors

On Mon, Jan 12, 2026, at 5:25 AM, Junio C Hamano wrote:
Show 8 quoted lines
> Now another question is which between the callers and these two
> helper functions is responsible to ensure that the message
> terminates with LF.  As these functions can be called only once, I
> think letting them add LF makes sense (if they can be called twice
> or more, we can imagine that a caller may find it useful to make two
> calls to produce a single log entry by ending only the later call
> with LF, but such a use-case clearly cannot be supported with these
> NORETURN functions).  So I think this design makes sense.
Agreed, the code clearly can't log more messages at this point!
> Somehow it feels overly heavyweight to call fprintf() just to send a
> single literal byte to the standard error stream.  putc('\n', stderr)
> perhaps?  The same comment forr the other hunk.

I sent a v2 to fix this (hopefully correctly, I haven't had a whole lot of experience sending patches to mailing lists with git-send-email :/)

← back to recent threads