Commit Graph

87 Commits

Author SHA1 Message Date
Matthias Krüger
7be94a8a95 don't use .into() to convert types into identical types.
example:
    let s: String = format!("hello").into();
2020-02-27 23:32:46 +01:00
Lzu Tao
dd8f072233 Use drop instead of the toilet closure |_| () 2020-01-02 08:56:12 +00:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Jeremy Fitzhardinge
232022ff17 Fix up Command Debug output when arg0 is specified.
PR https://github.com/rust-lang/rust/pull/66512 added the ability to set argv[0] on
Command. As a side effect, it changed the Debug output to print both the program and
argv[0], which in practice results in stuttery output ("echo echo foo").

This PR reverts the behaviour to the the old one, so that the command is only printed
once - unless arg0 has been set. In that case it emits "[command] arg0 arg1 ...".
2019-12-16 14:44:16 -08:00
David Tolnay
c34fbfaad3
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd/sys -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd/sys outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of the files.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:37:58 -08:00
Jeremy Fitzhardinge
6dee1a5a9f Add unix::process::CommandExt::arg0
This allows argv[0] to be overridden on the executable's command-line. This also makes the program
executed independent of argv[0].

Does Fuchsia have the same semantics?

Addresses: #66510
2019-11-19 11:01:52 -08:00
Tyler Mandry
80db06d6da Fix ExitStatus on Fuchsia
Fuchsia exit codes don't follow the convention of libc::WEXITSTATUS et
al, and they are 64 bits instead of 32 bits. This gives Fuchsia its own
representation of ExitStatus.

Additionally, the zircon syscall structs were out of date, causing us to
see bogus return codes.
2019-09-25 15:26:42 -07:00
Mazdak Farrokhzad
8bee18baa3
Rollup merge of #64023 - tmandry:libstd-fuchsia-fixes, r=cramertj
libstd fuchsia fixes

This fixes two bugs in libstd on Fuchsia:

- `zx_time_t` was changed to an `i64`, but this never made it into libstd
- When spawning processes where any of the stdio were null, libstd attempts to open `/dev/null`, which doesn't exist on Fuchsia

r? @cramertj
2019-09-07 20:01:41 +02:00
Alex Crichton
0b7ba6ec54 std: Improve downstream codegen in Command::env
This commit rejiggers the generics used in the implementation of
`Command::env` with the purpose of reducing the amount of codegen that
needs to happen in consumer crates, instead preferring to generate code
into libstd.

This was found when profiling the compile times of the `cc` crate where
the binary rlib produced had a lot of `BTreeMap` code compiled into it
but the crate doesn't actually use `BTreeMap`. It turns out that
`Command::env` is generic enough to codegen the entire implementation in
calling crates, but in this case there's no performance concern so it's
fine to compile the code into the standard library.

This change is done by removing the generic on the `CommandEnv` map
which is intended to handle case-insensitive variables on Windows.
Instead now a generic isn't used but rather a `use` statement defined
per-platform is used.

With this commit a debug build of `Command::new("foo").env("a", "b")`
drops from 21k lines of LLVM IR to 10k.
2019-09-05 11:43:35 -07:00
Tyler Mandry
5f91ad0e33 fuchsia: Fix default environment behavior when spawning 2019-08-30 18:52:26 -07:00
Tyler Mandry
7bfa2be4ef fuchsia: Don't fail to spawn if no stdin exists 2019-08-30 18:22:49 -07:00
Tyler Mandry
403701f976 Don't try to use /dev/null on Fuchsia 2019-08-30 11:55:34 -07:00
Tyler Mandry
5da1123c5e Update zx_time_t to an i64 2019-08-29 17:51:50 -07:00
bors
f834695781 Auto merge of #63521 - newpavlov:redox_builder, r=pietroalbini
Re-enable Redox builder (take 2)

Closes: #63160
2019-08-23 08:58:24 +00:00
Joe Richey
8e91dca596 Consolidate sigemptyset workarounds
In sys/unix/process, we work around the sigemptyset linking issues
on android in two different ways. This change consolidates these
workarounds, and avoids duplicating bindings from `libc`.
2019-08-19 16:15:34 -07:00
Artyom Pavlov
34c9f8c649
remove any from cfgs 2019-08-19 20:02:50 +00:00
Artyom Pavlov
1dd2d3076d
cfg fix 2 2019-08-19 20:01:02 +00:00
Artyom Pavlov
1417f53863
fix cfg 2019-08-19 19:58:35 +00:00
Jeremy Soller
ebb648d4fb
Fix cfg_if usage 2019-08-06 19:32:39 -06:00
Jeremy Soller
0498da9a3d
redox: convert to target_family unix 2019-08-06 16:18:23 -06:00
Mateusz Mikuła
124f6ef7cd Fix clippy::len_zero warnings 2019-07-18 15:14:56 +02:00
Josh Stone
b533aff927 Use pointer::write_bytes for android sigemptyset 2019-06-26 16:27:54 -07:00
Josh Stone
3ba1f39fe7 Avoid mem::uninitialized() in std::sys::unix
For `libc` types that will be initialized in FFI calls, we can just use
`MaybeUninit` and then pass around raw pointers.

