aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/process_TEST.cc
diff options
context:
space:
mode:
authorAvatar Johannes Nixdorf <mixi@exherbo.org> 2016-09-11 21:36:32 +0200
committerAvatar Heiko Becker <heirecka@exherbo.org> 2018-06-13 21:30:36 +0000
commitce07b7232bcf2a39c84f77909fe2fa205643a1d9 (patch)
tree532a3f43e7c676c160255bef5f73ce26fe76f874 /paludis/util/process_TEST.cc
parent3169132a3231fbbfa0bc118eb8ab315baebc41f3 (diff)
downloadpaludis-ce07b7232bcf2a39c84f77909fe2fa205643a1d9.tar.gz
paludis-ce07b7232bcf2a39c84f77909fe2fa205643a1d9.tar.xz
process.cc: don't allocate after fork
In multithreaded processes POSIX specifies that after fork only AS-safe functions may be called. [1] This fixes a race condition I observed in "cave generate-metadata" with musl libc. This does happen regularily with musl libc, but the general problem also affects glibc. (test [2] if you don't believe me - with glibc it happens more rarely and causes a deadlock inside of malloc locks instead of a crash). This does not fix these problems for as_main_process, as there never will be an exec in the child process that way, which makes it impossible to do safely this way. [1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html [2]: https://shadowice.org/~mixi/examples/never-fork-and-malloc-in-multiple-threads.c
Diffstat (limited to 'paludis/util/process_TEST.cc')
-rw-r--r--paludis/util/process_TEST.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/paludis/util/process_TEST.cc b/paludis/util/process_TEST.cc
index 8eedf0306..f872836c5 100644
--- a/paludis/util/process_TEST.cc
+++ b/paludis/util/process_TEST.cc
@@ -304,6 +304,18 @@ TEST(Process, Clearenv)
EXPECT_EQ("", stdout_stream.str());
}
+TEST(Process, ClearenvPres)
+{
+ ::setenv("PALUDIS_BANANAS", "PALUDIS_IN PYJAMAS", 1);
+ std::stringstream stdout_stream;
+ Process printenv_process(ProcessCommand({"printenv", "PALUDIS_BANANAS"}));
+ printenv_process.capture_stdout(stdout_stream);
+ printenv_process.clearenv();
+
+ EXPECT_EQ(0, printenv_process.run().wait());
+ EXPECT_EQ("PALUDIS_IN PYJAMAS\n", stdout_stream.str());
+}
+
TEST(Process, SendFD)
{
std::stringstream stdout_stream, in_stream;
@@ -330,3 +342,9 @@ TEST(Process, SendFDFixed)
EXPECT_EQ("monkey\n", stdout_stream.str());
}
+TEST(Process, ExecError)
+{
+ Process process(ProcessCommand({"paludis-nonexisting-command"}));
+ EXPECT_THROW({ process.run(); }, ProcessError);
+}
+