[1/6] batctl: Consume genl ACKs after setting reads

Message ID 20210510194945.103735-2-sven@narfation.org (mailing list archive)
State Accepted, archived
Delegated to: Simon Wunderlich
Headers
Series batctl: Use shared batadv genl socket for requests |

Commit Message

Sven Eckelmann May 10, 2021, 7:49 p.m. UTC
  The kernel is sending an ACK after an successful read request via the
batadv genl socket. This ack must be consumed manually after the actual
message was processed. Otherwise, the next user of the socket can get
confused by the unexpected ACK in the socket queue.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 sys.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
  

Patch

diff --git a/sys.c b/sys.c
index 6dd8c10..f1dc275 100644
--- a/sys.c
+++ b/sys.c
@@ -107,7 +107,13 @@  int sys_simple_nlquery(struct state *state, enum batadv_nl_commands nl_cmd,
 	nl_send_auto_complete(state->sock, msg);
 	nlmsg_free(msg);
 
-	nl_recvmsgs(state->sock, state->cb);
+	if (callback) {
+		ret = nl_recvmsgs(state->sock, state->cb);
+		if (ret < 0)
+			return ret;
+	}
+
+	nl_wait_for_ack(state->sock);
 
 	return result;
 }