[PATCH] opkg_archive: output libarchive's errno wherever we output a string

26 views
Skip to first unread message

Brenda Streiff

unread,
Nov 17, 2021, 3:41:25 PM11/17/21
to opkg-...@googlegroups.com, Brenda Streiff
libarchive has both "archive_error_string" and "archive_errno" methods;
the latter can provide greater detail. For instance, libarchive's
"file_open" will set the error to a string of "Failed to open '%s'",
but also set the errno value to the errno from the underlying open()
call, which can provide a bit more detail, like if we failed due to
ENOENT or ENOSPC, etc.

This patch adds archive_errno reporting to every msg in opkg_archive.c
where we are already returning the archive_error_string.

Signed-off-by: Brenda Streiff <brenda....@ni.com>
---
libopkg/opkg_archive.c | 101 +++++++++++++++++++++--------------------
1 file changed, 53 insertions(+), 48 deletions(-)

diff --git a/libopkg/opkg_archive.c b/libopkg/opkg_archive.c
index 1045a6c..03a4afb 100644
--- a/libopkg/opkg_archive.c
+++ b/libopkg/opkg_archive.c
@@ -97,13 +97,13 @@ static size_t read_data(struct archive *a, void *buffer, size_t len, int *eof)
/* We don't know the size read so we have to treat this
* as an error.
*/
- opkg_msg(ERROR, "Warning when reading data from archive: %s\n",
- archive_error_string(a));
+ opkg_msg(ERROR, "Warning when reading data from archive: %s (errno=%d)\n",
+ archive_error_string(a), archive_errno(a));
return 0;

case ARCHIVE_RETRY:
- opkg_msg(ERROR, "Failed to read data from archive: %s\n",
- archive_error_string(a));
+ opkg_msg(ERROR, "Failed to read data from archive: %s (errno=%d)\n",
+ archive_error_string(a), archive_errno(a));
if (retries++ < 3) {
opkg_msg(NOTICE, "Retrying...");
goto retry;
@@ -111,8 +111,8 @@ static size_t read_data(struct archive *a, void *buffer, size_t len, int *eof)
return 0;

default:
- opkg_msg(ERROR, "Failed to read data from archive: %s\n",
- archive_error_string(a));
+ opkg_msg(ERROR, "Failed to read data from archive: %s (errno=%d)\n",
+ archive_error_string(a), archive_errno(a));
return 0;
}
}
@@ -269,8 +269,8 @@ static struct archive_entry *read_header(struct archive *ar, int *eof)
break;

case ARCHIVE_WARN:
- opkg_msg(NOTICE, "Warning when reading ar archive header: %s\n",
- archive_error_string(ar));
+ opkg_msg(NOTICE, "Warning when reading ar archive header: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
break;

case ARCHIVE_EOF:
@@ -279,16 +279,16 @@ static struct archive_entry *read_header(struct archive *ar, int *eof)
return NULL;

case ARCHIVE_RETRY:
- opkg_msg(ERROR, "Failed to read archive header: %s\n",
- archive_error_string(ar));
+ opkg_msg(ERROR, "Failed to read archive header: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
if (retries++ < 3)
goto retry;
else
return NULL;

default:
- opkg_msg(ERROR, "Failed to read archive header: %s\n",
- archive_error_string(ar));
+ opkg_msg(ERROR, "Failed to read archive header: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
return NULL;
}

@@ -370,22 +370,22 @@ static struct archive *open_disk(int flags)

r = archive_write_disk_set_options(disk, flags);
if (r == ARCHIVE_WARN)
- opkg_msg(NOTICE, "Warning when setting disk options: %s\n",
- archive_error_string(disk));
+ opkg_msg(NOTICE, "Warning when setting disk options: %s (errno=%d)\n",
+ archive_error_string(disk), archive_errno(disk));
else if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to set disk options: %s\n",
- archive_error_string(disk));
+ opkg_msg(ERROR, "Failed to set disk options: %s (errno=%d)\n",
+ archive_error_string(disk), archive_errno(disk));
goto err_cleanup;
}

r = archive_write_disk_set_standard_lookup(disk);
if (r == ARCHIVE_WARN)
opkg_msg(NOTICE,
- "Warning when setting user/group lookup functions: %s\n",
- archive_error_string(disk));
+ "Warning when setting user/group lookup functions: %s (errno=%d)\n",
+ archive_error_string(disk), archive_errno(disk));
else if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to set user/group lookup functions: %s\n",
- archive_error_string(disk));
+ opkg_msg(ERROR, "Failed to set user/group lookup functions: %s (errno=%d)\n",
+ archive_error_string(disk), archive_errno(disk));
goto err_cleanup;
}

