syslog-ng/syslog-ng-3.3.4-afunix.c-di...

89 lines
3.2 KiB
Diff

From: Balazs Scheidler <bazsi@balabit.hu>
Date: Wed, 14 Dec 2011 14:21:05 +0000 (+0100)
Subject: afunix: clarified error messages in case of a failure
X-Git-Url: http://git.balabit.hu/?p=bazsi%2Fsyslog-ng-3.3.git;a=commitdiff_plain;h=606c8cc0b10aa4e877f70726b707402d100bb0f9
afunix: clarified error messages in case of a failure
On Fedora systems, syslog-ng was configured to use unix-stream() /dev/log
whereas systemd supplied a unix-dgram() one, which caused difficult to
diagnose problems.
This patch adds further logging to this case and causes syslog-ng to fail
with an error message if it finds that /dev/log is using an incorrect
socket type.
Reported-By: Michal Schmidt <mschmidt@redhat.com>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
---
diff --git a/modules/afsocket/afunix.c b/modules/afsocket/afunix.c
index cd86798..8145f1a 100644
--- a/modules/afsocket/afunix.c
+++ b/modules/afsocket/afunix.c
@@ -75,7 +75,7 @@ static gboolean
afunix_sd_acquire_socket(AFSocketSourceDriver *s, gint *result_fd)
{
AFUnixSourceDriver *self = (AFUnixSourceDriver *) s;
- gint fd, fds, t, r;
+ gint fd, fds;
*result_fd = -1;
fd = -1;
@@ -100,13 +100,40 @@ afunix_sd_acquire_socket(AFSocketSourceDriver *s, gint *result_fd)
{
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + fds; fd++)
{
- t = (self->super.flags & AFSOCKET_STREAM) ? SOCK_STREAM : SOCK_DGRAM;
- r = sd_is_socket_unix(fd, t, -1, self->filename, 0);
- if (r == 1)
+ /* check if any type is available */
+ if (sd_is_socket_unix(fd, 0, -1, self->filename, 0))
{
- *result_fd = fd;
- break;
- }
+ int type = (self->super.flags & AFSOCKET_STREAM) ? SOCK_STREAM : SOCK_DGRAM;
+
+ /* check if it matches our idea of the socket type */
+ if (sd_is_socket_unix(fd, type, -1, self->filename, 0))
+ {
+ *result_fd = fd;
+ break;
+ }
+ else
+ {
+ msg_error("The systemd supplied UNIX domain socket is of a different type, check the configured driver and the matching systemd unit file",
+ evt_tag_str("filename", self->filename),
+ evt_tag_int("systemd-sock-fd", fd),
+ evt_tag_str("expecting", type == SOCK_STREAM ? "unix-stream()" : "unix-dgram()"),
+ NULL);
+ return FALSE;
+ }
+ }
+ else
+ {
+
+ /* systemd passed an fd we didn't really care about. This is
+ * not an error, but might be worth mentioning it at the debug
+ * level.
+ */
+
+ msg_debug("Ignoring systemd supplied fd as it is not a UNIX domain socket",
+ evt_tag_str("filename", self->filename),
+ evt_tag_int("systemd-sock-fd", fd),
+ NULL);
+ }
}
}
else
@@ -123,7 +150,7 @@ afunix_sd_acquire_socket(AFSocketSourceDriver *s, gint *result_fd)
}
else
{
- msg_debug("Failed to acquire systemd socket, opening nevertheless",
+ msg_debug("Failed to acquire systemd socket, trying to open ourselves",
evt_tag_str("filename", self->filename),
NULL);
}