summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* Use pointers instead of offsets in ul_buffer_tGergely Nagy2012-06-222-30/+31
| | | | | | | This avoids various additions and subtractions on the fast path. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Simplify extending the bufferGergely Nagy2012-06-221-26/+35
| | | | | | | | | Most of the callers know how much the buffer needs extending, so don't ask them for the total size: new _ul_buffer_reserve_size replaces _ul_buffer_ensure_size, and the fast path is now inlined. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Change return type of _ul_str_escapeMiloslav Trmač2012-06-221-11/+8
| | | | | | | Use an integer instead of pointer, like in the other cases in buffer.c. We won't need the return value in the future. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Fix error handling in buffer.cGergely Nagy2012-06-223-28/+33
| | | | | | | | | | | | | * Don't lose old msg on realloc() failure * Don't dereference NULL on failure when buffer = (...) if (!buffer) { buffer->len = orig_len; ...} * To avoid the above pattern, use integer return values: "buffer" itself will not change in any case. * Add missing error handling Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Use a static exception mapGergely Nagy2012-06-221-51/+25
| | | | | | | | | | | | | | * Make the map static, read-only and preinitialized, to avoid thread-safety problems. * Invert the map, making it non-zero for exceptional characters (so that non-exceptional characters don't need to be mentioned) * Tighten the set of exceptional characters, so that most of ASCII goes through the fast path. This increases the speed of test_perf_* by 7.7-20.6%. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Don't use \f in JSONGergely Nagy2012-06-221-4/+0
| | | | | | | JSON-c 0.9 does not parse \f, so fall back to \uNNNN for now. Signed-off-by: Miloslav Trmač <mitr@redhat.com> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix 1-byte heap overflow in ul_buffer_finalizeMiloslav Trmač2012-06-221-2/+6
| | | | Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Remove an unnecessary pointer to arrayMiloslav Trmač2012-06-221-1/+1
| | | | | | | Be a little more explicit instead of relying on the compiler to optimize the variable away. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
* Reduce the number of memory allocationsGergely Nagy2012-04-291-14/+32
| | | | | | | | Make the string escape use an ul_buffer_t, to avoid unnecessary memory allocations. This greatly reduces the number of mallocs made, and thus results in a noticable increase in speed. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Generate the manual page if rst2man is presentGergely Nagy2012-04-291-0/+9
| | | | | | | If rst2man is present at configure time, generate the manual page with it, which is to be included in the dist tarball too. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Preparations for 0.2.1Gergely Nagy2012-04-281-2/+2
| | | | | | | Bump software and library interface versions, and start adding NEWS entries. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Add a closelog() wrapper to clear the environmentGergely Nagy2012-04-284-1/+25
| | | | | | | | | | | | | | | Our openlog() wrapper fills in a couple of variables, and those were kept around even after a closelog(), and thus, affected ul_format() calls even after a closelog(). This in turn, made one of the test cases fail, as that was relying on the default behaviour, which was modified due to an openlog() in an earlier test case. We now wrap closelog() aswell, and NULL out our settings to get a clean state, and add a test case to verify this behaviour aswell. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Resolve facility & priority properlyGergely Nagy2012-04-201-6/+11
| | | | | | | | | | | | | | | | | | | The priority passed to the syslog() call can contain a facility embedded, so we need to extract it to find both the facility and the priority. This also means that the facility set at openlog()-time can be overridden later, so _find_facility() has to take the priority value into account. This patch makes libumberlog do just the above: extract both priority and facility from the priority passed to syslog(), and if facility is 0, use the default set at openlog()-time, if any. Added a test case to test this expected behaviour. Reported-by: Peter Czanik <czanik@balabit.hu> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Properly reset the JSON buffer in all cases.Gergely Nagy2012-04-201-2/+2
| | | | | | | | | | | | Previously the JSON buffer was only reset when ul_vformat() was called, but not everything goes through that, so some messages ended up being garbled. The proper thing to do is to reset in _ul_vformat(), as everything goes through that, and that's the right place to do this anyway. Reported-by: Peter Czanik <czanik@balabit.hu> Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Free up the JSON buffer on exitGergely Nagy2012-04-161-0/+7
| | | | | | | This adds a destructor that simply frees up the JSON buffer, so that to not upset valgrind and similar tools too much. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Improve string escape performance a littleGergely Nagy2012-04-161-6/+5
| | | | | | | | | | Instead of escaping a string, returning a new one and running strlen() on that, use an output variable to store the length, since we can easily calculate that during the escape process anyway. This should shave off a tiny bit of CPU time. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Correctly NULL-terminate the JSON buffer in all cases.Gergely Nagy2012-04-131-1/+1
| | | | | | | When finalizing the JSON buffer, always NULL-terminate it at the appropriate length. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Do use the library versionGergely Nagy2012-04-131-2/+3
| | | | | | | | | | We had the LUL_* variables set in lib/Makefile.am, but they weren't used. Now they are. While there, bumped LUL_CURRENT to 1, because of the dropped JSON dependency. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement string escaping.Gergely Nagy2012-04-131-7/+132
| | | | | | With this patch, both JSON keys and values will be properly escaped. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix ul_buffer_finalize().Gergely Nagy2012-04-131-2/+3
| | | | | | | ul_buffer_finalize() was off by one, and instead of overriding the trailing ",", it overwrote the trailing nul-byte. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Format JSON ourselves, without json-c.Gergely Nagy2012-04-134-80/+196
| | | | | | | | | | | To make the library thinner, we now format JSON ourselves: there was so little we used from json-c, that doing it ourselves is lighter and faster. With this commit, we have the architecture in place, with only a few little things remaining to be done, such as escaping string values. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Properly handle va_lists, by copying.Gergely Nagy2012-04-081-4/+97
| | | | | | | | | | | | Up until now, the library abused that passing va_list around without copying works on various architectures. On others, that does not. To remedy the issue, the library now parses format strings itself, and copies va_list. This makes it work on all architectures, independent on the internal implementation of va_list, and preserves both API and ABI. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Override __syslog_chk if present, always.Gergely Nagy2012-04-021-20/+2
| | | | | | | Always override __syslog_chk if it is supported by the system, instead of only overriding it if using fortification. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Put the man page in section 3, instead of 1Gergely Nagy2012-03-241-1/+1
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Include the linker script and the API docs in the dist tarball.Gergely Nagy2012-03-241-0/+2
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix infinite recursion on FreeBSD.Gergely Nagy2012-03-241-1/+20
| | | | | | | | | | | | | | On FreeBSD, syslog() calls vsyslog(), our own replacement version. So when from syslog(), we call our vsyslog(), which calls the old syslog(), that ends up calling our own vsyslog() again. To work around this issue, use a thread-local static variable that signals whether we're recursing, and if we are, then call the old vsyslog from the new one, thus breaking the loop. This makes the library function correctly on FreeBSD too. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* More portability fixesGergely Nagy2012-03-241-1/+1
| | | | | | | | | | While on glibc-based systems, we need -ldl (for dlopen) and -lrt (for clock_gettime), FreeBSD has both in libc, and does not have these extra libraries. Teach configure about this. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Portability fixesGergely Nagy2012-03-241-3/+3
| | | | | | | | Use _POSIX_HOST_NAME_MAX instead of HOST_NAME_MAX: both Linux and FreeBSD have the former, but FreeBSD does not have HOST_NAME_MAX in limits.h Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Allow compilation with clang, too.Gergely Nagy2012-03-241-0/+2
| | | | | | | Clang tries to expand the syslog and vsyslog macros when we define our overrides. To work around that, #undef them first. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement proper error handling.Gergely Nagy2012-03-243-63/+139
| | | | | | | | | | | | | | | | Instead of calling abort() if vasprintf() fails, and ignoring possible errors from the JSON library, do handle errors reasonably sanely: check return values, and return an error state from all functions, and propagate it up to the application level, too. This means that the legacy overrides will silently fail, but set errno appropriately in case serializing to JSON fails, and do what the system libc does with syslog otherwise. The new functions can return NULL or non-zero on error, which the application can then handle as it sees fit. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Mark a few internal functions inline.Gergely Nagy2012-03-241-5/+5
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Fix a formatting mistake in the API docs.Gergely Nagy2012-03-231-2/+2
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Convert the manual page from roff to rst.Gergely Nagy2012-03-233-213/+139
| | | | | | | The advantage of ReStructuredText is that this allows converting the same source into different formats, such as HTML. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Rename the project to libumberlogGergely Nagy2012-03-237-174/+171
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement wrappers for __syslog_chk, when appropriate.Gergely Nagy2012-03-221-0/+33
| | | | | | | | | | | | | When compiled with __USE_FORTIFY_LEVEL, software using <syslog.h> will use the __syslog_chk function instead of syslog(), so we need to wrap that too. To do this properly, the library will wrap __syslog_chk when built with fortification, and use that from both the syslog() and the __syslog_chk() overrides. If built without, it will use the standard syslog() function. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Do not version overridden symbols.Gergely Nagy2012-03-221-5/+0
| | | | | | | Versioning overridden symbols kills the ability to LD_PRELOAD the library. Oops! Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Check (v)asprintf() return values.Gergely Nagy2012-03-221-2/+4
| | | | | | | If (v)asprintf() returns an error, abort() away, because we can't possibly proceed. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Hide two inherited symbols with the version script.Gergely Nagy2012-03-221-0/+5
| | | | | | | We inherit facilitynames and prioritynames from syslog.h, but they should not be exported by us. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement and enable symbol versioning.Gergely Nagy2012-03-222-0/+18
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Rename the manual page to libcee-syslog.3Gergely Nagy2012-03-222-1/+1
| | | | Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* libcee-syslog.pc: Don't add -ldl to Libs.Gergely Nagy2012-03-221-1/+1
| | | | | | | libcee-syslog is linked against -ldl, no need to add it to the pkg-config .pc file's Libs: too. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Add a manual page.Gergely Nagy2012-03-222-0/+213
| | | | | | | Wrote a manual page explaining the new functions, and also mentioning the few we override. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Add the timestamp to the JSON payload too.Gergely Nagy2012-03-213-1/+27
| | | | | | Add high-precision timestamp to the JSON payload (unless disabled). Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Include the hostname in the JSON payload.Gergely Nagy2012-03-211-0/+13
| | | | | | | Include the hostname (as returned by gethostname()) in the JSON payload. Test case updated to verify this. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Export the syslog() wrapper as cee_legacy_syslog()Gergely Nagy2012-03-212-5/+9
| | | | | | | For documentation purposes, and for clarity, export the syslog() wrappers under a sensible name. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement a test suite.Gergely Nagy2012-03-201-1/+1
| | | | | | | | The test suite uses cee_format() to format the messages, and parses the resulting string back into JSON, and verifies that certain key values are what we expect them to be. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Implement UID/GID discovery.Gergely Nagy2012-03-202-3/+30
| | | | | | | | | | | We now cache the uid and gid upon openlog(), and add it to the automatic fields unless discovery is disabled. The caching can be turned off by passing either the LOG_CEE_NOCACHE or the LOG_CEE_NOCACHE_UID flag to openlog(). The latter also disables caching the gid. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
* Add the identity to the automatically added fields.Gergely Nagy2012-03-201-0/+3
| | | | | | | | | The identity, as set by the first argument to openlog() can be cached away, and later used as the program name (that's pretty much how syslogds treat it, too), so add it to the list of automatically discovered fields. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Implement a wrapper for setlogmask()Gergely Nagy2012-03-202-2/+23
| | | | | | | | Since we'd like to avoid doing useless work during logging, wrap setlogmask() too, and save the mask set, so during _cee_vsyslog(), we can bail out early, if our priority is not set in the mask. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
* Implement LOG_CEE_NOCACHE & LOG_CEE_NODISCOVER handlingGergely Nagy2012-03-201-1/+13
| | | | | | | | | When LOG_CEE_NODISCOVER is set during openlog(), then don't do any discovery, not even when the value is cached. When _NOCACHE is set, then do not use the cached values for properties that can change during runtime, and their new value can be detected at runtime too. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>