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

[PATCH v3 03/11] reftable: handle interrupted writes

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 11, 2023, 09:07 UTC
Message-ID
<1700d00d1ca017730d9188caf4eff9c02720131a.1702285387.git.ps@pks.im>
In-Reply-To
<cover.1702285387.git.ps@pks.im>

There are calls to write(3P) where we don't properly handle interrupts. Convert them to use `write_in_full()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/stack.c      | 6 +++---
 reftable/stack_test.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/reftable/stack.c b/reftable/stack.c
index ed108a929b..f0cadad490 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -42,7 +42,7 @@ static void stack_filename(struct strbuf *dest, struct reftable_stack *st,
 static ssize_t reftable_fd_write(void *arg, const void *data, size_t sz)
 {
 	int *fdp = (int *)arg;
-	return write(*fdp, data, sz);
+	return write_in_full(*fdp, data, sz);
 }
 
 int reftable_new_stack(struct reftable_stack **dest, const char *dir,
@@ -554,7 +554,7 @@ int reftable_addition_commit(struct reftable_addition *add)
 		strbuf_addstr(&table_list, "\n");
 	}
 
-	err = write(add->lock_file_fd, table_list.buf, table_list.len);
+	err = write_in_full(add->lock_file_fd, table_list.buf, table_list.len);
 	strbuf_release(&table_list);
 	if (err < 0) {
 		err = REFTABLE_IO_ERROR;
@@ -1024,7 +1024,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
 		strbuf_addstr(&ref_list_contents, "\n");
 	}
 
-	err = write(lock_file_fd, ref_list_contents.buf, ref_list_contents.len);
+	err = write_in_full(lock_file_fd, ref_list_contents.buf, ref_list_contents.len);
 	if (err < 0) {
 		err = REFTABLE_IO_ERROR;
 		unlink(new_table_path.buf);
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index d0b717510f..0644c8ad2e 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -78,7 +78,7 @@ static void test_read_file(void)
 	int i = 0;
 
 	EXPECT(fd > 0);
-	n = write(fd, out, strlen(out));
+	n = write_in_full(fd, out, strlen(out));
 	EXPECT(n == strlen(out));
 	err = close(fd);
 	EXPECT(err >= 0);
-- 
2.43.0
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 45 of 58 in “reftable: small set of fixes”
  1. 0/8 reftable: small set of fixesPatrick Steinhardt, Nov 21, 2023
  2. 1/8 reftable: wrap EXPECT macros in do/whilePatrick Steinhardt, Nov 21, 2023
  3. 2/8 reftable: handle interrupted readsPatrick Steinhardt, Nov 21, 2023
  4. 3/8 reftable: handle interrupted writesPatrick Steinhardt, Nov 21, 2023
  5. 4/8 reftable/stack: verify that `reftable_stack_add()` uses auto-compactionPatrick Steinhardt, Nov 21, 2023
  6. 5/8 reftable/stack: perform auto-compaction with transactional interfacePatrick Steinhardt, Nov 21, 2023
  7. Han-Wen NienhuysDec 21, 2023
  8. Patrick SteinhardtDec 21, 2023
  9. 6/8 reftable/stack: reuse buffers when reloading stackPatrick Steinhardt, Nov 21, 2023
  10. 7/8 reftable/merged: reuse buffer to compute record keysPatrick Steinhardt, Nov 21, 2023
  11. Han-Wen NienhuysDec 21, 2023
  12. 8/8 reftable/stack: fix stale lock when dyingPatrick Steinhardt, Nov 21, 2023
  13. 00/11 reftable: small set of fixesPatrick Steinhardt, Dec 8, 2023
  14. 01/11 reftable: wrap EXPECT macros in do/whilePatrick Steinhardt, Dec 8, 2023
  15. 02/11 reftable: handle interrupted readsPatrick Steinhardt, Dec 8, 2023
  16. Taylor BlauDec 8, 2023
  17. Patrick SteinhardtDec 11, 2023
  18. 03/11 reftable: handle interrupted writesPatrick Steinhardt, Dec 8, 2023
  19. 04/11 reftable/stack: verify that `reftable_stack_add()` uses auto-compactionPatrick Steinhardt, Dec 8, 2023
  20. Taylor BlauDec 8, 2023
  21. Eric SunshineDec 8, 2023
  22. Patrick SteinhardtDec 11, 2023
  23. Eric SunshineDec 11, 2023
  24. 05/11 reftable/stack: perform auto-compaction with transactional interfacePatrick Steinhardt, Dec 8, 2023
  25. Taylor BlauDec 8, 2023
  26. Patrick SteinhardtDec 11, 2023
  27. 06/11 reftable/stack: reuse buffers when reloading stackPatrick Steinhardt, Dec 8, 2023
  28. Taylor BlauDec 8, 2023
  29. Patrick SteinhardtDec 11, 2023
  30. Han-Wen NienhuysDec 21, 2023
  31. 07/11 reftable/stack: fix stale lock when dyingPatrick Steinhardt, Dec 8, 2023
  32. Taylor BlauDec 8, 2023
  33. Patrick SteinhardtDec 11, 2023
  34. 08/11 reftable/stack: fix use of unseeded randomnessPatrick Steinhardt, Dec 8, 2023
  35. Han-Wen NienhuysDec 21, 2023
  36. 09/11 reftable/merged: reuse buffer to compute record keysPatrick Steinhardt, Dec 8, 2023
  37. 10/11 reftable/block: introduce macro to initialize `struct block_iter`Patrick Steinhardt, Dec 8, 2023
  38. 11/11 reftable/block: reuse buffer to compute record keysPatrick Steinhardt, Dec 8, 2023
  39. Han-Wen NienhuysDec 21, 2023
  40. Patrick SteinhardtDec 28, 2023
  41. Taylor BlauDec 8, 2023
  42. 00/11 reftable: small set of fixesPatrick Steinhardt, Dec 11, 2023
  43. 01/11 reftable: wrap EXPECT macros in do/whilePatrick Steinhardt, Dec 11, 2023
  44. 02/11 reftable: handle interrupted readsPatrick Steinhardt, Dec 11, 2023
  45. 03/11 reftable: handle interrupted writesPatrick Steinhardt, Dec 11, 2023
  46. 04/11 reftable/stack: verify that `reftable_stack_add()` uses auto-compactionPatrick Steinhardt, Dec 11, 2023
  47. Taylor BlauDec 11, 2023
  48. Patrick SteinhardtDec 12, 2023
  49. 05/11 reftable/stack: perform auto-compaction with transactional interfacePatrick Steinhardt, Dec 11, 2023
  50. 06/11 reftable/stack: reuse buffers when reloading stackPatrick Steinhardt, Dec 11, 2023
  51. 07/11 reftable/stack: fix stale lock when dyingPatrick Steinhardt, Dec 11, 2023
  52. 08/11 reftable/stack: fix use of unseeded randomnessPatrick Steinhardt, Dec 11, 2023
  53. 09/11 reftable/merged: reuse buffer to compute record keysPatrick Steinhardt, Dec 11, 2023
  54. 10/11 reftable/block: introduce macro to initialize `struct block_iter`Patrick Steinhardt, Dec 11, 2023
  55. 11/11 reftable/block: reuse buffer to compute record keysPatrick Steinhardt, Dec 11, 2023
  56. Taylor BlauDec 11, 2023
  57. Patrick SteinhardtDec 12, 2023
  58. Han-Wen NienhuysDec 21, 2023

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.