about summary refs log tree commit diff
path: root/library/std/src/sys/unix/process/process_common.rs
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-03-19 14:50:24 +0100
committerGitHub <noreply@github.com>2022-03-19 14:50:24 +0100
commit3545003b290102a15e28ad5dd3af10c39fdcac6c (patch)
tree727ba9514119953c40b9c8f3c4ac32fbbccc3c88 /library/std/src/sys/unix/process/process_common.rs
parent31535841701e0bf7ef33998024376f2cedd8b3e3 (diff)
parentb628497b7cf8235a7f74fa037e86051fa78b5188 (diff)
downloadrust-3545003b290102a15e28ad5dd3af10c39fdcac6c.tar.gz
rust-3545003b290102a15e28ad5dd3af10c39fdcac6c.zip
Rollup merge of #93858 - krallin:process-process_group, r=dtolnay
Add a `process_group` method to UNIX `CommandExt`

- Tracking issue: #93857
- RFC: https://github.com/rust-lang/rfcs/pull/3228

Add a `process_group` method to `std::os::unix::process::CommandExt` that
allows setting the process group id (i.e. calling `setpgid`) in the child, thus
enabling users to set process groups while leveraging the `posix_spawn` fast
path.
Diffstat (limited to 'library/std/src/sys/unix/process/process_common.rs')
-rw-r--r--library/std/src/sys/unix/process/process_common.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
index 97985ddd331..27bee714f5b 100644
--- a/library/std/src/sys/unix/process/process_common.rs
+++ b/library/std/src/sys/unix/process/process_common.rs
@@ -18,7 +18,7 @@ use crate::sys_common::IntoInner;
 #[cfg(not(target_os = "fuchsia"))]
 use crate::sys::fs::OpenOptions;
 
-use libc::{c_char, c_int, gid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS};
+use libc::{c_char, c_int, gid_t, pid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS};
 
 cfg_if::cfg_if! {
     if #[cfg(target_os = "fuchsia")] {
@@ -82,6 +82,7 @@ pub struct Command {
     stderr: Option<Stdio>,
     #[cfg(target_os = "linux")]
     create_pidfd: bool,
+    pgroup: Option<pid_t>,
 }
 
 // Create a new type for argv, so that we can make it `Send` and `Sync`
@@ -145,6 +146,7 @@ impl Command {
             stdin: None,
             stdout: None,
             stderr: None,
+            pgroup: None,
         }
     }
 
@@ -167,6 +169,7 @@ impl Command {
             stdout: None,
             stderr: None,
             create_pidfd: false,
+            pgroup: None,
         }
     }
 
@@ -202,6 +205,9 @@ impl Command {
     pub fn groups(&mut self, groups: &[gid_t]) {
         self.groups = Some(Box::from(groups));
     }
+    pub fn pgroup(&mut self, pgroup: pid_t) {
+        self.pgroup = Some(pgroup);
+    }
 
     #[cfg(target_os = "linux")]
     pub fn create_pidfd(&mut self, val: bool) {
@@ -265,6 +271,10 @@ impl Command {
     pub fn get_groups(&self) -> Option<&[gid_t]> {
         self.groups.as_deref()
     }
+    #[allow(dead_code)]
+    pub fn get_pgroup(&self) -> Option<pid_t> {
+        self.pgroup
+    }
 
     pub fn get_closures(&mut self) -> &mut Vec<Box<dyn FnMut() -> io::Result<()> + Send + Sync>> {
         &mut self.closures