MCPcopy Create free account
hub / github.com/F-Stack/f-stack / MsgCmd

Function MsgCmd

tools/ngctl/msg.c:66–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64};
65
66static int
67MsgCmd(int ac, char **av)
68{
69 char *buf;
70 char *path, *cmdstr;
71 int i, len;
72
73 /* Get arguments */
74 if (ac < 3)
75 return (CMDRTN_USAGE);
76 path = av[1];
77 cmdstr = av[2];
78
79 /* Put command and arguments back together as one string */
80 for (len = 1, i = 3; i < ac; i++)
81 len += strlen(av[i]) + 1;
82 if ((buf = malloc(len)) == NULL) {
83 warn("malloc");
84 return (CMDRTN_ERROR);
85 }
86 for (*buf = '\0', i = 3; i < ac; i++) {
87 snprintf(buf + strlen(buf),
88 len - strlen(buf), " %s", av[i]);
89 }
90
91 /* Send it */
92 if (NgSendAsciiMsg(csock, path, "%s%s", cmdstr, buf) < 0) {
93 free(buf);
94 warn("send msg");
95 return (CMDRTN_ERROR);
96 }
97 free(buf);
98
99#ifndef FSTACK
100 /* See if a synchronous reply awaits */
101 {
102 struct timeval tv;
103 fd_set rfds;
104
105 FD_ZERO(&rfds);
106 FD_SET(csock, &rfds);
107 memset(&tv, 0, sizeof(tv));
108 switch (select(csock + 1, &rfds, NULL, NULL, &tv)) {
109 case -1:
110 err(EX_OSERR, "select");
111 case 0:
112 break;
113 default:
114 MsgRead();
115 break;
116 }
117 }
118#else
119 MsgRead();
120#endif
121
122 /* Done */
123 return (CMDRTN_OK);

Callers

nothing calls this directly

Calls 7

mallocFunction · 0.85
snprintfFunction · 0.85
NgSendAsciiMsgFunction · 0.85
memsetFunction · 0.85
selectFunction · 0.85
MsgReadFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected