Auto merge of #132121 - workingjubilee:rollup-yrtn33e, r=workingjubilee · qinheping/verify-rust-std@2da7b7f (original) (raw)

`@@ -448,7 +448,6 @@ impl Command {

`

448

448

`use core::sync::atomic::{AtomicU8, Ordering};

`

449

449

``

450

450

`use crate::mem::MaybeUninit;

`

451

``

`-

use crate::sys::weak::weak;

`

452

451

`use crate::sys::{self, cvt_nz, on_broken_pipe_flag_used};

`

453

452

``

454

453

`if self.get_gid().is_some()

`

`@@ -462,6 +461,8 @@ impl Command {

`

462

461

``

463

462

` cfg_if::cfg_if! {

`

464

463

`if #[cfg(target_os = "linux")] {

`

``

464

`+

use crate::sys::weak::weak;

`

``

465

+

465

466

` weak! {

`

466

467

`fn pidfd_spawnp(

`

467

468

`*mut libc::c_int,

`

`@@ -575,16 +576,44 @@ impl Command {

`

575

576

`}

`

576

577

`}

`

577

578

``

578

``

`-

// Solaris, glibc 2.29+, and musl 1.24+ can set a new working directory,

`

579

``

`-

// and maybe others will gain this non-POSIX function too. We'll check

`

580

``

`-

// for this weak symbol as soon as it's needed, so we can return early

`

581

``

`-

// otherwise to do a manual chdir before exec.

`

582

``

`-

weak! {

`

583

``

`-

fn posix_spawn_file_actions_addchdir_np(

`

584

``

`-

*mut libc::posix_spawn_file_actions_t,

`

585

``

`-

*const libc::c_char

`

586

``

`-

) -> libc::c_int

`

``

579

`+

type PosixSpawnAddChdirFn = unsafe extern "C" fn(

`

``

580

`+

*mut libc::posix_spawn_file_actions_t,

`

``

581

`+

*const libc::c_char,

`

``

582

`+

) -> libc::c_int;

`

``

583

+

``

584

`+

/// Get the function pointer for adding a chdir action to a

`

``

585

`` +

/// posix_spawn_file_actions_t, if available, assuming a dynamic libc.

``

``

586

`+

///

`

``

587

`+

/// Some platforms can set a new working directory for a spawned process in the

`

``

588

`` +

/// posix_spawn path. This function looks up the function pointer for adding

``

``

589

`` +

/// such an action to a posix_spawn_file_actions_t struct.

``

``

590

`+

#[cfg(not(all(target_os = "linux", target_env = "musl")))]

`

``

591

`+

fn get_posix_spawn_addchdir() -> Option {

`

``

592

`+

use crate::sys::weak::weak;

`

``

593

+

``

594

`+

weak! {

`

``

595

`+

fn posix_spawn_file_actions_addchdir_np(

`

``

596

`+

*mut libc::posix_spawn_file_actions_t,

`

``

597

`+

*const libc::c_char

`

``

598

`+

) -> libc::c_int

`

``

599

`+

}

`

``

600

+

``

601

`+

posix_spawn_file_actions_addchdir_np.get()

`

``

602

`+

}

`

``

603

+

``

604

`+

/// Get the function pointer for adding a chdir action to a

`

``

605

`` +

/// posix_spawn_file_actions_t, if available, on platforms where the function

``

``

606

`+

/// is known to exist.

`

``

607

`+

///

`

``

608

`+

/// Weak symbol lookup doesn't work with statically linked libcs, so in cases

`

``

609

`+

/// where static linking is possible we need to either check for the presence

`

``

610

`+

/// of the symbol at compile time or know about it upfront.

`

``

611

`+

#[cfg(all(target_os = "linux", target_env = "musl"))]

`

``

612

`+

fn get_posix_spawn_addchdir() -> Option {

`

``

613

`+

// Our minimum required musl supports this function, so we can just use it.

`

``

614

`+

Some(libc::posix_spawn_file_actions_addchdir_np)

`

587

615

`}

`

``

616

+

588

617

`let addchdir = match self.get_cwd() {

`

589

618

`Some(cwd) => {

`

590

619

`if cfg!(target_vendor = "apple") {

`

`@@ -597,7 +626,10 @@ impl Command {

`

597

626

`return Ok(None);

`

598

627

`}

`

599

628

`}

`

600

``

`-

match posix_spawn_file_actions_addchdir_np.get() {

`

``

629

`+

// Check for the availability of the posix_spawn addchdir

`

``

630

`+

// function now. If it isn't available, bail and use the

`

``

631

`+

// fork/exec path.

`

``

632

`+

match get_posix_spawn_addchdir() {

`

601

633

`Some(f) => Some((f, cwd)),

`

602

634

`None => return Ok(None),

`

603

635

`}

`