@@ -425,13 +425,15 @@ static int extract_entry(struct archive *a, struct archive_entry *entry,
break;

case ARCHIVE_WARN:
- opkg_msg(NOTICE, "Warning when extracting archive entry '%s': %s\n",
- archive_entry_pathname(entry), archive_error_string(a));
+ opkg_msg(NOTICE, "Warning when extracting archive entry '%s': %s (errno=%d)\n",
+ archive_entry_pathname(entry), archive_error_string(a),
+ archive_errno(a));
break;

case ARCHIVE_RETRY:
- opkg_msg(ERROR, "Failed to extract archive entry '%s': %s\n",
- archive_entry_pathname(entry), archive_error_string(a));
+ opkg_msg(ERROR, "Failed to extract archive entry '%s': %s (errno=%d)\n",
+ archive_entry_pathname(entry), archive_error_string(a),
+ archive_errno(a));
if (retries++ < 3) {
opkg_msg(NOTICE, "Retrying...\n");
goto retry;
@@ -439,8 +441,9 @@ static int extract_entry(struct archive *a, struct archive_entry *entry,
return -1;

default:
- opkg_msg(ERROR, "Failed to extract archive entry '%s': %s\n",
- archive_entry_pathname(entry), archive_error_string(a));
+ opkg_msg(ERROR, "Failed to extract archive entry '%s': %s (errno=%d)\n",
+ archive_entry_pathname(entry), archive_error_string(a),
+ archive_errno(a));
return -1;
}

@@ -508,8 +511,8 @@ static struct archive *open_outer(const char *filename)
/* Outer package is in 'ar' format, uncompressed. */
r = archive_read_support_format_ar(outer);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Ar format not supported: %s\n",
- archive_error_string(outer));
+ opkg_msg(ERROR, "Ar format not supported: %s (errno=%d)\n",
+ archive_error_string(outer), archive_errno(outer));
goto err_cleanup;
}
r = archive_read_support_filter_gzip(outer);
@@ -524,16 +527,16 @@ static struct archive *open_outer(const char *filename)
}
r = archive_read_support_format_tar(outer);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Tar format not supported: %s\n",
- archive_error_string(outer));
+ opkg_msg(ERROR, "Tar format not supported: %s (errno=%d)\n",
+ archive_error_string(outer), archive_errno(outer));
goto err_cleanup;
}

r = archive_read_open_filename(outer, filename, EXTRACT_BUFFER_LEN);
if (r != ARCHIVE_OK)
{
- opkg_msg(ERROR, "Failed to open package '%s': %s\n", filename,
- archive_error_string(outer));
+ opkg_msg(ERROR, "Failed to open package '%s': %s (errno=%d)\n",
+ filename, archive_error_string(outer), archive_errno(outer));
goto err_cleanup;
}
return outer;
@@ -626,22 +629,22 @@ static struct archive *open_inner(struct archive *outer)

r = archive_read_support_format_tar(inner);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Tar format not supported: %s\n",
- archive_error_string(outer));
+ opkg_msg(ERROR, "Tar format not supported: %s (errno=%d)\n",
+ archive_error_string(outer), archive_errno(outer));
goto err_cleanup;
}

r = archive_read_support_format_empty(inner);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Empty format not supported: %s\n",
- archive_error_string(inner));
+ opkg_msg(ERROR, "Empty format not supported: %s (errno=%d)\n",
+ archive_error_string(inner), archive_errno(inner));
goto err_cleanup;
}

r = archive_read_open(inner, data, NULL, inner_read, inner_close);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to open inner archive: %s\n",
- archive_error_string(inner));
+ opkg_msg(ERROR, "Failed to open inner archive: %s (errno=%d)\n",
+ archive_error_string(inner), archive_errno(inner));
return NULL;
}

@@ -732,30 +735,30 @@ static struct archive *open_compressed_file(const char *filename)
*/
opkg_msg(INFO, "Gzip support provided by external program.\n");
} else if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Gzip format not supported: %s\n",
- archive_error_string(ar));
+ opkg_msg(ERROR, "Gzip format not supported: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
goto err_cleanup;
}

r = archive_read_support_format_raw(ar);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Raw format not supported: %s\n",
- archive_error_string(ar));
+ opkg_msg(ERROR, "Raw format not supported: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
goto err_cleanup;
}

r = archive_read_support_format_empty(ar);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Empty format not supported: %s\n",
- archive_error_string(ar));
+ opkg_msg(ERROR, "Empty format not supported: %s (errno=%d)\n",
+ archive_error_string(ar), archive_errno(ar));
goto err_cleanup;
}

/* Open input file and prepare for reading. */
r = archive_read_open_filename(ar, filename, EXTRACT_BUFFER_LEN);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to open compressed file '%s': %s\n", filename,
- archive_error_string(ar));
+ opkg_msg(ERROR, "Failed to open compressed file '%s': %s (errno=%d)\n",
+ filename, archive_error_string(ar), archive_errno(ar));
goto err_cleanup;
}

@@ -788,7 +791,8 @@ int gz_write_archive(const char *filename, const char *gz_filename)

r = archive_read_next_header2(disk, entry);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to read file: '%s' : %s", filename, archive_error_string(disk));
+ opkg_msg(ERROR, "Failed to read file: '%s' : %s (errno=%d)",
+ filename, archive_error_string(disk), archive_errno(disk));
goto cleanup;
}

@@ -797,7 +801,8 @@ int gz_write_archive(const char *filename, const char *gz_filename)

r = archive_write_header(a, entry);
if (r != ARCHIVE_OK) {
- opkg_msg(ERROR, "Failed to create compressed file: '%s' : %s", gz_filename, archive_error_string(a));
+ opkg_msg(ERROR, "Failed to create compressed file: '%s' : %s (errno=%d)",
+ gz_filename, archive_error_string(a), archive_errno(a));
goto cleanup;
}

--
2.20.1

Alex Stewart

unread,
Nov 18, 2021, 1:00:49 PM11/18/21
to opkg-...@googlegroups.com, Brenda Streiff
Pulled to master as commit e07e035bd179d8870fd13499ff4a7bc4053c89b1.

https://git.yoctoproject.org/cgit/cgit.cgi/opkg/commit/?id=e07e035bd179d8870fd13499ff4a7bc4053c89b1

Thanks,
Alex Stewart
Software Engineer - NI Real-Time OS
NI (National Instruments)

alex.s...@ni.com

Reply all
Reply to author
Forward
0 new messages