Wait for the creation of a socket 51/302851/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 14 Dec 2023 11:16:25 +0000 (20:16 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 15 Dec 2023 01:13:08 +0000 (10:13 +0900)
When the app launcher tool receives a request to execute through the -f option,
it waits for the creation of a socket in the launchpad-process-pool.
If the socket is not created yet, we call usleep() every 100ms and monitor.
The maximum timeout is 10 seconds.

Change-Id: I98b5e0dc704fe08ae6130d46d0057e3041f9d260
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
tool/app_launcher/app_launcher.c

index d2da2f3..57e3a18 100644 (file)
@@ -599,6 +599,30 @@ end:
        return ret;
 }
 
+static int __cmd_fast_start_init(struct launch_arg *arg)
+{
+       char buf[PATH_MAX];
+       int retry_count = 0;
+
+       if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
+               fprintf(stderr, "Failed to set appinfo. appid(%s), uid(%u)\n",
+                               arg->appid, arg->uid);
+               return -1;
+       }
+
+       snprintf(buf, sizeof(buf), "/run/aul/daemons/%u/%s",
+                       arg->uid, LAUNCHPAD_PROCESS_POOL_SOCK);
+       while (access(buf, F_OK) != 0) {
+               usleep(100 * 1000);
+               if (++retry_count > 100) {
+                       fprintf(stderr, "%s is not created\n", buf);
+                       break;
+               }
+       }
+
+       return 0;
+}
+
 static int __cmd_fast_start_run(struct launch_arg *arg)
 {
        int fd;
@@ -606,21 +630,17 @@ static int __cmd_fast_start_run(struct launch_arg *arg)
        if (!access(PATH_AMD_READY, F_OK))
                return __cmd_start_run(arg);
 
-       if (__set_appinfo_for_launchpad(arg->b, arg->appid, arg->uid) < 0) {
-               printf("Failed to set appinfo\n");
-               return -1;
-       }
-
        fd = aul_sock_create_launchpad_client_without_timeout(
                        LAUNCHPAD_PROCESS_POOL_SOCK, arg->uid);
        if (fd < 0) {
-               printf("Failed to create client socket. error: %d\n", fd);
+               fprintf(stderr, "Failed to create client socket. error: %d\n",
+                               fd);
                return -1;
        }
 
        arg->pid = aul_sock_send_bundle_with_fd(fd, 0, arg->b, AUL_SOCK_NONE);
        if (arg->pid <= 0) {
-               printf("... launch failed\n");
+               fprintf(stderr, "... launch failed\n");
                return -1;
        }
 
@@ -753,7 +773,7 @@ static struct command cmd_table[] = {
        },
        [CMD_FAST_START] = {
                .name = "fast-start",
-               .init = NULL,
+               .init = __cmd_fast_start_init,
                .run = __cmd_fast_start_run,
                .finish = __cmd_fast_start_finish
        },