Skip to content

Commit f34e7f4

Browse files
committed
Don't set cmsg fields in msghdr if we have no cmsg to send
1 parent 12efa53 commit f34e7f4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/std/src/sys/unix/process/process_unix.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,12 @@ impl Command {
698698

699699
msg.msg_iov = &mut iov as *mut _ as *mut _;
700700
msg.msg_iovlen = 1;
701-
msg.msg_controllen = mem::size_of_val(&cmsg.buf) as _;
702-
msg.msg_control = &mut cmsg.buf as *mut _ as *mut _;
703701

704702
// only attach cmsg if we successfully acquired the pidfd
705703
if pidfd >= 0 {
704+
msg.msg_controllen = mem::size_of_val(&cmsg.buf) as _;
705+
msg.msg_control = &mut cmsg.buf as *mut _ as *mut _;
706+
706707
let hdr = CMSG_FIRSTHDR(&mut msg as *mut _ as *mut _);
707708
(*hdr).cmsg_level = SOL_SOCKET;
708709
(*hdr).cmsg_type = SCM_RIGHTS;
@@ -719,7 +720,7 @@ impl Command {
719720
// so we get a consistent SEQPACKET order
720721
match cvt_r(|| libc::sendmsg(sock.as_raw(), &msg, 0)) {
721722
Ok(0) => {}
722-
_ => rtabort!("failed to communicate with parent process"),
723+
other => rtabort!("failed to communicate with parent process. {:?}", other),
723724
}
724725
}
725726
}

0 commit comments

Comments
 (0)