Make some of fwrite/fclose/write/close failures visible
PATCH 1/3 Make some of fwrite/fclose/write/close failures visible
So that full filesystem conditions or permissions problems wont go unnoticed.
---
This and the follow-up patches is fallout of Windows debugging sessions. I implemented random error handling code just to figure out where it might be going wrong. None of that code actually helped to fix something (and lots was just thrown away), but some, I think, still makes sense.
This patch adds error handling only to fwrite/fputs where the return value was ignored and writing was definitely into a file. BTW, libc headers in Ubuntu 8.10 have warn_unused_result attribute added to many functions (fwrite(3) and write(2) amongst them). This helps finding the problem places.
builtin-fsck.c | 8 ++++++-- builtin-merge.c | 6 ++++-- rerere.c | 46 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 15 deletions(-)
builtin-fsck.c +6 -2
@@ -201,12 +201,16 @@ static void check_unreachable_object(struct object *obj)char *buf =read_sha1_file (obj->sha1, &type, &size);if (buf) { -fwrite (buf, size,1 , f); +if (fwrite (buf, size,1 , f) !=1 ) +die ("Could not write %s: %s" , + filename,strerror (errno));free (buf); } }else fprintf (f,"%s\n" ,sha1_to_hex (obj->sha1)); -fclose (f); +if (fclose (f)) +die ("Could not finish %s: %s" , + filename,strerror (errno)); }return ; }
builtin-merge.c +4 -2
@@ -293,8 +293,10 @@ static void squash_message(void)pretty_print_commit (rev.commit_format, commit, &out, rev.abbrev,NULL ,NULL , rev.date_mode,0 ); } -write (fd, out.buf, out.len); -close (fd); +if (write (fd, out.buf, out.len) <0 ) +die ("Writing SQUASH_MSG: %s" ,strerror (errno)); +if (close (fd)) +die ("Finishing SQUASH_MSG: %s" ,strerror (errno));strbuf_release (&out); }
rerere.c +35 -11
88 lines not on this page · raw message
Signature · 1 line
1.6.1.rc1.29.gb140
PATCH 2/3 Make chdir failures visible
--- git.c | 4 ++-- setup.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
git.c +2 -2
@@ -195,8 +195,8 @@ static int handle_alias(int *argcp, const char ***argv) ret =1 ; } -if (subdir) -chdir (subdir); +if (subdir &&chdir (subdir)) +die ("Cannot change to %s: %s" , subdir,strerror (errno)); errno = saved_errno;
setup.c +2 -1
@@ -470,7 +470,8 @@ const char *setup_git_directory_gently(int *nongit_ok) }die ("Not a git repository" ); } -chdir (".." ); +if (chdir (".." )) +die ("Cannot change to %s/..: %s" , cwd,strerror (errno)); } inside_git_dir =0 ;
Signature · 1 line
1.6.1.rc1.29.gb140
PATCH 3/3 Report symlink failures in merge-recursive
In reply to Alex Riesen---
I don't check for unlink success in the line above, because symlink will fail if unlink failed to cleanup the new path.
merge-recursive.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
merge-recursive.c +2 -1
@@ -525,7 +525,8 @@ static void update_file_flags(struct merge_options *o,char *lnk =xmemdupz (buf, size);safe_create_leading_directories_const (path);unlink (path); -symlink (lnk, path); +if (symlink (lnk, path)) +die ("failed to symlink %s: %s" , path,strerror (errno));free (lnk); }else die("do not know what to do with %06o %s '%s'",
Signature · 1 line
1.6.1.rc1.29.gb140
All of them obviously look correct. Will apply to the tip of master.
Thanks.