[RFC] Cleaning up die() error messages

4 messages, 4 authors, 2016-06-15 · open the first message on its own page

[RFC] Cleaning up die() error messages

From: Elfyn McBratney <hidden>
Date: 2016-06-15 22:42:08

Hello git list,

I've started working on cleaning up the various die() error messages
found throughout git, and had a few thoughts along the way.

Currently, I've been adding missing program name prefixes, and quoting path
names (e.g., "%s" -> "'%s'"), but before I go any further, I'm wondering
if this is a) desired, or perhaps b) superfluous?  This may be best
discussed with along-side the patch - which'll follow shortly. ;)

Also, I got to thinking whether it might be an idea to use the following
idiom in the code:

	[shell scripts]
	prog="`basename $0`"
	..
	foo || die "${prog}: foo failed"

	[C sources]
	static char *prog;
	..
	static inline void set_prog_name (char *argv0)
	{
		prog = strrchr(argv0, '/');
		if (prog)
			prog++;
		else
			prog = argv0;
	}
	..
	int main (int argc, char **argv)
	{
		set_prog_name(argv[0]);
		..
		if (!do_bar())
			die("%s: do_bar() failed", prog);
		..
	}

The idea behind this being that, if any of the git programs get renamed
(again :) there won't be a need for s/git-foo/git-bar/g just to fix-up
die() error messages, and it'll also shave a *bit* off of the size of the
compiled binaries. ;)

(Of course, the C parts (`prog' and `set_prog_name()') would go into a
header, and not in every single C source file. ;)

So, any thoughts/comments/flames? :)

Best,
Elfyn

-- 
Elfyn McBratney
Gentoo Developer/Perl Team Lead
beu/irc.freenode.net                            http://dev.gentoo.org/~beu/
+------------O.o--------------------- http://dev.gentoo.org/~beu/pubkey.asc

PGP Key ID: 0x69DF17AD
PGP Key Fingerprint:
  DBD3 B756 ED58 B1B4 47B9  B3BD 8D41 E597 69DF 17AD

Re: [RFC] Cleaning up die() error messages

From: Daniel Barkalow <hidden>
Date: 2016-06-15 22:42:08

On Mon, 10 Oct 2005, Elfyn McBratney wrote:
	[C sources]
	static char *prog;
	..
	static inline void set_prog_name (char *argv0)
	{
		prog = strrchr(argv0, '/');
		if (prog)
			prog++;
		else
			prog = argv0;
	}
	..
	int main (int argc, char **argv)
	{
		set_prog_name(argv[0]);
		..
		if (!do_bar())
			die("%s: do_bar() failed", prog);
		..
	}
Just put set_prog_name() next to die(), and have die() write "prog: " at 
the beginning if set_prog_name() got called. Assuming it's useful at all 
to show the name of the program, it's not going to be less useful if the 
error is actually found in a library function called by the program.

	-Daniel
*This .sig left intentionally blank*

Re: [RFC] Cleaning up die() error messages

From: Alex Riesen <hidden>
Date: 2016-06-15 22:42:08

On 10/10/05, Elfyn McBratney [off-list ref] wrote:
        int main (int argc, char **argv)
        {
                set_prog_name(argv[0]);
I'd also use readlink on /proc/self/exe by default (if set_prog_name
_not_ called).
It simplifies the code at least on linux, and makes possible very slow
transition for other platforms. So you don't have to update each and
every .c file containing "main[[:space:]]*(" ;)

Re: [RFC] Cleaning up die() error messages

From: "H. Peter Anvin" <hpa@zytor.com>
Date: 2016-06-15 22:42:08

Alex Riesen wrote:
On 10/10/05, Elfyn McBratney [off-list ref] wrote:
quoted
       int main (int argc, char **argv)
       {
               set_prog_name(argv[0]);

I'd also use readlink on /proc/self/exe by default (if set_prog_name
_not_ called).
It simplifies the code at least on linux, and makes possible very slow
transition for other platforms. So you don't have to update each and
every .c file containing "main[[:space:]]*(" ;)
It's really better just to put the stuff at the beginning of each main. 
  If that's too annoying, librarize main and rename your mains "git_main".

	-hpa
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help