manager: remove fork()/execv() using 16/149616/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 12 Sep 2017 15:35:44 +0000 (18:35 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Tue, 12 Sep 2017 15:35:44 +0000 (18:35 +0300)
Change-Id: I12ba76c332d0ca99548ad47e2411122052c0c5c5
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/da_protocol.c
daemon/daemon.c
daemon/utils.c
daemon/utils.h

index e5f5306..7395dd8 100644 (file)
@@ -50,6 +50,7 @@
 #include "da_data.h"
 #include "wsi.h"
 #include "cpp/features/feature_manager_c.h"
+#include "cpp/auxd/auxd_client_c.h"
 
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -741,6 +742,12 @@ void stop_all_done(void)
        pthread_mutex_unlock(&stop_all_mutex);
 }
 
+static void terminate_web_app(const char *app_id)
+{
+       if (!auxd_client_tizen_app_terminate(manager.auxd_client, app_id))
+               LOGE("Cannot terminate app_id='%s'\n", app_id);
+}
+
 static void stop_web_apps(void)
 {
        const struct app_info_t *app_info;
@@ -749,7 +756,7 @@ static void stop_web_apps(void)
        app_info = app_info_get_first(&app);
        while (app_info) {
                if (app_info->app_type == APP_TYPE_WEB)
-                       kill_app_web(app_info->app_id);
+                       terminate_web_app(app_info->app_id);
                app_info = app_info_get_next(&app);
        }
 }
index 8bd65c8..2c3b245 100644 (file)
@@ -324,12 +324,9 @@ static int exec_app(const struct app_info_t *app_info)
                LOGI("already started\n");
                break;
        case APP_TYPE_COMMON:
-               if (exec_app_common(app_info->exe_path)) {
-                       LOGE("Cannot exec common app %s\n", app_info->exe_path);
-                       res = -1;
-               } else {
-                       inc_apps_to_run();
-               }
+               /* TODO: use auxd for implement */
+               LOGE("Common app is not supported\n");
+               res = -1;
                break;
        case APP_TYPE_WEB:
                res = exec_app_case_type_web(app_info);
index 8cec29d..6f84116 100644 (file)
@@ -162,177 +162,6 @@ int change_user(const char *username)
        return 0;
 }
 
