git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git_progname (was: Re: User-relative paths)

From
Petr Baudis <pasky@suse.cz>
Date
Oct 25, 2005, 09:31 UTC
Message-ID
<20051025093150.GB30889@pasky.or.cz>
In-Reply-To
<435DF6DA.6010205@op5.se>
Could you please also trim the mails you are replying to a bit?

Dear diary, on Tue, Oct 25, 2005 at 11:11:54AM CEST, I got a letter where Andreas Ericsson <ae@op5.se> told me that...

Show 5 quoted lines
> See the attached patch, which adds git_progname as a global variable to 
> daemon.c with a minimum of fuzz. The one-liner below will add it to the 
> rest of the programs. GNU sed >= 4.0.9 required.
> 
> grep -l "int main" *.c | xargs -- sed -i '/^#include/i#include "main.h"'

Urgh. Now this is ugly. What about making it a bit more intrusive while quite more saner?

Show 18 quoted lines
> diff --git a/cache.h b/cache.h
> index d776016..db5d667 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -45,6 +45,13 @@
>  #endif
>  #endif
>  
> +#if defined(__GLIBC__)
> +extern const char *__progname;
> +#define git_progname __progname
> +#else
> +extern const char *git_progname;
> +#endif
> +
>  /*
>   * Intensive research over the course of many years has shown that
>   * port 9418 is totally unused by anything else. Or

Also, when you already solve this for non-__GLIBC__ systems, I doubt that there is any win in keeping the __GLIBC__-specific hack, except that most developers won't see any bugs in the generic solution since they are using glibc.

Show 28 quoted lines
> diff --git a/main.h b/main.h
> new file mode 100644
> index 0000000..472f134
> --- /dev/null
> +++ b/main.h
> @@ -0,0 +1,22 @@
> +/* unistd.h must be available and the glibc version includes features.h
> + * from it which #defines __GLIBC__ and friends */
> +#include <unistd.h>
> +#ifndef __GLIBC__
> +const char *git_progname;
> +static int git_main(int, char **);
> +
> +int main(int argc, char **argv)
> +{
> +	char *p;
> +	git_progname = p = *argv;
> +
> +	/* don't use any library functions. We won't have the headers */
> +	while(*p)
> +		if(*p++ == '/')
> +			git_progname = p;
> +
> +	return git_main(argc, argv);
> +}
> +
> +#define main(argc, argv) git_main(argc, argv)
> +#endif /* __GLIBC__ */

Someone said that converting main()s to git_main()s would help the libification effort, but I suspect that you actually want to set the progname to whatever you call when you call its git_main().

We can make it go into the init section, but that won't be too portable either.

So I'd say just add setup_progname("foo") at the start of your main().
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
Previous: Andreas EricssonNext: Andreas Ericsson
Message 24 of 30 in “Server side programs”
  1. Andreas EricssonOct 22, 2005
  2. Junio C HamanoOct 23, 2005
  3. Andreas EricssonOct 23, 2005
  4. Petr BaudisOct 23, 2005
  5. Junio C HamanoOct 23, 2005
  6. Petr BaudisOct 23, 2005
  7. Junio C HamanoOct 23, 2005
  8. Daniel BarkalowOct 24, 2005
  9. Andreas EricssonOct 25, 2005
  10. Junio C HamanoOct 23, 2005
  11. Linus TorvaldsOct 23, 2005
  12. Junio C HamanoOct 23, 2005
  13. Junio C HamanoOct 23, 2005
  14. H. Peter AnvinOct 24, 2005
  15. Linus TorvaldsOct 24, 2005
  16. H. Peter AnvinOct 24, 2005
  17. Junio C HamanoOct 24, 2005
  18. Add git-shell.Junio C Hamano, Oct 24, 2005
  19. Linus TorvaldsOct 24, 2005
  20. Linus TorvaldsOct 24, 2005
  21. Junio C HamanoOct 24, 2005
  22. Junio C HamanoOct 24, 2005
  23. git_progname (was: Re: User-relative paths)Andreas Ericsson, Oct 25, 2005
  24. Petr BaudisOct 25, 2005
  25. Andreas EricssonOct 25, 2005
  26. Andreas EricssonOct 25, 2005
  27. Petr BaudisOct 25, 2005
  28. Junio C HamanoOct 26, 2005
  29. Matthias UrlichsOct 27, 2005
  30. Linus TorvaldsOct 23, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.