On Tue, Jan 31, 2017 at 11:36 PM, Justin Cinkelj <justin.cink...@xlab.si>
wrote:

> The caller will use returned thread ID to check that app finished.
> The check-if-finished will be implemented in a follow-up patch.
>

Amnon, if we're changing the return value of the app/command REST API in
OSv from always returning a null string to returning a string with numbers
in it, are we supposed to modify some API description somewhere?


>
> Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
> ---
>  modules/httpserver/api/app.cc | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/modules/httpserver/api/app.cc b/modules/httpserver/api/app.cc
> index 6464d40..694b00e 100644
> --- a/modules/httpserver/api/app.cc
> +++ b/modules/httpserver/api/app.cc
> @@ -22,7 +22,7 @@ using namespace std;
>  using namespace json;
>  using namespace app_json;
>
> -static void exec_app(const std::string& cmnd_line) {
> +static std::string exec_app(const std::string& cmnd_line) {
>      bool ok;
>      auto new_commands = osv::parse_command_line(cmnd_line, ok);
>      if (!ok) {
> @@ -34,10 +34,18 @@ static void exec_app(const std::string& cmnd_line) {
>              throw bad_param_exception("The use of ; is not allowed, use &
> for multiple commands");
>          }
>      }
> +    std::string app_ids;
>      for (auto cmnd: new_commands) {
>          std::vector<std::string> c(cmnd.begin(), std::prev(cmnd.end()));
> -        osv::run_background(c);
> +        auto app = osv::application::run(c);
> +        pid_t pid = app->get_main_thread_id();
> +        assert(pid != 0);
> +        app_ids += std::to_string(pid) + " ";
>      }
> +    if (app_ids.size()) {
> +        app_ids.pop_back(); // remove trailing space
> +    }
> +    return app_ids;
>  }
>
>  void init(routes& routes)
> @@ -45,8 +53,9 @@ void init(routes& routes)
>      app_json_init_path("app API");
>      run_app.set_handler([](const_req req) {
>          string command = req.get_query_param("command");
> -        exec_app(command);
> -        return "";
> +        static std::string app_ids; // static, so that c_str data is not
> invalidated after return.
> +        app_ids = exec_app(command);
> +        return app_ids.c_str();
>

I don't like this "static" trick. It means that if we call this function
twice in parallel, it will get mixed up. It's not a common use case, but
why take this chance?

Won't "return app_ids" work, without the c_str() part (and without the
static)?
Or even more simply "return exec_app(command)"?


>      });
>  }
>  }
> --
> 2.9.3
>
> --
> 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.
>

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