-int exec_with_user(const char *username, const char *path,
-                  char *const app_argv[])
-{
-       int ret;
-
-       if (username) {
-               int myuid = getuid();
-
-               if (myuid != 0) {
-                       LOGE("uid %d is not root\n", myuid);
-               } else {
-                       ret = change_user(username);
-                       if (ret)
-                               LOGE("failed to set user \"%s\"\n", username);
-               }
-       }
-
-       ret = execv(path, app_argv);
-       if (ret < 0)
-               LOGE("failed to exec \"%s\"(%d)\n", path, ret);
-
-       _Exit(EXIT_FAILURE);
-}
-
-/* execute applcation with executable binary path */
-int exec_app_tizen(const char *app_id, const char *exec_path)
-{
-       pid_t pid;
-
-       LOGI("exec %s\n", exec_path);
-
-       if (exec_path == NULL || !strlen(exec_path)) {
-               LOGE("Executable path is not correct\n");
-               return -1;
-       }
-       LOGI("launch app path is %s, executable path is %s\n"
-            "launch app name (%s), app_id (%s)\n",
-            LAUNCH_APP_PATH, exec_path, LAUNCH_APP_NAME, app_id);
-
-       pid = fork();
-       if (pid == -1)
-               return -1;
-
-       if (pid > 0) { /* parent */
-               int status, ret;
-               do
-                       ret = waitpid(pid, &status, 0);
-               while (ret == -1 && errno == EINTR);
-               return 0;
-       } else { /* child */
-               char *app_argv[] = {
-                       LAUNCH_APP_NAME,
-                       (char *)app_id,
-                       NULL
-               };
-
-               exec_with_user(EXEC_USER, LAUNCH_APP_PATH, app_argv);
-       }
-
-       return 0;
-}
-
-int exec_app_common(const char* exec_path)
-{
-       pid_t pid;
-
-       LOGI("exec %s\n", exec_path);
-       if (exec_path == NULL || !strlen(exec_path)) {
-               LOGE("Executable path is not correct\n");
-               return -1;
-       }
-
-       pid = fork();
-       if (pid == -1)
-               return -1;
-
-       if (pid > 0) { /* parent */
-               return 0;
-       } else { /* child */
-               char command[PATH_MAX];
-               char *app_argv[] = {
-                       SHELL_CMD,
-                       "-c",
-                       command,
-                       NULL
-               };
-
-               snprintf(command, sizeof(command), "%s", exec_path);
-               LOGI("cmd: <%s>\n", command);
-               exec_with_user(EXEC_USER, SHELL_CMD, app_argv);
-       }
-
-       return 0;
-}
-
-int exec_app_web(const char *app_id)
-{
-       pid_t pid;
-
-       LOGI("wrt-launcher path is %s,\n"
-            "wrt-launcher name (%s), app_id (%s)\n",
-            APP_LAUNCHER_PATH, APP_LAUNCHER_NAME, app_id);
-
-       pid = fork();
-       if (pid == -1)
-               return -1;
-
-       if (pid > 0) { /* parent */
-               int status, ret;
-               do
-                       ret = waitpid(pid, &status, 0);
-               while (ret == -1 && errno == EINTR);
-               return 0;
-       } else { /* child */
-               char *web_argv_with_profile[] = {
-                       APP_LAUNCHER_NAME,
-                       "-w"
-                       "-s",
-                       (char *)app_id,
-                       NULL
-               };
-               char *web_argv[] = {
-                       APP_LAUNCHER_NAME,
-                       "-s",
-                       (char *)app_id,
-                       NULL
-               };
-
-               if (is_feature_enabled(FL_WEB_PROFILING))
-                       exec_with_user(EXEC_USER, APP_LAUNCHER_PATH,
-                                      web_argv_with_profile);
-               else
-                       exec_with_user(EXEC_USER, APP_LAUNCHER_PATH, web_argv);
-       }
-
-       return 0;
-}
-
-void kill_app_web(const char *app_id)
-{
-       pid_t pid;
-
-       LOGI("wrt-launcher path is %s,\n"
-            "wrt-launcher name (%s), app_id (%s)\n",
-            APP_LAUNCHER_PATH, APP_LAUNCHER_NAME, app_id);
-
-       pid = fork();
-       if (pid == -1)
-               return;
-
-       if (pid > 0) { /* parent */
-               int status, ret;
-               do
-                       ret = waitpid(pid, &status, 0);
-               while (ret == -1 && errno == EINTR);
-               return;
-       } else { /* child */
-               char *web_argv[] = {
-                       APP_LAUNCHER_NAME,
-                       "-k",
-                       (char *)app_id,
-                       NULL
-               };
-
-               exec_with_user(EXEC_USER, APP_LAUNCHER_PATH, web_argv);
-               /* FIXME: If code flows here, it deserves greater attention */
-               LOGE("Cannot run exec!\n");
-               _Exit(EXIT_FAILURE);
-       }
-}
-
 static char *dereference_tizen_exe_path(const char *path, char *resolved);
 
 int is_same_app_process(char* appPath, int pid)
index 7fe8a65..409feee 100644 (file)
@@ -57,10 +57,6 @@ int remove_indir(const char *dirname);
 
 int is_same_app_process(char* appPath, int pid);
 
-int exec_app_tizen(const char *app_id, const char *exec_path);
-int exec_app_common(const char* exec_path);
-int exec_app_web(const char *app_id);
-void kill_app_web(const char *app_id);
 float get_uptime(void);
 
 void swap_usleep(useconds_t usec);