[syslog-ng] [PATCH (3.4)] tfuuid: New template function to generate UUIDs.
Gergely Nagy
algernon at balabit.hu
Fri Feb 3 11:45:08 CET 2012
Balazs Scheidler <bazsi at balabit.hu> writes:
>> diff --git a/configure.in b/configure.in
>> index 734d703..83b81ac 100644
>> --- a/configure.in
>> +++ b/configure.in
>> +if test "x$enable_uuid" = "xyes" || test "x$enable_uuid" = "xauto"; then
>> + PKG_CHECK_MODULES(UUID, uuid, with_uuid="yes", with_uuid="no")
>> + if test "x$with_uuid" = "xno" && test "x$enable_uuid" = "xyes"; then
>> + AC_MSG_ERROR([Could not find libuuid, and uuid support was explicitly enabled.])
>> + fi
>> + enable_uuid="$with_uuid"
>> +fi
>> +
>
> If possible I'd avoid using another library, there'd a random based UUID
> generator function in modules/dbparser/patternize.c
>
> Can you check if libuuid does anything more than that?
libuuid does something more: by default, it uses /dev/urandom, or if
that's not available, then falls back to a combination of current time,
local ethernet MAC address (if available) and pseudo-random data.
I think it's a bit more through than the implementation in
patternize.c. On the other hand, I can make the module work with either:
libuuid, if available, the implementation in patternize otherwise.
I'll see how much work it would be to be able to choose. If it's too
much effort, I'll just switch over to your implementation of uuid
instead.
>> +static void
>> +tf_uuid(LogMessage *msg, gint argc, GString *argv[], GString *result)
>> +{
>> + uuid_t uuid;
>> + gint i;
>> +
>> + uuid_generate (uuid);
>> +
>> + for (i = 0; i < sizeof (uuid); i++)
>> + g_string_append_printf (result, "%02x", uuid[i]);
>> +}
>
> hmm... UUID's have a well defined format (with some dashes) and I'd
> prefer to use that, if the function is called $(uuid).
Acknowledged, I changed my local copy to use uuid_unparse(), which is
both faster (doesn't append byte-by-byte, but generates a dashed hex
string, and appends it to result in one go), and uses the dashed format.
If I end up with using libuuid, then that'll use the dashed format too.
>> +
>> +TEMPLATE_FUNCTION_SIMPLE(tf_uuid);
>> +
>> +static Plugin tfuuid_plugins[] =
>> + {
>> + TEMPLATE_FUNCTION_PLUGIN(tf_uuid, "UUID"),
>> + TEMPLATE_FUNCTION_PLUGIN(tf_uuid, "uuid"),
>> + };
>
> why use two names? I'd prefer the lower case one.
I convinced my fingers that $(uuid) is fine, so I'll remove the other
one.
--
|8]
More information about the syslog-ng
mailing list