Only set control msg metadata when actually sending a control msg

This commit is contained in:
Kovid Goyal 2022-07-07 14:16:47 +05:30
parent 90f3c0f9af
commit 5d1cf49fb6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -294,12 +294,17 @@ create_launch_msg(int argc, char *argv[]) {
sio(stdin, STDIN_FILENO); sio(stdout, STDOUT_FILENO); sio(stderr, STDERR_FILENO);
#undef sio
w("finish", "");
if (num_fds) {
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&launch_msg_container);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fds[0]) * num_fds);
memcpy(CMSG_DATA(cmsg), fds, num_fds * sizeof(fds[0]));
launch_msg_container.msg_controllen = cmsg->cmsg_len;
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
} else {
launch_msg_container.msg_controllen = 0;
launch_msg_container.msg_control = 0;
}
return true;
#undef w
}