From: Igor Kotrasinski Date: Wed, 1 Aug 2018 07:38:53 +0000 (+0200) Subject: Make simdaemon use the new debugproxy X-Git-Tag: submit/tizen/20180828.110226~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F185690%2F3;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Make simdaemon use the new debugproxy Instead of running gdbserver to listen on a port, we run it in stdin/out mode and replace the descriptor with the debugproxy socket fd. Change-Id: Ifa06dd42d008a1efb4628061a0dee05cbc51ada9 Signed-off-by: Igor Kotrasinski --- diff --git a/simulatordaemon/src/TAFactory.cpp b/simulatordaemon/src/TAFactory.cpp index 89cc70b..023e586 100644 --- a/simulatordaemon/src/TAFactory.cpp +++ b/simulatordaemon/src/TAFactory.cpp @@ -27,6 +27,7 @@ #include #include +#include #include "TAFactory.h" #include "UUIDUtils.h" #include "ResponseCommands/ResMakeCommand.h" @@ -447,10 +448,10 @@ bool TAFactory::launchTAInDebugMode(uint32_t port, string image_path, { char *argv[5]; string gdbserver = "/usr/bin/gdbserver"; - string port_str = "localhost:" + std::to_string(port); + string io_str = "-"; argv[0] = &gdbserver[0]; - argv[1] = &port_str[0]; + argv[1] = &io_str[0]; argv[2] = &image_path[0]; argv[3] = &argument[0]; argv[4] = NULL; @@ -459,8 +460,29 @@ bool TAFactory::launchTAInDebugMode(uint32_t port, string image_path, pid = fork(); if (0 == pid) { LOGD(MODULE_SIM_DAEMON, "In Child Process"); + int err; + struct sockaddr_un addr = { + AF_UNIX, + DEBUGPROXY_SOCK_PATH, + }; + int sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) { + err = errno; + goto exit; + } + if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) == -1) + goto clean_socket; + if (write(sock, &port, sizeof(port)) == -1) + goto clean_socket; + if (dup2(sock, 0) == -1 || + dup2(sock, 1) == -1) + goto clean_socket; execv(argv[0], argv); - LOGE(MODULE_SIM_DAEMON, "Launching Trusted Application FAILED"); +clean_socket: + err = errno; + close(sock); +exit: + LOGE(MODULE_SIM_DAEMON, "Launching Trusted Application FAILED: %s", strerror(err)); pthread_mutex_unlock(&lock); return false; }