aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaul E Rangel <rrangel@chromium.org>2019-07-25 15:49:52 -0600
committerPatrick Georgi <pgeorgi@google.com>2019-08-30 10:42:29 +0000
commit7b2deddbb0ef350e189fe42c025b07c943aedc4c (patch)
tree7b2ef4460f7c8def555033edae8523d84f487ab8
parentd2f90a0659ff1036fd313b37705b04e9e9633b01 (diff)
Kconfig: Write tmp files into same directory as target files
This removes the need for COREBOOT_BUILD_DIR in Kconfig. Since the original files will be replaced with the tmp file, the parent directory already needs to be writable. Before this change, the tmp files would be created in the CWD (src) if COREBOOT_BUILD_DIR was not specified. BUG=b:112267918 TEST=emerge-grunt coreboot and verified no tmp files were created in the src directory. Change-Id: Icdaf2ff3dd1ec98813b75ef55b96e38e1ca19ec7 Signed-off-by: Raul E Rangel <rrangel@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/34244 Reviewed-by: Martin Roth <martinroth@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r--Documentation/getting_started/kconfig.md3
-rw-r--r--util/kconfig/confdata.c112
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;