From 2df050ad10cde5237970359fd21baf0c0d33b83c Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Thu, 12 Jan 2006 19:14:40 +0000 Subject: In the splnet(9) times netgraph(4) was synchronous and if a message had been replied, the reply was always delivered to the originator synchronously. With introduction of netgraph item callbacks and a wait channel with mutex in ng_socket(4), we have fixed the problem with ngctl(8) returning earlier than the command has been proceeded by target node. But still ngctl(8) can return prior to the reply has arrived to its node. To fix this: - Introduce a new flag for netgraph(4) messages - NGM_HASREPLY. This flag is or'ed with message like NGM_READONLY. - In netgraph userland library if we have sent a message with NGM_HASREPLY flag, then select(2) until reply comes. - Mark appropriate generic commands with NGM_HASREPLY flag, gathering them into one enum {}. Bump generic cookie. --- lib/libnetgraph/msg.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/libnetgraph/msg.c') diff --git a/lib/libnetgraph/msg.c b/lib/libnetgraph/msg.c index cca957325ab2..8b4ca06a7166 100644 --- a/lib/libnetgraph/msg.c +++ b/lib/libnetgraph/msg.c @@ -232,6 +232,22 @@ NgDeliverMsg(int cs, const char *path, goto done; } + /* Wait for reply if there should be one. */ + if (msg->header.cmd & NGM_HASREPLY) { + fd_set rfds; + int n; + + FD_ZERO(&rfds); + FD_SET(cs, &rfds); + n = select(cs + 1, &rfds, NULL, NULL, NULL); + if (n == -1) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("select"); + rtn = -1; + } + } + done: /* Done */ free(buf); /* OK if buf is NULL */ -- cgit v1.3