From 278ea4097e4deca33da1a08d746e8d80a620ce95 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 28 Mar 2003 10:33:34 +0000 Subject: [PATCH] * Don't fork in `nix run'. --- src/nix.cc | 64 +++++++++++------------------------ test/build/pan-run.sh | 5 ++- test/tmpl/pan-0.13.91-run.nix | 2 +- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/nix.cc b/src/nix.cc index c24cb1fd7..275a37bea 100644 --- a/src/nix.cc +++ b/src/nix.cc @@ -406,52 +406,29 @@ void runPkg(string hash, const vector & args) runner = getFromEnv(env, "run"); - /* Fork a child to build the package. */ - pid_t pid; - switch (pid = fork()) { - - case -1: - throw Error("unable to fork"); - - 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::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); } - + /* 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()); } - /* parent */ + /* Create the list of arguments. */ + const char * args2[env.size() + 2]; + int i = 0; + args2[i++] = runner.c_str(); + for (vector::const_iterator it = args.begin(); + it != args.end(); it++, i++) + args2[i] = it->c_str(); + args2[i] = 0; - /* Wait for the child to finish. */ - int status; - if (waitpid(pid, &status, 0) != pid) - throw Error("unable to wait for child"); - - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - throw Error("unable to run package"); + /* Execute the runner. This should not return. */ + execv(runner.c_str(), (char * *) args2); + + cout << strerror(errno) << endl; + throw Error("unable to execute runner"); } @@ -750,7 +727,6 @@ void main2(int argc, char * * argv) /* Parse the global flags. */ while (argc) { string arg(*argv); - cout << arg << endl; if (arg == "-h" || arg == "--help") { printUsage(); return; diff --git a/test/build/pan-run.sh b/test/build/pan-run.sh index c933a3803..1d9db5377 100755 --- a/test/build/pan-run.sh +++ b/test/build/pan-run.sh @@ -4,4 +4,7 @@ export LD_LIBRARY_PATH=$glib/lib:$atk/lib:$pango/lib:$gtk/lib:$gnet/lib:$pspell/ ldd $pan/bin/pan -$pan/bin/pan $* \ No newline at end of file +prog=$1 +shift + +$pan/bin/$prog $* diff --git a/test/tmpl/pan-0.13.91-run.nix b/test/tmpl/pan-0.13.91-run.nix index a28459916..f9c13e64d 100644 --- a/test/tmpl/pan-0.13.91-run.nix +++ b/test/tmpl/pan-0.13.91-run.nix @@ -1,4 +1,4 @@ -id : pan-0.13.91-run +id : pan-0.13.91-run-2 pan <- ./pan-0.13.91.nix