From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Added option suffix "!" to force termination of remaining application threads

Some applications like JVM leave other threads running after
main thread terminates. OSv is pedantic about it and likes to keep
application running and prevents regular Java 'Hello World'
app from exiting. This is exactly why java.cc terminates all other threads
upon exit of the main one.

In order to run unmodified JVM on OSV without OSV 'java wrapper'
we need to allow an ability to pass a suffix '!' in command line that gives
a hint to OSv to terminate any remaining application threads like so:

./scripts/run.py -e '/usr/bin/java -cp / Hello !'

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
Message-Id: <20190519204643.16368-1-jwkozac...@gmail.com>

---
diff --git a/core/commands.cc b/core/commands.cc
--- a/core/commands.cc
+++ b/core/commands.cc
@@ -40,11 +40,11 @@ struct command : qi::grammar<sciter,
("\\r", '\r')("\\t", '\t')("\\v", '\v')("\\\\", '\\')
                        ("\\\'", '\'')("\\\"", '\"');

-        string %= qi::no_skip[+(unesc_char | (char_ - ' ' - ';' - '&'))];
+ string %= qi::no_skip[+(unesc_char | (char_ - ' ' - ';' - '&' - '!'))]; quoted_string %= lexeme['"' >> *(unesc_char | (char_ - '"'))
'"'];

         start %= ((quoted_string | string) % *space) >>
-                (char_(';') | qi::string("&!") | char_('&') | qi::eoi);
+ (char_(';') | qi::string("&!") | char_('&') | char_('!') | qi::eoi);
     }

     qi::rule<sciter, std::string(), ascii::space_type> string;
diff --git a/loader.cc b/loader.cc
--- a/loader.cc
+++ b/loader.cc
@@ -330,6 +330,13 @@ static std::string read_file(std::string fn)
           std::istreambuf_iterator<char>());
 }

+static void stop_all_remaining_app_threads()
+{
+    while(!application::unsafe_stop_and_abandon_other_threads()) {
+        usleep(100000);
+    }
+}
+
 void* do_main_thread(void *_main_args)
 {
     auto app_cmdline = static_cast<char*>(_main_args);
@@ -507,7 +514,14 @@ void* do_main_thread(void *_main_args)
         auto suffix = it.back();
         try {
             bool background = (suffix == "&") || (suffix == "&!");
-            auto app = application::run(newvec);
+
+            shared_app_t app;
+            if (suffix == "!") {
+ app = application::run(newvec[0], newvec, false, nullptr, "main", stop_all_remaining_app_threads);
+            } else {
+                app = application::run(newvec);
+            }
+
             if (suffix == "&!") {
                 detached.push_back(app);
             } else if (!background) {

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000c38f6705894ddab7%40google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to