From: Nadav Har'El <n...@scylladb.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master
loader: do not kill httpserver prematurely
Commit e270cf9c (more than two years ago) was well-intentioned, but
introduced a new bug: we no longer wait for the background programs
to finish before stopping httpserver. So for example if the command
line is something like
/cli/cli.so & finish_quickly.so
And finish_quickly.so finishes quickly, we do not wait for cli.so to
finish before killing httpserver.
One user discovered that because of that, the image created by
"./scripts/build image=java-example,cli" runs the short-lived java-example
but then the CLI doesn't work: It can't run any commands because the
httpserver it relies on is already dead.
So this patch partially reverts e270cf9c... We keep the "app registry"
introduced there, but we still have a separate list of background apps
started in the command line - and wait for them to finish before asking
httpserver to exit.
Signed-off-by: Nadav Har'El <n...@scylladb.com>
Message-Id: <20161225220455.8746-1-...@scylladb.com>
---
diff --git a/loader.cc b/loader.cc
--- a/loader.cc
+++ b/loader.cc
@@ -495,6 +495,7 @@ void* do_main_thread(void *_main_args)
// empty otherwise, to run in this thread. '&!' is the same as '&', but
// doesn't wait for the thread to finish before exiting OSv.
std::vector<shared_app_t> detached;
+ std::vector<shared_app_t> bg;
for (auto &it : commands) {
std::vector<std::string> newvec(it.begin(), std::prev(it.end()));
auto suffix = it.back();
@@ -505,13 +506,19 @@ void* do_main_thread(void *_main_args)
detached.push_back(app);
} else if (!background) {
app->join();
+ } else {
+ bg.push_back(app);
}
} catch (const launch_error& e) {
std::cerr << e.what() << ". Powering off.\n";
osv::poweroff();
}
}
+ for (auto app : bg) {
+ app->join();
+ }
+
for (auto app : detached) {
app->request_termination();
debug("Requested termination of %s, waiting...\n",
app->get_command());
--
You received this message because you are subscribed to the Google Groups "OSv
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.