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>
Subject: [PATCH 1/2] scripts: imx-image: Be more informative on open errors
Date: Tue,  5 Feb 2019 09:59:00 +0100	[thread overview]
Message-ID: <20190205085901.2271-1-s.hauer@pengutronix.de> (raw)

When opening a file fails then consistently print a message which
file we cannot open and why. In one place no error checking was done at
all, so add this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/imx/imx-image.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 34a072039d..4933703fdc 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -153,7 +153,8 @@ static int extract_key(const char *certfile, uint8_t **modulus, int *modulus_len
 
 	fp = fopen(certfile, "r");
 	if (!fp) {
-		fprintf(stderr, "unable to open certfile: %s\n", certfile);
+		fprintf(stderr, "unable to open certfile %s: %s\n", certfile,
+			strerror(errno));
 		return -errno;
 	}
 
@@ -458,7 +459,8 @@ static void write_dcd(const char *outfile)
 
 	outfd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 	if (outfd < 0) {
-		perror("open");
+		fprintf(stderr, "Cannot open %s for wrinting: %s\n", outfile,
+			strerror(errno));
 		exit(1);
 	}
 
@@ -671,6 +673,11 @@ static int hab_sign(struct config_data *data)
 	}
 
 	outfd = open(data->outfile, O_WRONLY | O_APPEND);
+	if (outfd < 0) {
+		fprintf(stderr, "Cannot open %s for writing: %s\n", data->outfile,
+			strerror(errno));
+		exit(1);
+	}
 
 	ret = xwrite(outfd, buf, csf_space);
 	if (ret < 0) {
@@ -695,7 +702,7 @@ static void *read_file(const char *filename, size_t *size)
 
 	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
-		perror("open");
+		fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno));
 		exit(1);
 	}
 
@@ -930,7 +937,8 @@ int main(int argc, char *argv[])
 
 	outfd = open(data.outfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 	if (outfd < 0) {
-		perror("open");
+		fprintf(stderr, "Cannot open %s for writing: %s\n", data.outfile,
+			strerror(errno));
 		exit(1);
 	}
 
-- 
2.20.1


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

             reply	other threads:[~2019-02-05  8:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05  8:59 Sascha Hauer [this message]
2019-02-05  8:59 ` [PATCH 2/2] scripts: imx-image: make read_file behaviour consistent 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=20190205085901.2271-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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