git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Thomas Rast <trast@student.ethz.ch>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] add strerror(errno) to die() calls where applicable
Date: Tue, 2 Jun 2009 21:55:03 -0400	[thread overview]
Message-ID: <20090603015503.GA14166@coredump.intra.peff.net> (raw)
In-Reply-To: <8df45fb3586160fa5c47af39d2a7eb2b8d405a3c.1243978065.git.trast@student.ethz.ch>

On Tue, Jun 02, 2009 at 11:34:33PM +0200, Thomas Rast wrote:

> Lots of die() calls did not actually report the kind of error, which
> can leave the user confused as to the real problem.  Add a
> strerror(errno) where the die() is immediately preceded by a
> system/library call that sets errno on failure, or by one of the
> following that wrap such calls:

I like this, as I remember being frustrated in the past by "cannot $foo"
messages with no indication of the cause of the error. My only questions
or concerns with such a patch would be:

  1. How did you determine the set of callsites? Did you check that each
     non-syscall function always sets errno? Are there are functions
     which are setting errno which could also be included?

  2. Extra error conditions may leak information about the filesystem to
     people feeding bogus paths to upload-pack. I didn't see anything
     obvious in your patch that would cause this, but it is something to
     consider.

  3. This is such a common thing to do, I wonder if we would be better
     off adding a "diesys" function that appends ": strerror(errno)"
     to the emitted error. Something like the (totally untested) patch
     below.

And a few comments on the patch itself:

