Support plugin module 32/233632/4
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 18 May 2020 03:09:41 +0000 (12:09 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Tue, 19 May 2020 00:10:48 +0000 (00:10 +0000)
Before dropping capabilities of child process, the plugin module is called
to prepare changing the application.

Change-Id: I18600b383a3c7a87e8f0df012b7fda219bccbd6f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/common/inc/launchpad_plugin.h [new file with mode: 0644]
src/common/src/launchpad_plugin.c [new file with mode: 0644]
src/launchpad/CMakeLists.txt
src/launchpad/src/launchpad.c
src/lib/src/launchpad_lib.c

diff --git a/src/common/inc/launchpad_plugin.h b/src/common/inc/launchpad_plugin.h
new file mode 100644 (file)
index 0000000..f2cf987
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHPAD_PLUGIN_H__
+#define __LAUNCHPAD_PLUGIN_H__
+
+#include <bundle.h>
+
+int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb);
+
+#endif /* __LAUNCHPAD_PLUGIN_H__ */
diff --git a/src/common/src/launchpad_plugin.c b/src/common/src/launchpad_plugin.c
new file mode 100644 (file)
index 0000000..d54d4ec
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "launchpad_plugin.h"
+#include "log_private.h"
+
+#define PATH_LAUNCHPAD_PLUGIN "/usr/share/aul/plugin/liblaunchpad-plugin.so"
+#define TAG_LAUNCHPAD_PLUGIN_PREPARE_APP "LAUNCHPAD_PLUGIN_PREPARE_APP"
+
+int _launchpad_plugin_prepare_app(const char *app_id, bundle *kb)
+{
+       void *handle;
+       int (*prepare_app)(const char *, bundle *);
+       int ret;
+
+       ret = access(PATH_LAUNCHPAD_PLUGIN, F_OK);
+       if (ret != 0) {
+               _D("plugin module does not exist. errno(%d)", errno);
+               return 0;
+       }
+
+       handle = dlopen(PATH_LAUNCHPAD_PLUGIN, RTLD_LAZY | RTLD_LOCAL);
+       if (!handle) {
+               _W("Failed to open plugin so. error(%s)", dlerror());
+               return 0;
+       }
+
+       prepare_app = dlsym(handle, TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
+       if (!prepare_app) {
+               _W("Failed to load %s", TAG_LAUNCHPAD_PLUGIN_PREPARE_APP);
+               return 0;
+       }
+
+       _W("LAUNCHPAD_PLUGIN_PREPARE_APP ++");
+       ret = prepare_app(app_id, kb);
+       _W("LAUNCHPAD_PLUGIN_PREPARE_APP --");
+       if (ret != 0)
+               return -1;
+
+       return 0;
+}
index a51f395..39ce5c8 100644 (file)
@@ -53,9 +53,9 @@ SET(LAUNCHPAD_PROCESS_POOL_SOURCE_FILES
 ADD_EXECUTABLE(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_SOURCE_FILES})
 
 IF(_TIZEN_FEATURE_PRELINK)
-TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm")
+TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-lm -ldl")
 ELSE(_TIZEN_FEATURE_PRELINK)
-TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm")
+TARGET_LINK_LIBRARIES(${LAUNCHPAD_PROCESS_POOL} ${LAUNCHPAD_PROCESS_POOL_PKGS_LDFLAGS} "-pie -lm -ldl")
 ENDIF(_TIZEN_FEATURE_PRELINK)
 
 SET_TARGET_PROPERTIES(${LAUNCHPAD_PROCESS_POOL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_pool})
index de35efb..9c7239d 100644 (file)
@@ -47,6 +47,7 @@
 #include "launchpad_inotify.h"
 #include "launchpad_io_channel.h"
 #include "launchpad_memory_monitor.h"
+#include "launchpad_plugin.h"
 #include "launchpad_proc.h"
 #include "launchpad_signal.h"
 #include "launchpad_types.h"
@@ -1211,6 +1212,12 @@ static int __prepare_exec(const char *appid, const char *app_path,
        /* TODO : should be add to check permission in the kernel*/
        setsid();
 
+       ret = _launchpad_plugin_prepare_app(appid, kb);
+       if (ret < 0) {
+               _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret);
+               return PAD_ERR_FAILED;
+       }
+
        ret = _enable_external_pkg(kb, menu_info->pkgid,
                        menu_info->global ? GLOBAL_USER : getuid());
        if (ret < 0)
index 45a59f9..d9d4434 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "launchpad.h"
 #include "launchpad_common.h"
+#include "launchpad_plugin.h"
 #include "launchpad_types.h"
 #include "preexec.h"
 
@@ -71,6 +72,12 @@ static int __prepare_exec(const char *appid, const char *app_path,
 
        __preexec_run(pkg_type, appid, app_path);
 
+       ret = _launchpad_plugin_prepare_app(appid, kb);
+       if (ret != 0) {
+               _E("_launchpad_plugin_prepare_app() is failed. error(%d)", ret);
+               return -1;
+       }
+
        ret = _enable_external_pkg(kb, pkgid, global ? GLOBAL_USER : getuid());
        if (ret < 0)
                return -1;