Commit graph

365 commits

Author SHA1 Message Date
Vladimir Panteleev
bb0c2953dd std.process: Fix memory corruption in exec functions
Fixes issue #10639.
2025-02-18 13:24:48 +01:00
Iain Buclaw
d643650ee5 Merge remote-tracking branch 'upstream/stable' into merge_stable 2025-01-09 22:30:38 +00:00
Elias Batek
63fdb282f1
Replace internal getEnvironPtr with its equivalent from druntime (#10614)
* Replace internal `getEnvironPtr` with its equivalent from druntime

* Further simplify
2025-01-08 23:57:35 -08:00
Vladimir Panteleev
8c6fca9ccd Fix issue 10587 - std.process.kill should fail for a terminated pid
https://github.com/dlang/phobos/issues/10587
2024-12-29 13:06:58 +01:00
Steven Schveighoffer
d767448ea6 Fix #10574 - environment pointer sometimes changes before exec, causing
segfault in child process.
2024-12-07 22:43:50 +01:00
Martin Kinkelin
b0ef9ac009 Merge remote-tracking branch 'origin/stable' into merge_stable 2024-11-17 01:17:07 +01:00
Steven Schveighoffer
2a730adc07
Fix bugzilla 24524: Very slow process fork if RLIMIT_NOFILE is too high (#9077) 2024-10-31 20:45:15 -07:00
Steven Schveighoffer
10076badd8
Fix Bugzilla Issue 24824 - ensure we exit a child that does not succeed in exec. (#9065) 2024-10-22 15:10:24 +08:00
Andrei Horodniceanu
48d581a1f5
Fix Bugzilla 24715 - std/process: Default to libc closefrom in spawnProcessPosix
The current implementation of spawnProcessPosix is broken on systems
with a large `ulimit -n` because it always OOMs making it impossible
to spawn processes. Using the libc implementation, when available, for
doing file descriptor operations en-mass partially solves this problem.

Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
2024-08-26 14:59:53 +03:00
Iain Buclaw
3a59a5a7cf Merge remote-tracking branch 'upstream/stable' into merge_stable 2024-05-27 09:41:34 +00:00
Martin Kinkelin
acd2013413 Get rid of obsolete CRuntime_DigitalMars support 2024-05-25 21:45:49 +02:00
Steven Schveighoffer
82e8e32b2f Fix bugzilla issue 24549 -- environment.get(null) segfaults on Linux 2024-05-16 20:09:04 +02:00
chloekek
7a280a938e Add std.process.Config.preExecDelegate
std.process.Config.preExecDelegate is just like
std.process.Config.preExecFunction, but can capture an environment, for
example:

    import core.sys.linux.sys.prctl : PR_SET_PDEATHSIG, prctl;
    import std.process : Config, execute;

    void runProgram(int pdeathsig)
    {
        execute(
            ["program"],
            config: Config(
                preExecDelegate: () @trusted =>
                    prctl(PR_SET_PDEATHSIG, pdeathsig, 0, 0, 0) != -1,
            ),
        );
    }

preExecFunction is retained for backwards compatibility. If both
preExecFunction and preExecDelegate are given, both are called.
2024-04-26 12:38:38 +02:00
chloekek
5ce5344593 Promote std.process.Config.preExecFunction to a delegate
std.process.Config.preExecFunction is now a delegate instead of a function
pointer, and can therefore capture an environment, for example:

    import core.sys.linux.sys.prctl : PR_SET_PDEATHSIG, prctl;
    import std.process : Config, execute;

    void runProgram(int pdeathsig)
    {
        execute(
            ["program"],
            config: Config(
                preExecFunction: () @trusted =>
                    prctl(PR_SET_PDEATHSIG, pdeathsig, 0, 0, 0) != -1,
            ),
        );
    }

Despite function pointers implicitly converting to delegates, this is a
backwards-incompatible change, as user code may rely on the field being a
function pointer. For example, code like the following will no longer compile:

    import std.process : Config;

    nothrow pure @nogc @safe
    bool f() { return true; }

    void example()
    {
        auto config = Config(preExecFunction: &f);
        bool function() g = config.preExecFunction;
    }
2024-04-26 01:13:56 +02:00
Steven Schveighoffer
fa5d1b138b Revert "Fixing a memory leak"
This reverts commit cbb455fb34.
2023-02-21 11:03:57 -05:00
Andrea Fontana
cbb455fb34 Fixing a memory leak
In the forked process, the array "pfds" is allocated and is never free'd.
That's a problem if you're going to spawn and keep running a lot of processes, since it's a quite big array.
2023-02-21 11:41:37 +01:00
Vladimir Panteleev
fdceb11b3b
Fix Issue 23706 - Do not escape POSIX shell parameters unless necessary
POSIX follow-up to Issue 13447 / 09a0b876c8.
2023-02-14 14:53:52 +00:00
Vladimir Panteleev
8e95b68bb2
std.process: Fix running unit tests in Wine
Batch files generally don't have trailing semicolons.
2023-02-14 14:53:52 +00:00
Vladimir Panteleev
a9df76d04e
std.process: Add additional test cases discovered with unittest_burnin 2023-02-14 14:53:48 +00:00
Vladimir Panteleev
298bb286e6
std.process: Fix unittest_burnin compilation 2023-02-14 14:49:53 +00:00
Vladimir Panteleev
8c2b3d18fa
std.process: Explain escapeShellCommand test failures 2023-02-14 14:33:13 +00:00
Lucian Danescu
c81788f512 style fix 2022-11-12 19:40:28 +02:00
Lucian Danescu
322fed7bf7 add local imports 2022-11-12 19:29:28 +02:00
yori
b22224db3f Added @nogc to thisProcessID and thisThreadID in std.process 2022-05-16 21:21:20 +00:00
MoonlightSentinel
362e81830c
Fix 13541 - Replace usages of sysErrorString` with a helper function
`sysErrorString` throws an exception for unknown error codes (e.g. from
libraries using `SetLastError`) and hence could hide the actual error
that caused the call to `sysErrorString`.

The new helper function wraps the error code lookup and returns `Error X`
on failure.
2022-03-28 01:01:25 +02:00
MoonlightSentinel
304160f5af
Issue 13541 - Use wenforce instead of enforce + sysErrorString
This ensures that the actual error message won't be suppressed when the
lookup error code => message fails. The exception will also be more
informative because `WindowsException` is explicitly intended for
Windows API errors.
2022-03-28 01:01:19 +02:00
WebFreak001
dac59a4bde add isSomeFiniteCharInputRange as simplification
combines the very common constraint
`isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R)`
and adds a bunch of documentation with examples for users to understand
it better. This should lower the neccessary needed technical insight to
read basic docs, especially std.path and std.file docs.
2022-01-15 18:38:52 +01:00
dkorpel
ea76f45494 Use return scope instead of just return 2021-11-26 17:03:06 +01:00
dkorpel
cd7389266e Add explicit return to inout functions 2021-11-16 23:22:33 +00:00
Andrei Alexandrescu
bd19a80b8f Replace lsof failure with warning for CI's sake 2021-10-22 21:53:40 +00:00
Paul Backus
3ad8dbd41c Check return value of 'open' in std.process test
Previously, if this call to 'open' failed, it would result in a spurious
test failure. Now, it instead causes the test to be skipped.

Possibly related to https://issues.dlang.org/show_bug.cgi?id=22350
2021-10-03 22:35:00 +00:00
Per Nordlöw
52304683d7 Improve searchPathFor 2021-09-25 01:47:13 +02:00
Hiroki Noda
e1bb58a742 rendered in red warning 2021-08-26 22:34:51 +09:00
Hiroki Noda
1aad510fb3 Note that all of the code in preExecFunction must be async-signal-safe 2021-08-26 21:52:14 +09:00
Martin Nowak
df280fd7ab Merge remote-tracking branch 'upstream/stable' into merge_stable 2021-07-20 10:54:24 +02:00
Vladimir Panteleev
baf6ede6de
Fix Issue 22125 - std.process.Config was changed to a struct but miss operator overloads 2021-07-15 12:17:39 +00:00
dkorpel
9ec24190b1 add explicit scope/return for pure functions 2021-07-11 13:34:25 +00:00
Walter Bright
74a40f4783 add @trusted for scope pointer to scope pointer 2021-05-31 00:45:26 +02:00
nordlow
db6a3ac21c Annotate std/process.d to please dlang/dmd#12520 2021-05-17 19:00:50 +08:00
Iain Buclaw
859a367ffa Cleanup temp files in std.process and std.experimental.checkedint
Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de>
2021-05-14 15:03:34 +02:00
Martin Nowak
0f71d7494f Merge remote-tracking branch 'upstream/master' into stable 2021-05-12 08:29:15 +02:00
Iain Buclaw
567b2d716f std.process: Add scope to pipeProcessImpl command parameter 2021-05-03 11:46:50 +02:00
MoonlightSentinel
fa905436d9
Make std.process.browse @safe and sync attributes for windows/posix
Add `@trusted` wrappers for calls to C functions that are always
called with valid arguments.
2021-04-27 10:57:43 +02:00
Nicholas Wilson
2d9e4e2717
Merge branch 'master' into merge_stable 2021-04-27 16:28:29 +08:00
MoonlightSentinel
9d5db86e9d Issue 20257 - Add wait(Pid, Duration) for windows
`wait(Pid, Duration)` allows to wait until the process terminates
or the timeout expires.

It's currently windows-only because a decent posix implementation
is quite difficult and this allows us to sort out the API beforehand.
2021-04-26 17:37:06 +02:00
Martin Nowak
dd2dc35c31 Merge remote-tracking branch 'upstream/stable' into merge_stable 2021-04-25 21:19:23 +02:00
MoonlightSentinel
d186363752
Merge OSX and Posix implementations of browse
They are identical except their usage of open vs. xdg-open
2021-04-21 10:42:38 +02:00
MoonlightSentinel
08927149cc
Fix 20886 - Retain tempCString buffer in browse
The temporary buffer returned by `tempCString` was assigned to a `char*`
and hence destroyed after the statement. This worked by accident for
small URL's because the space was allocated on the stack and not
overwritten before forking.
2021-04-21 10:28:41 +02:00
Tomoya Tanjo
7b4a336bf7
Fix issue 21575 - Child processes spawned by std.process.spawnProcess accidentally inherit signal masks in parent process (#7766)
Fix issue 21575 - Child processes spawned by std.process.spawnProcess accidentally inherit signal masks in parent process
merged-on-behalf-of: unknown
2021-04-19 17:58:16 +02:00
Iain Buclaw
c6c8b12852 Implement missing OpenBSD ports in phobos 2021-02-01 18:46:54 +01:00