summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-08-10 16:35:40 +0200
committerGergely Nagy <algernon@balabit.hu>2012-08-10 16:53:06 +0200
commit1c707ea147d40ff2119b430512fe4e45c564ce32 (patch)
treef834b2cca835a4f8aa634117a0c15380fc2a70a6
parent2c5439de564f25e4a839586f2f764d2ad8c99968 (diff)
downloadlibumberlog-1c707ea147d40ff2119b430512fe4e45c564ce32.tar.gz
libumberlog-1c707ea147d40ff2119b430512fe4e45c564ce32.tar.xz
libumberlog-1c707ea147d40ff2119b430512fe4e45c564ce32.zip
Support disabling discovery for the LD_PRELOAD variant
When compiled with --disable-discovery, the LD_PRELOAD variant will have automatic field discovery disabled. This does not affect the linkable library, which always has them enabled by default. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
-rw-r--r--configure.ac12
-rw-r--r--lib/umberlog.c8
-rw-r--r--lib/umberlog.rst3
-rw-r--r--t/test_umberlog.c31
-rw-r--r--t/test_umberlog_preload.c7
5 files changed, 58 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index e8b984e..233382a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,6 +73,18 @@ AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_SIZE_T
+AC_ARG_ENABLE([discovery],
+ AS_HELP_STRING([--disable-discovery],
+ [Do not add automatically-discovered field when using the LD_PRELOAD lib [default=enabled]]),
+ [], [enable_discovery=yes])
+if test "x$enable_discovery" != xno; then
+ DEFAULT_DISCOVER_FLAGS=LOG_UL_ALL
+else
+ DEFAULT_DISCOVER_FLAGS=LOG_UL_NODISCOVER
+fi
+AC_DEFINE_UNQUOTED([DEFAULT_DISCOVER_FLAGS], [$DEFAULT_DISCOVER_FLAGS],
+ [Default flags if ul_set_log_flags() is not called])
+
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [package name])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [version number])
diff --git a/lib/umberlog.c b/lib/umberlog.c
index be0b9d6..b64d715 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -77,7 +77,13 @@ static struct
char hostname[_POSIX_HOST_NAME_MAX + 1];
} ul_process_data =
{
- PTHREAD_MUTEX_INITIALIZER, 0, LOG_USER, NULL,
+ PTHREAD_MUTEX_INITIALIZER,
+#if __UL_PRELOAD__
+ DEFAULT_DISCOVER_FLAGS,
+#else
+ LOG_UL_ALL,
+#endif
+ LOG_USER, NULL,
-1, (uid_t)-1, (gid_t)-1, { 0, }
};
diff --git a/lib/umberlog.rst b/lib/umberlog.rst
index 5ae5c7c..7c3af99 100644
--- a/lib/umberlog.rst
+++ b/lib/umberlog.rst
@@ -125,7 +125,8 @@ flags:
LOG_UL_ALL
Enable all automatically discovered fields. This is the default
- setting.
+ setting for the linkable library, but for the LD_PRELOAD variant, it
+ can be changed at the library's configure time.
LOG_UL_NODISCOVER
Disable all automatic discovery, and only include the *message*,
diff --git a/t/test_umberlog.c b/t/test_umberlog.c
index 07b2d17..291bf43 100644
--- a/t/test_umberlog.c
+++ b/t/test_umberlog.c
@@ -15,6 +15,36 @@
#include <check.h>
+START_TEST (test_defaults)
+{
+ char *msg;
+ struct json_object *jo;
+
+ char host[_POSIX_HOST_NAME_MAX + 1];
+
+ ul_openlog ("umberlog/test_defaults", 0, LOG_LOCAL0);
+
+ msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ gethostname (host, _POSIX_HOST_NAME_MAX);
+
+ verify_value (jo, "msg", "hello, I'm test_defaults!");
+ verify_value (jo, "facility", "local0");
+ verify_value (jo, "priority", "debug");
+ verify_value (jo, "program", "umberlog/test_defaults");
+ verify_value_exists (jo, "pid");
+ verify_value_exists (jo, "uid");
+ verify_value_exists (jo, "gid");
+ verify_value_exists (jo, "timestamp");
+ verify_value (jo, "host", host);
+
+ json_object_put (jo);
+
+ ul_closelog ();
+}
+END_TEST
START_TEST (test_overrides)
{
@@ -229,6 +259,7 @@ main (void)
s = suite_create ("Umberlog (linkable) functional testsuite");
ft = tcase_create ("Basic tests");
+ tcase_add_test (ft, test_defaults);
tcase_add_test (ft, test_overrides);
tcase_add_test (ft, test_ul_openlog);
tcase_add_test (ft, test_ul_openlog_flag_ignore);
diff --git a/t/test_umberlog_preload.c b/t/test_umberlog_preload.c
index 09d3210..d4db896 100644
--- a/t/test_umberlog_preload.c
+++ b/t/test_umberlog_preload.c
@@ -202,6 +202,7 @@ START_TEST (test_openlog_defaults)
if (getgid () != 0)
verify_value_differs (jo, "gid", "0");
verify_value_differs (jo, "host", "");
+
json_object_put (jo);
closelog ();
@@ -219,10 +220,12 @@ main (void)
s = suite_create ("Umberlog (LD_PRELOAD) functional testsuite");
ft = tcase_create ("Basic tests");
+#if DEFAULT_DISCOVER_FLAGS == LOG_UL_ALL
tcase_add_test (ft, test_openlog_defaults);
tcase_add_test (ft, test_simple);
- tcase_add_test (ft, test_additional_fields);
tcase_add_test (ft, test_discover_priority);
+#endif
+ tcase_add_test (ft, test_additional_fields);
#ifdef HAVE_PARSE_PRINTF_FORMAT
tcase_add_test (ft, test_positional_params);
#endif
@@ -230,7 +233,9 @@ main (void)
bt = tcase_create ("Bug tests");
tcase_add_test (bt, test_json_escape);
+#if DEFAULT_DISCOVER_FLAGS == LOG_UL_ALL
tcase_add_test (bt, test_facprio);
+#endif
suite_add_tcase (s, bt);
sr = srunner_create (s);