* Don't fork in `nix run'.

This commit is contained in:
Eelco Dolstra 2003-03-28 10:33:34 +00:00
parent f915f77349
commit 278ea4097e
3 changed files with 25 additions and 46 deletions

View file

@ -406,52 +406,29 @@ void runPkg(string hash, const vector<string> & args)
runner = getFromEnv(env, "run"); runner = getFromEnv(env, "run");
/* Fork a child to build the package. */ /* Fill in the environment. We don't bother freeing the
pid_t pid; strings, since we'll exec or die soon anyway. */
switch (pid = fork()) { for (Environment::iterator it = env.begin();
it != env.end(); it++)
case -1: {
throw Error("unable to fork"); string * s = new string(it->first + "=" + it->second);
putenv((char *) s->c_str());
case 0: { /* child */
/* Fill in the environment. We don't bother freeing the
strings, since we'll exec or die soon anyway. */
for (Environment::iterator it = env.begin();
it != env.end(); it++)
{
string * s = new string(it->first + "=" + it->second);
putenv((char *) s->c_str());
}
/* Create the list of arguments. */
const char * args2[env.size() + 2];
int i = 0;
args2[i++] = runner.c_str();
for (vector<string>::const_iterator it = args.begin();
it != args.end(); it++, i++)
args2[i] = it->c_str();
args2[i] = 0;
/* Execute the runner. This should not return. */
execv(runner.c_str(), (char * *) args2);
cout << strerror(errno) << endl;
cout << "unable to execute runner\n";
_exit(1); }
} }
/* parent */ /* Create the list of arguments. */
const char * args2[env.size() + 2];
int i = 0;
args2[i++] = runner.c_str();
for (vector<string>::const_iterator it = args.begin();
it != args.end(); it++, i++)
args2[i] = it->c_str();
args2[i] = 0;
/* Wait for the child to finish. */ /* Execute the runner. This should not return. */
int status; execv(runner.c_str(), (char * *) args2);
if (waitpid(pid, &status, 0) != pid)
throw Error("unable to wait for child");
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) cout << strerror(errno) << endl;
throw Error("unable to run package"); throw Error("unable to execute runner");
} }
@ -750,7 +727,6 @@ void main2(int argc, char * * argv)
/* Parse the global flags. */ /* Parse the global flags. */
while (argc) { while (argc) {
string arg(*argv); string arg(*argv);
cout << arg << endl;
if (arg == "-h" || arg == "--help") { if (arg == "-h" || arg == "--help") {
printUsage(); printUsage();
return; return;

View file

@ -4,4 +4,7 @@ export LD_LIBRARY_PATH=$glib/lib:$atk/lib:$pango/lib:$gtk/lib:$gnet/lib:$pspell/
ldd $pan/bin/pan ldd $pan/bin/pan
$pan/bin/pan $* prog=$1
shift
$pan/bin/$prog $*

View file

@ -1,4 +1,4 @@
id : pan-0.13.91-run id : pan-0.13.91-run-2
pan <- ./pan-0.13.91.nix pan <- ./pan-0.13.91.nix