Skip to content

Commit

Permalink
MINOR: protocol: always initialize the receivers list on registration
Browse files Browse the repository at this point in the history
Till now, protocols were required to self-initialize their receivers
list head, which is not very convenient, and is quite error prone.
Indeed, it's too easy to copy-paste a protocol definition and forget
to update the .receivers field to point to itself, resulting in mixed
lists. Let's just do that in protocol_register(). And while we're at
it, let's also zero the nb_receivers entry that works with it, so that
the protocol definition isn't required to pre-initialize stuff related
to internal book-keeping.
  • Loading branch information
wtarreau committed Aug 21, 2024
1 parent 0349741 commit 1cb3b0b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void protocol_register(struct protocol *proto)
BUG_ON(sock_family < 0 || sock_family >= AF_CUST_MAX);
BUG_ON(proto->proto_type >= PROTO_NUM_TYPES);

LIST_INIT(&proto->receivers);
proto->nb_receivers = 0;

HA_SPIN_LOCK(PROTO_LOCK, &proto_lock);
LIST_APPEND(&protocols, &proto->list);
__protocol_by_family[sock_family]
Expand Down

0 comments on commit 1cb3b0b

Please sign in to comment.