Fix Launchpad Recovery Feature 42/238242/5
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Jul 2020 00:56:03 +0000 (09:56 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 Jul 2020 05:25:58 +0000 (14:25 +0900)
To recovery launchpad, amd uses ".launchpad-recovery-sock" instead of
".launchpad-process-pool-sock".
Some product doesn't use ".launchpad-process-pool-sock" for socket activation.
Because, the launchpad-process-pool is started without systemd.

Change-Id: Ic18b61c320a8930d0a43d12ffa004697bfc90e01
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/amd_launchpad.h
src/core/amd_launch.c
src/core/amd_launchpad.c
src/core/amd_main.c

index 1e4f5f59b5e83b9bd35b474e939a622a7d017b02..3ba39087ebc070842160945f0b7c55ce82246409 100644 (file)
@@ -26,3 +26,7 @@ int _launchpad_set_launcher(int (*callback)(bundle *, uid_t, void *),
 int _launchpad_launch(bundle *kb, uid_t uid);
 
 int _launchpad_recover_launcher(uid_t uid);
+
+int _launchpad_init(void);
+
+void _launchpad_fini(void);
index 7d4e058fc38e28e87060df37909a98368a5a12c1..9e633a7cd35e9821147dd6af440d92c4c67a3192 100644 (file)
@@ -3090,7 +3090,8 @@ static int __do_starting_app(struct launch_s *handle, request_h req,
                                        ret, 0, NULL, NULL);
                        socket_exists =
                                _app_status_socket_exists(handle->app_status);
-                       if (ret == -ECOMM && socket_exists) {
+                       if ((ret == -ECOMM && socket_exists) ||
+                                       getpgid(handle->pid) < 0) {
                                _E("ECOMM error, we will term the app - %s:%d",
                                                handle->appid, handle->pid);
                                __kill_and_cleanup_status(handle, target_uid);
index d63fd4ab6cbd1937125b975264b1d89b4179bc97..bc8e136f3bdf40948867798f090fb003f835686b 100644 (file)
@@ -21,6 +21,7 @@
 #include <signal.h>
 
 #include <aul.h>
+#include <glib.h>
 
 #include "amd_app_status.h"
 #include "amd_config.h"
 #include "amd_login_monitor.h"
 #include "amd_signal.h"
 #include "amd_util.h"
+#include "amd_socket.h"
+
+#define TIMEOUT_INTERVAL 1000
+#define LAUNCHPAD_RECOVERY_SOCK ".launchpad-recovery-sock"
 
 struct launchpad_info {
        int (*launcher)(bundle *, uid_t t, void *);
@@ -36,6 +41,7 @@ struct launchpad_info {
 };
 
 static struct launchpad_info __launchpad;
+static GHashTable *__timer_tbl;
 
 int _launchpad_set_launcher(int (*callback)(bundle *, uid_t, void *),
                void *user_data)
@@ -56,6 +62,70 @@ int _launchpad_launch(bundle *kb, uid_t uid)
        return __launchpad.launcher(kb, uid, __launchpad.data);
 }
 
+static void __remove_recovery_timer(gpointer data)
+{
+       guint timer = GPOINTER_TO_UINT(data);
+
+       g_source_remove(timer);
+}
+
+static void __unset_recovery_timer(uid_t uid)
+{
+       if (!g_hash_table_contains(__timer_tbl, GUINT_TO_POINTER(uid)))
+               return;
+
+       g_hash_table_remove(__timer_tbl, GUINT_TO_POINTER(uid));
+       _W("[__RECOVERY__] timer is removed. uid(%u)", uid);
+}
+
+static gboolean __launchpad_recovery_cb(gpointer data)
+{
+       uid_t uid = GPOINTER_TO_UINT(data);
+       bundle *b;
+       pid_t pgid;
+       pid_t pid;
+       int ret;
+
+       pid = _login_monitor_get_launchpad_pid(uid);
+       if (pid > 0) {
+               pgid = getpgid(pid);
+               if (pgid > 0) {
+                       _W("[__RECOVERY__] launchpad(%d) is running", pid);
+                       return G_SOURCE_CONTINUE;
+               }
+       }
+
+       b = bundle_create();
+       ret = _send_cmd_to_launchpad_async(LAUNCHPAD_RECOVERY_SOCK, uid,
+                       0, b);
+       bundle_free(b);
+       if (ret < 0) {
+               _E("[__RECOVERY__] Failed to send recovery request. error(%d)",
+                               ret);
+               return G_SOURCE_CONTINUE;
+       }
+
+       _W("[__RECOVERY__] Recovery launchpad");
+       __unset_recovery_timer(uid);
+       return G_SOURCE_CONTINUE;
+}
+
+static void __set_recovery_timer(uid_t uid)
+{
+       guint timer;
+
+       timer = g_timeout_add(TIMEOUT_INTERVAL, __launchpad_recovery_cb,
+                       GUINT_TO_POINTER(uid));
+       g_hash_table_insert(__timer_tbl, GUINT_TO_POINTER(uid),
+                       GUINT_TO_POINTER(timer));
+       _W("[__RECOVERY__] timer(%u) is removed. uid(%u)", timer, uid);
+}
+
+static bool __is_recovering(uid_t uid)
+{
+       return g_hash_table_contains(__timer_tbl, GUINT_TO_POINTER(uid));
+}
+
 static void __running_appinfo_cb(app_status_h app_status, void *user_data)
 {
        const char *appid;
@@ -83,6 +153,9 @@ int _launchpad_recover_launcher(uid_t uid)
        pid_t pid;
        int ret;
 
+       if (__is_recovering(uid))
+               return 0;
+
        _W("[__RECOVERY__] uid(%u)", uid);
        pid = _login_monitor_get_launchpad_pid(uid);
        if (pid < 0) {
@@ -95,5 +168,28 @@ int _launchpad_recover_launcher(uid_t uid)
        ret = kill(pid, SIGABRT);
        _E("[__RECOVERY__] launchpad pid(%d), uid(%d), result(%d)",
                        pid, uid, ret);
+
+       __set_recovery_timer(uid);
        return ret;
 }
+
+int _launchpad_init(void)
+{
+       _D("LAUNCHPAD_INIT");
+
+       __timer_tbl = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+                       NULL, __remove_recovery_timer);
+       if (!__timer_tbl) {
+               _E("g_hash_table_new() is failed");
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+void _launchpad_fini(void)
+{
+       _D("LAUNCHPAD_FINI");
+       if (__timer_tbl)
+               g_hash_table_destroy(__timer_tbl);
+}
index 6c22ef7da2e6ad0d60069fbc9abddc41a001c2b4..7f6fb3e12050ff6bb903d01b303e6350d456f52b 100644 (file)
@@ -43,6 +43,7 @@
 #include "amd_inotify.h"
 #include "amd_launch.h"
 #include "amd_launcher_service.h"
+#include "amd_launchpad.h"
 #include "amd_logger.h"
 #include "amd_login_monitor.h"
 #include "amd_noti.h"
@@ -359,6 +360,7 @@ static int __init(void)
        _anr_monitor_init();
        _launcher_service_init();
        _signal_init();
+       _launchpad_init();
 
        if (access(AMD_MOD_PATH, F_OK) == 0) {
                if (__load_modules(AMD_MOD_PATH) < 0)
@@ -386,6 +388,7 @@ static void __finish(void)
 {
        __unload_modules();
 
+       _launchpad_fini();
        _launcher_service_fini();
        _anr_monitor_fini();
        _config_fini();