Make simdaemon use the new debugproxy 90/185690/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Wed, 1 Aug 2018 07:38:53 +0000 (09:38 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 21 Aug 2018 10:37:29 +0000 (12:37 +0200)
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 <i.kotrasinsk@partner.samsung.com>
simulatordaemon/src/TAFactory.cpp

index 89cc70b..023e586 100644 (file)
@@ -27,6 +27,7 @@
 #include <boost/optional.hpp>
 #include <boost/none.hpp>
 
+#include <config.h>
 #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;
                }