mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 09:01:02 +00:00
list: make LIST_FIND_TAIL work for empty lists
This commit is contained in:
@@ -75,20 +75,26 @@
|
||||
#define LIST_FIND_HEAD(name,item,head) \
|
||||
do { \
|
||||
typeof(*(item)) *_item = (item); \
|
||||
assert(_item); \
|
||||
while (_item->name##_prev) \
|
||||
_item = _item->name##_prev; \
|
||||
(head) = _item; \
|
||||
if (!_item) \
|
||||
(head) = NULL; \
|
||||
else { \
|
||||
while (_item->name##_prev) \
|
||||
_item = _item->name##_prev; \
|
||||
(head) = _item; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
/* Find the tail of the list */
|
||||
#define LIST_FIND_TAIL(name,item,tail) \
|
||||
do { \
|
||||
typeof(*(item)) *_item = (item); \
|
||||
assert(_item); \
|
||||
while (_item->name##_next) \
|
||||
_item = _item->name##_next; \
|
||||
(tail) = _item; \
|
||||
if (!_item) \
|
||||
(tail) = NULL; \
|
||||
else { \
|
||||
while (_item->name##_next) \
|
||||
_item = _item->name##_next; \
|
||||
(tail) = _item; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
/* Insert an item after another one (a = where, b = what) */
|
||||
|
||||
@@ -335,7 +335,7 @@ static int manager_clock_watch_setup(Manager *m) {
|
||||
assert(m);
|
||||
|
||||
m->event_clock_watch = sd_event_source_unref(m->event_clock_watch);
|
||||
m->clock_watch_fd = safe_close(m->clock_watch_fd);
|
||||
safe_close(m->clock_watch_fd);
|
||||
|
||||
m->clock_watch_fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
|
||||
if (m->clock_watch_fd < 0) {
|
||||
@@ -950,11 +950,8 @@ static int manager_add_server(Manager *m, const char *server) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (m->servers) {
|
||||
LIST_FIND_TAIL(names, m->servers, tail);
|
||||
LIST_INSERT_AFTER(names, m->servers, tail, n);
|
||||
} else
|
||||
LIST_PREPEND(names, m->servers, n);
|
||||
LIST_FIND_TAIL(names, m->servers, tail);
|
||||
LIST_INSERT_AFTER(names, m->servers, tail, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user