kconfig: Use more collision resistant temporary filenames
[coreboot.git] / util / kconfig / confdata.c
index 56a0eb08518709de8614504dbf7483b06cf651f2..79e0b359eaf1ac7af2e2bdecc8954d166cff1d06 100644 (file)
@@ -19,7 +19,7 @@
 #define mkdir(x,y) mkdir(x)
 #define UNLINK_IF_NECESSARY(x) unlink(x)
 #else
-#define UNLINK_IF_NECESSARY(X) 
+#define UNLINK_IF_NECESSARY(X)
 #endif
 
 static void conf_warning(const char *fmt, ...)
@@ -682,6 +682,7 @@ int conf_write_autoconf(void)
        FILE *out, *out_h;
        time_t now;
        int i, l;
+       char tmpname[128], tmpname_h[128];
 
        sym_clear_all_valid();
 
@@ -692,11 +693,13 @@ int conf_write_autoconf(void)
                return 1;
 #endif
 
-       out = fopen(".tmpconfig", "w");
+       sprintf(tmpname, ".tmpconfig.%d", (int)getpid());
+       out = fopen(tmpname, "w");
        if (!out)
                return 1;
 
-       out_h = fopen(".tmpconfig.h", "w");
+       sprintf(tmpname_h, ".tmpconfig.h.%d", (int)getpid());
+       out_h = fopen(tmpname_h, "w");
        if (!out_h) {
                fclose(out);
                return 1;
@@ -721,8 +724,15 @@ int conf_write_autoconf(void)
 
        for_all_symbols(i, sym) {
                sym_calc_value(sym);
-               if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
+               if (!sym->name)
                        continue;
+               if (!(sym->flags & SYMBOL_WRITE)) {
+                       if (sym->type == S_BOOLEAN || sym->type == S_HEX
+                           || sym->type == S_INT)
+                               fprintf(out_h, "#define CONFIG_%s 0\n",
+                                       sym->name);
+                       continue;
+               }
                switch (sym->type) {
                case S_BOOLEAN:
                case S_TRISTATE:
@@ -784,7 +794,7 @@ int conf_write_autoconf(void)
        if (!name)
                name = "include/linux/autoconf.h";
        UNLINK_IF_NECESSARY(name);
-       if (rename(".tmpconfig.h", name))
+       if (rename(tmpname_h, name))
                return 1;
        name = getenv("KCONFIG_AUTOCONFIG");
        if (!name)
@@ -794,7 +804,7 @@ int conf_write_autoconf(void)
         * and this marks the successful completion of the previous steps.
         */
        UNLINK_IF_NECESSARY(name);
-       if (rename(".tmpconfig", name))
+       if (rename(tmpname, name))
                return 1;
 
        return 0;