Commit graph

24 commits

Author SHA1 Message Date
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Ruben Kerkhof 6ff8806e1d Fix a few typos in log messages 2014-08-29 09:28:19 -04:00
Tom Gundersen 9021bb9f93 sd-event: name event sources used in libraries
This should help in debugging failing event sources.
2014-08-28 21:19:17 +02:00
Kay Sievers 3a43da2832 time-util: add and use USEC/NSEC_INFINIY 2014-07-29 13:20:20 +02:00
Tom Gundersen 66269b05cf rtnl: message - read group membership of incoming messages 2014-05-10 20:56:37 +02:00
Tom Gundersen 897e184c7d rtnl: change from bitmask to enum for rtnl groups
The bitmask is deprecated in the kernel, so move to the new interface. At the moment
this does not make a difference for us, but it avoids having to change the API in the future.
2014-05-10 20:56:37 +02:00
Tom Gundersen 6190b9f9d2 sd-rtnl: log when queues are exhausted 2014-04-20 10:28:28 +02:00
Tom Gundersen 4e996881b2 sd-rtnl: message - concatenate multi-part messages from different packets 2014-04-19 16:47:52 +02:00
Tom Gundersen a88f77c406 sd-rtnl: socket_read - use a read buffer
Rather than allocating/freeing memory for each message read, keep a global read buffer
in the rtnl object. Also, rather than using a fixed size, peek at the pending message
header to get the message size and reallocate as necessary.
2014-04-14 17:53:21 +02:00
Tom Gundersen bc078e7163 sd-rtnl: use SO_PASSCRED
This unifies the socket handling with other sd-* libraries.
2014-04-11 00:52:23 +02:00
Tom Gundersen 1b89cf5648 sd-rtnl: don't drop multi-part messages
We still only return the first message part in callback/synchronous calls.
2014-04-10 19:40:48 +02:00
Tom Gundersen 77768cbabc sd-rtnl: use GREEDY_REALLOC for message queues 2014-04-10 19:00:36 +02:00
Tom Gundersen 689703f618 sd-rtnl: modernize a bit 2014-03-31 14:43:34 +02:00
Tom Gundersen 8c57830308 sd-rtnl: message - don't reference associated rtnl object
The object is not currently used, so just drop the refenence. If/when we end up
using the object in the future, we must make sure to deal with possible mutual
references between rtnl busses and their queued messages; as is done in sd-bus.
2014-03-28 00:50:50 +01:00
Lennart Poettering 79e16ce3bf networkd: fix a couple of memory leaks 2014-03-24 23:46:13 +01:00
Tom Gundersen 3dd215e056 sd-rtnl: add sd_rtnl_message_enter_container()
Extend rta_offset_tb into a stack of offset tables, one for each parent of the
current container, and make sd_rtnl_message_{enter,exit}_container() pop/push
to this stack.

Also make sd_rtnl_message_rewind() parse the top-level container, and use this
when reading a message from the socket.

This changes the API by dropping the now redundant sd_rtnl_message_read()
method.
2014-03-24 16:59:30 +01:00
Lennart Poettering 6a0f1f6d5a sd-event: rework API to support CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM, too 2014-03-24 02:58:41 +01:00
David Herrmann 22fdeadcc0 sd-rtnl: fix self-reference leaks
Like sd-bus, sd-rtnl can have self-references through queued messages. In
particular, each queued message has the following self-ref loop:
  rtnl->wqueue[i]->rtnl == rtnl
Same is true for "rqueue".

When sd_rtnl_unref() gets called, we must therefore make sure we correctly
consider each self-reference when deciding to destroy the object. For each
queued message, there _might_ be one ref. However, rtnl-messages can be
created _without_ a bus-reference, therefore we need to verify the
actually required ref-count.

Once we know exactly how many self-refs exist, and we verified none of the
queued messages has external references, we can destruct the object.
We must immediately drop our own reference, then flush all queues and
destroy the bus object. Otherwise, each sd_rtnl_message_unref() call would
recurse into the same destruction logic as they enter with the same
rtnl-refcnt.

Note: We really should verify _all_ queued messages have m->rtnl set to
      the bus they're queued on. If that's given, we can change:
        if (REFCNT_GET(rtnl->n_ref) <= refs)
      to
        if (REFCNT_GET(rtnl->n_ref) == refs)
      and thus avoid recalculating the required refs for each message we
      remove from the queue during destruction.
2014-03-22 18:00:03 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Tom Gundersen 1f0db3ed88 sd-rtnl: never treat broadcasts as replies
Otherwise the sequence number of a broadcast may match the sequence number of a
pending unicast message and cause confusion.
2014-03-16 13:05:04 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Lennart Poettering cf6a891173 rtnl: drop "sd_" prefix from cleanup macros
The "sd_" prefix is supposed to be used on exported symbols only, and
not in the middle of names. Let's drop it from the cleanup macros hence,
to make things simpler.

The bus cleanup macros don't carry the "sd_" either, so this brings the
APIs a bit nearer.
2014-02-13 03:44:14 +01:00
Tom Gundersen 3815f36f05 sd-rtnl: beef up rtnl-util a bit 2014-01-30 14:30:39 +01:00
Tom Gundersen 607553f930 libsystemd: split up into subdirs
We still only produce on .so, but let's keep the sources separate to make things a bit
less messy.
2014-01-21 14:41:35 +01:00
Renamed from src/libsystemd/sd-rtnl.c (Browse further)