patches/avahi: improve log message in chroot communication

The following log message does not stem from an error in setting up the
chroot, but from the internal communication with the chroot.  This patch
adds the crucial missing file name in the log message.

  avahi-daemon[3590]: chroot.c: open() failed: No such file or directory

So that when the user sees this message, e.g., with "/etc/resolv.conf"
as the arg. to open(), they can be certain; "ah, no a biggie, we have
not created that file yet!"

Issue #896

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2025-02-28 16:10:24 +01:00
parent 77c321daa3
commit 05c197c457
3 changed files with 62 additions and 2 deletions
@@ -1,7 +1,7 @@
From 74ec0f8335f811e4f5becc8bbea4a52af4d3e749 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Tue, 17 Sep 2024 04:08:12 +0200
Subject: [PATCH 1/2] On SIGTERM, allow dispatcher to process event before
Subject: [PATCH 1/3] On SIGTERM, allow dispatcher to process event before
exiting
Organization: Addiva Elektronik
@@ -1,7 +1,7 @@
From bceb724d328f156efa4ad18f26f1760504bd093d Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Wed, 27 Nov 2024 08:44:57 +0100
Subject: [PATCH 2/2] avahi-daemon: allow adjusting log level
Subject: [PATCH 2/3] avahi-daemon: allow adjusting log level
Organization: Addiva Elektronik
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
@@ -0,0 +1,60 @@
From 50ddfbefe5ac4d87040cb177e7cf432d4da04e97 Mon Sep 17 00:00:00 2001
From: Joachim Wiberg <troglobit@gmail.com>
Date: Wed, 26 Feb 2025 17:42:08 +0100
Subject: [PATCH 3/3] avahi-daemon: improve error reporting in chroot
communication
Organization: Addiva Elektronik
Improve logging of error in chroot communication by including the
filename in the log message. Instead of this:
avahi-daemon[3590]: chroot.c: open() failed: No such file or directory
log this:
avahi-daemon[3590]: chroot.c: open(/etc/resolv.conf) failed: No such file or directory
Which on a system with resolvconf would make the sysadmin a lot calmer,
since the file had not yet been created at boot.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
---
avahi-daemon/chroot.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c
index ccd56be..fbaad69 100644
--- a/avahi-daemon/chroot.c
+++ b/avahi-daemon/chroot.c
@@ -237,12 +237,13 @@ static int helper_main(int fd) {
case AVAHI_CHROOT_GET_RECORD_BROWSER_INTROSPECT:
#endif
case AVAHI_CHROOT_GET_RESOLV_CONF: {
+ const char *fn = get_file_name_table[(int) command];
int payload;
- if ((payload = open(get_file_name_table[(int) command], O_RDONLY)) < 0) {
+ if ((payload = open(fn, O_RDONLY)) < 0) {
uint8_t c = AVAHI_CHROOT_FAILURE;
- avahi_log_error(__FILE__": open() failed: %s", strerror(errno));
+ avahi_log_error(__FILE__": open(%s) failed: %s", fn, strerror(errno));
if (write(fd, &c, sizeof(c)) != sizeof(c)) {
avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno));
@@ -262,9 +263,11 @@ static int helper_main(int fd) {
case AVAHI_CHROOT_UNLINK_SOCKET:
case AVAHI_CHROOT_UNLINK_PID: {
+ const char *fn = unlink_file_name_table[(int) command];
uint8_t c = AVAHI_CHROOT_SUCCESS;
- unlink(unlink_file_name_table[(int) command]);
+ if (unlink(fn) && errno != ENOENT)
+ avahi_log_error(__FILE__": unlink(%s) failed: %s", fn, strerror(errno));
if (write(fd, &c, sizeof(c)) != sizeof(c)) {
avahi_log_error(__FILE__": write() failed: %s\n", strerror(errno));
--
2.43.0