From: Justin Cinkelj <justin.cink...@xlab.si>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

osv_execve: fail gracefully if program file does not exist

If non-existent path is passed to osv_execve, osv::launch_error is raised.
This terminates VM if nobody catches the exception.

This patch implements exception catching, and silently ignores it -
osv_execve still returns 0 and doesn't set errno if exception occurs.

Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
Message-Id: <20170818120141.5343-2-justin.cink...@xlab.si>

---
diff --git a/core/osv_execve.cc b/core/osv_execve.cc
--- a/core/osv_execve.cc
+++ b/core/osv_execve.cc
@@ -24,19 +24,34 @@ static int thread_run_app_in_namespace(std::string filename,
 {
     const bool new_program = true; // run in new ELF namespace
     long tid = gettid(); // sched::thread::current()->id();
+    int ret = -1;
+    bool exception_raised = false;

     debugf_execve("thread_run_app_in_namespace... tid=%ld\n", tid);
     *thread_id = tid;

- auto app = osv::application::run_and_join(filename, args, new_program, &envp, parent_waiter);
-    auto ret = app->get_return_code();
- debugf_execve("thread_run_app_in_namespace ret = %d tid=%ld\n", ret, tid);
+    try {
+ auto app = osv::application::run_and_join(filename, args, new_program, &envp, parent_waiter);
+        ret = app->get_return_code();
+ debugf_execve("thread_run_app_in_namespace ret = %d tid=%ld\n", ret, tid);
+    }
+    catch (osv::launch_error &ex) {
+        exception_raised = true;
+    }

     WITH_LOCK(exec_mutex) {
         exited_threads[tid] = ret;
         cond.wake_all();
     }

+    if (exception_raised) {
+ // osv::application::run_and_join failed, and likely didn't wake up parent_waiter.
+        // Wake parent now.
+        if (parent_waiter) {
+            parent_waiter->wake();
+        }
+    }
+
// Trigger event notification via file descriptor (fd created with eventfd).
     if (notification_fd > 0) {
         uint64_t notif = 1;

--
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.

Reply via email to