diff options
author | ru <ru@FreeBSD.org> | 2004-01-27 21:52:52 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2004-01-27 21:52:52 +0000 |
commit | 63673a77c62cba3a0d5d7dd14598251962a825cf (patch) | |
tree | 5e63f8550269f9b83d76d8bfe7d46bd7fcc78cae /usr.sbin/ngctl/msg.c | |
parent | adc82a1e80759afba2cfae432d4ee1ca190be1f4 (diff) | |
download | FreeBSD-src-63673a77c62cba3a0d5d7dd14598251962a825cf.zip FreeBSD-src-63673a77c62cba3a0d5d7dd14598251962a825cf.tar.gz |
Get rid of all (but one in write.c) static size buffers.
Diffstat (limited to 'usr.sbin/ngctl/msg.c')
-rw-r--r-- | usr.sbin/ngctl/msg.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/usr.sbin/ngctl/msg.c b/usr.sbin/ngctl/msg.c index 50843ae..c71815b 100644 --- a/usr.sbin/ngctl/msg.c +++ b/usr.sbin/ngctl/msg.c @@ -40,8 +40,6 @@ #include "ngctl.h" -#define BUF_SIZE 4096 - static int MsgCmd(int ac, char **av); const struct ngcmd msg_cmd = { @@ -58,9 +56,9 @@ const struct ngcmd msg_cmd = { static int MsgCmd(int ac, char **av) { - char buf[BUF_SIZE]; + char *buf; char *path, *cmdstr; - int i; + int i, len; /* Get arguments */ if (ac < 3) @@ -69,16 +67,24 @@ MsgCmd(int ac, char **av) cmdstr = av[2]; /* Put command and arguments back together as one string */ + for (len = 1, i = 3; i < ac; i++) + len += strlen(av[i]) + 1; + if ((buf = malloc(len)) == NULL) { + warn("malloc"); + return(CMDRTN_ERROR); + } for (*buf = '\0', i = 3; i < ac; i++) { snprintf(buf + strlen(buf), - sizeof(buf) - strlen(buf), " %s", av[i]); + len - strlen(buf), " %s", av[i]); } /* Send it */ if (NgSendAsciiMsg(csock, path, "%s%s", cmdstr, buf) < 0) { + free(buf); warn("send msg"); return(CMDRTN_ERROR); } + free(buf); /* See if a synchronous reply awaits */ { @@ -109,13 +115,12 @@ MsgCmd(int ac, char **av) 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; + struct ng_mesg *m, *m2; + struct ng_mesg *ascii; char path[NG_PATHSIZ]; /* Get incoming message (in binary form) */ - if (NgRecvMsg(csock, m, sizeof(buf), path) < 0) { + if (NgAllocRecvMsg(csock, &m, path) < 0) { warn("recv incoming message"); return; } @@ -123,7 +128,7 @@ MsgRead() /* 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) { + || NgAllocRecvMsg(csock, &m2, NULL) < 0) { printf("Rec'd %s %d from \"%s\":\n", (m->header.flags & NGF_RESP) != 0 ? "response" : "command", m->header.cmd, path); @@ -131,10 +136,13 @@ MsgRead() printf("No arguments\n"); else DumpAscii(m->data, m->header.arglen); + free(m); return; } /* Display message in ASCII form */ + free(m); + ascii = (struct ng_mesg *)m2->data; printf("Rec'd %s \"%s\" (%d) from \"%s\":\n", (ascii->header.flags & NGF_RESP) != 0 ? "response" : "command", ascii->header.cmdstr, ascii->header.cmd, path); @@ -142,5 +150,6 @@ MsgRead() printf("Args:\t%s\n", ascii->data); else printf("No arguments\n"); + free(m2); } |