summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ngctl/msg.c
diff options
context:
space:
mode:
authorarchie <archie@FreeBSD.org>2000-06-20 18:51:38 +0000
committerarchie <archie@FreeBSD.org>2000-06-20 18:51:38 +0000
commitf1f4c483fe069bb5205af783ab7286e199e13e50 (patch)
treee85629626ce2b0c48a89acc911fe5678c322aa32 /usr.sbin/ngctl/msg.c
parent7743e6b8d993b6eacfeb5fda55117dcb76bdba9c (diff)
downloadFreeBSD-src-f1f4c483fe069bb5205af783ab7286e199e13e50.zip
FreeBSD-src-f1f4c483fe069bb5205af783ab7286e199e13e50.tar.gz
When the 'msg' command is used from the command line, check for a
synchronous reply, and display it (if any) before exiting. Requested by: phk
Diffstat (limited to 'usr.sbin/ngctl/msg.c')
-rw-r--r--usr.sbin/ngctl/msg.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/usr.sbin/ngctl/msg.c b/usr.sbin/ngctl/msg.c
index 926024e..4ae5171 100644
--- a/usr.sbin/ngctl/msg.c
+++ b/usr.sbin/ngctl/msg.c
@@ -40,7 +40,7 @@
#include "ngctl.h"
-#define BUF_SIZE 1024
+#define BUF_SIZE 4096
static int MsgCmd(int ac, char **av);
@@ -80,7 +80,67 @@ MsgCmd(int ac, char **av)
return(CMDRTN_ERROR);
}
+ /* See if a synchronous reply awaits */
+ {
+ struct timeval tv;
+ fd_set rfds;
+
+ FD_ZERO(&rfds);
+ FD_SET(csock, &rfds);
+ memset(&tv, 0, sizeof(tv));
+ switch (select(csock + 1, &rfds, NULL, NULL, &tv)) {
+ case -1:
+ err(EX_OSERR, "select");
+ case 0:
+ break;
+ default:
+ MsgRead();
+ break;
+ }
+ }
+
/* Done */
return(CMDRTN_OK);
}
+/*
+ * Read and display the next incoming control message
+ */
+void
+MsgRead()
+{
+ u_char buf[2 * sizeof(struct ng_mesg) + BUF_SIZE];
+ struct ng_mesg *const m = (struct ng_mesg *)buf;
+ struct ng_mesg *const ascii = (struct ng_mesg *)m->data;
+ char path[NG_PATHLEN+1];
+
+ /* Get incoming message (in binary form) */
+ if (NgRecvMsg(csock, m, sizeof(buf), path) < 0) {
+ warn("recv incoming message");
+ return;
+ }
+
+ /* Ask originating node to convert message to ASCII */
+ if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
+ NGM_BINARY2ASCII, m, sizeof(*m) + m->header.arglen) < 0
+ || NgRecvMsg(csock, m, sizeof(buf), NULL) < 0) {
+ printf("Rec'd %s %d from \"%s\":\n",
+ (m->header.flags & NGF_RESP) != 0 ? "response" : "command",
+ m->header.cmd, path);
+ if (m->header.arglen == 0)
+ printf("No arguments\n");
+ else
+ DumpAscii(m->data, m->header.arglen);
+ return;
+ }
+
+ /* Display message in ASCII form */
+ printf("Rec'd %s \"%s\" (%d) from \"%s\":\n",
+ (ascii->header.flags & NGF_RESP) != 0 ? "response" : "command",
+ ascii->header.cmdstr, ascii->header.cmd, path);
+ if (*ascii->data != '\0')
+ printf("Args:\t%s\n", ascii->data);
+ else
+ printf("No arguments\n");
+}
+
OpenPOWER on IntegriCloud