summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-09-26 19:41:27 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-10-02 05:19:08 -0700
commit2c7dfb4ebbe0428e3c52b9786024533111fb3bc7 (patch)
treed78197172185ae613a71e082abbf7e9eb50bb6fc
parent01d778c16a9272892ed8296d101ad299e1092e6c (diff)
downloadvboot-2c7dfb4ebbe0428e3c52b9786024533111fb3bc7.tar.gz
futility: updater: Refactor: localize temp files management
The creation and deletion of temp files can be managed in same context where updater config lives. BUG=chromium:875551 TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: Ic1745d27a071047d4882b21905bd11e15b5632cd Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1245644 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org>
-rw-r--r--futility/cmd_update.c1
-rw-r--r--futility/updater.c29
-rw-r--r--futility/updater.h6
3 files changed, 16 insertions, 20 deletions
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index ef9e3813..c944724a 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -178,7 +178,6 @@ static int do_update(int argc, char *argv[])
errorcnt ? "stopped due to error" : "exited successfully");
updater_delete_config(cfg);
- remove_all_temp_files(); /* TODO(hungte) Move this to updater */
return !!errorcnt;
}
diff --git a/futility/updater.c b/futility/updater.c
index 6441c367..113ffc59 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -129,30 +129,30 @@ enum quirk_types {
QUIRK_MAX,
};
+struct tempfile {
+ char *filepath;
+ struct tempfile *next;
+};
+
struct updater_config {
struct firmware_image image, image_current;
struct firmware_image ec_image, pd_image;
struct system_property system_properties[SYS_PROP_MAX];
struct quirk_entry quirks[QUIRK_MAX];
+ struct tempfile *tempfiles;
int try_update;
int force_update;
int legacy_update;
const char *emulation;
};
-struct tempfile {
- char *filepath;
- struct tempfile *next;
-};
-
-static struct tempfile *tempfiles;
/*
* Helper function to create a new temporary file.
* All files created will be removed by function remove_all_temp_files().
* Returns the path of new file, or NULL on failure.
*/
-static const char *create_temp_file()
+static const char *create_temp_file(struct updater_config *cfg)
{
struct tempfile *new_temp;
char new_path[] = P_tmpdir "/fwupdater.XXXXXX";
@@ -174,8 +174,8 @@ static const char *create_temp_file()
return NULL;
}
DEBUG("Created new temporary file: %s.", new_path);
- new_temp->next = tempfiles;
- tempfiles = new_temp;
+ new_temp->next = cfg->tempfiles;
+ cfg->tempfiles = new_temp;
return new_temp->filepath;
}
@@ -183,8 +183,9 @@ static const char *create_temp_file()
* Helper function to remove all files created by create_temp_file().
* This is intended to be called only once at end of program execution.
*/
-void remove_all_temp_files()
+static void remove_all_temp_files(struct updater_config *cfg)
{
+ struct tempfile *tempfiles = cfg->tempfiles;
while (tempfiles != NULL) {
struct tempfile *target = tempfiles;
DEBUG("Remove temporary file: %s.", target->filepath);
@@ -193,6 +194,7 @@ void remove_all_temp_files()
tempfiles = target->next;
free(target);
}
+ cfg->tempfiles = NULL;
}
/*
@@ -703,7 +705,7 @@ static int load_image(const char *file_name, struct firmware_image *image)
static int load_system_image(struct updater_config *cfg,
struct firmware_image *image)
{
- const char *tmp_file = create_temp_file();
+ const char *tmp_file = create_temp_file(cfg);
if (!tmp_file)
return -1;
@@ -866,7 +868,7 @@ static int write_firmware(struct updater_config *cfg,
const struct firmware_image *image,
const char *section_name)
{
- const char *tmp_file = create_temp_file();
+ const char *tmp_file = create_temp_file(cfg);
const char *programmer = image->programmer;
if (!tmp_file)
@@ -1428,7 +1430,7 @@ static int quirk_enlarge_image(struct updater_config *cfg)
if (image_from->size <= image_to->size)
return 0;
- tmp_path = create_temp_file();
+ tmp_path = create_temp_file(cfg);
if (!tmp_path)
return -1;
@@ -1873,5 +1875,6 @@ void updater_delete_config(struct updater_config *cfg)
free_image(&cfg->image_current);
free_image(&cfg->ec_image);
free_image(&cfg->pd_image);
+ remove_all_temp_files(cfg);
free(cfg);
}
diff --git a/futility/updater.h b/futility/updater.h
index bb738996..85540a90 100644
--- a/futility/updater.h
+++ b/futility/updater.h
@@ -68,12 +68,6 @@ int updater_setup_config(struct updater_config *cfg,
int try_update,
int force_update);
-/*
- * Helper function to remove all files created by create_temp_file().
- * This is intended to be called only once at end of program execution.
- */
-void remove_all_temp_files();
-
/* Prints the name and description from all supported quirks. */
void updater_list_config_quirks(const struct updater_config *cfg);