Add and use error_errno() and warning_errno()
cover Add and use error_errno() and warning_errno()
This is a spinoff from my worktree-move topic. This series adds die_errno() companions, error_errno() and warning_errno(), and use them where applicable to reduce the amount of typing (in future). Changes are split by file (which explains the huge number of patches). I leave builtin/apply.c and refs/files-backend.c untouched because they are currently hot zones.
Nguyễn Thái Ngọc Duy (41):
usage.c: move format processing out of die_errno() usage.c: add warning_errno() and error_errno() bisect.c: use die_errno() and warning_errno() builtin/am.c: use error_errno()
builtin/branch.c: use error_errno() builtin/fetch.c: use error_errno() builtin/help.c: use warning_errno() builtin/mailsplit.c: use error_errno() builtin/merge-file.c: use error_errno() builtin/pack-objects.c: use die_errno() and warning_errno() builtin/rm.c: use warning_errno() builtin/update-index.c: use error_errno() builtin/upload-archive.c: use error_errno() builtin/worktree.c: use error_errno() check-racy.c: use error_errno()
combine-diff.c: use error_errno() compat/win32/syslog.c: use warning_errno() config.c: use error_errno()
connected.c: use error_errno()
copy.c: use error_errno() credential-cache--daemon.c: use warning_errno() diff-no-index.c: use error_errno()
editor.c: use error_errno()
entry.c: use error_errno()
fast-import.c: use error_errno()
gpg-interface.c: use error_errno()
grep.c: use error_errno()
http.c: use error_errno() and warning_errno() ident.c: use warning_errno()
mailmap.c: use error_errno()
reachable.c: use error_errno()
rerere.c: use error_errno() and warning_errno() run-command.c: use error_errno()
sequencer.c: use error_errno()
server-info.c: use error_errno()
sha1_file.c: use {error,die,warning}_errno() transport-helper.c: use error_errno() unpack-trees.c: use error_errno()
upload-pack.c: use error_errno()
vcs-svn: use error_errno()
wrapper.c: use warning_errno()
bisect.c | 7 +++---- builtin/am.c | 11 +++++------ builtin/branch.c | 3 +-- builtin/fetch.c | 4 ++-- builtin/help.c | 8 ++++---- builtin/mailsplit.c | 10 +++++----- builtin/merge-file.c | 10 +++++----- builtin/pack-objects.c | 8 +++----- builtin/rm.c | 2 +- builtin/update-index.c | 8 ++++---- builtin/upload-archive.c | 3 +-- builtin/worktree.c | 2 +- check-racy.c | 2 +- combine-diff.c | 3 +-- compat/win32/syslog.c | 6 +++--- config.c | 22 +++++++++------------- connected.c | 9 +++------ copy.c | 6 +++--- credential-cache--daemon.c | 4 ++-- diff-no-index.c | 3 +-- editor.c | 3 +-- entry.c | 10 ++++------ fast-import.c | 10 +++++----- git-compat-util.h | 2 ++ gpg-interface.c | 6 ++---- grep.c | 4 ++-- http.c | 10 ++++------ ident.c | 8 +++----- mailmap.c | 3 +-- reachable.c | 3 +-- rerere.c | 18 +++++++----------- run-command.c | 15 +++++++-------- sequencer.c | 3 +-- server-info.c | 2 +- sha1_file.c | 32 +++++++++++++------------------- transport-helper.c | 6 +++--- unpack-trees.c | 6 ++---- upload-pack.c | 3 +-- usage.c | 44 ++++++++++++++++++++++++++++++++++---------- vcs-svn/line_buffer.c | 4 ++-- vcs-svn/sliding_window.c | 2 +- vcs-svn/svndiff.c | 4 ++-- vcs-svn/svndump.c | 4 ++-- wrapper.c | 4 ++-- 44 files changed, 161 insertions(+), 176 deletions(-)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 1/41 usage.c: move format processing out of die_errno()
fmt_with_err() will be shared with the coming error_errno() and warning_errno().
--- usage.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
usage.c +15 -10
@@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...)va_end (params); } -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err (const char *fmt) { -va_list params; -char fmt_with_err[1024 ]; +static char fmt_with_err[1024 ];char str_error[256 ], *err;int i, j; -if (die_is_recursing ()) { -fputs ("fatal: recursion detected in die_errno handler\n" , - stderr); -exit (128 ); - } - err =strerror (errno);for (i = j =0 ; err[i] && j <sizeof (str_error) -1 ; ) {if ((str_error[j++] = err[i++]) !='%' )
@@ -137,9 +130,21 @@ void NORETURN die_errno(const char *fmt, ...) } str_error[j] =0 ;snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); +return fmt_with_err; +} + +void NORETURN die_errno(const char *fmt, ...) +{ +va_list params; + +if (die_is_recursing ()) { +fputs ("fatal: recursion detected in die_errno handler\n" , + stderr); +exit (128 ); + }va_start (params, fmt); -die_routine (fmt_with_err, params); +die_routine (fmt_with_err (fmt), params);va_end (params); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
usage.c void NORETURN die(const char *err, ...) · line 111
Quoted 13 lines · Nguyễn Thái Ngọc Duy
fmt_with_err()will be shared with the comingerror_errno()andwarning_errno().Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
usage.c +2
-3@@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...) -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err (const char *fmt) { -va_list params; -char fmt_with_err[1024 ]; +static char fmt_with_err[1024 ];
Rather than this static buffer, did you consider having the caller pass in the buffer?
static const char *fmt_with_err(char *buf, size_t n, const char *fmt)
{
...
snprintf(buf, n, "%s: %s", fmt, str_error);
return buf;
}
void die_errno(const char *fmt, ...)
{
char fmtbuf[1024];
...
die_routine(fmt_with_err(fmtbuf, sizeof(fmtbuf), fmt),
params);
...
}Better? Worse? Indifferent?
Quoted 34 lines
usage.c +13
-7char str_error[256 ], *err;int i, j; -if (die_is_recursing ()) { -fputs ("fatal: recursion detected in die_errno handler\n" , - stderr); -exit (128 ); - } - err =strerror (errno);for (i = j =0 ; err[i] && j <sizeof (str_error) -1 ; ) {if ((str_error[j++] = err[i++]) !='%' )@@ -137,9 +130,21 @@ void NORETURN die_errno(const char *fmt, ...) } str_error[j] =0 ;snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); +return fmt_with_err; +} + +void NORETURN die_errno(const char *fmt, ...) +{ +va_list params; + +if (die_is_recursing ()) { +fputs ("fatal: recursion detected in die_errno handler\n" , + stderr); +exit (128 ); + }va_start (params, fmt); -die_routine (fmt_with_err, params); +die_routine (fmt_with_err (fmt), params);va_end (params); }
Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
Quoted 34 lines · Eric Sunshine
usage.c void NORETURN die(const char *err, ...) · line 111
Quoted 13 lines · Nguyễn Thái Ngọc Duy
fmt_with_err()will be shared with the comingerror_errno()andwarning_errno().Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
usage.c +2
-3@@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...) -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err (const char *fmt) { -va_list params; -char fmt_with_err[1024 ]; +static char fmt_with_err[1024 ];Rather than this static buffer, did you consider having the caller pass in the buffer?
static const char *fmt_with_err(char *buf, size_t n, const char *fmt) { ... snprintf(buf, n, "%s: %s", fmt, str_error); return buf; } void die_errno(const char *fmt, ...) { char fmtbuf[1024]; ... die_routine(fmt_with_err(fmtbuf, sizeof(fmtbuf), fmt), params); ... }
Quoted 1 line
Better? Worse? Indifferent?
Caller supplied buffer would be the way to go when multiple threads could be showing errors and warnings, right?
It would not make too much of a difference for die(), though.
Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
Quoted 4 lines · Junio C Hamano
Caller supplied buffer would be the way to go when multiple threads could be showing errors and warnings, right?
It would not make too much of a difference for
die(), though.
I think it can matter for die(). This is happening above the pluggable die_routine() layer, so it's possible for an async task to call die() which will end in pthread_exit(), while the main program is calling die() to end in regular exit().
I imagine it's exceedingly unlikely, and of course both threads are dying anyway, but it could result in some pretty weird memory errors. It's probably worth taking precautions against, especially because it's to easy to do so.
-Peff
Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
Quoted 12 lines · Jeff King
Quoted 4 lines · Junio C Hamano
Caller supplied buffer would be the way to go when multiple threads could be showing errors and warnings, right?
It would not make too much of a difference for
die(), though.I think it can matter for
die(). This is happening above the pluggabledie_routine()layer, so it's possible for an async task to calldie()which will end inpthread_exit(), while the main program is callingdie()to end in regularexit().
Quoted 4 lines
I imagine it's exceedingly unlikely, and of course both threads are dying anyway, but it could result in some pretty weird memory errors. It's probably worth taking precautions against, especially because it's to easy to do so.
So, sum it up, the new fmt_with_err() will take a buffer and size. die_errno() sticks to its static buffer as before. error_errno() and warning_errno() can allocate 1k on stack to be more multithread-friendly. Let me know if some other change is needed.
Signature · 1 line
Duy
Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
Quoted 18 lines · Duy Nguyen
Quoted 12 lines · Jeff King
Quoted 4 lines · Junio C Hamano
Caller supplied buffer would be the way to go when multiple threads could be showing errors and warnings, right?
It would not make too much of a difference for
die(), though.I think it can matter for
die(). This is happening above the pluggabledie_routine()layer, so it's possible for an async task to calldie()which will end inpthread_exit(), while the main program is callingdie()to end in regularexit().Quoted 4 lines
I imagine it's exceedingly unlikely, and of course both threads are dying anyway, but it could result in some pretty weird memory errors. It's probably worth taking precautions against, especially because it's to easy to do so.
Quoted 4 lines
So, sum it up, the new
fmt_with_err()will take a buffer and size.die_errno()sticks to its static buffer as before.error_errno()andwarning_errno()can allocate 1k on stack to be more multithread-friendly. Let me know if some other change is needed.
Yes, though note that die_errno() currently has a stack buffer, not a static one. It should remain that way (and error_errno and warning_errno should follow suit) to be friendly to multi-threading.
-Peff
PATCH 2/41 usage.c: add warning_errno() and error_errno()
In reply to Nguyễn Thái Ngọc DuySimilar to die_errno(), these functions will append strerror() automatically.
--- git-compat-util.h | 2 ++ usage.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+)
git-compat-util.h +2 -0
@@ -409,7 +409,9 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern int error_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void warning_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));#ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO
usage.c +19 -0
@@ -148,6 +148,16 @@ void NORETURN die_errno(const char *fmt, ...)va_end (params); } +int error_errno (const char *fmt, ...) +{ +va_list params; + +va_start (params, fmt); +error_routine (fmt_with_err (fmt), params); +va_end (params); +return -1 ; +} +#undef errorint error (const char *err, ...) {
@@ -159,6 +169,15 @@ int error(const char *err, ...)return -1 ; } +void warning_errno (const char *warn, ...) +{ +va_list params; + +va_start (params, warn); +warn_routine (fmt_with_err (warn), params); +va_end (params); +} +void warning (const char *warn, ...) {va_list params;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 3/41 bisect.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- bisect.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
bisect.c +3 -4
@@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)/* Create file BISECT_ANCESTORS_OK. */ fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY ,0600 );if (fd <0 ) -warning ("could not create file '%s': %s" , - filename,strerror (errno)); +warning_errno ("could not create file '%s'" , + filename);else close (fd); done:
@@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) *read_good ="good" ;return ; }else { -die ("could not read file '%s': %s" , filename, -strerror (errno)); +die_errno ("could not read file '%s'" , filename); } }else {strbuf_getline_lf (&str, fp);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 4/41 builtin/am.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
builtin/am.c +5 -6
@@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state, in =fopen (*paths,"r" );if (!in) -return error (_ ("could not open '%s' for reading: %s" ), - *paths,strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), + *paths); mail =mkpath ("%s/%0*d" , state->dir, state->prec, i +1 ); out =fopen (mail,"w" );if (!out) -return error (_ ("could not open '%s' for writing: %s" ), - mail,strerror (errno)); +return error_errno (_ ("could not open '%s' for writing" ), + mail); ret =fn (out, in, keep_cr);
@@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, fp =fopen (*paths,"r" );if (!fp) -return error (_ ("could not open '%s' for reading: %s" ), *paths, -strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), *paths);while (!strbuf_getline_lf (&sb, fp)) {if (*sb.buf =='#' )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 5/41 builtin/branch.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/branch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/branch.c +1 -2
@@ -593,8 +593,7 @@ static int edit_branch_description(const char *branch_name) branch_name, comment_line_char);if (write_file_gently (git_path (edit_description),"%s" , buf.buf)) {strbuf_release (&buf); -return error (_ ("could not write branch description template: %s" ), -strerror (errno)); +return error_errno (_ ("could not write branch description template" )); }strbuf_reset (&buf);if (launch_editor (git_path (edit_description), &buf,NULL )) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 6/41 builtin/fetch.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/fetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/fetch.c +2 -2
@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fp =fopen (filename,"a" );if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);if (raw_url) url =transport_anonymize_url (raw_url);
@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)FILE *fp =fopen_for_writing (filename);if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);fclose (fp);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 7/41 builtin/help.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/help.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/help.c +4 -4
@@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page) path ="emacsclient" ;strbuf_addf (&man_page,"(woman \"%s\")" , page);execlp (path,"emacsclient" ,"-e" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page) path ="kfmclient" ;strbuf_addf (&man_page,"man:%s(1)" , page);execlp (path, filename,"newTab" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page)if (!path) path ="man" ;execlp (path,"man" , page, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); }static void exec_man_cmd (const char *cmd,const char *page)
@@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page)struct strbuf shell_cmd =STRBUF_INIT ;strbuf_addf (&shell_cmd,"%s %s" , cmd, page);execl (SHELL_PATH ,SHELL_PATH ,"-c" , shell_cmd.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), cmd,strerror (errno)); +warning (_ ("failed to exec '%s'" ), cmd); }static void add_man_viewer (const char *name)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 8/41 builtin/mailsplit.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/mailsplit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/mailsplit.c +5 -5
@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)if ((dir =opendir (name)) ==NULL ) {if (errno ==ENOENT )continue ; -error ("cannot opendir %s (%s)" , name,strerror (errno)); +error_errno ("cannot opendir %s" , name); goto out; }
@@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir, f =fopen (file,"r" );if (!f) { -error ("cannot open mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot open mail %s" , file); goto out; }if (strbuf_getwholeline (&buf, f,'\n' )) { -error ("cannot read mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot read mail %s" , file); goto out; }
@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,int file_done =0 ;if (!f) { -error ("cannot open mbox %s" , file); +error_errno ("cannot open mbox %s" , file); goto out; }
@@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) }if (stat (arg, &argstat) ==-1 ) { -error ("cannot stat %s (%s)" , arg,strerror (errno)); +error_errno ("cannot stat %s" , arg);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH 08/41] builtin/mailsplit.c: use error_errno()
Quoted 12 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
builtin/mailsplit.c +1
-1@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)if ((dir =opendir (name)) ==NULL ) {if (errno ==ENOENT )continue ; -error ("cannot opendir %s (%s)" , name,strerror (errno)); +error_errno ("cannot opendir %s" , name); goto out; }
builtin/mailsplit.c static int split_mbox(const char *file, const char *dir, int allow_bare, · line 213
Quoted 5 lines
builtin/mailsplit.c +1
-1@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,int file_done =0 ;if (!f) { -error ("cannot open mbox %s" , file); +error_errno ("cannot open mbox %s" , file);
Unlike other cases in this patch which already printed strerror(errno), this one didn't, and the patch upgrades it to do so, which is valid since errno will not be clobbered between the preceding fopen() and this error_errno(). I see other patches in the series do likewise.
The error("cannot read mbox %s"" just below this code doesn't deserve the same treatment because strbuf_getwholeline() doesn't promise a meaningful errno. Okay.
PATCH 9/41 builtin/merge-file.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/merge-file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/merge-file.c +5 -5
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)usage_with_options (merge_file_usage, options);if (quiet) {if (!freopen ("/dev/null" ,"w" , stderr)) -return error ("failed to redirect stderr to /dev/null: " -"%s" ,strerror (errno)); +return error_errno ("failed to redirect stderr to /dev/null" ); }if (prefix)
@@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)FILE *f = to_stdout ? stdout :fopen (fpath,"wb" );if (!f) - ret =error ("Could not open %s for writing" , filename); + ret =error_errno ("Could not open %s for writing" , + filename);else if (result.size &&fwrite (result.ptr, result.size,1 , f) !=1 ) - ret =error ("Could not write to %s" , filename); + ret =error_errno ("Could not write to %s" , filename);else if (fclose (f)) - ret =error ("Could not close %s" , filename); + ret =error_errno ("Could not close %s" , filename);free (result.ptr); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 10/41 builtin/pack-objects.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/pack-objects.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
builtin/pack-objects.c +3 -5
@@ -828,8 +828,7 @@ static void write_pack_file(void)* to preserve this property. */ if (stat (pack_tmp_name, &st) <0 ) { -warning ("failed to stat %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed to stat %s" , pack_tmp_name); }else if (!last_mtime) { last_mtime = st.st_mtime; }else {
@@ -837,8 +836,7 @@ static void write_pack_file(void) utb.actime = st.st_atime; utb.modtime = --last_mtime;if (utime (pack_tmp_name, &utb) <0 ) -warning ("failed utime() on %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed utime() on %s" , pack_tmp_name); }strbuf_addf (&tmpname,"%s-" , base_name);
@@ -2020,7 +2018,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, ret =pthread_create (&p[i].thread,NULL , threaded_find_deltas, &p[i]);if (ret) -die ("unable to create thread: %s" ,strerror (ret)); +die_errno ("unable to create thread" ); active_threads++; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 11/41 builtin/rm.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/rm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rm.c +1 -1
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR ) -warning ("'%s': %s" , ce->name,strerror (errno)); +warning_errno ("'%s'" , ce->name);/* It already vanished from the working tree */ continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 12/41 builtin/update-index.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy"err" is deleted because it just causes confusion when "errno" is also used directly in process_lstat_error().
--- builtin/update-index.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/update-index.c +4 -4
@@ -251,11 +251,11 @@ static int remove_one_path(const char *path)* succeeds. * - permission error. That's never ok. */ -static int process_lstat_error (const char *path,int err) +static int process_lstat_error (const char *path) { -if (err ==ENOENT || err ==ENOTDIR ) +if (errno ==ENOENT || errno ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error_errno ("lstat(\"%s\")" , path); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)
@@ -382,7 +382,7 @@ static int process_path(const char *path)* what to do about the pathname! */ if (lstat (path, &st) <0 ) -return process_lstat_error (path, errno); +return process_lstat_error (path);if (S_ISDIR (st.st_mode))return process_directory (path, len, &st);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH 12/41] builtin/update-index.c: use error_errno()
Quoted 2 lines · Nguyễn Thái Ngọc Duy
"err" is deleted because it just causes confusion when "errno" is also used directly in
process_lstat_error().
Despite the function name which may imply that it is consulting errno, this change makes me feel slightly uncomfortable since it increases coupling. Whereas consulting of errno had been explicit, with this change, it becomes implicit, and someone changing the code needs to be extra careful about ensuring that errno does not get clobbered.
Not a big objection, but a nagging doubt...
Quoted 24 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
builtin/update-index.c +4
-4@@ -251,11 +251,11 @@ static int remove_one_path(const char *path) -static int process_lstat_error (const char *path,int err) +static int process_lstat_error (const char *path) { -if (err ==ENOENT || err ==ENOTDIR ) +if (errno ==ENOENT || errno ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error_errno ("lstat(\"%s\")" , path); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)@@ -382,7 +382,7 @@ static int process_path(const char *path)* what to do about the pathname! */ if (lstat (path, &st) <0 ) -return process_lstat_error (path, errno); +return process_lstat_error (path);if (S_ISDIR (st.st_mode))return process_directory (path, len, &st);
Re: [PATCH 12/41] builtin/update-index.c: use error_errno()
Quoted 11 lines · Eric Sunshine
Quoted 2 lines · Nguyễn Thái Ngọc Duy
"err" is deleted because it just causes confusion when "errno" is also used directly in
process_lstat_error().Despite the function name which may imply that it is consulting errno, this change makes me feel slightly uncomfortable since it increases coupling. Whereas consulting of errno had been explicit, with this change, it becomes implicit, and someone changing the code needs to be extra careful about ensuring that errno does not get clobbered.
Not a big objection, but a nagging doubt...
We could s/errno/err/ in this function and not convert to error_errno(). Or we could delete this function and move the code back to its only call site in process_path()?
Quoted 24 lines
Quoted 24 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
builtin/update-index.c +4
-4@@ -251,11 +251,11 @@ static int remove_one_path(const char *path) -static int process_lstat_error (const char *path,int err) +static int process_lstat_error (const char *path) { -if (err ==ENOENT || err ==ENOTDIR ) +if (errno ==ENOENT || errno ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error_errno ("lstat(\"%s\")" , path); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)@@ -382,7 +382,7 @@ static int process_path(const char *path)* what to do about the pathname! */ if (lstat (path, &st) <0 ) -return process_lstat_error (path, errno); +return process_lstat_error (path);if (S_ISDIR (st.st_mode))return process_directory (path, len, &st);
Signature · 1 line
Duy
PATCH 13/41 builtin/upload-archive.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/upload-archive.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/upload-archive.c +1 -2
@@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) pfd[1 ].events =POLLIN ;if (poll (pfd,2 ,-1 ) <0 ) {if (errno !=EINTR ) { -error ("poll failed resuming: %s" , -strerror (errno)); +error_errno ("poll failed resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 14/41 builtin/worktree.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/worktree.c +1 -1
@@ -110,7 +110,7 @@ static void prune_worktrees(void)if (ret <0 && errno ==ENOTDIR ) ret =unlink (path.buf);if (ret) -error (_ ("failed to remove: %s" ),strerror (errno)); +error_errno (_ ("failed to remove '%s'" ), path.buf); }closedir (dir);if (!show_only)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 15/41 check-racy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- check-racy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
check-racy.c +1 -1
@@ -12,7 +12,7 @@ int main(int ac, char **av)struct stat st;if (lstat (ce->name, &st)) { -error ("lstat(%s): %s" , ce->name,strerror (errno)); +error_errno ("lstat(%s)" , ce->name);continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 16/41 combine-diff.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- combine-diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
combine-diff.c +1 -2
@@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,struct strbuf buf =STRBUF_INIT ;if (strbuf_readlink (&buf, elem->path, st.st_size) <0 ) { -error ("readlink(%s): %s" , elem->path, -strerror (errno)); +error_errno ("readlink(%s)" , elem->path);return ; } result_size = buf.len;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 17/41 compat/win32/syslog.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- compat/win32/syslog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
compat/win32/syslog.c +3 -3
@@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning ("vsnprintf failed: '%s'" ,strerror (errno)); +warning_errno ("vsnprintf failed:" );return ; } str =malloc (st_add (str_len,1 ));if (!str) { -warning ("malloc failed: '%s'" ,strerror (errno)); +warning_errno ("malloc failed" );return ; }
@@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...)while ((pos =strstr (str,"%1" )) !=NULL ) { str =realloc (str,st_add (++str_len,1 ));if (!str) { -warning ("realloc failed: '%s'" ,strerror (errno)); +warning_errno ("realloc failed" );return ; }memmove (pos +2 , pos +1 ,strlen (pos));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH 17/41] compat/win32/syslog.c: use warning_errno()
compat/win32/syslog.c void syslog(int priority, const char *fmt, ...) · line 31
Quoted 9 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
compat/win32/syslog.c +1
-1@@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning ("vsnprintf failed: '%s'" ,strerror (errno)); +warning_errno ("vsnprintf failed:" );
s/failed:/failed/
Quoted 2 lines
compat/win32/syslog.c +0
-0return ; }
PATCH 18/41 config.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- config.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
config.c +9 -13
@@ -2012,7 +2012,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, lock =xcalloc (1 ,sizeof (struct lock_file )); fd =hold_lock_file_for_update (lock, config_filename,0 );if (fd <0 ) { -error ("could not lock config file %s: %s" , config_filename,strerror (errno)); +error_errno ("could not lock config file %s" , config_filename);free (store.key); ret =CONFIG_NO_LOCK ; goto out_free;
@@ -2026,8 +2026,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,free (store.key);if (ENOENT != errno ) { -error ("opening %s: %s" , config_filename, -strerror (errno)); +error_errno ("opening %s" , config_filename); ret =CONFIG_INVALID_FILE ;/* same as "invalid config file" */ goto out_free; }
@@ -2111,8 +2110,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,if (contents ==MAP_FAILED ) {if (errno ==ENODEV &&S_ISDIR (st.st_mode)) errno =EISDIR ; -error ("unable to mmap '%s': %s" , - config_filename,strerror (errno)); +error_errno ("unable to mmap '%s'" , config_filename); ret =CONFIG_INVALID_FILE ; contents =NULL ; goto out_free;
@@ -2121,8 +2119,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, in_fd =-1 ;if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { -error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); +error_errno ("chmod on %s failed" ,get_lock_file_path (lock)); ret =CONFIG_NO_WRITE ; goto out_free; }
@@ -2178,8 +2175,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, }if (commit_lock_file (lock) <0 ) { -error ("could not write config file %s: %s" , config_filename, -strerror (errno)); +error_errno ("could not write config file %s" , config_filename); ret =CONFIG_NO_WRITE ; lock =NULL ; goto out_free;
@@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename,fstat (fileno (config_file), &st);if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { - ret =error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); + ret =error_errno ("chmod on %s failed" , +get_lock_file_path (lock)); goto out; }
@@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename,fclose (config_file); unlock_and_out:if (commit_lock_file (lock) <0 ) - ret =error ("could not write config file %s: %s" , - config_filename,strerror (errno)); + ret =error_errno ("could not write config file %s" , + config_filename); out:free (filename_buf);return ret;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 19/41 connected.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- connected.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
connected.c +3 -6
@@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn,memcpy (commit,sha1_to_hex (sha1),40 );if (write_in_full (rev_list.in, commit,41 ) <0 ) {if (errno !=EPIPE && errno !=EINVAL ) -error (_ ("failed write to rev-list: %s" ), -strerror (errno)); +error_errno (_ ("failed write to rev-list" )); err =-1 ;break ; } }while (!fn (cb_data, sha1)); -if (close (rev_list.in)) { -error (_ ("failed to close rev-list's stdin: %s" ),strerror (errno)); - err =-1 ; - } +if (close (rev_list.in)) + err =error_errno (_ ("failed to close rev-list's stdin" ));sigchain_pop (SIGPIPE );return finish_command (&rev_list) || err;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 20/41 copy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
copy.c +3 -3
@@ -42,15 +42,15 @@ int copy_file(const char *dst, const char *src, int mode) status =copy_fd (fdi, fdo);switch (status) {case COPY_READ_ERROR : -error ("copy-fd: read returned %s" ,strerror (errno)); +error_errno ("copy-fd: read returned" );break ;case COPY_WRITE_ERROR : -error ("copy-fd: write returned %s" ,strerror (errno)); +error_errno ("copy-fd: write returned" );break ; }close (fdi);if (close (fdo) !=0 ) -return error ("%s: close error: %s" , dst,strerror (errno)); +return error_errno ("%s: close error" , dst);if (!status &&adjust_shared_perm (dst))return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 21/41 credential-cache--daemon.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- credential-cache--daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
credential-cache--daemon.c +2 -2
@@ -179,12 +179,12 @@ static int serve_cache_loop(int fd) client =accept (fd,NULL ,NULL );if (client <0 ) { -warning ("accept failed: %s" ,strerror (errno)); +warning_errno ("accept failed" );return 1 ; } client2 =dup (client);if (client2 <0 ) { -warning ("dup failed: %s" ,strerror (errno)); +warning_errno ("dup failed" );close (client);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 22/41 diff-no-index.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- diff-no-index.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff-no-index.c +1 -2
@@ -65,8 +65,7 @@ static int populate_from_stdin(struct diff_filespec *s)size_t size =0 ;if (strbuf_read (&buf,0 ,0 ) <0 ) -return error ("error while reading from stdin %s" , -strerror (errno)); +return error_errno ("error while reading from stdin" ); s->should_munmap =0 ; s->data =strbuf_detach (&buf, &size);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 23/41 editor.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- editor.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
editor.c +1 -2
@@ -63,7 +63,6 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *enif (!buffer)return 0 ;if (strbuf_read_file (buffer, path,0 ) <0 ) -return error ("could not read file '%s': %s" , - path,strerror (errno)); +return error_errno ("could not read file '%s'" , path);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 24/41 entry.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- entry.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
entry.c +4 -6
@@ -168,8 +168,8 @@ static int write_entry(struct cache_entry *ce, ret =symlink (new, path);free (new);if (ret) -return error ("unable to create symlink %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create symlink %s" , + path);break ; }
@@ -186,8 +186,7 @@ static int write_entry(struct cache_entry *ce, fd =open_output_fd (path, ce, to_tempfile);if (fd <0 ) {free (new); -return error ("unable to create file %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create file %s" , path); } wrote =write_in_full (fd, new, size);
@@ -284,8 +283,7 @@ int checkout_entry(struct cache_entry *ce,return error ("%s is a directory" , path.buf);remove_subtree (&path); }else if (unlink (path.buf)) -return error ("unable to unlink old '%s' (%s)" , - path.buf,strerror (errno)); +return error_errno ("unable to unlink old '%s'" , path.buf); }else if (state->not_new)return 0 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 25/41 fast-import.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- fast-import.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fast-import.c +5 -5
@@ -414,7 +414,7 @@ static void write_crash_report(const char *err)struct recent_command *rc;if (!rpt) { -error ("can't write crash report %s: %s" , loc,strerror (errno)); +error_errno ("can't write crash report %s" , loc);free (loc);return ; }
@@ -1806,8 +1806,8 @@ static void dump_marks(void)return ;if (hold_lock_file_for_update (&mark_lock, export_marks_file,0 ) <0 ) { - failure |=error ("Unable to write marks file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write marks file %s" , + export_marks_file);return ; }
@@ -1822,8 +1822,8 @@ static void dump_marks(void)dump_marks_helper (f,0 , marks);if (commit_lock_file (&mark_lock)) { - failure |=error ("Unable to write file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write file %s" , + export_marks_file);return ; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 26/41 gpg-interface.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- gpg-interface.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
gpg-interface.c +2 -4
@@ -219,11 +219,9 @@ int verify_signed_buffer(const char *payload, size_t payload_size, args_gpg[0 ] = gpg_program; fd =git_mkstemp (path,PATH_MAX ,".git_vtag_tmpXXXXXX" );if (fd <0 ) -return error (_ ("could not create temporary file '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("could not create temporary file '%s'" ), path);if (write_in_full (fd, signature, signature_size) <0 ) -return error (_ ("failed writing detached signature to '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("failed writing detached signature to '%s'" ), path);close (fd); gpg.argv = args_gpg;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 27/41 grep.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- grep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
grep.c +2 -2
@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error (_ ("'%s': %s" ), filename,strerror (errno)); +error_errno (_ ("'%s'" ), filename);return -1 ; }if (!S_ISREG (st.st_mode))
@@ -1743,7 +1743,7 @@ static int grep_source_load_file(struct grep_source *gs) goto err_ret; data =xmallocz (size);if (st.st_size !=read_in_full (i, data, size)) { -error (_ ("'%s': short read %s" ), filename,strerror (errno)); +error_errno (_ ("'%s': short read" ), filename);close (i);free (data);return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH 27/41] grep.c: use error_errno()
grep.c static int grep_source_load_file(struct grep_source *gs) · line 1735
Quoted 9 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
grep.c +1
-1@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error (_ ("'%s': %s" ), filename,strerror (errno)); +error_errno (_ ("'%s'" ), filename);
Does this still need to be wrapped in _(...)? (Did it ever?)
Quoted 12 lines
grep.c +1
-1return -1 ; }if (!S_ISREG (st.st_mode))@@ -1743,7 +1743,7 @@ static int grep_source_load_file(struct grep_source *gs) goto err_ret; data =xmallocz (size);if (st.st_size !=read_in_full (i, data, size)) { -error (_ ("'%s': short read %s" ), filename,strerror (errno)); +error_errno (_ ("'%s': short read" ), filename);close (i);free (data);return -1 ;
PATCH 28/41 http.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- http.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
http.c +4 -6
@@ -446,8 +446,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type) rc =setsockopt (fd,SOL_SOCKET ,SO_KEEPALIVE , (void *)&ka, len);if (rc <0 ) -warning ("unable to set SO_KEEPALIVE on socket %s" , -strerror (errno)); +warning_errno ("unable to set SO_KEEPALIVE on socket" );return 0 ;/* CURL_SOCKOPT_OK only exists since curl 7.21.5 */ }
@@ -1894,8 +1893,7 @@ struct http_object_request *new_http_object_request(const char *base_url, }if (freq->localfile <0 ) { -error ("Couldn't create temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't create temporary file %s" , freq->tmpfile); goto abort; }
@@ -1940,8 +1938,8 @@ struct http_object_request *new_http_object_request(const char *base_url, prev_posn =0 ;lseek (freq->localfile,0 ,SEEK_SET );if (ftruncate (freq->localfile,0 ) <0 ) { -error ("Couldn't truncate temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't truncate temporary file %s" , + freq->tmpfile); goto abort; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 29/41 ident.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- ident.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
ident.c +3 -5
@@ -75,14 +75,12 @@ static int add_mailname_host(struct strbuf *buf) mailname =fopen ("/etc/mailname" ,"r" );if (!mailname) {if (errno !=ENOENT ) -warning ("cannot open /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot open /etc/mailname" );return -1 ; }if (strbuf_getline (&mailnamebuf, mailname) ==EOF ) {if (ferror (mailname)) -warning ("cannot read /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot read /etc/mailname" );strbuf_release (&mailnamebuf);fclose (mailname);return -1 ;
@@ -125,7 +123,7 @@ static void add_domainname(struct strbuf *out, int *is_bogus)char buf[1024 ];if (gethostname (buf,sizeof (buf))) { -warning ("cannot get host name: %s" ,strerror (errno)); +warning_errno ("cannot get host name" );strbuf_addstr (out,"(none)" ); *is_bogus =1 ;return ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 30/41 mailmap.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- mailmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mailmap.c +1 -2
@@ -189,8 +189,7 @@ static int read_mailmap_file(struct string_list *map, const char *filename,if (!f) {if (errno ==ENOENT )return 0 ; -return error ("unable to open mailmap at %s: %s" , - filename,strerror (errno)); +return error_errno ("unable to open mailmap at %s" , filename); }while (fgets (buffer,sizeof (buffer), f) !=NULL )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 31/41 reachable.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- reachable.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
reachable.c +1 -2
@@ -119,8 +119,7 @@ static int add_recent_loose(const unsigned char *sha1,*/ if (errno ==ENOENT )return 0 ; -return error ("unable to stat %s: %s" , -sha1_to_hex (sha1),strerror (errno)); +return error_errno ("unable to stat %s" ,sha1_to_hex (sha1)); }add_recent_object (sha1, st.st_mtime, data);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 32/41 rerere.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- rerere.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
rerere.c +7 -11
@@ -501,8 +501,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *outputerror ("There were errors while writing %s (%s)" , path,strerror (io.io.wrerror));if (io.io.output &&fclose (io.io.output)) - io.io.wrerror =error ("Failed to flush %s: %s" , - path,strerror (errno)); + io.io.wrerror =error_errno ("Failed to flush %s" , path);if (hunk_no <0 ) {if (output)
@@ -684,20 +683,17 @@ static int merge(const struct rerere_id *id, const char *path)* Mark that "postimage" was used to help gc. */ if (utime (rerere_path (id,"postimage" ),NULL ) <0 ) -warning ("failed utime() on %s: %s" , -rerere_path (id,"postimage" ), -strerror (errno)); +warning_errno ("failed utime() on %s" , +rerere_path (id,"postimage" ));/* Update "path" with the resolution */ f =fopen (path,"w" );if (!f) -return error ("Could not open %s: %s" , path, -strerror (errno)); +return error_errno ("Could not open %s" , path);if (fwrite (result.ptr, result.size,1 , f) !=1 ) -error ("Could not write %s: %s" , path,strerror (errno)); +error_errno ("Could not write %s" , path);if (fclose (f)) -return error ("Writing %s failed: %s" , path, -strerror (errno)); +return error_errno ("Writing %s failed" , path); out:free (cur.ptr);
@@ -1071,7 +1067,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)if (unlink (filename))return (errno ==ENOENT ?error ("no remembered resolution for %s" , path) - :error ("cannot unlink %s: %s" , filename,strerror (errno))); + :error_errno ("cannot unlink %s" , filename));/* * Update the preimage so that the user can resolve the
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 33/41 run-command.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- run-command.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
run-command.c +7 -8
@@ -233,7 +233,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)if (waiting <0 ) { failed_errno = errno; -error ("waitpid for %s failed: %s" , argv0,strerror (errno)); +error_errno ("waitpid for %s failed" , argv0); }else if (waiting != pid) {error ("waitpid is confused (%s)" , argv0); }else if (WIFSIGNALED (status)) {
@@ -420,8 +420,7 @@ fail_pipe: } }if (cmd->pid <0 ) -error ("cannot fork() for %s: %s" , cmd->argv[0 ], -strerror (errno)); +error_errno ("cannot fork() for %s" , cmd->argv[0 ]);else if (cmd->clean_on_exit)mark_child_for_cleanup (cmd->pid);
@@ -482,7 +481,7 @@ fail_pipe: cmd->dir, fhin, fhout, fherr); failed_errno = errno;if (cmd->pid <0 && (!cmd->silent_exec_failure || errno !=ENOENT )) -error ("cannot spawn %s: %s" , cmd->argv[0 ],strerror (errno)); +error_errno ("cannot spawn %s" , cmd->argv[0 ]);if (cmd->clean_on_exit && cmd->pid >=0 )mark_child_for_cleanup (cmd->pid);
@@ -703,7 +702,7 @@ int start_async(struct async *async)if (pipe (fdin) <0 ) {if (async->out >0 )close (async->out); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->in = fdin[1 ]; }
@@ -715,7 +714,7 @@ int start_async(struct async *async)close_pair (fdin); else if (async->in) close(async->in); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->out = fdout[0 ]; }
@@ -740,7 +739,7 @@ int start_async(struct async *async) async->pid =fork ();if (async->pid <0 ) { -error ("fork (async) failed: %s" ,strerror (errno)); +error_errno ("fork (async) failed" ); goto error; }if (!async->pid) {
@@ -787,7 +786,7 @@ int start_async(struct async *async) {int err =pthread_create (&async->tid,NULL , run_thread, async);if (err) { -error ("cannot create thread: %s" ,strerror (err)); +error_errno ("cannot create thread" ); goto error; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 34/41 sequencer.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- sequencer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sequencer.c +1 -2
@@ -875,8 +875,7 @@ static int sequencer_rollback(struct replay_opts *opts)return rollback_single_pick (); }if (!f) -return error (_ ("cannot open %s: %s" ),git_path_head_file (), -strerror (errno)); +return error_errno (_ ("cannot open %s" ),git_path_head_file ());if (strbuf_getline_lf (&buf, f)) {error (_ ("cannot read %s: %s" ),git_path_head_file (),ferror (f) ?strerror (errno) :_ ("unexpected end of file" ));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 35/41 server-info.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- server-info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
server-info.c +1 -1
@@ -36,7 +36,7 @@ static int update_info_file(char *path, int (*generate)(FILE *)) out:if (ret) { -error ("unable to update %s: %s" , path,strerror (errno)); +error_errno ("unable to update %s" , path);if (fp)fclose (fp);else if (fd >=0 )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 36/41 sha1_file.c: use {error,die,warning}_errno()
In reply to Nguyễn Thái Ngọc Duy--- sha1_file.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
sha1_file.c +13 -19
@@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,PROT_READ ,MAP_PRIVATE , p->pack_fd, win->offset);if (win->base ==MAP_FAILED ) -die ("packfile %s cannot be mapped: %s" , - p->pack_name, -strerror (errno)); +die_errno ("packfile %s cannot be mapped" , + p->pack_name);if (!win->offset && win->len == p->pack_size && !p->do_not_close)close_pack_fd (p);
@@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local) dir =opendir (path.buf);if (!dir) {if (errno !=ENOENT ) -error ("unable to open object pack directory: %s: %s" , - path.buf,strerror (errno)); +error_errno ("unable to open object pack directory: %s" , + path.buf);strbuf_release (&path);return ; }
@@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)unlink_or_warn (tmpfile);if (ret) {if (ret !=EEXIST ) { -return error ("unable to write sha1 filename %s: %s" , filename,strerror (ret)); +return error_errno ("unable to write sha1 filename %s" , filename); }/* FIXME!!! Collision check here ? */ }
@@ -2998,7 +2997,7 @@ out:static int write_buffer (int fd,const void *buf,size_t len) {if (write_in_full (fd, buf, len) <0 ) -return error ("file write error (%s)" ,strerror (errno)); +return error_errno ("file write error" );return 0 ; }
@@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,if (errno ==EACCES )return error ("insufficient permission for adding an object to repository database %s" ,get_object_directory ());else -return error ("unable to create temporary file: %s" ,strerror (errno)); +return error_errno ("unable to create temporary file" ); }/* Set it up */
@@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, utb.actime = mtime; utb.modtime = mtime;if (utime (tmp_file.buf, &utb) <0 ) -warning ("failed utime() on %s: %s" , - tmp_file.buf,strerror (errno)); +warning_errno ("failed utime() on %s" , tmp_file.buf); }return finalize_object_file (tmp_file.buf, filename);
@@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,if (size ==read_in_full (fd, buf, size)) ret =index_mem (sha1, buf, size, type, path, flags);else - ret =error ("short read %s" ,strerror (errno)); + ret =error_errno ("short read" );free (buf); }else {void *buf =xmmap (NULL , size,PROT_READ ,MAP_PRIVATE , fd,0 );
@@ -3425,18 +3423,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsignedcase S_IFREG : fd =open (path,O_RDONLY );if (fd <0 ) -return error ("open(\"%s\"): %s" , path, -strerror (errno)); +return error_errno ("open(\"%s\")" , path);if (index_fd (sha1, fd, st,OBJ_BLOB , path, flags) <0 )return error ("%s: failed to insert into database" , path);break ;case S_IFLNK : -if (strbuf_readlink (&sb, path, st->st_size)) { -char *errstr =strerror (errno); -return error ("readlink(\"%s\"): %s" , path, - errstr); - } +if (strbuf_readlink (&sb, path, st->st_size)) +return error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_sha1_file (sb.buf, sb.len, blob_type, sha1);else if (write_sha1_file (sb.buf, sb.len, blob_type, sha1))
@@ -3492,7 +3486,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,if (!dir) {if (errno ==ENOENT )return 0 ; -return error ("unable to open %s: %s" , path->buf,strerror (errno)); +return error_errno ("unable to open %s" , path->buf); }while ((de =readdir (dir))) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 37/41 transport-helper.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- transport-helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
transport-helper.c +3 -3
@@ -1166,7 +1166,7 @@ static int udt_do_read(struct unidirectional_transfer *t) bytes =read (t->src, t->buf + t->bufuse,BUFFERSIZE - t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK && errno !=EAGAIN && errno !=EINTR ) { -error ("read(%s) failed: %s" , t->src_name,strerror (errno)); +error_errno ("read(%s) failed" , t->src_name);return -1 ; }else if (bytes ==0 ) { transfer_debug("%s EOF (with %i bytes in buffer)",
@@ -1193,7 +1193,7 @@ static int udt_do_write(struct unidirectional_transfer *t)transfer_debug ("%s is writable" , t->dest_name); bytes =xwrite (t->dest, t->buf, t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK ) { -error ("write(%s) failed: %s" , t->dest_name,strerror (errno)); +error_errno ("write(%s) failed" , t->dest_name);return -1 ; }else if (bytes >0 ) { t->bufuse -= bytes;
@@ -1306,7 +1306,7 @@ static int tloop_join(pid_t pid, const char *name) {int tret;if (waitpid (pid, &tret,0 ) <0 ) { -error ("%s process failed to wait: %s" , name,strerror (errno)); +error_errno ("%s process failed to wait" , name);return 1 ; }if (!WIFEXITED (tret) ||WEXITSTATUS (tret)) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 38/41 unpack-trees.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- unpack-trees.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
unpack-trees.c +2 -4
@@ -1499,8 +1499,7 @@ static int verify_absent_1(const struct cache_entry *ce, path =xmemdupz (ce->name, len);if (lstat (path, &st)) - ret =error ("cannot stat '%s': %s" , path, -strerror (errno)); + ret =error_errno ("cannot stat '%s'" , path);else ret =check_ok_to_remove (path, len,DT_UNKNOWN ,NULL , &st, error_type, o);
@@ -1508,8 +1507,7 @@ static int verify_absent_1(const struct cache_entry *ce,return ret; }else if (lstat (ce->name, &st)) {if (errno !=ENOENT ) -return error ("cannot stat '%s': %s" , ce->name, -strerror (errno)); +return error_errno ("cannot stat '%s'" , ce->name);return 0 ; }else { return check_ok_to_remove(ce->name, ce_namelen(ce),
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 39/41 upload-pack.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- upload-pack.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
upload-pack.c +1 -2
@@ -174,8 +174,7 @@ static void create_pack_file(void)if (ret <0 ) {if (errno !=EINTR ) { -error ("poll failed, resuming: %s" , -strerror (errno)); +error_errno ("poll failed, resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 40/41 vcs-svn: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- vcs-svn/line_buffer.c | 4 ++-- vcs-svn/sliding_window.c | 2 +- vcs-svn/svndiff.c | 4 ++-- vcs-svn/svndump.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
vcs-svn/line_buffer.c +2 -2
@@ -53,9 +53,9 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf) {long pos =ftell (buf->infile);if (pos <0 ) -return error ("ftell error: %s" ,strerror (errno)); +return error_errno ("ftell error" );if (fseek (buf->infile,0 ,SEEK_SET )) -return error ("seek error: %s" ,strerror (errno)); +return error_errno ("seek error" );return pos; }
vcs-svn/sliding_window.c +1 -1
@@ -12,7 +12,7 @@ static int input_error(struct line_buffer *file) {if (!buffer_ferror (file))return error ("delta preimage ends early" ); -return error ("cannot read delta preimage: %s" ,strerror (errno)); +return error_errno ("cannot read delta preimage" ); }static int skip_or_whine (struct line_buffer *file,off_t gap)
vcs-svn/svndiff.c +2 -2
@@ -64,13 +64,13 @@ static int write_strbuf(struct strbuf *sb, FILE *out) {if (fwrite (sb->buf,1 , sb->len, out) == sb->len)/* Success. */ return 0 ; -return error ("cannot write delta postimage: %s" ,strerror (errno)); +return error_errno ("cannot write delta postimage" ); }static int error_short_read (struct line_buffer *input) {if (buffer_ferror (input)) -return error ("error reading delta: %s" ,strerror (errno)); +return error_errno ("error reading delta" );return error ("invalid delta: unexpected end of file" ); }
vcs-svn/svndump.c +2 -2
@@ -501,7 +501,7 @@ static void init(int report_fd)int svndump_init (const char *filename) {if (buffer_init (&input, filename)) -return error ("cannot open %s: %s" , filename ? filename :"NULL" ,strerror (errno)); +return error_errno ("cannot open %s" , filename ? filename :"NULL" );init (REPORT_FILENO );return 0 ; }
@@ -509,7 +509,7 @@ int svndump_init(const char *filename)int svndump_init_fd (int in_fd,int back_fd) {if (buffer_fdinit (&input,xdup (in_fd))) -return error ("cannot open fd %d: %s" , in_fd,strerror (errno)); +return error_errno ("cannot open fd %d" , in_fd);init (xdup (back_fd));return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH 41/41 wrapper.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- wrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
wrapper.c +2 -2
@@ -572,7 +572,7 @@ static int warn_if_unremovable(const char *op, const char *file, int rc)if (!rc || errno ==ENOENT )return 0 ; err = errno; -warning ("unable to %s %s: %s" , op, file,strerror (errno)); +warning_errno ("unable to %s %s" , op, file); errno = err;return rc; }
@@ -608,7 +608,7 @@ int remove_or_warn(unsigned int mode, const char *file)void warn_on_inaccessible (const char *path) { -warning (_ ("unable to access '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("unable to access '%s'" ), path); }static int access_error_is_ok (int err,unsigned flag)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Quoted 3 lines · Nguyễn Thái Ngọc Duy
This is a spinoff from my worktree-move topic. This series adds
die_errno()companions,error_errno()andwarning_errno(), and use them where applicable to reduce the amount of typing (in future).
I had this patch in the series but excluded it before sending because there is something wrong about it.
The patch shows two code blocks that follow the same pattern:closesocket() then print an error with strerror(). The second block suggests that closesocket() can change errno. But if that's true, the first block should do the same.
Which is right? Fix the first block to save errno, or drop the saving in the second block?
compat/mingw.c +2 -5
@@ -1555,8 +1555,7 @@ int mingw_socket(int domain, int type, int protocol)/* convert into a file descriptor */ if ((sockfd =_open_osfhandle (s,O_RDWR |O_BINARY )) <0 ) {closesocket (s); -return error ("unable to make a socket file descriptor: %s" , -strerror (errno)); +return error_errno ("unable to make a socket file descriptor" ); }return sockfd; }
@@ -1606,10 +1605,8 @@ int mingw_accept(int sockfd1, struct sockaddr *sa, socklen_t *sz)/* convert into a file descriptor */ if ((sockfd2 =_open_osfhandle (s2,O_RDWR |O_BINARY )) <0 ) { -int err = errno;closesocket (s2); -return error ("unable to make a socket file descriptor: %s" , -strerror (err)); +return error_errno ("unable to make a socket file descriptor" ); }return sockfd2; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
v2 cover Add and use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc DuyChanges are in
[01/41] usage.c: move format processing out of die_errno() [02/41] usage.c: add warning_errno() and error_errno()
[12/41] builtin/update-index.c: prefer "err" to "errno" in process_lstat_error [17/41] compat/win32/syslog.c: use warning_errno()
[27/41] grep.c: use error_errno()
12/41 is basically a revert with s/strerror(errno)/strerror(err)/. Interdiff from v1
-- 8< --
builtin/update-index.c +4 -4
@@ -251,11 +251,11 @@ static int remove_one_path(const char *path)* succeeds. * - permission error. That's never ok. */ -static int process_lstat_error (const char *path) +static int process_lstat_error (const char *path,int err) { -if (errno ==ENOENT || errno ==ENOTDIR ) +if (err ==ENOENT || err ==ENOTDIR )return remove_one_path (path); -return error_errno ("lstat(\"%s\")" , path); +return error ("lstat(\"%s\"): %s" , path,strerror (err)); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)
@@ -382,7 +382,7 @@ static int process_path(const char *path)* what to do about the pathname! */ if (lstat (path, &st) <0 ) -return process_lstat_error (path); +return process_lstat_error (path, errno);if (S_ISDIR (st.st_mode))return process_directory (path, len, &st);
compat/win32/syslog.c +1 -1
@@ -28,7 +28,7 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning_errno ("vsnprintf failed:" ); +warning_errno ("vsnprintf failed" );return ; }
grep.c +1 -1
@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error_errno (_ ("'%s'" ), filename); +error_errno ("'%s'" , filename);return -1 ; }if (!S_ISREG (st.st_mode))
usage.c +9 -7
@@ -109,9 +109,8 @@ void NORETURN die(const char *err, ...)va_end (params); } -static const char *fmt_with_err (const char *fmt) +static const char *fmt_with_err (char *buf,int n,const char *fmt) { -static char fmt_with_err[1024 ];char str_error[256 ], *err;int i, j;
@@ -129,12 +128,13 @@ static const char *fmt_with_err(const char *fmt) } } str_error[j] =0 ; -snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); -return fmt_with_err; +snprintf (buf, n,"%s: %s" , fmt, str_error); +return buf; } void NORETURN die_errno(const char *fmt, ...) { +char buf[1024 ];va_list params;if (die_is_recursing ()) {
@@ -144,16 +144,17 @@ void NORETURN die_errno(const char *fmt, ...) }va_start (params, fmt); -die_routine (fmt_with_err (fmt), params); +die_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params); }int error_errno (const char *fmt, ...) { +char buf[1024 ];va_list params;va_start (params, fmt); -error_routine (fmt_with_err (fmt), params); +error_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params);return -1 ; }
@@ -171,10 +172,11 @@ int error(const char *err, ...)void warning_errno (const char *warn, ...) { +char buf[1024 ];va_list params;va_start (params, warn); -warn_routine (fmt_with_err (warn), params); +warn_routine (fmt_with_err (buf,sizeof (buf), warn), params);va_end (params); }
-- 8< --
--
Duy
PATCH v2 1/41 usage.c: move format processing out of die_errno()
fmt_with_err() will be shared with the coming error_errno() and warning_errno().
--- usage.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
usage.c +16 -11
@@ -109,19 +109,11 @@ void NORETURN die(const char *err, ...)va_end (params); } -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err (char *buf,int n,const char *fmt) { -va_list params; -char fmt_with_err[1024 ];char str_error[256 ], *err;int i, j; -if (die_is_recursing ()) { -fputs ("fatal: recursion detected in die_errno handler\n" , - stderr); -exit (128 ); - } - err =strerror (errno);for (i = j =0 ; err[i] && j <sizeof (str_error) -1 ; ) {if ((str_error[j++] = err[i++]) !='%' )
@@ -136,10 +128,23 @@ void NORETURN die_errno(const char *fmt, ...) } } str_error[j] =0 ; -snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); +snprintf (buf, n,"%s: %s" , fmt, str_error); +return buf; +} + +void NORETURN die_errno(const char *fmt, ...) +{ +char buf[1024 ]; +va_list params; + +if (die_is_recursing ()) { +fputs ("fatal: recursion detected in die_errno handler\n" , + stderr); +exit (128 ); + }va_start (params, fmt); -die_routine (fmt_with_err, params); +die_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 2/41 usage.c: add warning_errno() and error_errno()
In reply to Nguyễn Thái Ngọc DuySimilar to die_errno(), these functions will append strerror() automatically.
--- git-compat-util.h | 2 ++ usage.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
git-compat-util.h +2 -0
@@ -409,7 +409,9 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern int error_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void warning_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));#ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO
usage.c +21 -0
@@ -148,6 +148,17 @@ void NORETURN die_errno(const char *fmt, ...)va_end (params); } +int error_errno (const char *fmt, ...) +{ +char buf[1024 ]; +va_list params; + +va_start (params, fmt); +error_routine (fmt_with_err (buf,sizeof (buf), fmt), params); +va_end (params); +return -1 ; +} +#undef errorint error (const char *err, ...) {
@@ -159,6 +170,16 @@ int error(const char *err, ...)return -1 ; } +void warning_errno (const char *warn, ...) +{ +char buf[1024 ]; +va_list params; + +va_start (params, warn); +warn_routine (fmt_with_err (buf,sizeof (buf), warn), params); +va_end (params); +} +void warning (const char *warn, ...) {va_list params;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 3/41 bisect.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- bisect.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
bisect.c +3 -4
@@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)/* Create file BISECT_ANCESTORS_OK. */ fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY ,0600 );if (fd <0 ) -warning ("could not create file '%s': %s" , - filename,strerror (errno)); +warning_errno ("could not create file '%s'" , + filename);else close (fd); done:
@@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) *read_good ="good" ;return ; }else { -die ("could not read file '%s': %s" , filename, -strerror (errno)); +die_errno ("could not read file '%s'" , filename); } }else {strbuf_getline_lf (&str, fp);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 4/41 builtin/am.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
builtin/am.c +5 -6
@@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state, in =fopen (*paths,"r" );if (!in) -return error (_ ("could not open '%s' for reading: %s" ), - *paths,strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), + *paths); mail =mkpath ("%s/%0*d" , state->dir, state->prec, i +1 ); out =fopen (mail,"w" );if (!out) -return error (_ ("could not open '%s' for writing: %s" ), - mail,strerror (errno)); +return error_errno (_ ("could not open '%s' for writing" ), + mail); ret =fn (out, in, keep_cr);
@@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, fp =fopen (*paths,"r" );if (!fp) -return error (_ ("could not open '%s' for reading: %s" ), *paths, -strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), *paths);while (!strbuf_getline_lf (&sb, fp)) {if (*sb.buf =='#' )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 5/41 builtin/branch.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/branch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/branch.c +1 -2
@@ -593,8 +593,7 @@ static int edit_branch_description(const char *branch_name) branch_name, comment_line_char);if (write_file_gently (git_path (edit_description),"%s" , buf.buf)) {strbuf_release (&buf); -return error (_ ("could not write branch description template: %s" ), -strerror (errno)); +return error_errno (_ ("could not write branch description template" )); }strbuf_reset (&buf);if (launch_editor (git_path (edit_description), &buf,NULL )) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 6/41 builtin/fetch.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/fetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/fetch.c +2 -2
@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fp =fopen (filename,"a" );if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);if (raw_url) url =transport_anonymize_url (raw_url);
@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)FILE *fp =fopen_for_writing (filename);if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);fclose (fp);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 06/41] builtin/fetch.c: use error_errno()
Quoted 14 lines · Nguyễn Thái Ngọc Duy
builtin/fetch.c +1
-1@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fp =fopen (filename,"a" );if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);if (raw_url) url =transport_anonymize_url (raw_url);
builtin/fetch.c static int truncate_fetch_head(void) · line 854
Quoted 8 lines
builtin/fetch.c +1
-1@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)FILE *fp =fopen_for_writing (filename);if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);fclose (fp);return 0 ; }
Both of these original had unwanted \n at the end, and the updated one loses them, which is good.
PATCH v2 7/41 builtin/help.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/help.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/help.c +4 -4
@@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page) path ="emacsclient" ;strbuf_addf (&man_page,"(woman \"%s\")" , page);execlp (path,"emacsclient" ,"-e" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page) path ="kfmclient" ;strbuf_addf (&man_page,"man:%s(1)" , page);execlp (path, filename,"newTab" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page)if (!path) path ="man" ;execlp (path,"man" , page, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); }static void exec_man_cmd (const char *cmd,const char *page)
@@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page)struct strbuf shell_cmd =STRBUF_INIT ;strbuf_addf (&shell_cmd,"%s %s" , cmd, page);execl (SHELL_PATH ,SHELL_PATH ,"-c" , shell_cmd.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), cmd,strerror (errno)); +warning (_ ("failed to exec '%s'" ), cmd); }static void add_man_viewer (const char *name)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 8/41 builtin/mailsplit.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/mailsplit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/mailsplit.c +5 -5
@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)if ((dir =opendir (name)) ==NULL ) {if (errno ==ENOENT )continue ; -error ("cannot opendir %s (%s)" , name,strerror (errno)); +error_errno ("cannot opendir %s" , name); goto out; }
@@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir, f =fopen (file,"r" );if (!f) { -error ("cannot open mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot open mail %s" , file); goto out; }if (strbuf_getwholeline (&buf, f,'\n' )) { -error ("cannot read mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot read mail %s" , file); goto out; }
@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,int file_done =0 ;if (!f) { -error ("cannot open mbox %s" , file); +error_errno ("cannot open mbox %s" , file); goto out; }
@@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) }if (stat (arg, &argstat) ==-1 ) { -error ("cannot stat %s (%s)" , arg,strerror (errno)); +error_errno ("cannot stat %s" , arg);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 08/41] builtin/mailsplit.c: use error_errno()
builtin/mailsplit.c static int split_maildir(const char *maildir, const char *dir,
Quoted 9 lines · Nguyễn Thái Ngọc Duy
builtin/mailsplit.c +4
-4-error ("cannot opendir %s (%s)" , name,strerror (errno)); +error_errno ("cannot opendir %s" , name); -error ("cannot open mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot open mail %s" , file); -error ("cannot read mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot read mail %s" , file); -error ("cannot stat %s (%s)" , arg,strerror (errno)); +error_errno ("cannot stat %s" , arg);
These all used to use its own formatting, but will use "<message>: <errno>" format like everybody else, which is good.
builtin/mailsplit.c static int split_mbox(const char *file, const char *dir, int allow_bare, · line 215
Quoted 8 lines
builtin/mailsplit.c +1
-1@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,int file_done =0 ;if (!f) { -error ("cannot open mbox %s" , file); +error_errno ("cannot open mbox %s" , file); goto out; }
It may be a bit unclear from the context, but it uses errno that was set when fopen() returned a NULL.
The changes in this patch are not faithful conversion like other patches, but they are all good, I would say.
Thanks.
PATCH v2 9/41 builtin/merge-file.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/merge-file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/merge-file.c +5 -5
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)usage_with_options (merge_file_usage, options);if (quiet) {if (!freopen ("/dev/null" ,"w" , stderr)) -return error ("failed to redirect stderr to /dev/null: " -"%s" ,strerror (errno)); +return error_errno ("failed to redirect stderr to /dev/null" ); }if (prefix)
@@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)FILE *f = to_stdout ? stdout :fopen (fpath,"wb" );if (!f) - ret =error ("Could not open %s for writing" , filename); + ret =error_errno ("Could not open %s for writing" , + filename);else if (result.size &&fwrite (result.ptr, result.size,1 , f) !=1 ) - ret =error ("Could not write to %s" , filename); + ret =error_errno ("Could not write to %s" , filename);else if (fclose (f)) - ret =error ("Could not close %s" , filename); + ret =error_errno ("Could not close %s" , filename);free (result.ptr); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 10/41 builtin/pack-objects.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/pack-objects.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
builtin/pack-objects.c +3 -5
@@ -828,8 +828,7 @@ static void write_pack_file(void)* to preserve this property. */ if (stat (pack_tmp_name, &st) <0 ) { -warning ("failed to stat %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed to stat %s" , pack_tmp_name); }else if (!last_mtime) { last_mtime = st.st_mtime; }else {
@@ -837,8 +836,7 @@ static void write_pack_file(void) utb.actime = st.st_atime; utb.modtime = --last_mtime;if (utime (pack_tmp_name, &utb) <0 ) -warning ("failed utime() on %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed utime() on %s" , pack_tmp_name); }strbuf_addf (&tmpname,"%s-" , base_name);
@@ -2020,7 +2018,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, ret =pthread_create (&p[i].thread,NULL , threaded_find_deltas, &p[i]);if (ret) -die ("unable to create thread: %s" ,strerror (ret)); +die_errno ("unable to create thread" ); active_threads++; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 10/41] builtin/pack-objects.c: use die_errno() and warning_errno()
builtin/pack-objects.c static void ll_find_deltas(struct object_entry **list, unsigned list_size, · line 2021
Quoted 9 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
builtin/pack-objects.c +1
-1@@ -2020,7 +2018,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, ret =pthread_create (&p[i].thread,NULL , threaded_find_deltas, &p[i]);if (ret) -die ("unable to create thread: %s" ,strerror (ret)); +die_errno ("unable to create thread" );
This deserves a mention in the log message. pthread_create() returns 0 on success and it returns "an error number" on error. We used to format that returned value with strerror().
I do not see anywhere in the updated code that copies ret back to errno, which would mean die_errno() would use whatever happens to be in errno, and the relationship between the returned value 'ret' and the value that is in 'errno' at this point in the code is unclear to me.
PATCH v2 11/41 builtin/rm.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/rm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rm.c +1 -1
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR ) -warning ("'%s': %s" , ce->name,strerror (errno)); +warning_errno ("'%s'" , ce->name);/* It already vanished from the working tree */ continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 11/41] builtin/rm.c: use warning_errno()
Quoted 10 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/rm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/rm.c +0
-0
builtin/rm.c static int check_local_mod(unsigned char *head, int index_only) · line 157
Quoted 7 lines
builtin/rm.c +1
-1@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR ) -warning ("'%s': %s" , ce->name,strerror (errno)); +warning_errno ("'%s'" , ce->name);/* It already vanished from the working tree */ continue ;
Not a new problem with this patch, but this would say
warning: 'Makefile': Permission denied.
or whatever error we may happen to have hit.
I think we show strerror(errno) as an additional explanation and there must be something _else_ that is the primary thing we would want to say, e.g.
warning: cannot remove 'Makefile': Permission denied.
Without that primary message from us, it looks somewhat wrong.
PATCH v2 12/41 builtin/update-index.c: prefer "err" to "errno" in process_lstat_error
In reply to Nguyễn Thái Ngọc Duy"errno" is already passed in as "err". Here we should use err instead of errno. errno is probably a copy/paste mistake in e011054 (Teach git-update-index about gitlinks - 2007-04-12)
--- builtin/update-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/update-index.c +1 -1
@@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err) {if (err ==ENOENT || err ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error ("lstat(\"%s\"): %s" , path,strerror (err)); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 12/41] builtin/update-index.c: prefer "err" to "errno" in process_lstat_error
Quoted 3 lines · Nguyễn Thái Ngọc Duy
"errno" is already passed in as "err". Here we should use err instead of errno. errno is probably a copy/paste mistake in e011054 (Teach git-update-index about gitlinks - 2007-04-12)
Thanks, this version is quite sensible and doesn't trigger any feelings of discomfort[1].
[1]: http://thread.gmane.org/gmane.comp.version-control.git/293150/focus=293205
Quoted 20 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/update-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/update-index.c +1
-2@@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err) {if (err ==ENOENT || err ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error ("lstat(\"%s\"): %s" , path,strerror (err)); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st) --2.8.0.rc0.210.gd302cd2
PATCH v2 13/41 builtin/upload-archive.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/upload-archive.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/upload-archive.c +1 -2
@@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) pfd[1 ].events =POLLIN ;if (poll (pfd,2 ,-1 ) <0 ) {if (errno !=EINTR ) { -error ("poll failed resuming: %s" , -strerror (errno)); +error_errno ("poll failed resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 14/41 builtin/worktree.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/worktree.c +1 -1
@@ -110,7 +110,7 @@ static void prune_worktrees(void)if (ret <0 && errno ==ENOTDIR ) ret =unlink (path.buf);if (ret) -error (_ ("failed to remove: %s" ),strerror (errno)); +error_errno (_ ("failed to remove '%s'" ), path.buf); }closedir (dir);if (!show_only)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Re: [PATCH v2 14/41] builtin/worktree.c: use error_errno()
Quoted 10 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/worktree.c +0
-0
builtin/worktree.c static void prune_worktrees(void) · line 113
Quoted 5 lines
builtin/worktree.c +1
-1@@ -110,7 +110,7 @@ static void prune_worktrees(void)if (ret <0 && errno ==ENOTDIR ) ret =unlink (path.buf);if (ret) -error (_ ("failed to remove: %s" ),strerror (errno)); +error_errno (_ ("failed to remove '%s'" ), path.buf);
This also deserves a mention in the log message. We didn't say what we failed to remove, now we do, which is an improvement.
PATCH v2 15/41 check-racy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- check-racy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
check-racy.c +1 -1
@@ -12,7 +12,7 @@ int main(int ac, char **av)struct stat st;if (lstat (ce->name, &st)) { -error ("lstat(%s): %s" , ce->name,strerror (errno)); +error_errno ("lstat(%s)" , ce->name);continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 16/41 combine-diff.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- combine-diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
combine-diff.c +1 -2
@@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,struct strbuf buf =STRBUF_INIT ;if (strbuf_readlink (&buf, elem->path, st.st_size) <0 ) { -error ("readlink(%s): %s" , elem->path, -strerror (errno)); +error_errno ("readlink(%s)" , elem->path);return ; } result_size = buf.len;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 17/41 compat/win32/syslog.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- compat/win32/syslog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
compat/win32/syslog.c +3 -3
@@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning ("vsnprintf failed: '%s'" ,strerror (errno)); +warning_errno ("vsnprintf failed" );return ; } str =malloc (st_add (str_len,1 ));if (!str) { -warning ("malloc failed: '%s'" ,strerror (errno)); +warning_errno ("malloc failed" );return ; }
@@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...)while ((pos =strstr (str,"%1" )) !=NULL ) { str =realloc (str,st_add (++str_len,1 ));if (!str) { -warning ("realloc failed: '%s'" ,strerror (errno)); +warning_errno ("realloc failed" );return ; }memmove (pos +2 , pos +1 ,strlen (pos));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 18/41 config.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- config.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
config.c +9 -13
@@ -2012,7 +2012,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, lock =xcalloc (1 ,sizeof (struct lock_file )); fd =hold_lock_file_for_update (lock, config_filename,0 );if (fd <0 ) { -error ("could not lock config file %s: %s" , config_filename,strerror (errno)); +error_errno ("could not lock config file %s" , config_filename);free (store.key); ret =CONFIG_NO_LOCK ; goto out_free;
@@ -2026,8 +2026,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,free (store.key);if (ENOENT != errno ) { -error ("opening %s: %s" , config_filename, -strerror (errno)); +error_errno ("opening %s" , config_filename); ret =CONFIG_INVALID_FILE ;/* same as "invalid config file" */ goto out_free; }
@@ -2111,8 +2110,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,if (contents ==MAP_FAILED ) {if (errno ==ENODEV &&S_ISDIR (st.st_mode)) errno =EISDIR ; -error ("unable to mmap '%s': %s" , - config_filename,strerror (errno)); +error_errno ("unable to mmap '%s'" , config_filename); ret =CONFIG_INVALID_FILE ; contents =NULL ; goto out_free;
@@ -2121,8 +2119,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, in_fd =-1 ;if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { -error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); +error_errno ("chmod on %s failed" ,get_lock_file_path (lock)); ret =CONFIG_NO_WRITE ; goto out_free; }
@@ -2178,8 +2175,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, }if (commit_lock_file (lock) <0 ) { -error ("could not write config file %s: %s" , config_filename, -strerror (errno)); +error_errno ("could not write config file %s" , config_filename); ret =CONFIG_NO_WRITE ; lock =NULL ; goto out_free;
@@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename,fstat (fileno (config_file), &st);if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { - ret =error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); + ret =error_errno ("chmod on %s failed" , +get_lock_file_path (lock)); goto out; }
@@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename,fclose (config_file); unlock_and_out:if (commit_lock_file (lock) <0 ) - ret =error ("could not write config file %s: %s" , - config_filename,strerror (errno)); + ret =error_errno ("could not write config file %s" , + config_filename); out:free (filename_buf);return ret;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 19/41 connected.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- connected.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
connected.c +3 -6
@@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn,memcpy (commit,sha1_to_hex (sha1),40 );if (write_in_full (rev_list.in, commit,41 ) <0 ) {if (errno !=EPIPE && errno !=EINVAL ) -error (_ ("failed write to rev-list: %s" ), -strerror (errno)); +error_errno (_ ("failed write to rev-list" )); err =-1 ;break ; } }while (!fn (cb_data, sha1)); -if (close (rev_list.in)) { -error (_ ("failed to close rev-list's stdin: %s" ),strerror (errno)); - err =-1 ; - } +if (close (rev_list.in)) + err =error_errno (_ ("failed to close rev-list's stdin" ));sigchain_pop (SIGPIPE );return finish_command (&rev_list) || err;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 20/41 copy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
copy.c +3 -3
@@ -42,15 +42,15 @@ int copy_file(const char *dst, const char *src, int mode) status =copy_fd (fdi, fdo);switch (status) {case COPY_READ_ERROR : -error ("copy-fd: read returned %s" ,strerror (errno)); +error_errno ("copy-fd: read returned" );break ;case COPY_WRITE_ERROR : -error ("copy-fd: write returned %s" ,strerror (errno)); +error_errno ("copy-fd: write returned" );break ; }close (fdi);if (close (fdo) !=0 ) -return error ("%s: close error: %s" , dst,strerror (errno)); +return error_errno ("%s: close error" , dst);if (!status &&adjust_shared_perm (dst))return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 21/41 credential-cache--daemon.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- credential-cache--daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
credential-cache--daemon.c +2 -2
@@ -179,12 +179,12 @@ static int serve_cache_loop(int fd) client =accept (fd,NULL ,NULL );if (client <0 ) { -warning ("accept failed: %s" ,strerror (errno)); +warning_errno ("accept failed" );return 1 ; } client2 =dup (client);if (client2 <0 ) { -warning ("dup failed: %s" ,strerror (errno)); +warning_errno ("dup failed" );close (client);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 22/41 diff-no-index.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- diff-no-index.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff-no-index.c +1 -2
@@ -65,8 +65,7 @@ static int populate_from_stdin(struct diff_filespec *s)size_t size =0 ;if (strbuf_read (&buf,0 ,0 ) <0 ) -return error ("error while reading from stdin %s" , -strerror (errno)); +return error_errno ("error while reading from stdin" ); s->should_munmap =0 ; s->data =strbuf_detach (&buf, &size);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 23/41 editor.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- editor.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
editor.c +1 -2
@@ -63,7 +63,6 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *enif (!buffer)return 0 ;if (strbuf_read_file (buffer, path,0 ) <0 ) -return error ("could not read file '%s': %s" , - path,strerror (errno)); +return error_errno ("could not read file '%s'" , path);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 24/41 entry.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- entry.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
entry.c +4 -6
@@ -168,8 +168,8 @@ static int write_entry(struct cache_entry *ce, ret =symlink (new, path);free (new);if (ret) -return error ("unable to create symlink %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create symlink %s" , + path);break ; }
@@ -186,8 +186,7 @@ static int write_entry(struct cache_entry *ce, fd =open_output_fd (path, ce, to_tempfile);if (fd <0 ) {free (new); -return error ("unable to create file %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create file %s" , path); } wrote =write_in_full (fd, new, size);
@@ -284,8 +283,7 @@ int checkout_entry(struct cache_entry *ce,return error ("%s is a directory" , path.buf);remove_subtree (&path); }else if (unlink (path.buf)) -return error ("unable to unlink old '%s' (%s)" , - path.buf,strerror (errno)); +return error_errno ("unable to unlink old '%s'" , path.buf); }else if (state->not_new)return 0 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 25/41 fast-import.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- fast-import.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fast-import.c +5 -5
@@ -414,7 +414,7 @@ static void write_crash_report(const char *err)struct recent_command *rc;if (!rpt) { -error ("can't write crash report %s: %s" , loc,strerror (errno)); +error_errno ("can't write crash report %s" , loc);free (loc);return ; }
@@ -1806,8 +1806,8 @@ static void dump_marks(void)return ;if (hold_lock_file_for_update (&mark_lock, export_marks_file,0 ) <0 ) { - failure |=error ("Unable to write marks file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write marks file %s" , + export_marks_file);return ; }
@@ -1822,8 +1822,8 @@ static void dump_marks(void)dump_marks_helper (f,0 , marks);if (commit_lock_file (&mark_lock)) { - failure |=error ("Unable to write file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write file %s" , + export_marks_file);return ; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 26/41 gpg-interface.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- gpg-interface.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
gpg-interface.c +2 -4
@@ -219,11 +219,9 @@ int verify_signed_buffer(const char *payload, size_t payload_size, args_gpg[0 ] = gpg_program; fd =git_mkstemp (path,PATH_MAX ,".git_vtag_tmpXXXXXX" );if (fd <0 ) -return error (_ ("could not create temporary file '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("could not create temporary file '%s'" ), path);if (write_in_full (fd, signature, signature_size) <0 ) -return error (_ ("failed writing detached signature to '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("failed writing detached signature to '%s'" ), path);close (fd); gpg.argv = args_gpg;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 27/41 grep.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- grep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
grep.c +2 -2
@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error (_ ("'%s': %s" ), filename,strerror (errno)); +error_errno ("'%s'" , filename);return -1 ; }if (!S_ISREG (st.st_mode))
@@ -1743,7 +1743,7 @@ static int grep_source_load_file(struct grep_source *gs) goto err_ret; data =xmallocz (size);if (st.st_size !=read_in_full (i, data, size)) { -error (_ ("'%s': short read %s" ), filename,strerror (errno)); +error_errno (_ ("'%s': short read" ), filename);close (i);free (data);return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 28/41 http.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- http.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
http.c +4 -6
@@ -446,8 +446,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type) rc =setsockopt (fd,SOL_SOCKET ,SO_KEEPALIVE , (void *)&ka, len);if (rc <0 ) -warning ("unable to set SO_KEEPALIVE on socket %s" , -strerror (errno)); +warning_errno ("unable to set SO_KEEPALIVE on socket" );return 0 ;/* CURL_SOCKOPT_OK only exists since curl 7.21.5 */ }
@@ -1894,8 +1893,7 @@ struct http_object_request *new_http_object_request(const char *base_url, }if (freq->localfile <0 ) { -error ("Couldn't create temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't create temporary file %s" , freq->tmpfile); goto abort; }
@@ -1940,8 +1938,8 @@ struct http_object_request *new_http_object_request(const char *base_url, prev_posn =0 ;lseek (freq->localfile,0 ,SEEK_SET );if (ftruncate (freq->localfile,0 ) <0 ) { -error ("Couldn't truncate temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't truncate temporary file %s" , + freq->tmpfile); goto abort; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 29/41 ident.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- ident.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
ident.c +3 -5
@@ -75,14 +75,12 @@ static int add_mailname_host(struct strbuf *buf) mailname =fopen ("/etc/mailname" ,"r" );if (!mailname) {if (errno !=ENOENT ) -warning ("cannot open /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot open /etc/mailname" );return -1 ; }if (strbuf_getline (&mailnamebuf, mailname) ==EOF ) {if (ferror (mailname)) -warning ("cannot read /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot read /etc/mailname" );strbuf_release (&mailnamebuf);fclose (mailname);return -1 ;
@@ -125,7 +123,7 @@ static void add_domainname(struct strbuf *out, int *is_bogus)char buf[1024 ];if (gethostname (buf,sizeof (buf))) { -warning ("cannot get host name: %s" ,strerror (errno)); +warning_errno ("cannot get host name" );strbuf_addstr (out,"(none)" ); *is_bogus =1 ;return ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 30/41 mailmap.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- mailmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mailmap.c +1 -2
@@ -189,8 +189,7 @@ static int read_mailmap_file(struct string_list *map, const char *filename,if (!f) {if (errno ==ENOENT )return 0 ; -return error ("unable to open mailmap at %s: %s" , - filename,strerror (errno)); +return error_errno ("unable to open mailmap at %s" , filename); }while (fgets (buffer,sizeof (buffer), f) !=NULL )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 31/41 reachable.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- reachable.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
reachable.c +1 -2
@@ -119,8 +119,7 @@ static int add_recent_loose(const unsigned char *sha1,*/ if (errno ==ENOENT )return 0 ; -return error ("unable to stat %s: %s" , -sha1_to_hex (sha1),strerror (errno)); +return error_errno ("unable to stat %s" ,sha1_to_hex (sha1)); }add_recent_object (sha1, st.st_mtime, data);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 32/41 rerere.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- rerere.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
rerere.c +7 -11
@@ -501,8 +501,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *outputerror ("There were errors while writing %s (%s)" , path,strerror (io.io.wrerror));if (io.io.output &&fclose (io.io.output)) - io.io.wrerror =error ("Failed to flush %s: %s" , - path,strerror (errno)); + io.io.wrerror =error_errno ("Failed to flush %s" , path);if (hunk_no <0 ) {if (output)
@@ -684,20 +683,17 @@ static int merge(const struct rerere_id *id, const char *path)* Mark that "postimage" was used to help gc. */ if (utime (rerere_path (id,"postimage" ),NULL ) <0 ) -warning ("failed utime() on %s: %s" , -rerere_path (id,"postimage" ), -strerror (errno)); +warning_errno ("failed utime() on %s" , +rerere_path (id,"postimage" ));/* Update "path" with the resolution */ f =fopen (path,"w" );if (!f) -return error ("Could not open %s: %s" , path, -strerror (errno)); +return error_errno ("Could not open %s" , path);if (fwrite (result.ptr, result.size,1 , f) !=1 ) -error ("Could not write %s: %s" , path,strerror (errno)); +error_errno ("Could not write %s" , path);if (fclose (f)) -return error ("Writing %s failed: %s" , path, -strerror (errno)); +return error_errno ("Writing %s failed" , path); out:free (cur.ptr);
@@ -1071,7 +1067,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)if (unlink (filename))return (errno ==ENOENT ?error ("no remembered resolution for %s" , path) - :error ("cannot unlink %s: %s" , filename,strerror (errno))); + :error_errno ("cannot unlink %s" , filename));/* * Update the preimage so that the user can resolve the
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 33/41 run-command.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- run-command.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
run-command.c +7 -8
@@ -233,7 +233,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)if (waiting <0 ) { failed_errno = errno; -error ("waitpid for %s failed: %s" , argv0,strerror (errno)); +error_errno ("waitpid for %s failed" , argv0); }else if (waiting != pid) {error ("waitpid is confused (%s)" , argv0); }else if (WIFSIGNALED (status)) {
@@ -420,8 +420,7 @@ fail_pipe: } }if (cmd->pid <0 ) -error ("cannot fork() for %s: %s" , cmd->argv[0 ], -strerror (errno)); +error_errno ("cannot fork() for %s" , cmd->argv[0 ]);else if (cmd->clean_on_exit)mark_child_for_cleanup (cmd->pid);
@@ -482,7 +481,7 @@ fail_pipe: cmd->dir, fhin, fhout, fherr); failed_errno = errno;if (cmd->pid <0 && (!cmd->silent_exec_failure || errno !=ENOENT )) -error ("cannot spawn %s: %s" , cmd->argv[0 ],strerror (errno)); +error_errno ("cannot spawn %s" , cmd->argv[0 ]);if (cmd->clean_on_exit && cmd->pid >=0 )mark_child_for_cleanup (cmd->pid);
@@ -703,7 +702,7 @@ int start_async(struct async *async)if (pipe (fdin) <0 ) {if (async->out >0 )close (async->out); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->in = fdin[1 ]; }
@@ -715,7 +714,7 @@ int start_async(struct async *async)close_pair (fdin); else if (async->in) close(async->in); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->out = fdout[0 ]; }
@@ -740,7 +739,7 @@ int start_async(struct async *async) async->pid =fork ();if (async->pid <0 ) { -error ("fork (async) failed: %s" ,strerror (errno)); +error_errno ("fork (async) failed" ); goto error; }if (!async->pid) {
@@ -787,7 +786,7 @@ int start_async(struct async *async) {int err =pthread_create (&async->tid,NULL , run_thread, async);if (err) { -error ("cannot create thread: %s" ,strerror (err)); +error_errno ("cannot create thread" ); goto error; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 34/41 sequencer.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- sequencer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sequencer.c +1 -2
@@ -875,8 +875,7 @@ static int sequencer_rollback(struct replay_opts *opts)return rollback_single_pick (); }if (!f) -return error (_ ("cannot open %s: %s" ),git_path_head_file (), -strerror (errno)); +return error_errno (_ ("cannot open %s" ),git_path_head_file ());if (strbuf_getline_lf (&buf, f)) {error (_ ("cannot read %s: %s" ),git_path_head_file (),ferror (f) ?strerror (errno) :_ ("unexpected end of file" ));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 35/41 server-info.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- server-info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
server-info.c +1 -1
@@ -36,7 +36,7 @@ static int update_info_file(char *path, int (*generate)(FILE *)) out:if (ret) { -error ("unable to update %s: %s" , path,strerror (errno)); +error_errno ("unable to update %s" , path);if (fp)fclose (fp);else if (fd >=0 )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 36/41 sha1_file.c: use {error,die,warning}_errno()
In reply to Nguyễn Thái Ngọc Duy--- sha1_file.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
sha1_file.c +13 -19
@@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,PROT_READ ,MAP_PRIVATE , p->pack_fd, win->offset);if (win->base ==MAP_FAILED ) -die ("packfile %s cannot be mapped: %s" , - p->pack_name, -strerror (errno)); +die_errno ("packfile %s cannot be mapped" , + p->pack_name);if (!win->offset && win->len == p->pack_size && !p->do_not_close)close_pack_fd (p);
@@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local) dir =opendir (path.buf);if (!dir) {if (errno !=ENOENT ) -error ("unable to open object pack directory: %s: %s" , - path.buf,strerror (errno)); +error_errno ("unable to open object pack directory: %s" , + path.buf);strbuf_release (&path);return ; }
@@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)unlink_or_warn (tmpfile);if (ret) {if (ret !=EEXIST ) { -return error ("unable to write sha1 filename %s: %s" , filename,strerror (ret)); +return error_errno ("unable to write sha1 filename %s" , filename); }/* FIXME!!! Collision check here ? */ }
@@ -2998,7 +2997,7 @@ out:static int write_buffer (int fd,const void *buf,size_t len) {if (write_in_full (fd, buf, len) <0 ) -return error ("file write error (%s)" ,strerror (errno)); +return error_errno ("file write error" );return 0 ; }
@@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,if (errno ==EACCES )return error ("insufficient permission for adding an object to repository database %s" ,get_object_directory ());else -return error ("unable to create temporary file: %s" ,strerror (errno)); +return error_errno ("unable to create temporary file" ); }/* Set it up */
@@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, utb.actime = mtime; utb.modtime = mtime;if (utime (tmp_file.buf, &utb) <0 ) -warning ("failed utime() on %s: %s" , - tmp_file.buf,strerror (errno)); +warning_errno ("failed utime() on %s" , tmp_file.buf); }return finalize_object_file (tmp_file.buf, filename);
@@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,if (size ==read_in_full (fd, buf, size)) ret =index_mem (sha1, buf, size, type, path, flags);else - ret =error ("short read %s" ,strerror (errno)); + ret =error_errno ("short read" );free (buf); }else {void *buf =xmmap (NULL , size,PROT_READ ,MAP_PRIVATE , fd,0 );
@@ -3425,18 +3423,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsignedcase S_IFREG : fd =open (path,O_RDONLY );if (fd <0 ) -return error ("open(\"%s\"): %s" , path, -strerror (errno)); +return error_errno ("open(\"%s\")" , path);if (index_fd (sha1, fd, st,OBJ_BLOB , path, flags) <0 )return error ("%s: failed to insert into database" , path);break ;case S_IFLNK : -if (strbuf_readlink (&sb, path, st->st_size)) { -char *errstr =strerror (errno); -return error ("readlink(\"%s\"): %s" , path, - errstr); - } +if (strbuf_readlink (&sb, path, st->st_size)) +return error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_sha1_file (sb.buf, sb.len, blob_type, sha1);else if (write_sha1_file (sb.buf, sb.len, blob_type, sha1))
@@ -3492,7 +3486,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,if (!dir) {if (errno ==ENOENT )return 0 ; -return error ("unable to open %s: %s" , path->buf,strerror (errno)); +return error_errno ("unable to open %s" , path->buf); }while ((de =readdir (dir))) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 37/41 transport-helper.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- transport-helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
transport-helper.c +3 -3
@@ -1166,7 +1166,7 @@ static int udt_do_read(struct unidirectional_transfer *t) bytes =read (t->src, t->buf + t->bufuse,BUFFERSIZE - t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK && errno !=EAGAIN && errno !=EINTR ) { -error ("read(%s) failed: %s" , t->src_name,strerror (errno)); +error_errno ("read(%s) failed" , t->src_name);return -1 ; }else if (bytes ==0 ) { transfer_debug("%s EOF (with %i bytes in buffer)",
@@ -1193,7 +1193,7 @@ static int udt_do_write(struct unidirectional_transfer *t)transfer_debug ("%s is writable" , t->dest_name); bytes =xwrite (t->dest, t->buf, t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK ) { -error ("write(%s) failed: %s" , t->dest_name,strerror (errno)); +error_errno ("write(%s) failed" , t->dest_name);return -1 ; }else if (bytes >0 ) { t->bufuse -= bytes;
@@ -1306,7 +1306,7 @@ static int tloop_join(pid_t pid, const char *name) {int tret;if (waitpid (pid, &tret,0 ) <0 ) { -error ("%s process failed to wait: %s" , name,strerror (errno)); +error_errno ("%s process failed to wait" , name);return 1 ; }if (!WIFEXITED (tret) ||WEXITSTATUS (tret)) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 38/41 unpack-trees.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- unpack-trees.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
unpack-trees.c +2 -4
@@ -1499,8 +1499,7 @@ static int verify_absent_1(const struct cache_entry *ce, path =xmemdupz (ce->name, len);if (lstat (path, &st)) - ret =error ("cannot stat '%s': %s" , path, -strerror (errno)); + ret =error_errno ("cannot stat '%s'" , path);else ret =check_ok_to_remove (path, len,DT_UNKNOWN ,NULL , &st, error_type, o);
@@ -1508,8 +1507,7 @@ static int verify_absent_1(const struct cache_entry *ce,return ret; }else if (lstat (ce->name, &st)) {if (errno !=ENOENT ) -return error ("cannot stat '%s': %s" , ce->name, -strerror (errno)); +return error_errno ("cannot stat '%s'" , ce->name);return 0 ; }else { return check_ok_to_remove(ce->name, ce_namelen(ce),
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 39/41 upload-pack.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- upload-pack.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
upload-pack.c +1 -2
@@ -174,8 +174,7 @@ static void create_pack_file(void)if (ret <0 ) {if (errno !=EINTR ) { -error ("poll failed, resuming: %s" , -strerror (errno)); +error_errno ("poll failed, resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 40/41 vcs-svn: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- vcs-svn/line_buffer.c | 4 ++-- vcs-svn/sliding_window.c | 2 +- vcs-svn/svndiff.c | 4 ++-- vcs-svn/svndump.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
vcs-svn/line_buffer.c +2 -2
@@ -53,9 +53,9 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf) {long pos =ftell (buf->infile);if (pos <0 ) -return error ("ftell error: %s" ,strerror (errno)); +return error_errno ("ftell error" );if (fseek (buf->infile,0 ,SEEK_SET )) -return error ("seek error: %s" ,strerror (errno)); +return error_errno ("seek error" );return pos; }
vcs-svn/sliding_window.c +1 -1
@@ -12,7 +12,7 @@ static int input_error(struct line_buffer *file) {if (!buffer_ferror (file))return error ("delta preimage ends early" ); -return error ("cannot read delta preimage: %s" ,strerror (errno)); +return error_errno ("cannot read delta preimage" ); }static int skip_or_whine (struct line_buffer *file,off_t gap)
vcs-svn/svndiff.c +2 -2
@@ -64,13 +64,13 @@ static int write_strbuf(struct strbuf *sb, FILE *out) {if (fwrite (sb->buf,1 , sb->len, out) == sb->len)/* Success. */ return 0 ; -return error ("cannot write delta postimage: %s" ,strerror (errno)); +return error_errno ("cannot write delta postimage" ); }static int error_short_read (struct line_buffer *input) {if (buffer_ferror (input)) -return error ("error reading delta: %s" ,strerror (errno)); +return error_errno ("error reading delta" );return error ("invalid delta: unexpected end of file" ); }
vcs-svn/svndump.c +2 -2
@@ -501,7 +501,7 @@ static void init(int report_fd)int svndump_init (const char *filename) {if (buffer_init (&input, filename)) -return error ("cannot open %s: %s" , filename ? filename :"NULL" ,strerror (errno)); +return error_errno ("cannot open %s" , filename ? filename :"NULL" );init (REPORT_FILENO );return 0 ; }
@@ -509,7 +509,7 @@ int svndump_init(const char *filename)int svndump_init_fd (int in_fd,int back_fd) {if (buffer_fdinit (&input,xdup (in_fd))) -return error ("cannot open fd %d: %s" , in_fd,strerror (errno)); +return error_errno ("cannot open fd %d" , in_fd);init (xdup (back_fd));return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v2 41/41 wrapper.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- wrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
wrapper.c +2 -2
@@ -572,7 +572,7 @@ static int warn_if_unremovable(const char *op, const char *file, int rc)if (!rc || errno ==ENOENT )return 0 ; err = errno; -warning ("unable to %s %s: %s" , op, file,strerror (errno)); +warning_errno ("unable to %s %s" , op, file); errno = err;return rc; }
@@ -608,7 +608,7 @@ int remove_or_warn(unsigned int mode, const char *file)void warn_on_inaccessible (const char *path) { -warning (_ ("unable to access '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("unable to access '%s'" ), path); }static int access_error_is_ok (int err,unsigned flag)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
Quoted 10 lines · Nguyễn Thái Ngọc Duy
Changes are in
[01/41]
usage.c: move format processing out ofdie_errno()[02/41]usage.c: addwarning_errno()anderror_errno()
[12/41]builtin/update-index.c: prefer "err" to "errno" inprocess_lstat_error[17/41]compat/win32/syslog.c: usewarning_errno()
[27/41]grep.c: useerror_errno()12/41 is basically a revert with s/strerror(errno)/strerror(err)/. Interdiff from v1
The interdiff looks quite sensible. Thanks.
Quoted 120 lines
-- 8< --
builtin/update-index.c +4
-4@@ -251,11 +251,11 @@ static int remove_one_path(const char *path)* succeeds. * - permission error. That's never ok. */ -static int process_lstat_error (const char *path) +static int process_lstat_error (const char *path,int err) { -if (errno ==ENOENT || errno ==ENOTDIR ) +if (err ==ENOENT || err ==ENOTDIR )return remove_one_path (path); -return error_errno ("lstat(\"%s\")" , path); +return error ("lstat(\"%s\"): %s" , path,strerror (err)); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)@@ -382,7 +382,7 @@ static int process_path(const char *path)* what to do about the pathname! */ if (lstat (path, &st) <0 ) -return process_lstat_error (path); +return process_lstat_error (path, errno);if (S_ISDIR (st.st_mode))return process_directory (path, len, &st);compat/win32/syslog.c +1
-1@@ -28,7 +28,7 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning_errno ("vsnprintf failed:" ); +warning_errno ("vsnprintf failed" );return ; }grep.c +1
-1@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error_errno (_ ("'%s'" ), filename); +error_errno ("'%s'" , filename);return -1 ; }if (!S_ISREG (st.st_mode))usage.c +9
-8@@ -109,9 +109,8 @@ void NORETURN die(const char *err, ...)va_end (params); } -static const char *fmt_with_err (const char *fmt) +static const char *fmt_with_err (char *buf,int n,const char *fmt) { -static char fmt_with_err[1024 ];char str_error[256 ], *err;int i, j;@@ -129,12 +128,13 @@ static const char *fmt_with_err(const char *fmt) } } str_error[j] =0 ; -snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); -return fmt_with_err; +snprintf (buf, n,"%s: %s" , fmt, str_error); +return buf; } void NORETURN die_errno(const char *fmt, ...) { +char buf[1024 ];va_list params;if (die_is_recursing ()) {@@ -144,16 +144,17 @@ void NORETURN die_errno(const char *fmt, ...) }va_start (params, fmt); -die_routine (fmt_with_err (fmt), params); +die_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params); }int error_errno (const char *fmt, ...) { +char buf[1024 ];va_list params;va_start (params, fmt); -error_routine (fmt_with_err (fmt), params); +error_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params);return -1 ; }@@ -171,10 +172,11 @@ int error(const char *err, ...)void warning_errno (const char *warn, ...) { +char buf[1024 ];va_list params;va_start (params, warn); -warn_routine (fmt_with_err (warn), params); +warn_routine (fmt_with_err (buf,sizeof (buf), warn), params);va_end (params); } -- 8< --
Quoted 10 lines · Nguyễn Thái Ngọc Duy
Changes are in
[01/41]
usage.c: move format processing out ofdie_errno()[02/41]usage.c: addwarning_errno()anderror_errno()
[12/41]builtin/update-index.c: prefer "err" to "errno" inprocess_lstat_error[17/41]compat/win32/syslog.c: usewarning_errno()
[27/41]grep.c: useerror_errno()12/41 is basically a revert with s/strerror(errno)/strerror(err)/. Interdiff from v1
Thanks. The earlier parts that lay the foundation looked good, and most of the conversion of the callers were, too (I think there was only one whose validity I wasn't sure about, though).
Some of the changes that are more than a straight and faithful conversion, i.e. fixes to places that used to show an extra newline, used to lack errno in the output, etc., deserve to be mentioned in the log message of respective patches.
Thanks.
v3 cover Add and use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc DuyCode changes compared to v2 is below (one incorrect conversion reverted, two error message improvements). Other changes are text in these commits, not shown as diff in this mail:
[06/41] builtin/fetch.c: use error_errno()
[08/41] builtin/mailsplit.c: use error_errno()
[09/41] builtin/merge-file.c: use error_errno()
[11/41] builtin/rm.c: use warning_errno()
[14/41] builtin/worktree.c: use error_errno()
[27/41] grep.c: use error_errno()
I didn't mention string format changes (e.g. from "abc (error)" to "abc: error") in the commit messages though.
builtin/pack-objects.c +1 -1
@@ -2018,7 +2018,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, ret =pthread_create (&p[i].thread,NULL , threaded_find_deltas, &p[i]);if (ret) -die_errno ("unable to create thread" ); +die ("unable to create thread: %s" ,strerror (ret)); active_threads++; }
builtin/rm.c +1 -1
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR ) -warning_errno ("'%s'" , ce->name); +warning_errno (_ ("failed to stat '%s'" ), ce->name);/* It already vanished from the working tree */ continue ; }
grep.c +1 -1
@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error_errno ("'%s'" , filename); +error_errno (_ ("failed to stat '%s'" ), filename);return -1 ; }if (!S_ISREG (st.st_mode))
PATCH v3 1/41 usage.c: move format processing out of die_errno()
fmt_with_err() will be shared with the coming error_errno() and warning_errno().
--- usage.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
usage.c +16 -11
@@ -109,19 +109,11 @@ void NORETURN die(const char *err, ...)va_end (params); } -void NORETURN die_errno(const char *fmt, ...) +static const char *fmt_with_err (char *buf,int n,const char *fmt) { -va_list params; -char fmt_with_err[1024 ];char str_error[256 ], *err;int i, j; -if (die_is_recursing ()) { -fputs ("fatal: recursion detected in die_errno handler\n" , - stderr); -exit (128 ); - } - err =strerror (errno);for (i = j =0 ; err[i] && j <sizeof (str_error) -1 ; ) {if ((str_error[j++] = err[i++]) !='%' )
@@ -136,10 +128,23 @@ void NORETURN die_errno(const char *fmt, ...) } } str_error[j] =0 ; -snprintf (fmt_with_err,sizeof (fmt_with_err),"%s: %s" , fmt, str_error); +snprintf (buf, n,"%s: %s" , fmt, str_error); +return buf; +} + +void NORETURN die_errno(const char *fmt, ...) +{ +char buf[1024 ]; +va_list params; + +if (die_is_recursing ()) { +fputs ("fatal: recursion detected in die_errno handler\n" , + stderr); +exit (128 ); + }va_start (params, fmt); -die_routine (fmt_with_err, params); +die_routine (fmt_with_err (buf,sizeof (buf), fmt), params);va_end (params); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 2/41 usage.c: add warning_errno() and error_errno()
In reply to Nguyễn Thái Ngọc DuySimilar to die_errno(), these functions will append strerror() automatically.
--- git-compat-util.h | 2 ++ usage.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
git-compat-util.h +2 -0
@@ -409,7 +409,9 @@ extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern int error_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));extern void warning (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void warning_errno (const char *err, ...) __attribute__((format (printf,1 ,2 )));#ifndef NO_OPENSSL #ifdef APPLE_COMMON_CRYPTO
usage.c +21 -0
@@ -148,6 +148,17 @@ void NORETURN die_errno(const char *fmt, ...)va_end (params); } +int error_errno (const char *fmt, ...) +{ +char buf[1024 ]; +va_list params; + +va_start (params, fmt); +error_routine (fmt_with_err (buf,sizeof (buf), fmt), params); +va_end (params); +return -1 ; +} +#undef errorint error (const char *err, ...) {
@@ -159,6 +170,16 @@ int error(const char *err, ...)return -1 ; } +void warning_errno (const char *warn, ...) +{ +char buf[1024 ]; +va_list params; + +va_start (params, warn); +warn_routine (fmt_with_err (buf,sizeof (buf), warn), params); +va_end (params); +} +void warning (const char *warn, ...) {va_list params;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 3/41 bisect.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- bisect.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
bisect.c +3 -4
@@ -860,8 +860,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)/* Create file BISECT_ANCESTORS_OK. */ fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY ,0600 );if (fd <0 ) -warning ("could not create file '%s': %s" , - filename,strerror (errno)); +warning_errno ("could not create file '%s'" , + filename);else close (fd); done:
@@ -910,8 +910,7 @@ void read_bisect_terms(const char **read_bad, const char **read_good) *read_good ="good" ;return ; }else { -die ("could not read file '%s': %s" , filename, -strerror (errno)); +die_errno ("could not read file '%s'" , filename); } }else {strbuf_getline_lf (&str, fp);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 4/41 builtin/am.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
builtin/am.c +5 -6
@@ -769,15 +769,15 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state, in =fopen (*paths,"r" );if (!in) -return error (_ ("could not open '%s' for reading: %s" ), - *paths,strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), + *paths); mail =mkpath ("%s/%0*d" , state->dir, state->prec, i +1 ); out =fopen (mail,"w" );if (!out) -return error (_ ("could not open '%s' for writing: %s" ), - mail,strerror (errno)); +return error_errno (_ ("could not open '%s' for writing" ), + mail); ret =fn (out, in, keep_cr);
@@ -857,8 +857,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, fp =fopen (*paths,"r" );if (!fp) -return error (_ ("could not open '%s' for reading: %s" ), *paths, -strerror (errno)); +return error_errno (_ ("could not open '%s' for reading" ), *paths);while (!strbuf_getline_lf (&sb, fp)) {if (*sb.buf =='#' )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 5/41 builtin/branch.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/branch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/branch.c +1 -2
@@ -593,8 +593,7 @@ static int edit_branch_description(const char *branch_name) branch_name, comment_line_char);if (write_file_gently (git_path (edit_description),"%s" , buf.buf)) {strbuf_release (&buf); -return error (_ ("could not write branch description template: %s" ), -strerror (errno)); +return error_errno (_ ("could not write branch description template" )); }strbuf_reset (&buf);if (launch_editor (git_path (edit_description), &buf,NULL )) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 6/41 builtin/fetch.c: use error_errno()
In reply to Nguyễn Thái Ngọc DuyA couple of newlines are also removed, because both error() and error_errno() automatically append a newline.
--- builtin/fetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/fetch.c +2 -2
@@ -607,7 +607,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, fp =fopen (filename,"a" );if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);if (raw_url) url =transport_anonymize_url (raw_url);
@@ -848,7 +848,7 @@ static int truncate_fetch_head(void)FILE *fp =fopen_for_writing (filename);if (!fp) -return error (_ ("cannot open %s: %s\n" ), filename,strerror (errno)); +return error_errno (_ ("cannot open %s" ), filename);fclose (fp);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 7/41 builtin/help.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/help.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
builtin/help.c +4 -4
@@ -127,7 +127,7 @@ static void exec_woman_emacs(const char *path, const char *page) path ="emacsclient" ;strbuf_addf (&man_page,"(woman \"%s\")" , page);execlp (path,"emacsclient" ,"-e" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -148,7 +148,7 @@ static void exec_man_konqueror(const char *path, const char *page) path ="kfmclient" ;strbuf_addf (&man_page,"man:%s(1)" , page);execlp (path, filename,"newTab" , man_page.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); } }
@@ -157,7 +157,7 @@ static void exec_man_man(const char *path, const char *page)if (!path) path ="man" ;execlp (path,"man" , page, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("failed to exec '%s'" ), path); }static void exec_man_cmd (const char *cmd,const char *page)
@@ -165,7 +165,7 @@ static void exec_man_cmd(const char *cmd, const char *page)struct strbuf shell_cmd =STRBUF_INIT ;strbuf_addf (&shell_cmd,"%s %s" , cmd, page);execl (SHELL_PATH ,SHELL_PATH ,"-c" , shell_cmd.buf, (char *)NULL ); -warning (_ ("failed to exec '%s': %s" ), cmd,strerror (errno)); +warning (_ ("failed to exec '%s'" ), cmd); }static void add_man_viewer (const char *name)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 8/41 builtin/mailsplit.c: use error_errno()
In reply to Nguyễn Thái Ngọc DuyThere's one change, in split_mbox(), where an error() without strerror() as argument is converted to error_errno(). This is correct because the previous call is fopen (not shown in the context lines), which should set errno if it returns NULL.
--- builtin/mailsplit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/mailsplit.c +5 -5
@@ -109,7 +109,7 @@ static int populate_maildir_list(struct string_list *list, const char *path)if ((dir =opendir (name)) ==NULL ) {if (errno ==ENOENT )continue ; -error ("cannot opendir %s (%s)" , name,strerror (errno)); +error_errno ("cannot opendir %s" , name); goto out; }
@@ -174,12 +174,12 @@ static int split_maildir(const char *maildir, const char *dir, f =fopen (file,"r" );if (!f) { -error ("cannot open mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot open mail %s" , file); goto out; }if (strbuf_getwholeline (&buf, f,'\n' )) { -error ("cannot read mail %s (%s)" , file,strerror (errno)); +error_errno ("cannot read mail %s" , file); goto out; }
@@ -210,7 +210,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,int file_done =0 ;if (!f) { -error ("cannot open mbox %s" , file); +error_errno ("cannot open mbox %s" , file); goto out; }
@@ -318,7 +318,7 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix) }if (stat (arg, &argstat) ==-1 ) { -error ("cannot stat %s (%s)" , arg,strerror (errno)); +error_errno ("cannot stat %s" , arg);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 9/41 builtin/merge-file.c: use error_errno()
In reply to Nguyễn Thái Ngọc DuyAll these error() calls do not print error message previously, but because when they are called, errno should be set. Use error_errno() instead to give more information.
--- builtin/merge-file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/merge-file.c +5 -5
@@ -62,8 +62,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)usage_with_options (merge_file_usage, options);if (quiet) {if (!freopen ("/dev/null" ,"w" , stderr)) -return error ("failed to redirect stderr to /dev/null: " -"%s" ,strerror (errno)); +return error_errno ("failed to redirect stderr to /dev/null" ); }if (prefix)
@@ -95,12 +94,13 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)FILE *f = to_stdout ? stdout :fopen (fpath,"wb" );if (!f) - ret =error ("Could not open %s for writing" , filename); + ret =error_errno ("Could not open %s for writing" , + filename);else if (result.size &&fwrite (result.ptr, result.size,1 , f) !=1 ) - ret =error ("Could not write to %s" , filename); + ret =error_errno ("Could not write to %s" , filename);else if (fclose (f)) - ret =error ("Could not close %s" , filename); + ret =error_errno ("Could not close %s" , filename);free (result.ptr); }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 10/41 builtin/pack-objects.c: use die_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/pack-objects.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
builtin/pack-objects.c +2 -4
@@ -828,8 +828,7 @@ static void write_pack_file(void)* to preserve this property. */ if (stat (pack_tmp_name, &st) <0 ) { -warning ("failed to stat %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed to stat %s" , pack_tmp_name); }else if (!last_mtime) { last_mtime = st.st_mtime; }else {
@@ -837,8 +836,7 @@ static void write_pack_file(void) utb.actime = st.st_atime; utb.modtime = --last_mtime;if (utime (pack_tmp_name, &utb) <0 ) -warning ("failed utime() on %s: %s" , - pack_tmp_name,strerror (errno)); +warning_errno ("failed utime() on %s" , pack_tmp_name); }strbuf_addf (&tmpname,"%s-" , base_name);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 11/41 builtin/rm.c: use warning_errno()
In reply to Nguyễn Thái Ngọc DuyWhile at there, improve the message a bit (what operation failed?) and mark it for translation since the format string is now a sentence.
--- builtin/rm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rm.c +1 -1
@@ -152,7 +152,7 @@ static int check_local_mod(unsigned char *head, int index_only)if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR ) -warning ("'%s': %s" , ce->name,strerror (errno)); +warning_errno (_ ("failed to stat '%s'" ), ce->name);/* It already vanished from the working tree */ continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 12/41 builtin/update-index.c: prefer "err" to "errno" in process_lstat_error
In reply to Nguyễn Thái Ngọc Duy"errno" is already passed in as "err". Here we should use err instead of errno. errno is probably a copy/paste mistake in e011054 (Teach git-update-index about gitlinks - 2007-04-12)
--- builtin/update-index.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/update-index.c +1 -1
@@ -255,7 +255,7 @@ static int process_lstat_error(const char *path, int err) {if (err ==ENOENT || err ==ENOTDIR )return remove_one_path (path); -return error ("lstat(\"%s\"): %s" , path,strerror (errno)); +return error ("lstat(\"%s\"): %s" , path,strerror (err)); }static int add_one_path (const struct cache_entry *old,const char *path,int len,struct stat *st)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 13/41 builtin/upload-archive.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- builtin/upload-archive.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/upload-archive.c +1 -2
@@ -104,8 +104,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) pfd[1 ].events =POLLIN ;if (poll (pfd,2 ,-1 ) <0 ) {if (errno !=EINTR ) { -error ("poll failed resuming: %s" , -strerror (errno)); +error_errno ("poll failed resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 14/41 builtin/worktree.c: use error_errno()
In reply to Nguyễn Thái Ngọc DuyWhile at there, improve the error message to say _what_ failed to remove.
--- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/worktree.c +1 -1
@@ -110,7 +110,7 @@ static void prune_worktrees(void)if (ret <0 && errno ==ENOTDIR ) ret =unlink (path.buf);if (ret) -error (_ ("failed to remove: %s" ),strerror (errno)); +error_errno (_ ("failed to remove '%s'" ), path.buf); }closedir (dir);if (!show_only)
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 15/41 check-racy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- check-racy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
check-racy.c +1 -1
@@ -12,7 +12,7 @@ int main(int ac, char **av)struct stat st;if (lstat (ce->name, &st)) { -error ("lstat(%s): %s" , ce->name,strerror (errno)); +error_errno ("lstat(%s)" , ce->name);continue ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 16/41 combine-diff.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- combine-diff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
combine-diff.c +1 -2
@@ -1005,8 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,struct strbuf buf =STRBUF_INIT ;if (strbuf_readlink (&buf, elem->path, st.st_size) <0 ) { -error ("readlink(%s): %s" , elem->path, -strerror (errno)); +error_errno ("readlink(%s)" , elem->path);return ; } result_size = buf.len;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 17/41 compat/win32/syslog.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- compat/win32/syslog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
compat/win32/syslog.c +3 -3
@@ -28,13 +28,13 @@ void syslog(int priority, const char *fmt, ...)va_end (ap);if (str_len <0 ) { -warning ("vsnprintf failed: '%s'" ,strerror (errno)); +warning_errno ("vsnprintf failed" );return ; } str =malloc (st_add (str_len,1 ));if (!str) { -warning ("malloc failed: '%s'" ,strerror (errno)); +warning_errno ("malloc failed" );return ; }
@@ -45,7 +45,7 @@ void syslog(int priority, const char *fmt, ...)while ((pos =strstr (str,"%1" )) !=NULL ) { str =realloc (str,st_add (++str_len,1 ));if (!str) { -warning ("realloc failed: '%s'" ,strerror (errno)); +warning_errno ("realloc failed" );return ; }memmove (pos +2 , pos +1 ,strlen (pos));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 18/41 config.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- config.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
config.c +9 -13
@@ -2012,7 +2012,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, lock =xcalloc (1 ,sizeof (struct lock_file )); fd =hold_lock_file_for_update (lock, config_filename,0 );if (fd <0 ) { -error ("could not lock config file %s: %s" , config_filename,strerror (errno)); +error_errno ("could not lock config file %s" , config_filename);free (store.key); ret =CONFIG_NO_LOCK ; goto out_free;
@@ -2026,8 +2026,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,free (store.key);if (ENOENT != errno ) { -error ("opening %s: %s" , config_filename, -strerror (errno)); +error_errno ("opening %s" , config_filename); ret =CONFIG_INVALID_FILE ;/* same as "invalid config file" */ goto out_free; }
@@ -2111,8 +2110,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,if (contents ==MAP_FAILED ) {if (errno ==ENODEV &&S_ISDIR (st.st_mode)) errno =EISDIR ; -error ("unable to mmap '%s': %s" , - config_filename,strerror (errno)); +error_errno ("unable to mmap '%s'" , config_filename); ret =CONFIG_INVALID_FILE ; contents =NULL ; goto out_free;
@@ -2121,8 +2119,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, in_fd =-1 ;if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { -error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); +error_errno ("chmod on %s failed" ,get_lock_file_path (lock)); ret =CONFIG_NO_WRITE ; goto out_free; }
@@ -2178,8 +2175,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, }if (commit_lock_file (lock) <0 ) { -error ("could not write config file %s: %s" , config_filename, -strerror (errno)); +error_errno ("could not write config file %s" , config_filename); ret =CONFIG_NO_WRITE ; lock =NULL ; goto out_free;
@@ -2330,8 +2326,8 @@ int git_config_rename_section_in_file(const char *config_filename,fstat (fileno (config_file), &st);if (chmod (get_lock_file_path (lock), st.st_mode &07777 ) <0 ) { - ret =error ("chmod on %s failed: %s" , -get_lock_file_path (lock),strerror (errno)); + ret =error_errno ("chmod on %s failed" , +get_lock_file_path (lock)); goto out; }
@@ -2385,8 +2381,8 @@ int git_config_rename_section_in_file(const char *config_filename,fclose (config_file); unlock_and_out:if (commit_lock_file (lock) <0 ) - ret =error ("could not write config file %s: %s" , - config_filename,strerror (errno)); + ret =error_errno ("could not write config file %s" , + config_filename); out:free (filename_buf);return ret;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 19/41 connected.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- connected.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
connected.c +3 -6
@@ -86,17 +86,14 @@ static int check_everything_connected_real(sha1_iterate_fn fn,memcpy (commit,sha1_to_hex (sha1),40 );if (write_in_full (rev_list.in, commit,41 ) <0 ) {if (errno !=EPIPE && errno !=EINVAL ) -error (_ ("failed write to rev-list: %s" ), -strerror (errno)); +error_errno (_ ("failed write to rev-list" )); err =-1 ;break ; } }while (!fn (cb_data, sha1)); -if (close (rev_list.in)) { -error (_ ("failed to close rev-list's stdin: %s" ),strerror (errno)); - err =-1 ; - } +if (close (rev_list.in)) + err =error_errno (_ ("failed to close rev-list's stdin" ));sigchain_pop (SIGPIPE );return finish_command (&rev_list) || err;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 20/41 copy.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- copy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
copy.c +3 -3
@@ -42,15 +42,15 @@ int copy_file(const char *dst, const char *src, int mode) status =copy_fd (fdi, fdo);switch (status) {case COPY_READ_ERROR : -error ("copy-fd: read returned %s" ,strerror (errno)); +error_errno ("copy-fd: read returned" );break ;case COPY_WRITE_ERROR : -error ("copy-fd: write returned %s" ,strerror (errno)); +error_errno ("copy-fd: write returned" );break ; }close (fdi);if (close (fdo) !=0 ) -return error ("%s: close error: %s" , dst,strerror (errno)); +return error_errno ("%s: close error" , dst);if (!status &&adjust_shared_perm (dst))return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 21/41 credential-cache--daemon.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- credential-cache--daemon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
credential-cache--daemon.c +2 -2
@@ -179,12 +179,12 @@ static int serve_cache_loop(int fd) client =accept (fd,NULL ,NULL );if (client <0 ) { -warning ("accept failed: %s" ,strerror (errno)); +warning_errno ("accept failed" );return 1 ; } client2 =dup (client);if (client2 <0 ) { -warning ("dup failed: %s" ,strerror (errno)); +warning_errno ("dup failed" );close (client);return 1 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 22/41 diff-no-index.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- diff-no-index.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff-no-index.c +1 -2
@@ -65,8 +65,7 @@ static int populate_from_stdin(struct diff_filespec *s)size_t size =0 ;if (strbuf_read (&buf,0 ,0 ) <0 ) -return error ("error while reading from stdin %s" , -strerror (errno)); +return error_errno ("error while reading from stdin" ); s->should_munmap =0 ; s->data =strbuf_detach (&buf, &size);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 23/41 editor.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- editor.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
editor.c +1 -2
@@ -63,7 +63,6 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *enif (!buffer)return 0 ;if (strbuf_read_file (buffer, path,0 ) <0 ) -return error ("could not read file '%s': %s" , - path,strerror (errno)); +return error_errno ("could not read file '%s'" , path);return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 24/41 entry.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- entry.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
entry.c +4 -6
@@ -168,8 +168,8 @@ static int write_entry(struct cache_entry *ce, ret =symlink (new, path);free (new);if (ret) -return error ("unable to create symlink %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create symlink %s" , + path);break ; }
@@ -186,8 +186,7 @@ static int write_entry(struct cache_entry *ce, fd =open_output_fd (path, ce, to_tempfile);if (fd <0 ) {free (new); -return error ("unable to create file %s (%s)" , - path,strerror (errno)); +return error_errno ("unable to create file %s" , path); } wrote =write_in_full (fd, new, size);
@@ -284,8 +283,7 @@ int checkout_entry(struct cache_entry *ce,return error ("%s is a directory" , path.buf);remove_subtree (&path); }else if (unlink (path.buf)) -return error ("unable to unlink old '%s' (%s)" , - path.buf,strerror (errno)); +return error_errno ("unable to unlink old '%s'" , path.buf); }else if (state->not_new)return 0 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 25/41 fast-import.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- fast-import.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fast-import.c +5 -5
@@ -414,7 +414,7 @@ static void write_crash_report(const char *err)struct recent_command *rc;if (!rpt) { -error ("can't write crash report %s: %s" , loc,strerror (errno)); +error_errno ("can't write crash report %s" , loc);free (loc);return ; }
@@ -1806,8 +1806,8 @@ static void dump_marks(void)return ;if (hold_lock_file_for_update (&mark_lock, export_marks_file,0 ) <0 ) { - failure |=error ("Unable to write marks file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write marks file %s" , + export_marks_file);return ; }
@@ -1822,8 +1822,8 @@ static void dump_marks(void)dump_marks_helper (f,0 , marks);if (commit_lock_file (&mark_lock)) { - failure |=error ("Unable to write file %s: %s" , - export_marks_file,strerror (errno)); + failure |=error_errno ("Unable to write file %s" , + export_marks_file);return ; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 26/41 gpg-interface.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- gpg-interface.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
gpg-interface.c +2 -4
@@ -219,11 +219,9 @@ int verify_signed_buffer(const char *payload, size_t payload_size, args_gpg[0 ] = gpg_program; fd =git_mkstemp (path,PATH_MAX ,".git_vtag_tmpXXXXXX" );if (fd <0 ) -return error (_ ("could not create temporary file '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("could not create temporary file '%s'" ), path);if (write_in_full (fd, signature, signature_size) <0 ) -return error (_ ("failed writing detached signature to '%s': %s" ), - path,strerror (errno)); +return error_errno (_ ("failed writing detached signature to '%s'" ), path);close (fd); gpg.argv = args_gpg;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 27/41 grep.c: use error_errno()
In reply to Nguyễn Thái Ngọc DuyWhile at there, improve the error message a bit (what operation failed?)
--- grep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
grep.c +2 -2
@@ -1732,7 +1732,7 @@ static int grep_source_load_file(struct grep_source *gs)if (lstat (filename, &st) <0 ) { err_ret:if (errno !=ENOENT ) -error (_ ("'%s': %s" ), filename,strerror (errno)); +error_errno (_ ("failed to stat '%s'" ), filename);return -1 ; }if (!S_ISREG (st.st_mode))
@@ -1743,7 +1743,7 @@ static int grep_source_load_file(struct grep_source *gs) goto err_ret; data =xmallocz (size);if (st.st_size !=read_in_full (i, data, size)) { -error (_ ("'%s': short read %s" ), filename,strerror (errno)); +error_errno (_ ("'%s': short read" ), filename);close (i);free (data);return -1 ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 28/41 http.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- http.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
http.c +4 -6
@@ -446,8 +446,7 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type) rc =setsockopt (fd,SOL_SOCKET ,SO_KEEPALIVE , (void *)&ka, len);if (rc <0 ) -warning ("unable to set SO_KEEPALIVE on socket %s" , -strerror (errno)); +warning_errno ("unable to set SO_KEEPALIVE on socket" );return 0 ;/* CURL_SOCKOPT_OK only exists since curl 7.21.5 */ }
@@ -1894,8 +1893,7 @@ struct http_object_request *new_http_object_request(const char *base_url, }if (freq->localfile <0 ) { -error ("Couldn't create temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't create temporary file %s" , freq->tmpfile); goto abort; }
@@ -1940,8 +1938,8 @@ struct http_object_request *new_http_object_request(const char *base_url, prev_posn =0 ;lseek (freq->localfile,0 ,SEEK_SET );if (ftruncate (freq->localfile,0 ) <0 ) { -error ("Couldn't truncate temporary file %s: %s" , - freq->tmpfile,strerror (errno)); +error_errno ("Couldn't truncate temporary file %s" , + freq->tmpfile); goto abort; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 29/41 ident.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- ident.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
ident.c +3 -5
@@ -75,14 +75,12 @@ static int add_mailname_host(struct strbuf *buf) mailname =fopen ("/etc/mailname" ,"r" );if (!mailname) {if (errno !=ENOENT ) -warning ("cannot open /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot open /etc/mailname" );return -1 ; }if (strbuf_getline (&mailnamebuf, mailname) ==EOF ) {if (ferror (mailname)) -warning ("cannot read /etc/mailname: %s" , -strerror (errno)); +warning_errno ("cannot read /etc/mailname" );strbuf_release (&mailnamebuf);fclose (mailname);return -1 ;
@@ -125,7 +123,7 @@ static void add_domainname(struct strbuf *out, int *is_bogus)char buf[1024 ];if (gethostname (buf,sizeof (buf))) { -warning ("cannot get host name: %s" ,strerror (errno)); +warning_errno ("cannot get host name" );strbuf_addstr (out,"(none)" ); *is_bogus =1 ;return ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 30/41 mailmap.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- mailmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mailmap.c +1 -2
@@ -189,8 +189,7 @@ static int read_mailmap_file(struct string_list *map, const char *filename,if (!f) {if (errno ==ENOENT )return 0 ; -return error ("unable to open mailmap at %s: %s" , - filename,strerror (errno)); +return error_errno ("unable to open mailmap at %s" , filename); }while (fgets (buffer,sizeof (buffer), f) !=NULL )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 31/41 reachable.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- reachable.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
reachable.c +1 -2
@@ -119,8 +119,7 @@ static int add_recent_loose(const unsigned char *sha1,*/ if (errno ==ENOENT )return 0 ; -return error ("unable to stat %s: %s" , -sha1_to_hex (sha1),strerror (errno)); +return error_errno ("unable to stat %s" ,sha1_to_hex (sha1)); }add_recent_object (sha1, st.st_mtime, data);
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 32/41 rerere.c: use error_errno() and warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- rerere.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
rerere.c +7 -11
@@ -501,8 +501,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *outputerror ("There were errors while writing %s (%s)" , path,strerror (io.io.wrerror));if (io.io.output &&fclose (io.io.output)) - io.io.wrerror =error ("Failed to flush %s: %s" , - path,strerror (errno)); + io.io.wrerror =error_errno ("Failed to flush %s" , path);if (hunk_no <0 ) {if (output)
@@ -684,20 +683,17 @@ static int merge(const struct rerere_id *id, const char *path)* Mark that "postimage" was used to help gc. */ if (utime (rerere_path (id,"postimage" ),NULL ) <0 ) -warning ("failed utime() on %s: %s" , -rerere_path (id,"postimage" ), -strerror (errno)); +warning_errno ("failed utime() on %s" , +rerere_path (id,"postimage" ));/* Update "path" with the resolution */ f =fopen (path,"w" );if (!f) -return error ("Could not open %s: %s" , path, -strerror (errno)); +return error_errno ("Could not open %s" , path);if (fwrite (result.ptr, result.size,1 , f) !=1 ) -error ("Could not write %s: %s" , path,strerror (errno)); +error_errno ("Could not write %s" , path);if (fclose (f)) -return error ("Writing %s failed: %s" , path, -strerror (errno)); +return error_errno ("Writing %s failed" , path); out:free (cur.ptr);
@@ -1071,7 +1067,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)if (unlink (filename))return (errno ==ENOENT ?error ("no remembered resolution for %s" , path) - :error ("cannot unlink %s: %s" , filename,strerror (errno))); + :error_errno ("cannot unlink %s" , filename));/* * Update the preimage so that the user can resolve the
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 33/41 run-command.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- run-command.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
run-command.c +7 -8
@@ -233,7 +233,7 @@ static int wait_or_whine(pid_t pid, const char *argv0, int in_signal)if (waiting <0 ) { failed_errno = errno; -error ("waitpid for %s failed: %s" , argv0,strerror (errno)); +error_errno ("waitpid for %s failed" , argv0); }else if (waiting != pid) {error ("waitpid is confused (%s)" , argv0); }else if (WIFSIGNALED (status)) {
@@ -420,8 +420,7 @@ fail_pipe: } }if (cmd->pid <0 ) -error ("cannot fork() for %s: %s" , cmd->argv[0 ], -strerror (errno)); +error_errno ("cannot fork() for %s" , cmd->argv[0 ]);else if (cmd->clean_on_exit)mark_child_for_cleanup (cmd->pid);
@@ -482,7 +481,7 @@ fail_pipe: cmd->dir, fhin, fhout, fherr); failed_errno = errno;if (cmd->pid <0 && (!cmd->silent_exec_failure || errno !=ENOENT )) -error ("cannot spawn %s: %s" , cmd->argv[0 ],strerror (errno)); +error_errno ("cannot spawn %s" , cmd->argv[0 ]);if (cmd->clean_on_exit && cmd->pid >=0 )mark_child_for_cleanup (cmd->pid);
@@ -703,7 +702,7 @@ int start_async(struct async *async)if (pipe (fdin) <0 ) {if (async->out >0 )close (async->out); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->in = fdin[1 ]; }
@@ -715,7 +714,7 @@ int start_async(struct async *async)close_pair (fdin); else if (async->in) close(async->in); -return error ("cannot create pipe: %s" ,strerror (errno)); +return error_errno ("cannot create pipe" ); } async->out = fdout[0 ]; }
@@ -740,7 +739,7 @@ int start_async(struct async *async) async->pid =fork ();if (async->pid <0 ) { -error ("fork (async) failed: %s" ,strerror (errno)); +error_errno ("fork (async) failed" ); goto error; }if (!async->pid) {
@@ -787,7 +786,7 @@ int start_async(struct async *async) {int err =pthread_create (&async->tid,NULL , run_thread, async);if (err) { -error ("cannot create thread: %s" ,strerror (err)); +error_errno ("cannot create thread" ); goto error; } }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 34/41 sequencer.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- sequencer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
sequencer.c +1 -2
@@ -875,8 +875,7 @@ static int sequencer_rollback(struct replay_opts *opts)return rollback_single_pick (); }if (!f) -return error (_ ("cannot open %s: %s" ),git_path_head_file (), -strerror (errno)); +return error_errno (_ ("cannot open %s" ),git_path_head_file ());if (strbuf_getline_lf (&buf, f)) {error (_ ("cannot read %s: %s" ),git_path_head_file (),ferror (f) ?strerror (errno) :_ ("unexpected end of file" ));
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 35/41 server-info.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- server-info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
server-info.c +1 -1
@@ -36,7 +36,7 @@ static int update_info_file(char *path, int (*generate)(FILE *)) out:if (ret) { -error ("unable to update %s: %s" , path,strerror (errno)); +error_errno ("unable to update %s" , path);if (fp)fclose (fp);else if (fd >=0 )
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 36/41 sha1_file.c: use {error,die,warning}_errno()
In reply to Nguyễn Thái Ngọc Duy--- sha1_file.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-)
sha1_file.c +13 -19
@@ -1107,9 +1107,8 @@ unsigned char *use_pack(struct packed_git *p,PROT_READ ,MAP_PRIVATE , p->pack_fd, win->offset);if (win->base ==MAP_FAILED ) -die ("packfile %s cannot be mapped: %s" , - p->pack_name, -strerror (errno)); +die_errno ("packfile %s cannot be mapped" , + p->pack_name);if (!win->offset && win->len == p->pack_size && !p->do_not_close)close_pack_fd (p);
@@ -1279,8 +1278,8 @@ static void prepare_packed_git_one(char *objdir, int local) dir =opendir (path.buf);if (!dir) {if (errno !=ENOENT ) -error ("unable to open object pack directory: %s: %s" , - path.buf,strerror (errno)); +error_errno ("unable to open object pack directory: %s" , + path.buf);strbuf_release (&path);return ; }
@@ -2984,7 +2983,7 @@ int finalize_object_file(const char *tmpfile, const char *filename)unlink_or_warn (tmpfile);if (ret) {if (ret !=EEXIST ) { -return error ("unable to write sha1 filename %s: %s" , filename,strerror (ret)); +return error_errno ("unable to write sha1 filename %s" , filename); }/* FIXME!!! Collision check here ? */ }
@@ -2998,7 +2997,7 @@ out:static int write_buffer (int fd,const void *buf,size_t len) {if (write_in_full (fd, buf, len) <0 ) -return error ("file write error (%s)" ,strerror (errno)); +return error_errno ("file write error" );return 0 ; }
@@ -3081,7 +3080,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,if (errno ==EACCES )return error ("insufficient permission for adding an object to repository database %s" ,get_object_directory ());else -return error ("unable to create temporary file: %s" ,strerror (errno)); +return error_errno ("unable to create temporary file" ); }/* Set it up */
@@ -3126,8 +3125,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen, utb.actime = mtime; utb.modtime = mtime;if (utime (tmp_file.buf, &utb) <0 ) -warning ("failed utime() on %s: %s" , - tmp_file.buf,strerror (errno)); +warning_errno ("failed utime() on %s" , tmp_file.buf); }return finalize_object_file (tmp_file.buf, filename);
@@ -3360,7 +3358,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,if (size ==read_in_full (fd, buf, size)) ret =index_mem (sha1, buf, size, type, path, flags);else - ret =error ("short read %s" ,strerror (errno)); + ret =error_errno ("short read" );free (buf); }else {void *buf =xmmap (NULL , size,PROT_READ ,MAP_PRIVATE , fd,0 );
@@ -3425,18 +3423,14 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, unsignedcase S_IFREG : fd =open (path,O_RDONLY );if (fd <0 ) -return error ("open(\"%s\"): %s" , path, -strerror (errno)); +return error_errno ("open(\"%s\")" , path);if (index_fd (sha1, fd, st,OBJ_BLOB , path, flags) <0 )return error ("%s: failed to insert into database" , path);break ;case S_IFLNK : -if (strbuf_readlink (&sb, path, st->st_size)) { -char *errstr =strerror (errno); -return error ("readlink(\"%s\"): %s" , path, - errstr); - } +if (strbuf_readlink (&sb, path, st->st_size)) +return error_errno ("readlink(\"%s\")" , path);if (!(flags &HASH_WRITE_OBJECT ))hash_sha1_file (sb.buf, sb.len, blob_type, sha1);else if (write_sha1_file (sb.buf, sb.len, blob_type, sha1))
@@ -3492,7 +3486,7 @@ static int for_each_file_in_obj_subdir(int subdir_nr,if (!dir) {if (errno ==ENOENT )return 0 ; -return error ("unable to open %s: %s" , path->buf,strerror (errno)); +return error_errno ("unable to open %s" , path->buf); }while ((de =readdir (dir))) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 37/41 transport-helper.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- transport-helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
transport-helper.c +3 -3
@@ -1166,7 +1166,7 @@ static int udt_do_read(struct unidirectional_transfer *t) bytes =read (t->src, t->buf + t->bufuse,BUFFERSIZE - t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK && errno !=EAGAIN && errno !=EINTR ) { -error ("read(%s) failed: %s" , t->src_name,strerror (errno)); +error_errno ("read(%s) failed" , t->src_name);return -1 ; }else if (bytes ==0 ) { transfer_debug("%s EOF (with %i bytes in buffer)",
@@ -1193,7 +1193,7 @@ static int udt_do_write(struct unidirectional_transfer *t)transfer_debug ("%s is writable" , t->dest_name); bytes =xwrite (t->dest, t->buf, t->bufuse);if (bytes <0 && errno !=EWOULDBLOCK ) { -error ("write(%s) failed: %s" , t->dest_name,strerror (errno)); +error_errno ("write(%s) failed" , t->dest_name);return -1 ; }else if (bytes >0 ) { t->bufuse -= bytes;
@@ -1306,7 +1306,7 @@ static int tloop_join(pid_t pid, const char *name) {int tret;if (waitpid (pid, &tret,0 ) <0 ) { -error ("%s process failed to wait: %s" , name,strerror (errno)); +error_errno ("%s process failed to wait" , name);return 1 ; }if (!WIFEXITED (tret) ||WEXITSTATUS (tret)) {
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 38/41 unpack-trees.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- unpack-trees.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
unpack-trees.c +2 -4
@@ -1499,8 +1499,7 @@ static int verify_absent_1(const struct cache_entry *ce, path =xmemdupz (ce->name, len);if (lstat (path, &st)) - ret =error ("cannot stat '%s': %s" , path, -strerror (errno)); + ret =error_errno ("cannot stat '%s'" , path);else ret =check_ok_to_remove (path, len,DT_UNKNOWN ,NULL , &st, error_type, o);
@@ -1508,8 +1507,7 @@ static int verify_absent_1(const struct cache_entry *ce,return ret; }else if (lstat (ce->name, &st)) {if (errno !=ENOENT ) -return error ("cannot stat '%s': %s" , ce->name, -strerror (errno)); +return error_errno ("cannot stat '%s'" , ce->name);return 0 ; }else { return check_ok_to_remove(ce->name, ce_namelen(ce),
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 39/41 upload-pack.c: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- upload-pack.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
upload-pack.c +1 -2
@@ -174,8 +174,7 @@ static void create_pack_file(void)if (ret <0 ) {if (errno !=EINTR ) { -error ("poll failed, resuming: %s" , -strerror (errno)); +error_errno ("poll failed, resuming" );sleep (1 ); }continue ;
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 40/41 vcs-svn: use error_errno()
In reply to Nguyễn Thái Ngọc Duy--- vcs-svn/line_buffer.c | 4 ++-- vcs-svn/sliding_window.c | 2 +- vcs-svn/svndiff.c | 4 ++-- vcs-svn/svndump.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-)
vcs-svn/line_buffer.c +2 -2
@@ -53,9 +53,9 @@ long buffer_tmpfile_prepare_to_read(struct line_buffer *buf) {long pos =ftell (buf->infile);if (pos <0 ) -return error ("ftell error: %s" ,strerror (errno)); +return error_errno ("ftell error" );if (fseek (buf->infile,0 ,SEEK_SET )) -return error ("seek error: %s" ,strerror (errno)); +return error_errno ("seek error" );return pos; }
vcs-svn/sliding_window.c +1 -1
@@ -12,7 +12,7 @@ static int input_error(struct line_buffer *file) {if (!buffer_ferror (file))return error ("delta preimage ends early" ); -return error ("cannot read delta preimage: %s" ,strerror (errno)); +return error_errno ("cannot read delta preimage" ); }static int skip_or_whine (struct line_buffer *file,off_t gap)
vcs-svn/svndiff.c +2 -2
@@ -64,13 +64,13 @@ static int write_strbuf(struct strbuf *sb, FILE *out) {if (fwrite (sb->buf,1 , sb->len, out) == sb->len)/* Success. */ return 0 ; -return error ("cannot write delta postimage: %s" ,strerror (errno)); +return error_errno ("cannot write delta postimage" ); }static int error_short_read (struct line_buffer *input) {if (buffer_ferror (input)) -return error ("error reading delta: %s" ,strerror (errno)); +return error_errno ("error reading delta" );return error ("invalid delta: unexpected end of file" ); }
vcs-svn/svndump.c +2 -2
@@ -501,7 +501,7 @@ static void init(int report_fd)int svndump_init (const char *filename) {if (buffer_init (&input, filename)) -return error ("cannot open %s: %s" , filename ? filename :"NULL" ,strerror (errno)); +return error_errno ("cannot open %s" , filename ? filename :"NULL" );init (REPORT_FILENO );return 0 ; }
@@ -509,7 +509,7 @@ int svndump_init(const char *filename)int svndump_init_fd (int in_fd,int back_fd) {if (buffer_fdinit (&input,xdup (in_fd))) -return error ("cannot open fd %d: %s" , in_fd,strerror (errno)); +return error_errno ("cannot open fd %d" , in_fd);init (xdup (back_fd));return 0 ; }
Signature · 1 line
2.8.0.rc0.210.gd302cd2
PATCH v3 41/41 wrapper.c: use warning_errno()
In reply to Nguyễn Thái Ngọc Duy--- wrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
wrapper.c +2 -2
@@ -572,7 +572,7 @@ static int warn_if_unremovable(const char *op, const char *file, int rc)if (!rc || errno ==ENOENT )return 0 ; err = errno; -warning ("unable to %s %s: %s" , op, file,strerror (errno)); +warning_errno ("unable to %s %s" , op, file); errno = err;return rc; }
@@ -608,7 +608,7 @@ int remove_or_warn(unsigned int mode, const char *file)void warn_on_inaccessible (const char *path) { -warning (_ ("unable to access '%s': %s" ), path,strerror (errno)); +warning_errno (_ ("unable to access '%s'" ), path); }static int access_error_is_ok (int err,unsigned flag)
Signature · 1 line
2.8.0.rc0.210.gd302cd2