11From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
22From: David Greaves <david.greaves@jolla.com>
33Date: Wed, 20 Jan 2021 09:40:34 +0000
4- Subject: [PATCH] Provide ENV controls to bypass some sb2 calls between
5- fork exec
4+ Subject: [PATCH] Provide ENV controls to bypass some sb2 calls between fork
5+ exec
66
77In threaded systems there can be deadlocks caused by calling malloc
88after fork and before exec. Rust manages this but sb2 does not.
@@ -32,12 +32,13 @@ and the fallback fork/exec is used.
3232Note that some reworking of rust's handling of program/argv[0] was
3333needed to support the SHIM functionality
3434
35+ Co-authored-by: Ruben De Smet <ruben.de.smet@rubdos.be>
3536Signed-off-by: David Greaves <david.greaves@jolla.com>
3637Signed-off-by: Ruben De Smet <ruben.de.smet@rubdos.be>
3738---
3839 .../src/sys/unix/process/process_common.rs | 55 ++++++-
39- .../std/src/sys/unix/process/process_unix.rs | 138 ++++++++++++++++--
40- 2 files changed, 173 insertions(+), 20 deletions(-)
40+ .../std/src/sys/unix/process/process_unix.rs | 137 ++++++++++++++++--
41+ 2 files changed, 172 insertions(+), 20 deletions(-)
4142
4243diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
4344index 640648e8707..f15625e0514 100644
@@ -155,7 +156,7 @@ index 640648e8707..f15625e0514 100644
155156 // Set a new arg0
156157 let arg = os2c(arg, &mut self.saw_nul);
157158diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs
158- index 3963e7f52d5..d08e4db6199 100644
159+ index 3963e7f52d5..b491c2ad75f 100644
159160--- a/library/std/src/sys/unix/process/process_unix.rs
160161+++ b/library/std/src/sys/unix/process/process_unix.rs
161162@@ -25,7 +25,7 @@
@@ -253,13 +254,12 @@ index 3963e7f52d5..d08e4db6199 100644
253254 #[cfg(target_os = "linux")]
254255 if self.get_create_pidfd() {
255256 self.send_pidfd(&output);
256- @@ -268,7 +331,48 @@ pub fn exec(&mut self, default: Stdio) -> io::Error {
257+ @@ -268,7 +331,47 @@ pub fn exec(&mut self, default: Stdio) -> io::Error {
257258 Err(e) => e,
258259 }
259260 }
260261-
261- + fn unwrap_drop(&mut self, fh: sys::unix::pipe::AnonPipe) {
262- + use crate::os::unix::io::AsRawFd;
262+ + fn unwrap_drop(&mut self, fh: impl crate::os::unix::io::AsRawFd) {
263263+ // drop() simply calls libc::close(fh.fd)
264264+ match self.close {
265265+ Some(real_close) => {
@@ -303,7 +303,7 @@ index 3963e7f52d5..d08e4db6199 100644
303303 // And at this point we've reached a special time in the life of the
304304 // child. The child must now be considered hamstrung and unable to
305305 // do anything other than syscalls really. Consider the following
306- @@ -308,13 +412 ,13 @@ unsafe fn do_exec(
306+ @@ -308,13 +411 ,13 @@ unsafe fn do_exec(
307307 use crate::sys::{self, cvt_r};
308308
309309 if let Some(fd) = stdio.stdin.fd() {
@@ -320,7 +320,7 @@ index 3963e7f52d5..d08e4db6199 100644
320320 }
321321
322322 #[cfg(not(target_os = "l4re"))]
323- @@ -322,10 +426 ,10 @@ unsafe fn do_exec(
323+ @@ -322,10 +425 ,10 @@ unsafe fn do_exec(
324324 if let Some(_g) = self.get_groups() {
325325 //FIXME: Redox kernel does not support setgroups yet
326326 #[cfg(not(target_os = "redox"))]
@@ -333,7 +333,7 @@ index 3963e7f52d5..d08e4db6199 100644
333333 }
334334 if let Some(u) = self.get_uid() {
335335 // When dropping privileges from root, the `setgroups` call
336- @@ -337,13 +441 ,13 @@ unsafe fn do_exec(
336+ @@ -337,13 +440 ,13 @@ unsafe fn do_exec(
337337 //FIXME: Redox kernel does not support setgroups yet
338338 #[cfg(not(target_os = "redox"))]
339339 if libc::getuid() == 0 && self.get_groups().is_none() {
@@ -350,7 +350,7 @@ index 3963e7f52d5..d08e4db6199 100644
350350 }
351351
352352 if let Some(pgroup) = self.get_pgroup() {
353- @@ -401,8 +505 ,12 @@ fn drop(&mut self) {
353+ @@ -401,8 +504 ,12 @@ fn drop(&mut self) {
354354 _reset = Some(Reset(*sys::os::environ()));
355355 *sys::os::environ() = envp.as_ptr();
356356 }
@@ -365,15 +365,15 @@ index 3963e7f52d5..d08e4db6199 100644
365365 Err(io::Error::last_os_error())
366366 }
367367
368- @@ -429,6 +537 ,7 @@ fn posix_spawn(
368+ @@ -429,6 +536 ,7 @@ fn posix_spawn(
369369 _: &ChildPipes,
370370 _: Option<&CStringArray>,
371371 ) -> io::Result<Option<Process>> {
372372+ eprintln!("process_unix:270: in null posix_spawn");
373373 Ok(None)
374374 }
375375
376- @@ -452,12 +561 ,15 @@ fn posix_spawn(
376+ @@ -452,12 +560 ,15 @@ fn posix_spawn(
377377 use crate::mem::MaybeUninit;
378378 use crate::sys::{self, cvt_nz, unix_sigpipe_attr_specified};
379379
@@ -390,5 +390,5 @@ index 3963e7f52d5..d08e4db6199 100644
390390 return Ok(None);
391391 }
392392- -
393- 2.42 .0
393+ 2.43 .0
394394
0 commit comments