Redirect TA output to file before posix_spawn (append mode) 78/157878/5
authorLukasz Kostyra <l.kostyra@samsung.com>
Thu, 26 Oct 2017 15:08:08 +0000 (17:08 +0200)
committerKrzysztof Dynowski <k.dynowski@samsung.com>
Wed, 10 Jan 2018 14:44:26 +0000 (15:44 +0100)
Change-Id: Ic9e8853b86029badee226a6b263254102b98dc1c

include/include/config.h
simulatordaemon/src/TAFactory.cpp

index 51752fe..e5cd6c9 100644 (file)
@@ -27,6 +27,7 @@
 
 //TEEStub must have write access in this directory (creating socket per TA)
 #define TEE_TASOCK_ROOT "/tmp/"
+#define TEE_TALOG_ROOT "/tmp/"
 
 #define SHM_PATH "/tmp/shm"
 #define SIMDAEMON_SOCK_PATH "/tmp/simdaemon"
index 4c5bcbe..0ab0067 100644 (file)
@@ -400,8 +400,30 @@ bool TAFactory::launchTA(string TAUUID, std::stringstream& str, bool debug,
                argv[2] = NULL;
                envp[0] = NULL;
 
+               // redirect TA output to file
+               posix_spawn_file_actions_t child_fd_actions;
+               int ret = posix_spawn_file_actions_init(&child_fd_actions);
+               if (ret != 0) {
+                       LOGE(SIM_DAEMON, "posix_spawn_file_actions_init failed");
+                       return false;
+               }
+
+               ret = posix_spawn_file_actions_addopen(&child_fd_actions, 1,
+                                                      (TEE_TALOG_ROOT + TAUUID + ".log").c_str(),
+                                                      O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0644);
+               if (ret != 0) {
+                       LOGE(SIM_DAEMON, "posix_spawn_file_actions_addopen failed");
+                       return false;
+               }
+
+               ret = posix_spawn_file_actions_adddup2(&child_fd_actions, 1, 2);
+               if (ret != 0) {
+                       LOGE(SIM_DAEMON, "posix_spawn_file_actions_adddup2 failed");
+                       return false;
+               }
+
                // Spawn TA
-               result = posix_spawn(&pid, argv[0], NULL, NULL, argv, envp);
+               result = posix_spawn(&pid, argv[0], &child_fd_actions, NULL, argv, envp);
                if (result == 0) {
                        LOGD(SIM_DAEMON, "TA pid: %i\n", pid);
                        LOGD(SIM_DAEMON, "Launched Trusted Application");