summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-08-08 20:59:21 +1000
committerAmitay Isaacs <amitay@samba.org>2014-10-28 05:42:04 +0100
commit8ed3ff456ca7a239cba399e6b6d12c468a608db2 (patch)
treef56ea2fe46ee677aae2668919475317bbd9333ad
parenta6e770ec287b78ec2d2c85a6d0c22a67bd03a4d6 (diff)
downloadsamba-8ed3ff456ca7a239cba399e6b6d12c468a608db2.tar.gz
ctdb-logging: Add logging via UDP to 127.0.0.1:514 to syslog backend
This has most of the advantages of the old logd with none of the complexity of the extra process. There are several good syslog implementations that can listen on the UDP port. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rwxr-xr-xctdb/config/ctdbd_wrapper3
-rwxr-xr-xctdb/config/functions2
-rw-r--r--ctdb/doc/ctdbd.1.xml14
-rw-r--r--ctdb/doc/ctdbd.conf.5.xml15
-rw-r--r--ctdb/server/ctdb_logging_syslog.c72
5 files changed, 98 insertions, 8 deletions
diff --git a/ctdb/config/ctdbd_wrapper b/ctdb/config/ctdbd_wrapper
index dd9d66f4956..b22d1169a04 100755
--- a/ctdb/config/ctdbd_wrapper
+++ b/ctdb/config/ctdbd_wrapper
@@ -187,6 +187,9 @@ start()
fi
case "$CTDB_LOGGING" in
+ syslog:udp)
+ logger -t ctdbd "CTDB is being run with ${CTDB_LOGGING}. If nothing is logged then check your syslogd configuration"
+ ;;
syslog|syslog:*) : ;;
file:*)
logger -t ctdbd "CTDB is being run without syslog enabled. Logs will be in ${CTDB_LOGGING#file:}"
diff --git a/ctdb/config/functions b/ctdb/config/functions
index 5c9497dc520..53a36dc3355 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -102,6 +102,8 @@ script_log ()
} >>"$_file"
;;
*)
+ # Handle all syslog:* variants here too. There's no tool to do
+ # the lossy things, so just use logger.
logger -t "ctdbd: ${_tag}" $*
;;
esac
diff --git a/ctdb/doc/ctdbd.1.xml b/ctdb/doc/ctdbd.1.xml
index fdf03d1e3a0..fabc2446fab 100644
--- a/ctdb/doc/ctdbd.1.xml
+++ b/ctdb/doc/ctdbd.1.xml
@@ -179,6 +179,20 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>udp</term>
+ <listitem>
+ <para>
+ CTDB will log to syslog via UDP to
+ localhost:514. The syslog daemon must be
+ configured to listen on (at least)
+ localhost:514. Most syslog daemons will log
+ the messages with hostname "localhost" - this
+ is a limitation of the implementation, for
+ compatibility with more syslog daemons.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</listitem>
</varlistentry>
diff --git a/ctdb/doc/ctdbd.conf.5.xml b/ctdb/doc/ctdbd.conf.5.xml
index 95f37021d3a..7eb191e6059 100644
--- a/ctdb/doc/ctdbd.conf.5.xml
+++ b/ctdb/doc/ctdbd.conf.5.xml
@@ -268,6 +268,21 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>udp</term>
+ <listitem>
+ <para>
+ CTDB will log to syslog via UDP to
+ localhost:514. The syslog daemon must be
+ configured to listen on (at least)
+ localhost:514. Most implementations will log
+ the messages against hostname "localhost" -
+ this is a limit of the implementation for
+ compatibility with more syslog daemon
+ implementations.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</listitem>
</varlistentry>
diff --git a/ctdb/server/ctdb_logging_syslog.c b/ctdb/server/ctdb_logging_syslog.c
index 6a3fd02c162..cc699556e33 100644
--- a/ctdb/server/ctdb_logging_syslog.c
+++ b/ctdb/server/ctdb_logging_syslog.c
@@ -72,11 +72,14 @@ static int ctdb_debug_to_syslog_level(int dbglevel)
/* It appears that some syslog daemon implementations do not allow a
* hostname when messages are sent via a Unix domain socket, so omit
- * it. A timestamp could be sent but rsyslogd on Linux limits the
- * timestamp logged to the precision that was received on /dev/log.
- * It seems sane to send degenerate RFC3164 messages without a header
- * at all, so that the daemon will generate high resolution timestamps
- * if configured. */
+ * it. Similarly, syslogd on FreeBSD does not understand the hostname
+ * part of the header, even when logging via UDP. Note that most
+ * implementations will log messages against "localhost" when logging
+ * via UDP. A timestamp could be sent but rsyslogd on Linux limits
+ * the timestamp logged to the precision that was received on
+ * /dev/log. It seems sane to send degenerate RFC3164 messages
+ * without a header at all, so that the daemon will generate high
+ * resolution timestamps if configured. */
static int format_rfc3164(int dbglevel, struct ctdb_syslog_sock_state *state,
const char *str, char *buf, int bsize)
{
@@ -127,6 +130,23 @@ ctdb_syslog_sock_state_destructor(struct ctdb_syslog_sock_state *state)
return 0;
}
+static struct ctdb_syslog_sock_state *
+ctdb_log_setup_syslog_common(TALLOC_CTX *mem_ctx,
+ const char *app_name)
+{
+ struct ctdb_syslog_sock_state *state;
+
+ state = talloc_zero(mem_ctx, struct ctdb_syslog_sock_state);
+ if (state == NULL) {
+ return NULL;
+ }
+ state->fd = -1;
+ state->app_name = app_name;
+ talloc_set_destructor(state, ctdb_syslog_sock_state_destructor);
+
+ return state;
+}
+
static int ctdb_log_setup_syslog_un(TALLOC_CTX *mem_ctx,
const char *app_name)
{
@@ -134,7 +154,7 @@ static int ctdb_log_setup_syslog_un(TALLOC_CTX *mem_ctx,
struct sockaddr_un dest;
int ret;
- state = talloc_zero(mem_ctx, struct ctdb_syslog_sock_state);
+ state = ctdb_log_setup_syslog_common(mem_ctx, app_name);
if (state == NULL) {
return ENOMEM;
}
@@ -157,9 +177,41 @@ static int ctdb_log_setup_syslog_un(TALLOC_CTX *mem_ctx,
}
set_blocking(state->fd, false);
- state->app_name = app_name;
+ debug_set_callback(state, ctdb_log_to_syslog_sock);
+
+ return 0;
+}
+
+static int ctdb_log_setup_syslog_udp(TALLOC_CTX *mem_ctx,
+ const char *app_name)
+{
+ struct ctdb_syslog_sock_state *state;
+ struct sockaddr_in dest;
+ int ret;
+
+ state = ctdb_log_setup_syslog_common(mem_ctx, app_name);
+ if (state == NULL) {
+ return ENOMEM;
+ }
+
+ state->fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (state->fd == -1) {
+ int save_errno = errno;
+ talloc_free(state);
+ return save_errno;
+ }
+
+ dest.sin_family = AF_INET;
+ dest.sin_port = htons(514);
+ dest.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ ret = connect(state->fd,
+ (struct sockaddr *)&dest, sizeof(dest));
+ if (ret == -1) {
+ int save_errno = errno;
+ talloc_free(state);
+ return save_errno;
+ }
- talloc_set_destructor(state, ctdb_syslog_sock_state_destructor);
debug_set_callback(state, ctdb_log_to_syslog_sock);
return 0;
@@ -191,6 +243,10 @@ static int ctdb_log_setup_syslog(TALLOC_CTX *mem_ctx,
ctdb_log_setup_syslog_un(mem_ctx, app_name);
return 0;
}
+ if (strcmp(method, "udp") == 0) {
+ ctdb_log_setup_syslog_udp(mem_ctx, app_name);
+ return 0;
+ }
return EINVAL;
}