Skip to content

Commit b4a0422

Browse files
wkozaczuknyh
authored andcommitted
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 <[email protected]> Message-Id: <[email protected]>
1 parent 7bc0155 commit b4a0422

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

core/commands.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ struct command : qi::grammar<sciter,
4040
("\\r", '\r')("\\t", '\t')("\\v", '\v')("\\\\", '\\')
4141
("\\\'", '\'')("\\\"", '\"');
4242

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

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

5050
qi::rule<sciter, std::string(), ascii::space_type> string;

loader.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ static std::string read_file(std::string fn)
330330
std::istreambuf_iterator<char>());
331331
}
332332

333+
static void stop_all_remaining_app_threads()
334+
{
335+
while(!application::unsafe_stop_and_abandon_other_threads()) {
336+
usleep(100000);
337+
}
338+
}
339+
333340
void* do_main_thread(void *_main_args)
334341
{
335342
auto app_cmdline = static_cast<char*>(_main_args);
@@ -507,7 +514,14 @@ void* do_main_thread(void *_main_args)
507514
auto suffix = it.back();
508515
try {
509516
bool background = (suffix == "&") || (suffix == "&!");
510-
auto app = application::run(newvec);
517+
518+
shared_app_t app;
519+
if (suffix == "!") {
520+
app = application::run(newvec[0], newvec, false, nullptr, "main", stop_all_remaining_app_threads);
521+
} else {
522+
app = application::run(newvec);
523+
}
524+
511525
if (suffix == "&!") {
512526
detached.push_back(app);
513527
} else if (!background) {

0 commit comments

Comments
 (0)