Add a new function for loader termination 12/298812/4
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 14 Sep 2023 00:43:21 +0000 (09:43 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 14 Sep 2023 01:33:29 +0000 (10:33 +0900)
The launchpad_loader_dispose() function is added to dispose the loader iself.
The function sends a disposal request to the launchpad-process-pool.
When the launchpad-process-pool gets the request, it sends SIGKILL signal to
the running loader process.

Change-Id: I93889f3272704d140ce7f1ae86b328fbda384d13
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/launchpad-process-pool/src/launchpad.c
src/lib/common/inc/launchpad_common.h
src/lib/launchpad/inc/launchpad.h
src/lib/launchpad/src/launchpad_lib.c

index 9083b207f4443a89bc14ef3e0a42b55b6d56a1cd..637b20053616a2104b391114e67fb154b8574a9c 100644 (file)
@@ -2665,6 +2665,24 @@ static int __launch_request_handler(request_h request)
        return 0;
 }
 
+static int __dispose_loader_handler(request_h request)
+{
+       candidate_process_context_t *cpc;
+
+       cpc = __find_slot_from_pid(request->caller_pid);
+       if (cpc == NULL) {
+               _E("Failed to find slot. pid(%d)", request->caller_pid);
+               __request_send_result(request, -ENOENT);
+               return -1;
+       }
+
+       __dispose_candidate_process(cpc);
+       _W("[PAD_CMD_DISPOSE_LOADER] loader_name(%s), pid(%d)",
+                       cpc->loader_name, request->caller_pid);
+       __request_send_result(request, 0);
+       return 0;
+}
+
 static request_handler __request_handlers[] = {
        [PAD_CMD_VISIBILITY] = __visibility_request_handler,
        [PAD_CMD_ADD_LOADER] = __add_loader_request_handler,
@@ -2677,6 +2695,7 @@ static request_handler __request_handlers[] = {
        [PAD_CMD_UPDATE_APP_TYPE] = __update_app_type_request_handler,
        [PAD_CMD_CONNECT] = __connect_request_handler,
        [PAD_CMD_LAUNCH] = __launch_request_handler,
+       [PAD_CMD_DISPOSE_LOADER] = __dispose_loader_handler,
 };
 
 static bool __handle_launch_event(int fd, io_condition_e cond, void *data)
index 000606ac3cf2700affb50e8c3fc884dcced8ba76..afebbae24a3af4bb2d05e37e10984f4c7bad3099 100644 (file)
@@ -83,6 +83,7 @@ typedef enum {
        PAD_CMD_UPDATE_APP_TYPE = 16,
        PAD_CMD_PREPARE_APP_DEFINED_LOADER = 17,
        PAD_CMD_CONNECT = 18,
+       PAD_CMD_DISPOSE_LOADER = 21,
 } pad_cmd_e;
 
 typedef struct _app_pkt_t {
index b7d6c217c9e1e3fcd93cd2ef14b15c63da8bec6d..8ae9ca2b7a35d3440528845792e69e3c8c135f90 100644 (file)
@@ -102,6 +102,18 @@ int launchpad_loader_block_threads(void);
  */
 int launchpad_loader_unblock_threads(void);
 
+/**
+ * @brief Disposes the loader.
+ * @details This function sends a disposal request to the launchpad.
+ *          The launchpad will dispose the loader process using kill().
+ * @since_tizen 7.0
+ *
+ * @return @c on success,
+ *         otherwise a negative error value
+ * @see launchpad_loader_main();
+ */
+int launchpad_loader_dispose(void);
+
 #ifdef __cplusplus
 }
 #endif
index 716bec6f7c711ba7976f0ea02ee1b66fae14a5b7..899f5504bd55dc7042bd3845c2ce8cb964733ba3 100644 (file)
@@ -46,6 +46,9 @@
 #define AUL_PR_NAME 16
 #define SIGRTINT (SIGRTMIN + 2)
 
+extern int app_send_cmd_to_launchpad(const char *pad_type,
+               uid_t uid, int cmd, bundle *kb);
+
 typedef struct thread_handler_s {
        struct sigaction old;
        GMutex mutex;
@@ -687,3 +690,27 @@ API int launchpad_loader_unblock_threads(void)
 
        return 0;
 }
+
+API int launchpad_loader_dispose(void)
+{
+#define PROCESS_POOL_LAUNCHPAD_SOCK ".launchpad-process-pool-sock"
+       bundle *b;
+       int ret;
+
+       b = bundle_create();
+       if (b == NULL) {
+               _E("bundle_create() is failed");
+               return -ENOMEM;
+       }
+
+       ret = app_send_cmd_to_launchpad(PROCESS_POOL_LAUNCHPAD_SOCK, getuid(),
+                       PAD_CMD_DISPOSE_LOADER, b);
+       bundle_free(b);
+       if (ret != AUL_R_OK) {
+               _E("Failed to send disposal request. error(%d)", ret);
+               return -ECOMM;
+       }
+
+       _W("Success to send disposal request");
+       return 0;
+}