sequencer: avoid using errno clobbered by rollback_lock_file()
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sun, 11 Feb 2018 00:10:04 +0000 (01:10 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Feb 2018 22:43:36 +0000 (14:43 -0800)
As pointed out in a review of the `--recreate-merges` patch series,
`rollback_lock_file()` clobbers errno. Therefore, we have to report the
error message that uses errno before calling said function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
index 4d3f60594cbf0e9ddf2ea78e8c58eca312b4cac0..114db3b277577cc05770fa530a4f79311a28e7e6 100644 (file)
@@ -296,12 +296,14 @@ static int write_message(const void *buf, size_t len, const char *filename,
        if (msg_fd < 0)
                return error_errno(_("could not lock '%s'"), filename);
        if (write_in_full(msg_fd, buf, len) < 0) {
+               error_errno(_("could not write to '%s'"), filename);
                rollback_lock_file(&msg_file);
-               return error_errno(_("could not write to '%s'"), filename);
+               return -1;
        }
        if (append_eol && write(msg_fd, "\n", 1) < 0) {
+               error_errno(_("could not write eol to '%s'"), filename);
                rollback_lock_file(&msg_file);
-               return error_errno(_("could not write eol to '%s'"), filename);
+               return -1;
        }
        if (commit_lock_file(&msg_file) < 0) {
                rollback_lock_file(&msg_file);
@@ -1584,16 +1586,17 @@ static int save_head(const char *head)
 
        fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
        if (fd < 0) {
+               error_errno(_("could not lock HEAD"));
                rollback_lock_file(&head_lock);
-               return error_errno(_("could not lock HEAD"));
+               return -1;
        }
        strbuf_addf(&buf, "%s\n", head);
        written = write_in_full(fd, buf.buf, buf.len);
        strbuf_release(&buf);
        if (written < 0) {
+               error_errno(_("could not write to '%s'"), git_path_head_file());
                rollback_lock_file(&head_lock);
-               return error_errno(_("could not write to '%s'"),
-                                  git_path_head_file());
+               return -1;
        }
        if (commit_lock_file(&head_lock) < 0) {
                rollback_lock_file(&head_lock);