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 | |
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.
-rw-r--r-- | usr.sbin/ngctl/dot.c | 28 | ||||
-rw-r--r-- | usr.sbin/ngctl/list.c | 9 | ||||
-rw-r--r-- | usr.sbin/ngctl/main.c | 6 | ||||
-rw-r--r-- | usr.sbin/ngctl/msg.c | 29 | ||||
-rw-r--r-- | usr.sbin/ngctl/show.c | 12 | ||||
-rw-r--r-- | usr.sbin/ngctl/types.c | 9 |
6 files changed, 56 insertions, 37 deletions
diff --git a/usr.sbin/ngctl/dot.c b/usr.sbin/ngctl/dot.c index 42969be..d5a43f5 100644 --- a/usr.sbin/ngctl/dot.c +++ b/usr.sbin/ngctl/dot.c @@ -57,9 +57,8 @@ const struct ngcmd dot_cmd = { static int DotCmd(int ac, char **av) { - u_char nlrbuf[16 * 1024]; - struct ng_mesg *const nlresp = (struct ng_mesg *)nlrbuf; - struct namelist *const nlist = (struct namelist *)nlresp->data; + struct ng_mesg *nlresp; + struct namelist *nlist; FILE *f = stdout; int ch; u_int i; @@ -99,11 +98,12 @@ DotCmd(int ac, char **av) warn("send listnodes msg"); goto error; } - if (NgRecvMsg(csock, nlresp, sizeof(nlrbuf), NULL) < 0) { + if (NgAllocRecvMsg(csock, &nlresp, NULL) < 0) { warn("recv listnodes msg"); goto error; } + nlist = (struct namelist *)nlresp->data; fprintf(f, "graph netgraph {\n"); /* TODO: implement rank = same or subgraphs at some point */ fprintf(f, "\tedge [ weight = 1.0 ];\n"); @@ -125,10 +125,9 @@ DotCmd(int ac, char **av) fprintf(f, "\t};\n"); for (i = 0; i < nlist->numnames; i++) { - u_char hlrbuf[16 * 1024]; - struct ng_mesg *const hlresp = (struct ng_mesg *)hlrbuf; - struct hooklist *const hlist = (struct hooklist *)hlresp->data; - struct nodeinfo *const ninfo = &hlist->nodeinfo; + struct ng_mesg *hlresp; + struct hooklist *hlist; + struct nodeinfo *ninfo; char path[NG_PATHSIZ]; u_int j; @@ -138,16 +137,22 @@ DotCmd(int ac, char **av) /* Get node info and hook list */ if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0) < 0) { + free(nlresp); warn("send listhooks msg"); goto error; } - if (NgRecvMsg(csock, hlresp, sizeof(hlrbuf), NULL) < 0) { + if (NgAllocRecvMsg(csock, &hlresp, NULL) < 0) { + free(nlresp); warn("recv listhooks msg"); goto error; } - if (ninfo->hooks == 0) + hlist = (struct hooklist *)hlresp->data; + ninfo = &hlist->nodeinfo; + if (ninfo->hooks == 0) { + free(hlresp); continue; + } fprintf(f, "\tnode [ shape = octagon, fontsize = 10 ] {\n"); for (j = 0; j < ninfo->hooks; j++) @@ -174,11 +179,12 @@ DotCmd(int ac, char **av) (uintmax_t)hlist->link[j].nodeinfo.id, hlist->link[j].peerhook); } - + free(hlresp); } fprintf(f, "};\n"); + free(nlresp); if (f != stdout) (void)fclose(f); return (CMDRTN_OK); diff --git a/usr.sbin/ngctl/list.c b/usr.sbin/ngctl/list.c index ee4a84b..e905d33 100644 --- a/usr.sbin/ngctl/list.c +++ b/usr.sbin/ngctl/list.c @@ -54,9 +54,8 @@ const struct ngcmd list_cmd = { static int ListCmd(int ac, char **av) { - u_char rbuf[16 * 1024]; - struct ng_mesg *const resp = (struct ng_mesg *) rbuf; - struct namelist *const nlist = (struct namelist *) resp->data; + struct ng_mesg *resp; + struct namelist *nlist; int named_only = 0; int ch, rtn = CMDRTN_OK; u_int k; @@ -91,12 +90,13 @@ ListCmd(int ac, char **av) warn("send msg"); return(CMDRTN_ERROR); } - if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { warn("recv msg"); return(CMDRTN_ERROR); } /* Show each node */ + nlist = (struct namelist *) resp->data; printf("There are %d total %snodes:\n", nlist->numnames, named_only ? "named " : ""); for (k = 0; k < nlist->numnames; k++) { @@ -110,6 +110,7 @@ ListCmd(int ac, char **av) } /* Done */ + free(resp); return (rtn); } diff --git a/usr.sbin/ngctl/main.c b/usr.sbin/ngctl/main.c index 7fac106..fcd61df 100644 --- a/usr.sbin/ngctl/main.c +++ b/usr.sbin/ngctl/main.c @@ -236,13 +236,12 @@ DoInteractive(void) /* Display any incoming data packet */ if (FD_ISSET(dsock, &rfds)) { - u_char buf[8192]; + u_char *buf; char hook[NG_HOOKSIZ]; int rl; /* Read packet from socket */ - if ((rl = NgRecvData(dsock, - buf, sizeof(buf), hook)) < 0) + if ((rl = NgAllocRecvData(dsock, &buf, hook)) < 0) err(EX_OSERR, "reading hook \"%s\"", hook); if (rl == 0) errx(EX_OSERR, "EOF from hook \"%s\"?", hook); @@ -250,6 +249,7 @@ DoInteractive(void) /* Write packet to stdout */ printf("Rec'd data packet on hook \"%s\":\n", hook); DumpAscii(buf, rl); + free(buf); } /* Get any user input */ 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); } diff --git a/usr.sbin/ngctl/show.c b/usr.sbin/ngctl/show.c index a413a94..6921ec4 100644 --- a/usr.sbin/ngctl/show.c +++ b/usr.sbin/ngctl/show.c @@ -57,10 +57,9 @@ static int ShowCmd(int ac, char **av) { char *path; - u_char rbuf[16 * 1024]; - struct ng_mesg *const resp = (struct ng_mesg *) rbuf; - struct hooklist *const hlist = (struct hooklist *) resp->data; - struct nodeinfo *const ninfo = &hlist->nodeinfo; + struct ng_mesg *resp; + struct hooklist *hlist; + struct nodeinfo *ninfo; int ch, no_hooks = 0; /* Get options */ @@ -94,12 +93,14 @@ ShowCmd(int ac, char **av) warn("send msg"); return(CMDRTN_ERROR); } - if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { warn("recv msg"); return(CMDRTN_ERROR); } /* Show node information */ + hlist = (struct hooklist *) resp->data; + ninfo = &hlist->nodeinfo; if (!*ninfo->name) snprintf(ninfo->name, sizeof(ninfo->name), "%s", UNNAMED); printf(" Name: %-15s Type: %-15s ID: %08x Num hooks: %d\n", @@ -125,6 +126,7 @@ ShowCmd(int ac, char **av) peer->type, idbuf, link->peerhook); } } + free(resp); return(CMDRTN_OK); } diff --git a/usr.sbin/ngctl/types.c b/usr.sbin/ngctl/types.c index b22e9a4..30c5c16 100644 --- a/usr.sbin/ngctl/types.c +++ b/usr.sbin/ngctl/types.c @@ -52,9 +52,8 @@ const struct ngcmd types_cmd = { static int TypesCmd(int ac, char **av __unused) { - u_char rbuf[16 * 1024]; - struct ng_mesg *const resp = (struct ng_mesg *) rbuf; - struct typelist *const tlist = (struct typelist *) resp->data; + struct ng_mesg *resp; + struct typelist *tlist; int rtn = CMDRTN_OK; u_int k; @@ -72,12 +71,13 @@ TypesCmd(int ac, char **av __unused) warn("send msg"); return(CMDRTN_ERROR); } - if (NgRecvMsg(csock, resp, sizeof(rbuf), NULL) < 0) { + if (NgAllocRecvMsg(csock, &resp, NULL) < 0) { warn("recv msg"); return(CMDRTN_ERROR); } /* Show each type */ + tlist = (struct typelist *) resp->data; printf("There are %d total types:\n", tlist->numtypes); if (tlist->numtypes > 0) { printf("%15s Number of living nodes\n", "Type name"); @@ -89,6 +89,7 @@ TypesCmd(int ac, char **av __unused) } /* Done */ + free(resp); return (rtn); } |