diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2016-06-02 08:37:03 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2016-06-02 09:06:16 +0900 |
commit | 65f01f3440d500f4d0f6c0d318b21d64e91c9437 (patch) | |
tree | 294acf90f03c70a11901ac1c2a14165cae1a1ff2 | |
parent | 352bdf43ea733c0784a28b631eecc98cb45f7733 (diff) | |
download | launchpad-65f01f3440d500f4d0f6c0d318b21d64e91c9437.tar.gz launchpad-65f01f3440d500f4d0f6c0d318b21d64e91c9437.tar.bz2 launchpad-65f01f3440d500f4d0f6c0d318b21d64e91c9437.zip |
Define an enumerated type about arguments
Change-Id: I3c8175cf7811b4a1f5e933a3718a168a71b9b369
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | inc/launchpad_common.h | 8 | ||||
-rwxr-xr-x | src/launchpad.c | 31 | ||||
-rw-r--r-- | src/launchpad_lib.c | 17 | ||||
-rw-r--r-- | src/launchpad_loader.c | 18 |
4 files changed, 44 insertions, 30 deletions
diff --git a/inc/launchpad_common.h b/inc/launchpad_common.h index 8587052..8ae9705 100644 --- a/inc/launchpad_common.h +++ b/inc/launchpad_common.h @@ -68,6 +68,14 @@ } \ } while (0) +enum loader_arg { + LOADER_ARG_PATH, + LOADER_ARG_TYPE, + LOADER_ARG_ID, + LOADER_ARG_EXTRA, + LOADER_ARG_DUMMY, +}; + typedef struct _app_pkt_t { int cmd; int len; diff --git a/src/launchpad.c b/src/launchpad.c index cd5abed..05162bf 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -401,8 +401,8 @@ static int __prepare_candidate_process(int type, int loader_id) return -1; memset(argbuf, ' ', LOADER_ARG_LEN); - argbuf[LOADER_ARG_LEN-1] = '\0'; - argv[4] = argbuf; + argbuf[LOADER_ARG_LEN - 1] = '\0'; + argv[LOADER_ARG_DUMMY] = argbuf; cpt->last_exec_time = time(NULL); pid = fork(); @@ -412,11 +412,11 @@ static int __prepare_candidate_process(int type, int loader_id) type_str[0] = '0' + type; snprintf(loader_id_str, sizeof(loader_id_str), "%d", loader_id); - argv[0] = cpt->loader_path; - argv[1] = type_str; - argv[2] = loader_id_str; - argv[3] = cpt->loader_extra; - if (execv(argv[0], argv) < 0) + argv[LOADER_ARG_PATH] = cpt->loader_path; + argv[LOADER_ARG_TYPE] = type_str; + argv[LOADER_ARG_ID] = loader_id_str; + argv[LOADER_ARG_EXTRA] = cpt->loader_extra; + if (execv(argv[LOADER_ARG_PATH], argv) < 0) _E("Failed to prepare candidate_process"); else _D("Succeeded to prepare candidate_process"); @@ -491,16 +491,19 @@ static int __normal_fork_exec(int argc, char **argv) _D("start real fork and exec"); - libdir = _get_libdir(argv[0]); + libdir = _get_libdir(argv[LOADER_ARG_PATH]); if (libdir) setenv("LD_LIBRARY_PATH", libdir, 1); free(libdir); - if (execv(argv[0], argv) < 0) { /* Flawfinder: ignore */ - if (errno == EACCES) - _E("such a file is no executable - %s", argv[0]); - else - _E("unknown executable error - %s", argv[0]); + if (execv(argv[LOADER_ARG_PATH], argv) < 0) { /* Flawfinder: ignore */ + if (errno == EACCES) { + _E("such a file is no executable - %s", + argv[LOADER_ARG_PATH]); + } else { + _E("unknown executable error - %s", + argv[LOADER_ARG_PATH]); + } return -1; } /* never reach*/ @@ -517,7 +520,7 @@ static void __real_launch(const char *app_path, bundle * kb) putenv("TIZEN_DEBUGGING_PORT=1"); app_argv = _create_argc_argv(kb, &app_argc); - app_argv[0] = strdup(app_path); + app_argv[LOADER_ARG_PATH] = strdup(app_path); for (i = 0; i < app_argc; i++) { if ((i % 2) == 1) diff --git a/src/launchpad_lib.c b/src/launchpad_lib.c index f4cf180..bf25473 100644 --- a/src/launchpad_lib.c +++ b/src/launchpad_lib.c @@ -256,7 +256,7 @@ static int __candidate_process_launchpad_main_loop(app_pkt_t *pkt, *out_argv = tmp_argv; *out_argc = tmp_argc; - (*out_argv)[0] = out_app_path; + (*out_argv)[LOADER_ARG_PATH] = out_app_path; for (i = 0; i < *out_argc; i++) { SECURE_LOGD("input argument %d : %s##", i, @@ -302,10 +302,11 @@ static void __receiver_cb(int fd) __loader_adapter->remove_fd(__loader_user_data, fd); close(fd); - ret = __candidate_process_launchpad_main_loop(pkt, __argv[0], - &__argc, &__argv, __loader_type); + ret = __candidate_process_launchpad_main_loop(pkt, + __argv[LOADER_ARG_PATH], &__argc, &__argv, + __loader_type); SECURE_LOGD("[candidate] real app argv[0]: %s, real app argc: %d", - __argv[0], __argc); + __argv[LOADER_ARG_PATH], __argc); free(pkt); if (ret >= 0) { @@ -337,8 +338,8 @@ static int __before_loop(int argc, char **argv) setsid(); if (argc > 3) { - extra = bundle_decode((bundle_raw *)argv[3], - strlen(argv[3])); + extra = bundle_decode((bundle_raw *)argv[LOADER_ARG_EXTRA], + strlen(argv[LOADER_ARG_EXTRA])); } if (__loader_callbacks->create) { @@ -388,13 +389,13 @@ API int launchpad_loader_main(int argc, char **argv, return -1; } - __loader_type = argv[1][0] - '0'; + __loader_type = argv[LOADER_ARG_TYPE][0] - '0'; if (__loader_type < 0 || __loader_type >= LAUNCHPAD_TYPE_MAX) { _E("invalid argument. (type: %d)", __loader_type); return -1; } - __loader_id = atoi(argv[2]); + __loader_id = atoi(argv[LOADER_ARG_ID]); if (callbacks == NULL) { _E("invalid argument. callback is null"); diff --git a/src/launchpad_loader.c b/src/launchpad_loader.c index 17fc4bd..9d742f3 100644 --- a/src/launchpad_loader.c +++ b/src/launchpad_loader.c @@ -137,12 +137,13 @@ static int __loader_terminate_cb(int argc, char **argv, void *user_data) bool restore = false; char *libdir = NULL; - SECURE_LOGD("[candidate] Launch real application (%s)", argv[0]); + SECURE_LOGD("[candidate] Launch real application (%s)", + argv[LOADER_ARG_PATH]); if (getcwd(old_cwd, sizeof(old_cwd)) == NULL) goto do_dlopen; - libdir = _get_libdir(argv[0]); + libdir = _get_libdir(argv[LOADER_ARG_PATH]); if (libdir == NULL) goto do_dlopen; @@ -156,7 +157,7 @@ static int __loader_terminate_cb(int argc, char **argv, void *user_data) restore = true; do_dlopen: - handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL); + handle = dlopen(argv[LOADER_ARG_PATH], RTLD_LAZY | RTLD_GLOBAL); if (handle == NULL) { _E("dlopen failed(%s). Please complile with -fPIE and " "link with -pie flag", dlerror()); @@ -183,19 +184,20 @@ do_dlopen: return res; do_exec: - if (access(argv[0], F_OK | R_OK)) { + if (access(argv[LOADER_ARG_PATH], F_OK | R_OK)) { SECURE_LOGE("access() failed for file: \"%s\", error: %d (%s)", - argv[0], errno, + argv[LOADER_ARG_PATH], errno, strerror_r(errno, err_str, sizeof(err_str))); } else { - SECURE_LOGD("[candidate] Exec application (%s)", __argv[0]); + SECURE_LOGD("[candidate] Exec application (%s)", + __argv[LOADER_ARG_PATH]); __close_fds(); if (libdir) setenv("LD_LIBRARY_PATH", libdir, 1); free(libdir); - if (execv(argv[0], argv) < 0) { + if (execv(argv[LOADER_ARG_PATH], argv) < 0) { SECURE_LOGE("execv() failed for file: \"%s\", " - "error: %d (%s)", argv[0], errno, + "error: %d (%s)", argv[LOADER_ARG_PATH], errno, strerror_r(errno, err_str, sizeof(err_str))); } } |