diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2018-05-28 20:38:52 +0900 |
---|---|---|
committer | HwanKyu Jhun <h.jhun@samsung.com> | 2018-05-30 04:38:11 +0000 |
commit | 3f87111dd1a3935a7cb8b068c8bca98481b94aa7 (patch) | |
tree | 49d7f27af62070e3337fc58e5f8365c7ffdb027a | |
parent | 10c35396a09e048987e5fc9d9757a5ca1dfea3a7 (diff) | |
download | aul-1-3f87111dd1a3935a7cb8b068c8bca98481b94aa7.tar.gz aul-1-3f87111dd1a3935a7cb8b068c8bca98481b94aa7.tar.bz2 aul-1-3f87111dd1a3935a7cb8b068c8bca98481b94aa7.zip |
Fix launch_debug tool
- Adds a option for sync mode launcha
- Removes unused option
- Changes usage messages
Change-Id: I66c144e1d4af43473dd5367878465f5726c80d9b
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | tool/launch_debug.c | 92 |
1 files changed, 76 insertions, 16 deletions
diff --git a/tool/launch_debug.c b/tool/launch_debug.c index 182404d8..562453a6 100644 --- a/tool/launch_debug.c +++ b/tool/launch_debug.c @@ -17,10 +17,12 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <stdbool.h> #include <unistd.h> #include <sys/types.h> #include <string.h> +#include <glib.h> #include <bundle.h> #include <bundle_internal.h> #include <pkgmgr-info.h> @@ -31,9 +33,11 @@ #define LAUNCHPAD_PROCESS_POOL_SOCK ".launchpad-process-pool-sock" #define DLP_K_ATTACH_ARG "__DLP_ATTACH_ARG__" -#define DLP_K_GDBSERVER_PATH "__DLP_GDBSERVER_PATH__" #define SDK_ATTACH "ATTACH" +static GMainLoop *__mainloop; +static bool __sync_mode; + static bundle *create_internal_bundle(int argc, char **argv) { bundle *b; @@ -61,10 +65,13 @@ static bundle *create_internal_bundle(int argc, char **argv) bundle_add(b, SDK_ATTACH, DLP_K_ATTACH_ARG); bundle_add_str_array(b, DLP_K_ATTACH_ARG, NULL, cnt); - for (j = 0; j < cnt; j++) - bundle_set_str_array_element(b, DLP_K_ATTACH_ARG, j, arg[j]); - } else if (argv[i] && strcmp(argv[i], DLP_K_GDBSERVER_PATH) == 0) { - bundle_add(b, DLP_K_GDBSERVER_PATH, argv[i + 1]); + for (j = 0; j < cnt; j++) { + bundle_set_str_array_element(b, + DLP_K_ATTACH_ARG, j, arg[j]); + } + } else if (argv[i] && !strcmp(argv[i], "__LAUNCH_APP_MODE__")) { + if (argv[i + 1] && !strcmp(argv[i + 1], "SYNC")) + __sync_mode = true; } } @@ -73,10 +80,10 @@ static bundle *create_internal_bundle(int argc, char **argv) static void print_usage(char *progname) { - printf("[usage] %s [appid] %s %s %s <gdbserver_path> %s --attach,:[port],[pid]\n", - progname, AUL_K_SDK, SDK_ATTACH, DLP_K_GDBSERVER_PATH, DLP_K_ATTACH_ARG); - printf("ex) $ %s [appid] %s %s %s /usr/bin/gdbserver %s --attach,:10003,1234\n", - progname, AUL_K_SDK, SDK_ATTACH, DLP_K_GDBSERVER_PATH, DLP_K_ATTACH_ARG); + printf("[usage] %s [appid] %s <debugger name> %s --attach,:[port],[pid]\n", + progname, AUL_K_SDK, DLP_K_ATTACH_ARG); + printf("ex) $ %s [appid] %s %s %s --attach,:10003,1234\n", + progname, AUL_K_SDK, SDK_ATTACH, DLP_K_ATTACH_ARG); } static int __get_gles(void) @@ -134,6 +141,7 @@ static int __set_appinfo_for_debug_launchpad(bundle *kb, const char *appid) pkgmgrinfo_app_hwacceleration hwacc = PMINFO_HWACCELERATION_OFF; const char *hwacc_str = "NOT_USE"; bool process_pool = false; + char buf[12]; if (kb == NULL) return -1; @@ -191,15 +199,71 @@ static int __set_appinfo_for_debug_launchpad(bundle *kb, const char *appid) __set_pkg_api_version(kb, pkgid); aul_svc_set_loader_id(kb, PAD_LOADER_ID_DIRECT); + snprintf(buf, sizeof(buf), "%d", getpid()); + bundle_add(kb, AUL_K_CALLER_PID, buf); + end: pkgmgrinfo_appinfo_destroy_appinfo(handle); return 0; } -int main(int argc, char **argv) +static void __run_mainloop(void) +{ + __mainloop = g_main_loop_new(NULL, FALSE); + if (!__mainloop) { + printf("Failed to create glib main loop\n"); + exit(EXIT_FAILURE); + } + + g_main_loop_run(__mainloop); +} + +static void __quit_mainloop(void) +{ + if (__mainloop) { + g_main_loop_quit(__mainloop); + g_main_loop_unref(__mainloop); + __mainloop = NULL; + } +} + +static int __app_dead_handler(int pid, void *data) +{ + int launched_pid = GPOINTER_TO_INT(data); + + if (launched_pid == pid) + __quit_mainloop(); + + return 0; +} + +static gboolean __run_cb(gpointer data) { + bundle *b = (bundle *)data; int ret; + + if (!b) + return G_SOURCE_REMOVE; + + ret = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK, + getuid(), 0, b); + if (ret < 0) + printf("Failed to send launch request\n"); + + if (__sync_mode) { + aul_listen_app_dead_signal(__app_dead_handler, + GINT_TO_POINTER(ret)); + return G_SOURCE_REMOVE; + } + + __quit_mainloop(); + + return G_SOURCE_REMOVE; +} + +int main(int argc, char **argv) +{ bundle *b; if (argc < 2) { @@ -220,12 +284,8 @@ int main(int argc, char **argv) } __set_appinfo_for_debug_launchpad(b, argv[1]); - - ret = app_send_cmd_to_launchpad(LAUNCHPAD_PROCESS_POOL_SOCK, - getuid(), 0, b); - if (ret < 0) - printf("Failed to launch %s\n", argv[1]); - + g_idle_add(__run_cb, b); + __run_mainloop(); bundle_free(b); return 0; |