allocate peer_fds on stack
This commit is contained in:
@@ -50,13 +50,12 @@ int open_socket(char * pathname) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int * fds_from_msg(struct msghdr *msg) {
|
||||
int * fds_from_msg(struct msghdr *msg, int * peer_fds) {
|
||||
// * there may be multiple SCM_RIGHTS messages
|
||||
// * we expect three fds
|
||||
// * if we get some number other than three, we should
|
||||
// close them and return NULL
|
||||
|
||||
int *peer_fds = (int *) calloc(3, sizeof(int));
|
||||
for (struct cmsghdr* cmsg = CMSG_FIRSTHDR(msg);
|
||||
cmsg != NULL;
|
||||
cmsg = CMSG_NXTHDR(msg, cmsg)) {
|
||||
@@ -218,16 +217,18 @@ int main(int argc, char **argv)
|
||||
if(pollfds[0].revents) {
|
||||
if(find_peer(0)) {
|
||||
int len = recvmsg(socket, &msg , 0);
|
||||
int *peer_fds = fds_from_msg(&msg);
|
||||
char *argline = malloc(len);
|
||||
if(! argline) {
|
||||
die("malloc failed");
|
||||
}
|
||||
memmove(argline, buf, len);
|
||||
int peer_fds[3];
|
||||
if(fds_from_msg(&msg, peer_fds)) {
|
||||
char *argline = malloc(len);
|
||||
if(! argline) {
|
||||
die("malloc failed");
|
||||
}
|
||||
memmove(argline, buf, len);
|
||||
|
||||
pid_t child_pid = fork_lua(L, argline, len, peer_fds);
|
||||
if(child_pid >= 0) {
|
||||
register_peer(child_pid, &peer_addr, msg.msg_namelen);
|
||||
pid_t child_pid = fork_lua(L, argline, len, peer_fds);
|
||||
if(child_pid >= 0) {
|
||||
register_peer(child_pid, &peer_addr, msg.msg_namelen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user