All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kconfig: place git SHA1 in .config output if in SCM
@ 2010-03-03  1:18 Paul E. McKenney
  2010-03-03  1:29 ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2010-03-03  1:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: zippel, mingo, akpm, torvalds, geert, elendil, cloos

This patch appends the localversion string to the Linux kernel version.
For example, in a git tree with uncommitted changes, the .config file
might start as follows (but with leading hash marks):

	Automatically generated make config: don't edit
	Linux kernel version: 2.6.33-01836-g90a6501-dirty
	Mon Mar  1 17:05:59 2010

The "-01836-g90a6501-dirty" string is added by this patch.

This version of the patch incorporates feedback from Geert Uytterhoeven,
Linus Torvalds, Frans Pop, and James Cloos:

o	Fixed to work correctly with the "O=" Makefile argument and
	the KBUILD_OUTPUT environment variable, so that .config files
	created in directories outside of the source tree are tagged
	correctly.

o	Uses scripts/setlocalversion, which handles not only git, but
	also mercurial and svn.

o	Make the new behavior default-off, as scripts/setlocalversion
	has significant latency.  A new environment variable named
	"KBUILD_CONFIG_LOCALVERSION" must be set to enable the
	"-01836-g90a6501-dirty" style of string.

	This is intended to address James Cloos's concern that this
	feature will slow down casual kernel builds.

It has been suggested that this string be output at boot and oops time.
If there is general agreement, this will be the subject of a separate
patch.

Suggested-by: Ingo Molnar <mingo@elte.hu>
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Suggested-by: Frans Pop <elendil@planet.nl>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Frans Pop <elendil@planet.nl>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 confdata.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index c4dec80..ea7e750 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -399,10 +399,12 @@ int conf_read(const char *name)
 int conf_write(const char *name)
 {
 	FILE *out;
+	FILE *slv;
 	struct symbol *sym;
 	struct menu *menu;
 	const char *basename;
-	char dirname[128], tmpname[128], newname[128];
+	char dirname[128], tmpname[128], newname[128], localversion[128];
+	char cmdline[PATH_MAX * 2 + 128];
 	int type, l;
 	const char *str;
 	time_t now;
@@ -450,12 +452,28 @@ int conf_write(const char *name)
 	if (env && *env)
 		use_timestamp = 0;
 
+	localversion[0] = '\0';
+	if (getenv("KBUILD_CONFIG_LOCALVERSION")) {
+		env = getenv(SRCTREE);
+		if (env) {
+			sprintf(cmdline,
+				"%s/scripts/setlocalversion %s 2> /dev/null",
+				env, env);
+			slv = popen(cmdline, "r");
+			if (slv != NULL) {
+				fscanf(slv, " %127s ", localversion);
+				pclose(slv);
+			}
+		}
+	}
+
 	fprintf(out, _("#\n"
 		       "# Automatically generated make config: don't edit\n"
-		       "# Linux kernel version: %s\n"
+		       "# Linux kernel version: %s%s\n"
 		       "%s%s"
 		       "#\n"),
 		     sym_get_string_value(sym),
+		     localversion[0] != '\0' ? localversion : "",
 		     use_timestamp ? "# " : "",
 		     use_timestamp ? ctime(&now) : "");
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] kconfig: place git SHA1 in .config output if in SCM
  2010-03-03  1:18 [PATCH] kconfig: place git SHA1 in .config output if in SCM Paul E. McKenney
@ 2010-03-03  1:29 ` Linus Torvalds
  2010-03-03  2:16   ` Paul E. McKenney
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Torvalds @ 2010-03-03  1:29 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: linux-kernel, zippel, mingo, akpm, geert, elendil, cloos



