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

[PATCH v2 1/5] sequencer: make lockfiles non-static

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Feb 28, 2018, 19:07 UTC
Message-ID
<4572a84cfdcb1897b67c271a9d06ca38802a2352.1519843916.git.martin.agren@gmail.com>
In-Reply-To
<cover.1519843916.git.martin.agren@gmail.com>

After 076aa2cbd (tempfile: auto-allocate tempfiles on heap, 2017-09-05), we can have lockfiles on the stack.

One of these functions fails to always roll back the lock. That will be fixed in the next commit.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 sequencer.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 4d3f60594c..90807c4559 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -290,7 +290,7 @@ static void print_advice(int show_hint, struct replay_opts *opts)
 static int write_message(const void *buf, size_t len, const char *filename,
 			 int append_eol)
 {
-	static struct lock_file msg_file;
+	struct lock_file msg_file = LOCK_INIT;
 
 	int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0);
 	if (msg_fd < 0)
@@ -436,7 +436,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 	struct tree *result, *next_tree, *base_tree, *head_tree;
 	int clean;
 	char **xopt;
-	static struct lock_file index_lock;
+	struct lock_file index_lock = LOCK_INIT;
 
 	if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
 		return -1;
@@ -1183,7 +1183,7 @@ static int prepare_revs(struct replay_opts *opts)
 
 static int read_and_refresh_cache(struct replay_opts *opts)
 {
-	static struct lock_file index_lock;
+	struct lock_file index_lock = LOCK_INIT;
 	int index_fd = hold_locked_index(&index_lock, 0);
 	if (read_index_preload(&the_index, NULL) < 0) {
 		rollback_lock_file(&index_lock);
@@ -1577,7 +1577,7 @@ static int create_seq_dir(void)
 
 static int save_head(const char *head)
 {
-	static struct lock_file head_lock;
+	struct lock_file head_lock = LOCK_INIT;
 	struct strbuf buf = STRBUF_INIT;
 	int fd;
 	ssize_t written;
@@ -1702,7 +1702,7 @@ int sequencer_rollback(struct replay_opts *opts)
 
 static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
 {
-	static struct lock_file todo_lock;
+	struct lock_file todo_lock = LOCK_INIT;
 	const char *todo_path = get_todo_path(opts);
 	int next = todo_list->current, offset, fd;
 
-- 
2.16.2.246.ga4ee44448f
Previous: Martin ÅgrenNext: Martin Ågren
Message 10 of 26 in “roll back locks in various code paths”
  1. 0/5 roll back locks in various code pathsMartin Ågren, Feb 27, 2018
  2. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 27, 2018
  3. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 27, 2018
  4. Jeff KingFeb 27, 2018
  5. Martin ÅgrenFeb 27, 2018
  6. Jeff KingFeb 27, 2018
  7. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 27, 2018
  8. Martin ÅgrenFeb 28, 2018
  9. 0/5 roll back locks in various code pathsMartin Ågren, Feb 28, 2018
  10. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 28, 2018
  11. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 28, 2018
  12. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 28, 2018
  13. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 28, 2018
  14. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 28, 2018
  15. Martin ÅgrenFeb 28, 2018
  16. Junio C HamanoFeb 28, 2018
  17. Martin ÅgrenMar 1, 2018
  18. Jeff KingMar 1, 2018
  19. Junio C HamanoMar 1, 2018
  20. Martin ÅgrenMar 1, 2018
  21. Jeff KingMar 2, 2018
  22. Jeff KingMar 1, 2018
  23. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 27, 2018
  24. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 27, 2018
  25. Jeff KingFeb 27, 2018
  26. Junio C HamanoFeb 27, 2018

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.