For `sun_path_offset()`, which really wants `offset_of`, all callers
have a real `sockaddr_un` available, so we can use that reference.
2019-06-26 15:03:15 -07:00
Marcel Hellwig
5458b651b1 use exhaustive_patterns to be able to use ? 2019-05-06 15:40:34 +02:00
Marcel Hellwig
af6ace6209 convert custom try macro to ?
resolves #60580
2019-05-06 14:54:27 +02:00
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
Mazdak Farrokhzad
ec8ef1836a
Rollup merge of #58059 - RalfJung:before_exec, r=alexcrichton
deprecate before_exec in favor of unsafe pre_exec

Fixes https://github.com/rust-lang/rust/issues/39575

As per the [lang team decision](https://github.com/rust-lang/rust/issues/39575#issuecomment-442993358):

> The language team agreed that before_exec should be unsafe, and leaves the details of a transition plan to the libs team.

Cc @alexcrichton @rust-lang/libs how would you like to proceed?
2019-02-22 14:57:56 +01:00
Josh Stone
a301655c8a Use posix_spawn_file_actions_addchdir_np when possible
This is a non-POSIX extension implemented in Solaris and in glibc 2.29.
With this we can still use `posix_spawn()` when `Command::current_dir()`
has been set, otherwise we fallback to `fork(); chdir(); exec()`.
2019-02-13 12:20:23 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Ralf Jung
33ee99b26a more formatting 2019-02-03 11:16:37 +01:00
Ralf Jung
6bfb280189 deprecate before_exec in favor of unsafe pre_exec 2019-02-01 19:53:32 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
ljedrz
8c4129cd9a cleanup: remove static lifetimes from consts in libstd 2018-12-04 10:21:42 +01:00
Alex Crichton
4032b7a429 std: Synchronize access to global env during exec
This commit, after reverting #55359, applies a different fix for #46775
while also fixing #55775. The basic idea was to go back to pre-#55359
libstd, and then fix #46775 in a way that doesn't expose #55775.

The issue described in #46775 boils down to two problems:

* First, the global environment is reset during `exec` but, but if the
  `exec` call fails then the global environment was a dangling pointer
  into free'd memory as the block of memory was deallocated when
  `Command` is dropped. This is fixed in this commit by installing a
  `Drop` stack object which ensures that the `environ` pointer is
  preserved on a failing `exec`.

* Second, the global environment was accessed in an unsynchronized
  fashion during `exec`. This was fixed by ensuring that the
  Rust-specific environment lock is acquired for these system-level
  operations.

Thanks to Alex Gaynor for pioneering the solution here!

Closes #55775

Co-authored-by: Alex Gaynor <alex.gaynor@gmail.com>
2018-11-14 12:46:57 -08:00
Alex Crichton
5856797bda Revert "Fixes #46775 -- don't mutate the process's environment in Command::exec"
This reverts commit 36fe3b605a.
2018-11-14 07:21:01 -08:00
Alex Gaynor
36fe3b605a Fixes #46775 -- don't mutate the process's environment in Command::exec
Instead, pass the environment to execvpe, so the kernel can apply it directly to the new process. This avoids a use-after-free in the case where exec'ing the new process fails for any reason, as well as a race condition if there are other threads alive during the exec.
2018-11-01 12:51:24 +00:00
ljedrz
d28aed6dc4 Prefer unwrap_or_else to unwrap_or in case of function calls/allocations 2018-10-19 09:45:45 +02:00
ljedrz
b29a6fbabc Add missing dyn for cloudabi, redox, unix and wasm 2018-07-10 20:52:29 +02:00
Adam Barth
0c6cd26aec [fuchsia] Migrate from launchpad to fdio_spawn_etc
fdio_spawn_etc is the preferred way of creating processes on Fuchsia
now.
2018-06-07 09:22:59 -07:00
Alex Crichton
323f808791 std: Inline some Termination-related methods
These were showing up in tests and in binaries but are trivially optimize-able
away, so add `#[inline]` attributes so LLVM has an opportunity to optimize them
out.
2018-04-05 11:07:19 -07:00
Bryan Drewery
70559c54ce Command::env_saw_path() may be unused on platforms not using posix_spawn() 2018-03-22 09:49:20 -07:00
Bryan Drewery
6212904dd8 Don't use posix_spawn() if PATH was modified in the environment.
The expected behavior is that the environment's PATH should be used
to find the process.  posix_spawn() could be used if we iterated
PATH to search for the binary to execute.  For now just skip
posix_spawn() if PATH is modified.
2018-03-19 15:40:09 -07:00
Bryan Drewery
00dac20e01 Merge branch 'update-beta-freebsd' into freebsd-posix-spawn 2018-03-19 13:11:55 -07:00
Scott McMurray
74c5c6e6cb Move process::ExitCode internals to sys
Now begins the saga of fixing compilation errors on other platforms...
2018-03-03 18:44:44 -08:00
Bryan Drewery
d740083fc8 Support posix_spawn() for Linux glibc 2.24+.
The relevant support was added in https://sourceware.org/bugzilla/show_bug.cgi?id=10354#c12
2018-03-02 13:08:04 -08:00
Bryan Drewery
99b50efb6e Use _ 2018-03-02 08:50:37 -08:00
Bryan Drewery
ef73b3ae2e Add comment explaining when posix_spawn() can be supported. 2018-03-01 09:18:16 -08:00
Bryan Drewery
2e2d9260f9 posix_spawn() on OSX supports returning ENOENT. 2018-03-01 09:17:49 -08:00