about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2023-11-19 15:19:47 +0100
committerThe 8472 <git@infinite-source.de>2023-11-19 15:19:47 +0100
commitf34e7f4768c21c5c8b178d3714eeed8be40502af (patch)
treea24d82966f69487d7bb8f322c3ccc322f3bfe289
parent12efa53b19aad30747f566787853e773797edb26 (diff)
downloadrust-f34e7f4768c21c5c8b178d3714eeed8be40502af.tar.gz
rust-f34e7f4768c21c5c8b178d3714eeed8be40502af.zip
Don't set cmsg fields in msghdr if we have no cmsg to send
-rw-r--r--library/std/src/sys/unix/process/process_unix.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs
index c4107e29390..ee86a5f88dd 100644
--- a/library/std/src/sys/unix/process/process_unix.rs
+++ b/library/std/src/sys/unix/process/process_unix.rs
@@ -698,11 +698,12 @@ impl Command {
 
             msg.msg_iov = &mut iov as *mut _ as *mut _;
             msg.msg_iovlen = 1;
-            msg.msg_controllen = mem::size_of_val(&cmsg.buf) as _;
-            msg.msg_control = &mut cmsg.buf as *mut _ as *mut _;
 
             // only attach cmsg if we successfully acquired the pidfd
             if pidfd >= 0 {
+                msg.msg_controllen = mem::size_of_val(&cmsg.buf) as _;
+                msg.msg_control = &mut cmsg.buf as *mut _ as *mut _;
+
                 let hdr = CMSG_FIRSTHDR(&mut msg as *mut _ as *mut _);
                 (*hdr).cmsg_level = SOL_SOCKET;
                 (*hdr).cmsg_type = SCM_RIGHTS;
@@ -719,7 +720,7 @@ impl Command {
             // so we get a consistent SEQPACKET order
             match cvt_r(|| libc::sendmsg(sock.as_raw(), &msg, 0)) {
                 Ok(0) => {}
-                _ => rtabort!("failed to communicate with parent process"),
+                other => rtabort!("failed to communicate with parent process. {:?}", other),
             }
         }
     }