aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-06-17 11:55:04 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-06-21 15:32:44 +0200
commitdba7f0f5cee06dcfc205b0284ba19c2651f594c4 (patch)
tree94e8aea617e0e611bdca363e301038b2c47fa129 /util.c
parent92a22fef93a528030669e357a32c19f143a2d3b5 (diff)
downloadpasst-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar.gz
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar.bz2
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar.lz
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar.xz
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.tar.zst
passt-dba7f0f5cee06dcfc205b0284ba19c2651f594c4.zip
treewide: Replace strerror() calls
Now that we have logging functions embedding perror() functionality, we can make _some_ calls more terse by using them. In many places, the strerror() calls are still more convenient because, for example, they are used in flow debugging functions, or because the return code variable of interest is not 'errno'. While at it, convert a few error messages from a scant perror style to proper failure descriptions. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'util.c')
-rw-r--r--util.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/util.c b/util.c
index 77448ec..dd2e57f 100644
--- a/util.c
+++ b/util.c
@@ -315,7 +315,7 @@ void bitmap_or(uint8_t *dst, size_t size, const uint8_t *a, const uint8_t *b)
void ns_enter(const struct ctx *c)
{
if (setns(c->pasta_netns_fd, CLONE_NEWNET))
- die("setns() failed entering netns: %s", strerror(errno));
+ die_perror("setns() failed entering netns");
}
/**
@@ -330,10 +330,8 @@ bool ns_is_init(void)
bool ret = true;
int fd;
- if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) {
- die("Can't determine if we're in init namespace: %s",
- strerror(errno));
- }
+ if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0)
+ die_perror("Can't determine if we're in init namespace");
if (read(fd, buf, sizeof(root_uid_map)) != sizeof(root_uid_map) - 1 ||
strncmp(buf, root_uid_map, sizeof(root_uid_map)))
@@ -509,7 +507,7 @@ int write_file(const char *path, const char *buf)
size_t len = strlen(buf);
if (fd < 0) {
- warn("Could not open %s: %s", path, strerror(errno));
+ warn_perror("Could not open %s", path);
return -1;
}
@@ -517,7 +515,7 @@ int write_file(const char *path, const char *buf)
ssize_t rc = write(fd, buf, len);
if (rc <= 0) {
- warn("Couldn't write to %s: %s", path, strerror(errno));
+ warn_perror("Couldn't write to %s", path);
break;
}