[coreboot] New patch to review for coreboot: 051b64d Force coreboot mconf to create temp files in the output directory

Stefan Reinauer (stefan.reinauer@coreboot.org) gerrit at coreboot.org
Fri Mar 30 21:39:48 CEST 2012


Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/815

-gerrit

commit 051b64d6dda2a829454e5df752134dcbb0a35ba1
Author: Vadim Bendebury <vbendeb at chromium.org>
Date:   Mon Oct 24 14:06:23 2011 -0700

    Force coreboot mconf to create temp files in the output directory
    
    This change partially addresses the problem with attempting to
    generate coreboot image out of tree. The configuration step fails when
    in cheroot, if the destination directory is placed in /tmp.
    
    The problem is that the mconf package tries renaming the temporary
    file created in the local directory into the destination config file.
    If the destination root and the local directory are located on
    different file systems, the rename operation fails.
    
    The proper fix (still upcoming) would be to identify all places where
    mconf creates temp files, and make sure that all temp files get
    created in the destination tree.
    
    This change modifies just one location, which prevents building out of
    tree in the most common case.
    
    Test:
      run the following in the coreboot directory in chroot:
        (coreboot) cp config.lumpy .config
        (coreboot) /bin/rm -rf /tmp/cb
        (coreboot) CROSS_COMPILE=i686-pc-linux-gnu- make obj=/tmp/cb oldconfig
        (coreboot) CROSS_COMPILE=i686-pc-linux-gnu- make obj=/tmp/cb
    
      Observe the build succeed (it was failing during the config phase
      before this change)
    
    Change-Id: If4506e984b8afc192a1689c7b0aa956dd35f66c6
    Signed-off-by: Vadim Bendebury <vbendeb at chromium.org>
---
 util/kconfig/confdata.c |   53 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/util/kconfig/confdata.c b/util/kconfig/confdata.c
index 79e0b35..df39fcc 100644
--- a/util/kconfig/confdata.c
+++ b/util/kconfig/confdata.c
@@ -674,6 +674,33 @@ out:
 	return res;
 }
 
+/*
+ * Return malloced string the contents of which are a concatenation of the
+ * directory name of the first argument and the second argument.
+ */
+static char* get_tmp_file_name(const char* base, const char *tmp_name)
+{
+        char *file_name, *p;
+        /* for sure a few bytes longer than needed */
+        int file_name_size = strlen(base) + sizeof(file_name) + 10;
+
+        file_name = malloc(file_name_size);
+        if (!file_name) {
+                fprintf(stderr, "%s:%d: failed to allocate %d bytes\n",
+                        __FILE__, __LINE__, file_name_size);
+               return 0;
+        }
+
+        strcpy(file_name, base);
+        p = strrchr(file_name, '/');
+        if (p)
+                strcpy(p + 1, tmp_name);
+        else
+                strcpy(file_name, tmp_name);
+
+        return file_name;
+}
+
 int conf_write_autoconf(void)
 {
 	struct symbol *sym;
@@ -682,10 +709,19 @@ int conf_write_autoconf(void)
 	FILE *out, *out_h;
 	time_t now;
 	int i, l;
-	char tmpname[128], tmpname_h[128];
+	char *tmp_conf, *tmp_conf_h;
 
 	sym_clear_all_valid();
 
+	name = getenv("KCONFIG_AUTOHEADER");
+	if (!name)
+		name = "include/linux/autoconf.h";
+
+	tmp_conf = get_tmp_file_name(name, ".tmpconfig");
+	tmp_conf_h = get_tmp_file_name(name, ".tmpconfig.h");
+	if (!tmp_conf || !tmp_conf_h)
+		return 1;
+
 	file_write_dep("build/auto.conf.cmd");
 
 #if 0
@@ -693,13 +729,11 @@ int conf_write_autoconf(void)
 		return 1;
 #endif
 
-	sprintf(tmpname, ".tmpconfig.%d", (int)getpid());
-	out = fopen(tmpname, "w");
+	out = fopen(tmp_conf, "w");
 	if (!out)
 		return 1;
 
-	sprintf(tmpname_h, ".tmpconfig.h.%d", (int)getpid());
-	out_h = fopen(tmpname_h, "w");
+	out_h = fopen(tmp_conf_h, "w");
 	if (!out_h) {
 		fclose(out);
 		return 1;
@@ -790,11 +824,8 @@ int conf_write_autoconf(void)
 	fclose(out);
 	fclose(out_h);
 
-	name = getenv("KCONFIG_AUTOHEADER");
-	if (!name)
-		name = "include/linux/autoconf.h";
 	UNLINK_IF_NECESSARY(name);
-	if (rename(tmpname_h, name))
+	if (rename(tmp_conf_h, name))
 		return 1;
 	name = getenv("KCONFIG_AUTOCONFIG");
 	if (!name)
@@ -804,9 +835,11 @@ int conf_write_autoconf(void)
 	 * and this marks the successful completion of the previous steps.
 	 */
 	UNLINK_IF_NECESSARY(name);
-	if (rename(tmpname, name))
+	if (rename(tmp_conf, name))
 		return 1;
 
+	free(tmp_conf_h);
+	free(tmp_conf);
 	return 0;
 }
 




More information about the coreboot mailing list