git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] sideband: avoid short write(2)

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 2, 2024, 19:03 UTC
Message-ID
<20240302190348.3946569-3-gitster@pobox.com>
In-Reply-To
<20240302190348.3946569-1-gitster@pobox.com>

The sideband demultiplexor writes the data it receives on sideband with xwrite(). We can lose data if the underlying write(2) results in a short write.

If they are limited to unimportant bytes like eye-candy progress meter, it may be OK to lose them, but lets be careful and ensure that we use write_in_full() instead. Note that the original does not check for errors, and this rewrite does not check for one. At least not yet.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 sideband.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sideband.c b/sideband.c
index 266a67342b..5d8907151f 100644
--- a/sideband.c
+++ b/sideband.c
@@ -220,7 +220,7 @@ int demultiplex_sideband(const char *me, int status,
 			}
 
 			strbuf_addch(scratch, *brk);
-			xwrite(2, scratch->buf, scratch->len);
+			write_in_full(2, scratch->buf, scratch->len);
 			strbuf_reset(scratch);
 
 			b = brk + 1;
@@ -247,7 +247,7 @@ int demultiplex_sideband(const char *me, int status,
 		die("%s", scratch->buf);
 	if (scratch->len) {
 		strbuf_addch(scratch, '\n');
-		xwrite(2, scratch->buf, scratch->len);
+		write_in_full(2, scratch->buf, scratch->len);
 	}
 	strbuf_release(scratch);
 	return 1;
-- 
2.44.0-84-gb387623c12
Previous: Junio C Hamano
Message 7 of 7 in “Auditing use of xwrite()”
  1. 0/3 Auditing use of xwrite()Junio C Hamano, Mar 2, 2024
  2. 1/3 unpack: replace xwrite() loop with write_in_full()Junio C Hamano, Mar 2, 2024
  3. Patrick SteinhardtMar 4, 2024
  4. Junio C HamanoMar 4, 2024
  5. Junio C HamanoMar 4, 2024
  6. 3/3 repack: check error writing to pack-objects subprocessJunio C Hamano, Mar 2, 2024
  7. 2/3 sideband: avoid short write(2)Junio C Hamano, Mar 2, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.