> @@ -109,7 +113,8 @@ int is_directory(const char *path)
>  	} else {
>  		const char *cwd = get_pwd_cwd();
>  		if (!cwd)
> -			die("Cannot determine the current working directory");
> +			die("Cannot determine the current working directory",
> +			    strerror(errno));

Missing ": %s" here?

> -		die("closing file %s: %s", path, strerror(errno));
> +		die("closing file '%s': %s", path, strerror(errno));

This one is actually just a style change, though I think it is
worthwhile (and there are a few others like it).


The diesys patch is below.

---
diff --git a/git-compat-util.h b/git-compat-util.h
index 4236647..410ac87 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -155,6 +155,7 @@
 /* General helper functions */
 extern void usage(const char *err) NORETURN;
 extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
+extern void diesys(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
 extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
 extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
 
diff --git a/usage.c b/usage.c
index 820d09f..da5e58e 100644
--- a/usage.c
+++ b/usage.c
@@ -12,6 +12,14 @@ static void report(const char *prefix, const char *err, va_list params)
 	fprintf(stderr, "%s%s\n", prefix, msg);
 }
 
+static void report_sys(int err, const char *prefix, const char *fmt, va_list
+		params)
+{
+	char msg[1024];
+	vsnprintf(msg, sizeof(msg), fmt, params);
+	fprintf(stderr, "%s%s: %s\n", prefix, msg, hstrerror(err));
+}
+
 static NORETURN void usage_builtin(const char *err)
 {
 	fprintf(stderr, "usage: %s\n", err);
@@ -24,6 +32,12 @@ static NORETURN void die_builtin(const char *err, va_list params)
 	exit(128);
 }
 
+static NORETURN void diesys_builtin(int err, const char *fmt, va_list params)
+{
+	report_sys(err, "fatal: ", fmt, params);
+	exit(128);
+}
+
 static void error_builtin(const char *err, va_list params)
 {
 	report("error: ", err, params);
@@ -38,6 +52,7 @@ static void warn_builtin(const char *warn, va_list params)
  * (ugh), so keep things static. */
 static void (*usage_routine)(const char *err) NORETURN = usage_builtin;
 static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
+static void (*diesys_routine)(int err, const char *fmt, va_list params) NORETURN = diesys_builtin;
 static void (*error_routine)(const char *err, va_list params) = error_builtin;
 static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
 
@@ -60,6 +75,16 @@ void die(const char *err, ...)
 	va_end(params);
 }
 
+void diesys(const char *fmt, ...)
+{
+	va_list params;
+	int err = errno;
+
+	va_start(params, fmt);
+	diesys_routine(err, fmt, params);
+	va_end(params);
+}
+
 int error(const char *err, ...)
 {
 	va_list params;

  reply	other threads:[~2009-06-03  1:55 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 21:34 [PATCH] add strerror(errno) to die() calls where applicable Thomas Rast
2009-06-03  1:55 ` Jeff King [this message]
     [not found]   ` <2325a7950906031855t1977448lbb1c8aa671c72f3d@mail.gmail.com>
2009-06-04  1:58     ` Alexander Potashev
2009-06-04 20:32       ` Jeff King
2009-06-04  2:05   ` [PATCH] diesys calls die and also reports strerror(errno) Alexander Potashev
2009-06-04 20:50     ` Jeff King
2009-06-04 21:13       ` Junio C Hamano
2009-06-05  6:25       ` Johannes Sixt
2009-06-05  7:12         ` Junio C Hamano
2009-06-06 22:09           ` Jeff King
2009-06-06 13:09   ` [PATCH] add strerror(errno) to die() calls where applicable Thomas Rast
2009-06-06 14:44     ` [PATCH v2 0/3] Thomas Rast <trast@student.ethz.ch> Thomas Rast
2009-06-08 21:02       ` [PATCH v3 0/3] die_errno() Thomas Rast
2009-06-27 15:58         ` [PATCH v4 0/4] die_errno() Thomas Rast
2009-06-27 15:58           ` [PATCH v4 1/4] Introduce die_errno() that appends strerror(errno) to die() Thomas Rast
2009-06-27 15:58           ` [PATCH v4 2/4] die_errno(): double % in strerror() output just in case Thomas Rast
2009-06-27 15:58           ` [PATCH v4 3/4] Convert existing die(..., strerror(errno)) to die_errno() Thomas Rast
2009-06-27 15:58           ` [PATCH v4 4/4] Use die_errno() instead of die() when checking syscalls Thomas Rast
2009-06-27 18:38           ` [PATCH v4 0/4] die_errno() Junio C Hamano
2009-06-08 21:02       ` [PATCH v3 1/3] Introduce die_errno() that appends strerror(errno) to die() Thomas Rast
2009-06-08 22:07         ` Jeff King
2009-06-09  8:22           ` Thomas Rast
2009-06-09  8:53             ` Jeff King
2009-06-09  9:29               ` Andreas Ericsson
2009-06-08 21:02       ` [PATCH v3 2/3] Convert existing die(..., strerror(errno)) to die_errno() Thomas Rast
2009-06-08 21:02       ` [PATCH v3 3/3] Use die_errno() instead of die() when checking syscalls Thomas Rast
2009-06-06 14:44     ` [PATCH v2 1/3] Introduce die_errno() that appends strerror(errno) to die() Thomas Rast
2009-06-06 20:36       ` Johannes Sixt
2009-06-06 20:56         ` Thomas Rast
2009-06-06 21:17           ` Johannes Sixt
2009-06-06 22:47           ` Jeff King
2009-06-06 22:13       ` Jeff King
2009-06-07 11:12         ` Alexander Potashev
2009-06-07 16:57           ` Junio C Hamano
2009-06-08 12:36             ` Jeff King
2009-06-08 15:35               ` Alexander Potashev
2009-06-08 22:04                 ` Jeff King
2009-06-06 14:44     ` [PATCH v2 2/3] Convert existing die(..., strerror(errno)) to die_errno() Thomas Rast
2009-06-06 20:31       ` Johannes Sixt
2009-06-06 14:44     ` [PATCH v2 3/3] Use die_errno() instead of die() when checking syscalls Thomas Rast
2009-06-06 21:02       ` Johannes Sixt
2009-06-06 22:27         ` Thomas Rast

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090603015503.GA14166@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).