mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: "Edmund Henniges" <eh@emlix.com>, "Daniel Glöckner" <dg@emlix.com>
Subject: [PATCH 05/19] fastboot: Use unique tempfile name
Date: Wed, 20 May 2020 11:43:49 +0200	[thread overview]
Message-ID: <20200520094403.12651-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20200520094403.12651-1-s.hauer@pengutronix.de>

With fastboot over ethernet we now can have two instances of fastboot
running in parallel. Make sure that both instances use a different
temporary file to store data so that they do not influence each other.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/fastboot.c  | 21 ++++++++++++---------
 include/fastboot.h |  1 +
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 1e12f99915..6f54e939e7 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -45,8 +45,6 @@
 
 #define FASTBOOT_VERSION		"0.4"
 
-#define FASTBOOT_TMPFILE		"/.fastboot.img"
-
 static unsigned int fastboot_max_download_size = SZ_8M;
 
 struct fb_variable {
@@ -178,6 +176,7 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
 	int ret;
 	struct file_list_entry *fentry;
 	struct fb_variable *var;
+	static int instance;
 
 	var = fb_addvar(fb, "version");
 	fb_setvar(var, "0.4");
@@ -188,6 +187,8 @@ int fastboot_generic_init(struct fastboot *fb, bool export_bbu)
 		fb_setvar(var, "%u", fastboot_max_download_size);
 	}
 
+	fb->tempname = basprintf(".fastboot.%d.img", instance++);
+
 	if (IS_ENABLED(CONFIG_BAREBOX_UPDATE) && export_bbu)
 		bbu_handlers_iterate(fastboot_add_bbu_variables, fb);
 
@@ -211,6 +212,8 @@ void fastboot_generic_free(struct fastboot *fb)
 		free(var);
 	}
 
+	free(fb->tempname);
+
 	fb->active = false;
 }
 
@@ -372,7 +375,7 @@ static void cb_download(struct fastboot *fb, const char *cmd)
 			return;
 		}
 	} else {
-		fb->download_fd = open(FASTBOOT_TMPFILE, O_WRONLY | O_CREAT | O_TRUNC);
+		fb->download_fd = open(fb->tempname, O_WRONLY | O_CREAT | O_TRUNC);
 		if (fb->download_fd < 0) {
 			fastboot_tx_print(fb, FASTBOOT_MSG_FAIL,
 					  "internal error");
@@ -405,7 +408,7 @@ static void __maybe_unused cb_boot(struct fastboot *fb, const char *opt)
 	globalvar_set_match("linux.bootargs.dyn.", "");
 	globalvar_set_match("bootm.image", "");
 
-	data.os_file = FASTBOOT_TMPFILE;
+	data.os_file = fb->tempname;
 
 	ret = bootm_boot(&data);
 
@@ -534,7 +537,7 @@ static int fastboot_handle_sparse(struct fastboot *fb,
 	if (ret)
 		goto out_close_fd;
 
-	sparse = sparse_image_open(FASTBOOT_TMPFILE);
+	sparse = sparse_image_open(fb->tempname);
 	if (IS_ERR(sparse)) {
 		pr_err("Cannot open sparse image\n");
 		ret = PTR_ERR(sparse);
@@ -629,8 +632,8 @@ static void cb_flash(struct fastboot *fb, const char *cmd)
 		sourcefile = NULL;
 		filetype = file_detect_type(fb->buf, fb->download_bytes);
 	} else {
-		sourcefile = FASTBOOT_TMPFILE;
-		filetype = file_name_detect_type(FASTBOOT_TMPFILE);
+		sourcefile = fb->tempname;
+		filetype = file_name_detect_type(fb->tempname);
 	}
 
 	fastboot_tx_print(fb, FASTBOOT_MSG_INFO, "Copying file to %s...",
@@ -735,7 +738,7 @@ copy:
 	if (fastboot_download_to_buf(fb))
 		ret = write_file(filename, fb->buf, fb->download_size);
 	else
-		ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
+		ret = copy_file(fb->tempname, filename, 1);
 
 	if (ret)
 		fastboot_tx_print(fb, FASTBOOT_MSG_FAIL,
@@ -749,7 +752,7 @@ out:
 	fb->buf = NULL;
 
 	if (!fastboot_download_to_buf(fb))
-		unlink(FASTBOOT_TMPFILE);
+		unlink(fb->tempname);
 }
 
 static void cb_erase(struct fastboot *fb, const char *cmd)
diff --git a/include/fastboot.h b/include/fastboot.h
index 3b6cae8a58..b3e7155efa 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -25,6 +25,7 @@ struct fastboot {
 			 const char *filename, const void *buf, size_t len);
 	int download_fd;
 	void *buf;
+	char *tempname;
 
 	bool active;
 
-- 
2.26.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-05-20  9:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20  9:43 [PATCH 00/19] Slices and fastboot over UDP Sascha Hauer
2020-05-20  9:43 ` [PATCH 01/19] poller: Give pollers a name Sascha Hauer
2020-05-20  9:43 ` [PATCH 02/19] poller: Add a poller command Sascha Hauer
2020-05-20  9:43 ` [PATCH 03/19] fastboot: split generic code from USB gadget Sascha Hauer
2020-05-20  9:43 ` [PATCH 04/19] fastboot: don't close fd 0 when downloading to ram Sascha Hauer
2020-05-20  9:43 ` Sascha Hauer [this message]
2020-05-20  9:43 ` [PATCH 06/19] Introduce slices Sascha Hauer
2020-05-20  9:43 ` [PATCH 07/19] Introduce idle slice Sascha Hauer
2020-05-22 11:56   ` Daniel Glöckner
2020-05-25  8:09     ` Sascha Hauer
2020-05-20  9:43 ` [PATCH 08/19] net: Add a slice to struct eth_device Sascha Hauer
2020-05-20  9:43 ` [PATCH 09/19] net: mdiobus: Add slice Sascha Hauer
2020-05-20  9:43 ` [PATCH 10/19] usb: Add a slice to usb host controllers Sascha Hauer
2020-05-20  9:43 ` [PATCH 11/19] usbnet: Add slice Sascha Hauer
2020-05-20  9:43 ` [PATCH 12/19] net: Call net_poll() in a poller Sascha Hauer
2020-05-20  9:43 ` [PATCH 13/19] net: reply to ping requests Sascha Hauer
2020-05-20  9:43 ` [PATCH 14/19] usbnet: Be more friendly in the receive path Sascha Hauer
2020-05-20  9:43 ` [PATCH 15/19] poller: Allow to run pollers inside of pollers Sascha Hauer
2020-05-20  9:44 ` [PATCH 16/19] defconfigs: update renamed fastboot options Sascha Hauer
2020-05-20  9:44 ` [PATCH 17/19] fastboot: rename usbgadget.fastboot_* variables to fastboot.* Sascha Hauer
2020-05-20  9:44 ` [PATCH 18/19] fastboot net: implement fastboot over UDP Sascha Hauer
2020-05-20  9:44 ` [PATCH 19/19] fastboot net: remove may_send Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200520094403.12651-6-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=dg@emlix.com \
    --cc=eh@emlix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox