On Fri, Jan 27, 2017 at 12:26 AM, Justin Cinkelj <justin.cink...@xlab.si> wrote:
> The thread ID of thread running new app main() function is returned. > > Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si> > --- > core/app.cc | 12 ++++++++++-- > include/osv/app.hh | 7 ++++++- > 2 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/core/app.cc b/core/app.cc > index ad3145f..6ea5d6e 100644 > --- a/core/app.cc > +++ b/core/app.cc > @@ -133,8 +133,12 @@ shared_app_t application::run(const std::string& > command, > return app; > } > > -void run(const std::vector<std::string>& args) { > - application::run(args); > +void run(const std::vector<std::string>& args, pid_t *pid) { > + auto app = application::run(args); > + if (pid) { > + *pid = app->get_main_thread_id(); > + assert((*pid) != 0); > + } > I think this has the same bug we already solved in osv_execve() - when application::run returns, if I understand correctly, the thread may not be actually running, so its id is not yet set. I guess we can solve this like we did for osv_execve() (i.e., creating a new thread first, and then running the new application in the current thread) but I rather not go into this mess again :-( How about the idea I raised in another email to keep a list of osv::application pointers - instead of "thread ids" - in the httpserver (httpserver can assign numeric ids to those if it wishes)? > } > > shared_app_t application::run_and_join(const std::string& command, > @@ -419,6 +423,10 @@ std::string application::get_command() > return _command; > } > > +pid_t application::get_main_thread_id() { > + return pthread_gettid_np(_thread); > +} > + > // For simplicity, we will not reuse bits in the bitmap, since no > destructor is > // assigned to the program. In that case, a simple counter would do. But > coding > // this way is easy, and make this future extension simple. > diff --git a/include/osv/app.hh b/include/osv/app.hh > index 6fa503a..90bc7ce 100644 > --- a/include/osv/app.hh > +++ b/include/osv/app.hh > @@ -176,6 +176,11 @@ public: > */ > std::string get_command(); > > + /** > + * Returns thread_id/PID of thread running app main() function. > + */ > + pid_t get_main_thread_id(); > + > std::shared_ptr<application_runtime> runtime() const { return > _runtime; } > std::shared_ptr<elf::object> lib() const { return _lib; } > > @@ -238,7 +243,7 @@ namespace osv { > * Creates a new app > * args Arguments passed to the program's main() function. > */ > -void run(const std::vector<std::string>& args); > +void run(const std::vector<std::string>& args, pid_t *pid=nullptr); > By the way, I already committed a patch to rename this function run_background. If we adopt the idea I raised above, this run_background() function can return a shared_app_t instead of trying to return a thread id (because at the point of return, the app already exists but the thread does not). Nadav. -- 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.