aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-26 15:09:42 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-12-26 15:09:42 +0000
commitf652f7612e7c2e04164db5243866f26dab54ae3e (patch)
treea8cdb68eb1b6305ddada3e7e7449920ebc80458c
parentae63cf0e67bc73e0fe07f848f3a9e726f2e2d120 (diff)
downloadpaludis-f652f7612e7c2e04164db5243866f26dab54ae3e.tar.gz
paludis-f652f7612e7c2e04164db5243866f26dab54ae3e.tar.xz
Change how we do PALUDIS_PID
-rw-r--r--paludis/util/system.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 480251e..8c0c814 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -22,6 +22,7 @@
#include <paludis/util/log.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/stringify.hh>
+#include <paludis/util/destringify.hh>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -45,7 +46,24 @@ namespace
static int stderr_write_fd = -1;
static int stderr_close_fd = -1;
- static pid_t paludis_pid(getpid());
+ pid_t get_paludis_pid()
+ {
+ pid_t result(0);
+ std::string str;
+
+ if (((str = getenv_with_default("PALUDIS_PID", ""))).empty())
+ {
+ result = getpid();
+ setenv("PALUDIS_PID", stringify(result).c_str(), 1);
+ }
+ else
+ result = destringify<pid_t>(str);
+
+ return result;
+ }
+
+
+ static pid_t paludis_pid(get_paludis_pid());
/**
* Runs a command in a directory if needed, wait for it to terminate
@@ -56,14 +74,6 @@ namespace
int
real_run_command(const std::string & cmd, const FSEntry * const fsentry)
{
- static bool done_paludis_pid(false);
- if (! done_paludis_pid)
- {
- if (getenv_with_default("PALUDIS_PID", "").empty())
- setenv("PALUDIS_PID", stringify(paludis_pid).c_str(), 1);
- done_paludis_pid = true;
- }
-
pid_t child(fork());
if (0 == child)
{