diff options
-rw-r--r-- | Documentation/getting_started/kconfig.md | 3 | ||||
-rw-r--r-- | util/kconfig/confdata.c | 112 |
2 files changed, 63 insertions, 52 deletions
diff --git a/Documentation/getting_started/kconfig.md b/Documentation/getting_started/kconfig.md index 852ca08bf9..ecdfe62d4a 100644 --- a/Documentation/getting_started/kconfig.md +++ b/Documentation/getting_started/kconfig.md @@ -73,9 +73,6 @@ These variables are typically set in the makefiles or on the make command line. These variables were added to Kconfig specifically for coreboot and are not included in the Linux version. -- COREBOOT_BUILD_DIR=path for temporary files. This is used by coreboot’s - abuild tool. - - KCONFIG_STRICT=value. Define to enable warnings as errors. This is enabled in coreboot, and should not be changed. diff --git a/util/kconfig/confdata.c b/util/kconfig/confdata.c index 3c0818aaae..fc76e0e880 100644 --- a/util/kconfig/confdata.c +++ b/util/kconfig/confdata.c @@ -764,6 +764,16 @@ next_menu: return 0; } + +int conf_mktemp(const char *path, char *tmpfile) +{ + if (snprintf(tmpfile, PATH_MAX, "%s.tmp.XXXXXX", path) >= PATH_MAX) { + errno = EOVERFLOW; + return -1; + } + return mkstemp(tmpfile); +} + int conf_write(const char *name) { FILE *out; @@ -806,7 +816,7 @@ int conf_write(const char *name) sprintf(newname, "%s%s", dirname, basename); env = getenv("KCONFIG_OVERWRITECONFIG"); if (!env || !*env) { - sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); + conf_mktemp(newname, tmpname); out = fopen(tmpname, "w"); } else { *tmpname = 0; @@ -991,7 +1001,6 @@ out: int conf_write_autoconf(void) { struct symbol *sym; - const char *name; FILE *out, *tristate, *out_h; int i; int print_negatives; @@ -1008,49 +1017,41 @@ int conf_write_autoconf(void) if (conf_split_config()) return 1; - char *tmpconfig_name = malloc(PATH_MAX); - if (getenv("COREBOOT_BUILD_DIR")) { - sprintf(tmpconfig_name, "%s/.tmpconfig.XXXXXX", - getenv("COREBOOT_BUILD_DIR")); - } else { - tmpconfig_name = strdup(".tmpconfig.XXXXXX"); - } - if ((i = mkstemp(tmpconfig_name)) == -1) - return 1; + char tmpconfig_name[PATH_MAX]; + const char *config_name = conf_get_autoconfig_name(); + + i = conf_mktemp(config_name, tmpconfig_name); + if (i == -1) + goto error_auto_conf_cmd_tmp; out = fdopen(i, "w"); if (!out) - return 1; + goto error_auto_conf_cmd_open; + + char tmpconfig_triname[PATH_MAX]; + const char *config_triname = getenv("KCONFIG_TRISTATE"); + if (!config_triname) + config_triname = "include/config/tristate.conf"; + + i = conf_mktemp(config_triname, tmpconfig_triname); + if (i == -1) + goto error_tristate_tmp; - char *tmpconfig_triname = malloc(PATH_MAX); - if (getenv("COREBOOT_BUILD_DIR")) { - sprintf(tmpconfig_triname, "%s/.tmpconfig_tristate.XXXXXX", - getenv("COREBOOT_BUILD_DIR")); - } else { - tmpconfig_triname = strdup(".tmpconfig_tristate.XXXXXX"); - } - if ((i = mkstemp(tmpconfig_triname)) == -1) - return 1; tristate = fdopen(i, "w"); - if (!tristate) { - fclose(out); - return 1; - } + if (!tristate) + goto error_tristate_open; + + char tmpconfig_h[PATH_MAX]; + const char *config_h = getenv("KCONFIG_AUTOHEADER"); + if (!config_h) + config_h = "include/generated/autoconf.h"; + + i = conf_mktemp(config_h, tmpconfig_h); + if (i == -1) + goto error_auto_conf_h_tmp; - char *tmpconfig_h = malloc(PATH_MAX); - if (getenv("COREBOOT_BUILD_DIR")) { - sprintf(tmpconfig_h, "%s/.tmpconfig_tristate.XXXXXX", - getenv("COREBOOT_BUILD_DIR")); - } else { - tmpconfig_h = strdup(".tmpconfig_tristate.XXXXXX"); - } - if ((i = mkstemp(tmpconfig_h)) == -1) - return 1; out_h = fdopen(i, "w"); - if (!out_h) { - fclose(out); - fclose(tristate); - return 1; - } + if (!out_h) + goto error_auto_conf_h_open; conf_write_heading(out, &kconfig_printer_cb, NULL); @@ -1084,25 +1085,38 @@ int conf_write_autoconf(void) fclose(tristate); fclose(out_h); - name = getenv("KCONFIG_AUTOHEADER"); - if (!name) - name = "include/generated/autoconf.h"; - if (rename(tmpconfig_h, name)) + if (rename(tmpconfig_h, config_h)) return 1; - name = getenv("KCONFIG_TRISTATE"); - if (!name) - name = "include/config/tristate.conf"; - if (rename(tmpconfig_triname, name)) + + if (rename(tmpconfig_triname, config_triname)) return 1; - name = conf_get_autoconfig_name(); + /* * This must be the last step, kbuild has a dependency on auto.conf * and this marks the successful completion of the previous steps. */ - if (rename(tmpconfig_name, name)) + if (rename(tmpconfig_name, config_name)) return 1; return 0; + +error_auto_conf_h_open: + unlink(tmpconfig_h); + +error_auto_conf_h_tmp: + fclose(tristate); + +error_tristate_open: + unlink(tmpconfig_triname); + +error_tristate_tmp: + fclose(out); + +error_auto_conf_cmd_open: + unlink(tmpconfig_name); + +error_auto_conf_cmd_tmp: + return 1; } static int sym_change_count; |