On Tue, 2 Mar 2010, Paul E. McKenney wrote:
> +		env = getenv(SRCTREE);
> +		if (env) {
> +			sprintf(cmdline,
> +				"%s/scripts/setlocalversion %s 2> /dev/null",
> +				env, env);
> +			slv = popen(cmdline, "r");

I suspect this does various bad things if there are spaces or special 
characters in $SRCTREE.

It would be a lot safer to uses fork/execve rather than something 
that interprets a shell command line.

Of course, I didn't check that all our old users of SRCTREE are safe 
either, but at least docproc.c (the one I _did_ check) uses 'execvp()' and 
'fopen()' that both take real filenames, not a shell string.

			Linus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kconfig: place git SHA1 in .config output if in SCM
  2010-03-03  1:29 ` Linus Torvalds
@ 2010-03-03  2:16   ` Paul E. McKenney
  2010-03-03 17:28     ` James Cloos
  0 siblings, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2010-03-03  2:16 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel, zippel, mingo, akpm, geert, elendil, cloos

On Tue, Mar 02, 2010 at 05:29:50PM -0800, Linus Torvalds wrote:
> 
> 
> On Tue, 2 Mar 2010, Paul E. McKenney wrote:
> > +		env = getenv(SRCTREE);
> > +		if (env) {
> > +			sprintf(cmdline,
> > +				"%s/scripts/setlocalversion %s 2> /dev/null",
> > +				env, env);
> > +			slv = popen(cmdline, "r");
> 
> I suspect this does various bad things if there are spaces or special 
> characters in $SRCTREE.
> 
> It would be a lot safer to uses fork/execve rather than something 
> that interprets a shell command line.
> 
> Of course, I didn't check that all our old users of SRCTREE are safe 
> either, but at least docproc.c (the one I _did_ check) uses 'execvp()' and 
> 'fopen()' that both take real filenames, not a shell string.

Well, we certainly don't want or need bash's "$", "``", and other
interpretations in this case.  I will update and send out a new patch.

Hmmm...  It has been one good long time since I have used pipe(), dup2(),
exec*(), and friends.  In happy contrast to last time, some of the man
pages now seem to have nice examples.  ;-)

							Thanx, Paul

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kconfig: place git SHA1 in .config output if in SCM
  2010-03-03  2:16   ` Paul E. McKenney
@ 2010-03-03 17:28     ` James Cloos
  2010-03-03 19:58       ` Paul E. McKenney
  0 siblings, 1 reply; 6+ messages in thread
From: James Cloos @ 2010-03-03 17:28 UTC (permalink / raw)
  To: paulmck; +Cc: Linus Torvalds, linux-kernel, zippel, mingo, akpm, geert, elendil

Doesn't this patch simply duplicate CONFIG_LOCALVERSION_AUTO's
functionality, now that it calls scripts/setlocalversion?

I'd still like to get the hash and only elide the dirty check.

-JimC
-- 
James Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kconfig: place git SHA1 in .config output if in SCM
  2010-03-03 17:28     ` James Cloos
@ 2010-03-03 19:58       ` Paul E. McKenney
  2010-03-03 20:41         ` James Cloos
  0 siblings, 1 reply; 6+ messages in thread
From: Paul E. McKenney @ 2010-03-03 19:58 UTC (permalink / raw)
  To: James Cloos
  Cc: Linus Torvalds, linux-kernel, zippel, mingo, akpm, geert, elendil

On Wed, Mar 03, 2010 at 12:28:38PM -0500, James Cloos wrote:
> Doesn't this patch simply duplicate CONFIG_LOCALVERSION_AUTO's
> functionality, now that it calls scripts/setlocalversion?
> 
> I'd still like to get the hash and only elide the dirty check.

Would you be OK with having to set an environment variable to suppress
the dirty check?

							Thanx, Paul

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] kconfig: place git SHA1 in .config output if in SCM
  2010-03-03 19:58       ` Paul E. McKenney
@ 2010-03-03 20:41         ` James Cloos
  0 siblings, 0 replies; 6+ messages in thread
From: James Cloos @ 2010-03-03 20:41 UTC (permalink / raw)
  To: paulmck; +Cc: Linus Torvalds, linux-kernel, zippel, mingo, akpm, geert, elendil

>>>>> "Paul" == Paul E McKenney <paulmck@linux.vnet.ibm.com> writes:

JimC> Doesn't this patch simply duplicate CONFIG_LOCALVERSION_AUTO's
JimC> functionality, now that it calls scripts/setlocalversion?

JimC> I'd still like to get the hash and only elide the dirty check.

Paul> Would you be OK with having to set an environment variable to suppress
Paul> the dirty check?

Yes, most definitely OK.

-JimC
-- 
James Cloos <cloos@jhcloos.com>         OpenPGP: 1024D/ED7DAEA6

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-03-03 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-03  1:18 [PATCH] kconfig: place git SHA1 in .config output if in SCM Paul E. McKenney
2010-03-03  1:29 ` Linus Torvalds
2010-03-03  2:16   ` Paul E. McKenney
2010-03-03 17:28     ` James Cloos
2010-03-03 19:58       ` Paul E. McKenney
2010-03-03 20:41         ` James Cloos

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.