Check socket status 61/266361/4
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Nov 2021 03:54:14 +0000 (12:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Nov 2021 06:53:29 +0000 (15:53 +0900)
When handling the request that is app registration, AMD checks whether
the socket is listening or not. If the socket is listening, AMD will set
the 'true' to the socket_exists flag of the app status handle.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/266359/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/266360/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/266361/

Change-Id: I5bbc23aad20ee987c7d637e287810c40a2d3ae71
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_app_status.c

index 7576b20..68e5001 100644 (file)
@@ -2178,6 +2178,37 @@ static void __update_proc_status(int pid, int status, int focused, void *data)
        _app_status_update_status(app_status, status, false, true);
 }
 
+static void __check_socket_status(int pid, uid_t uid, const char *appid)
+{
+       app_status_h app_status;
+       char path[PATH_MAX];
+       char buf[12] = { 0, };
+       FILE *fp;
+
+       app_status = _app_status_find(pid);
+       if (!app_status)
+               return;
+
+       snprintf(path, sizeof(path), "/run/aul/apps/%u/%d/%s", pid, uid, appid);
+       fp = fopen(path, "r");
+       if (!fp) {
+               _E("fopen() is failed. path(%s), errno(%d)", path, errno);
+               return;
+       }
+
+       if (fgets(buf, sizeof(buf), fp) == NULL) {
+               _E("fgets() is failed. path(%s)", path);
+               fclose(fp);
+               return;
+       }
+       fclose(fp);
+
+       if (!strcmp(buf, "1")) {
+               _W("%s(%d) socket is listening", appid, pid);
+               app_status->socket_exists = true;
+       }
+}
+
 int _app_status_register_pid(int pid, const char *appid, uid_t uid)
 {
        struct appinfo *ai;
@@ -2208,6 +2239,7 @@ int _app_status_register_pid(int pid, const char *appid, uid_t uid)
        component_type = _appinfo_get_value(ai, AIT_COMPTYPE);
        _app_status_add_app_info(ai, pid, false, uid, getpid(),
                        false, NULL, false);
+       __check_socket_status(pid, uid, appid);
        _noti_send(AMD_NOTI_MSG_APP_STATUS_APP_REGISTER_PID, pid, 0, ai, NULL);
        if (component_type && strcmp(component_type, APP_TYPE_SERVICE) != 0) {
                ret = _signal_get_proc_status_async(pid,