From: jk7744.park Date: Sat, 24 Oct 2015 07:30:40 +0000 (+0900) Subject: tizen 2.4 release X-Git-Tag: submit/tizen_2.4/20151028.063843 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2Fsubmit%2Ftizen_2.4%2F20151028.063843;p=framework%2Fappfw%2Fdebug-launchpad.git tizen 2.4 release --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f830197..c6fb8ab 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED dlog x11 libprivilege-control dbus-glib-1 sqlite3 bundle vconf libsmack aul pkgmgr-info) +pkg_check_modules(pkgs REQUIRED ail dlog x11 libprivilege-control dbus-glib-1 sqlite3 bundle vconf libsmack aul pkgmgr-info libsystemd-daemon) FIND_LIBRARY(LIB_DL dl) @@ -53,6 +53,10 @@ ENDIF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DSHARE_PREFIX=\"/usr/share/aul\"") +IF(_APPFW_FEATURE_SOCKET_ACTIVATION) + ADD_DEFINITIONS("-D_APPFW_FEATURE_SOCKET_ACTIVATION") +ENDIF(_APPFW_FEATURE_SOCKET_ACTIVATION) + # Linker flags SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") @@ -70,19 +74,38 @@ add_executable(${AVATAR_NAME} MESSAGE(" "${pkgs_LDFLAGS}) target_link_libraries(${AVATAR_NAME} aul cap ${pkgs_LDFLAGS} ${LIB_DL} "-pie") +set_target_properties(${AVATAR_NAME} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") set_target_properties(${AVATAR_NAME} PROPERTIES SKIP_BUILD_RPATH true ) # remove rpath option that is automatically generated by cmake. +add_executable(appid2pid + src/appid2pid.c + ) + +MESSAGE(" "${pkgs_LDFLAGS}) +target_link_libraries(appid2pid "-pie" aul ${pkgs_LDFLAGS} ${LIB_DL}) +set_target_properties(appid2pid + PROPERTIES SKIP_BUILD_RPATH true + ) # remove rpath option that is automatically generated by cmake. INSTALL(TARGETS ${LAUNCH_AGENT} DESTINATION bin) +add_executable(launch_debug + src/app_sock.c + src/launch_debug + ) +MESSAGE(" "${pkgs_LDFLAGS}) +target_link_libraries(launch_debug "-pie" ${pkgs_LDFLAGS} ${LIB_DL}) +set_target_properties(launch_debug + PROPERTIES SKIP_BUILD_RPATH true + ) # remove rpath option that is automatically generated by cmake. # pkgconfig file ### Install ### INSTALL(TARGETS ${AVATAR_NAME} DESTINATION bin) - - +INSTALL(TARGETS appid2pid DESTINATION bin) +INSTALL(TARGETS launch_debug DESTINATION bin) diff --git a/debug-launchpad.manifest b/debug-launchpad.manifest index 5874aa8..9459761 100644 --- a/debug-launchpad.manifest +++ b/debug-launchpad.manifest @@ -4,5 +4,7 @@ + + diff --git a/include/app_sock.h b/include/app_sock.h index a7544d5..b840bbd 100755 --- a/include/app_sock.h +++ b/include/app_sock.h @@ -54,7 +54,7 @@ enum app_cmd { }; #define AUL_SOCK_PREFIX "/tmp/alaunch" -#define AUL_SOCK_MAXBUFF 65535 +#define AUL_SOCK_MAXBUFF 131071 #define DEBUG_LAUNCHPAD_PID -4 #define ELOCALLAUNCH_ID 128 #define EILLEGALACCESS 127 diff --git a/include/perf.h b/include/perf.h index bec46e8..a6011ce 100755 --- a/include/perf.h +++ b/include/perf.h @@ -26,6 +26,7 @@ #ifdef PERF_ACTIVATE #include +#include static struct timeval __g_base_time = { .tv_sec = 0, .tv_usec = 0 diff --git a/packaging/debug-launchpad.service b/packaging/debug-launchpad.service new file mode 100644 index 0000000..5d961fd --- /dev/null +++ b/packaging/debug-launchpad.service @@ -0,0 +1,8 @@ +[Unit] +Description=Start the debug preload/preinit daemon +Requires=xorg.service tizen-generate-env.service +After=dbus.service vconf-setup.service ac.service xorg.service tizen-generate-env.service + +[Service] +EnvironmentFile=/run/tizen-mobile-env +ExecStart=/usr/bin/debug_launchpad_preloading_preinitializing_daemon " " diff --git a/packaging/debug-launchpad.socket b/packaging/debug-launchpad.socket new file mode 100644 index 0000000..e3762cc --- /dev/null +++ b/packaging/debug-launchpad.socket @@ -0,0 +1,11 @@ +[Unit] +Description=The debug preload/preinit daemon Socket + +[Socket] +ListenStream=/tmp/alaunch/-4 +DirectoryMode=1777 +SmackLabelIPIn=* +SmackLabelIPOut=@ + +[Install] +WantedBy=sockets.target diff --git a/packaging/debug-launchpad.spec b/packaging/debug-launchpad.spec index 20c7f22..5036adf 100755 --- a/packaging/debug-launchpad.spec +++ b/packaging/debug-launchpad.spec @@ -5,6 +5,8 @@ Release: 1 Group: System Environment/Daemons License: Apache-2.0 Source0: %{name}-%{version}.tar.gz +Source1: debug-launchpad.service +Source2: debug-launchpad.socket BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires(post): /sbin/ldconfig @@ -23,8 +25,22 @@ BuildRequires: pkgconfig(libprivilege-control) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(ail) BuildRequires: libcap-devel BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(libsystemd-daemon) + +%if "%{?tizen_profile_name}" == "wearable" +%define appfw_feature_socket_activation 1 +%else +%if "%{?tizen_profile_name}" == "mobile" +%define appfw_feature_socket_activation 1 +%else +%if "%{?tizen_profile_name}" == "tv" +%define appfw_feature_socket_activation 0 +%endif +%endif +%endif %description @@ -34,10 +50,20 @@ Debug launchpad %setup -q %build +%if 0%{?appfw_feature_socket_activation} +_APPFW_FEATURE_SOCKET_ACTIVATION=ON +%endif + %ifarch %{ix86} -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=x86 +cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DARCH=x86 \ + -D_APPFW_FEATURE_SOCKET_ACTIVATION:BOOL=${_APPFW_FEATURE_SOCKET_ACTIVATION} \ + . %else -cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=arm +cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \ + -DARCH=arm \ + -D_APPFW_FEATURE_SOCKET_ACTIVATION:BOOL=${_APPFW_FEATURE_SOCKET_ACTIVATION} \ + . %endif make %{?jobs:-j%jobs} @@ -47,6 +73,13 @@ mkdir -p %{buildroot}/usr/share/license cp LICENSE %{buildroot}/usr/share/license/%{name} %make_install +%if 0%{?appfw_feature_socket_activation} +mkdir -p %{buildroot}/usr/lib/systemd/system/sockets.target.wants +install -m 0644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/debug-launchpad.service +install -m 0644 %{SOURCE2} %{buildroot}/usr/lib/systemd/system/debug-launchpad.socket +ln -s ../debug-launchpad.socket %{buildroot}/usr/lib/systemd/system/sockets.target.wants/debug-launchpad.socket +%endif + %clean rm -rf %{buildroot} @@ -55,4 +88,11 @@ rm -rf %{buildroot} %files /usr/share/license/%{name} %manifest debug-launchpad.manifest -%attr(0755, root, root) %{_bindir}/debug_launchpad_preloading_preinitializing_daemon +%attr(0750, root, root) %{_bindir}/debug_launchpad_preloading_preinitializing_daemon +%attr(0750, developer, developer) %{_bindir}/appid2pid +%attr(0750, developer, developer) %{_bindir}/launch_debug +%if 0%{?appfw_feature_socket_activation} +/usr/lib/systemd/system/debug-launchpad.service +/usr/lib/systemd/system/debug-launchpad.socket +/usr/lib/systemd/system/sockets.target.wants/debug-launchpad.socket +%endif diff --git a/src/app_sock.c b/src/app_sock.c index 1029ab4..9170a00 100755 --- a/src/app_sock.c +++ b/src/app_sock.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "app_sock.h" #include "simple_util.h" @@ -51,7 +52,6 @@ static inline void __set_sock_option(int fd, int cli) int __create_server_sock(int pid) { struct sockaddr_un saddr; - struct sockaddr_un p_saddr; int fd; mode_t orig_mask; @@ -128,6 +128,7 @@ int __create_server_sock(int pid) int pgid; pgid = getpgid(pid); if (pgid > 1) { + struct sockaddr_un p_saddr; snprintf(p_saddr.sun_path, UNIX_PATH_MAX, "%s/%d", AUL_SOCK_PREFIX, pgid); if (link(saddr.sun_path, p_saddr.sun_path) < 0) { @@ -148,6 +149,7 @@ int __create_client_sock(int pid) struct sockaddr_un saddr = { 0, }; int retry = 1; int ret = -1; + struct timespec retry_delay = { 0, 100 * 1000 * 1000 }; fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); /* support above version 2.6.27*/ @@ -172,7 +174,7 @@ int __create_client_sock(int pid) if (ret < -1) { _E("maybe peer not launched or peer daed\n"); if (retry > 0) { - usleep(100 * 1000); + nanosleep(&retry_delay, NULL); retry--; goto retry_con; } @@ -509,7 +511,10 @@ retry_recv: } else if (errno == EINTR) { goto retry_recv; } else { - _E("recv error %s\n", strerror(errno)); + char err_buf[100] = { 0, }; + strerror_r(errno, err_buf, sizeof(err_buf)); + _E("recv error %s\n", err_buf); + free(pkt); close(fd); return NULL; diff --git a/src/appid2pid.c b/src/appid2pid.c new file mode 100644 index 0000000..50a0b72 --- /dev/null +++ b/src/appid2pid.c @@ -0,0 +1,52 @@ +/* + * debug-launchpad + * + * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: MooChang Kim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * simple AUL daemon - launchpad + */ + +#include +#include + +void print_usage(const char *progname) +{ + printf("[usage] %s \n", progname); +} + +int main(int argc, char **argv) +{ + int pid; + char *appid = NULL; + + if (argc < 2) { + print_usage(argv[0]); + return -1; + } + + appid = argv[1]; + + pid = aul_app_get_pid(appid); + + /* get pid by appid */ + printf("%d\n", pid); + + return 0; +} diff --git a/src/launch_debug.c b/src/launch_debug.c new file mode 100644 index 0000000..0509285 --- /dev/null +++ b/src/launch_debug.c @@ -0,0 +1,115 @@ +/* + * debug-launchpad + * + * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Sangmin Jeong + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include +#include +#include "app_sock.h" +#include "simple_util.h" + +#define APP_PATH_MAX_LENGTH 1024 + +static char app_path[APP_PATH_MAX_LENGTH]; + +static void print_usage(const char *progname) +{ + printf("[usage] %s [appid] __AUL_SDK__ ATTACH __DLP_ATTACH_ARG__ --attach,:[port],[pid]\n", progname); + printf("ex) $ launch_debug [appid] __AUL_SDK__ ATTACH __DLP_ATTACH_ARG__ --attach,:10003,1234\n"); +} + +static int iterfunc(const aul_app_info *info, void *data) +{ + if (info && data && !strcmp(info->appid, (char *)data)) { + strncpy(app_path, info->app_path, APP_PATH_MAX_LENGTH - 1); + app_path[APP_PATH_MAX_LENGTH - 1] = '\0'; + return -1; + } + + return 0; +} + +int main(int argc, char **argv) +{ + int i, j, cnt; + int ret; + bundle *b; + int b_datalen; + bundle_raw *b_data; + char *bundle_args[10]; + + if (argc < 2) { + print_usage(argv[0]); + exit(-1); + } + + b = bundle_create(); + if (b == NULL) { + printf("out of memory"); + exit(-1); + } + + if(aul_get_running_app_info_from_proc(iterfunc, argv[1]) != AUL_R_OK) + _E("get running app info failed"); + + for (i = 2; i < argc; i++) { + if (argv[i] && !strcmp(argv[i], "__AUL_SDK__")) + bundle_add(b, "__AUL_SDK__", argv[i + 1]); + + if (argv[i] && !strcmp(argv[i], "__DLP_ATTACH_ARG__")) { + bundle_args[0] = strtok(argv[i + 1], ","); + + cnt = 1; + while ((bundle_args[cnt] = strtok(NULL, ",")) != NULL) + cnt++; + + bundle_add(b, "ATTACH", "__DLP_ATTACH_ARG__"); + bundle_add_str_array(b, "__DLP_ATTACH_ARG__", NULL, cnt); + + for (j = 0; j < cnt; j++) + bundle_set_str_array_element(b, "__DLP_ATTACH_ARG__", j, bundle_args[j]); + } + } + + bundle_add(b, "__AUL_PKG_NAME__", argv[1]); + bundle_add(b, "__AUL_STARTTIME__", "1441865531/743961"); + bundle_add(b, "__AUL_CALLER_PID__", "0"); + bundle_add(b, "__AUL_HWACC__", "SYS"); + bundle_add(b, "__AUL_TASKMANAGE__", "true"); + bundle_add(b, "__AUL_EXEC__", app_path); + bundle_add(b, "__AUL_PACKAGETYPE__", "rpm"); + bundle_add(b, "__AUL_INTERNAL_POOL__", "false"); + bundle_add(b, "__AUL_PKGID_", argv[1]); + bundle_add(b, "__AUL_HIGHPRIORITY__", "true"); + + bundle_encode(b, &b_data, &b_datalen); + + ret = __app_send_raw(DEBUG_LAUNCHPAD_PID, APP_START, b_data, b_datalen); + if (ret < 0) + _E("Bundle send fail"); + + free(b_data); + + return ret; +} diff --git a/src/launchpad.c b/src/launchpad.c index 8c81ff4..f823944 100755 --- a/src/launchpad.c +++ b/src/launchpad.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "app_sock.h" #include "aul.h" @@ -51,6 +52,7 @@ #include "sigchild.h" #include "aul_util.h" #include "pkgmgr-info.h" +#include "fileutils.h" #include "heap_dbg.h" @@ -60,6 +62,9 @@ #include #include "fileutils.h" #include +#ifdef _APPFW_FEATURE_SOCKET_ACTIVATION +#include +#endif #define _static_ static inline #define POLLFD_MAX 1 @@ -79,6 +84,7 @@ #define DLP_K_DEBUG_ARG "__DLP_DEBUG_ARG__" #define DLP_K_UNIT_TEST_ARG "__DLP_UNIT_TEST_ARG__" #define DLP_K_VALGRIND_ARG "__DLP_VALGRIND_ARG__" +#define DLP_K_ATTACH_ARG "__DLP_ATTACH_ARG__" #define PATH_GDBSERVER "/home/developer/sdk_tools/gdbserver/gdbserver" #define PATH_VALGRIND "/home/developer/sdk_tools/valgrind/usr/bin/valgrind" @@ -103,6 +109,7 @@ static int initialized = 0; static int poll_outputfile = 0; static int is_gdbserver_launched; +static const char *debuggee_appid = NULL; void __set_env(app_info_from_db * menu_info, bundle * kb); int __prepare_exec(const char *pkg_name, @@ -205,14 +212,17 @@ int __prepare_exec(const char *pkg_name, __preexec_run(menu_info->pkg_type, pkg_name, app_path); - /* SET PRIVILEGES*/ - _D("pkg_name : %s / pkg_type : %s / app_path : %s", pkg_name - , menu_info->pkg_type, app_path); - if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) { - _D("fail to set privileges - check your package's credential : %d\n" - , ret); - return -1; + if (strcmp(bundle_get_val(kb, "__AUL_SDK__"), "ATTACH")) { + /* SET PRIVILEGES*/ + _D("pkg_name : %s / pkg_type : %s / app_path : %s", pkg_name + , menu_info->pkg_type, app_path); + if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) { + _D("fail to set privileges - check your package's credential : %d\n" + , ret); + return -1; + } } + /* SET DUMPABLE - for coredump*/ prctl(PR_SET_DUMPABLE, 1); @@ -255,9 +265,9 @@ char** __add_arg(bundle * kb, char **argv, int *margc, const char *key) const char **str_array = NULL; int len = 0; int i; - char ** new_argv = NULL; + char **new_argv = NULL; - if(bundle_get_type(kb, key) & BUNDLE_TYPE_ARRAY) { + if (bundle_get_type(kb, key) & BUNDLE_TYPE_ARRAY) { str_array = bundle_get_str_array(kb, key, &len); } else { str = bundle_get_val(kb, key); @@ -266,10 +276,10 @@ char** __add_arg(bundle * kb, char **argv, int *margc, const char *key) len = 1; } } + if(str_array != NULL) { if(strncmp(key, DLP_K_DEBUG_ARG, strlen(key)) == 0 - || strncmp(key, DLP_K_VALGRIND_ARG, strlen(key)) == 0) - { + || strncmp(key, DLP_K_VALGRIND_ARG, strlen(key)) == 0) { new_argv = (char **) realloc(argv , sizeof(char *) * (*margc+len+2)); if(!new_argv) { @@ -288,6 +298,13 @@ char** __add_arg(bundle * kb, char **argv, int *margc, const char *key) _D("euid : %d", geteuid()); _D("gid : %d", getgid()); _D("egid : %d", getegid()); + } else if (strncmp(key, DLP_K_ATTACH_ARG, strlen(key)) == 0) { + new_argv = (char **) malloc((len + 2) * sizeof(char *)); + for (i = 0; i < len; i++) { + new_argv[1+i] = strdup(str_array[i]); + } + *margc = 0; + len = len + 1; } else { new_argv = (char **) realloc(argv , sizeof(char *) * (*margc+len+1)); @@ -345,56 +362,62 @@ char **__create_argc_argv(bundle * kb, int *margc, const char *app_path) exit(-1); } - if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) { + if (bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) { str_array = bundle_get_str_array(kb, AUL_K_SDK, &len); } else { str = bundle_get_val(kb, AUL_K_SDK); - if(str) { + if (str) { str_array = &str; len = 1; } } - if(str_array == NULL) { + + if (str_array == NULL) { *margc = argc; return argv; } for (i = 0; i < len; i++) { - if(str_array[i] == NULL) break; + if (str_array[i] == NULL) + break; + _D("index : [%d]", i); /* gdbserver */ - if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0) - { + if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0) { char buf[MAX_LOCAL_BUFSZ]; - if (argv[0]) free(argv[0]); - snprintf(buf,MAX_LOCAL_BUFSZ,"%s.exe",app_path); + if (argv[0]) + free(argv[0]); + snprintf(buf, MAX_LOCAL_BUFSZ, "%s.exe", app_path); // this code is added because core app don't have '.exe' excutable // if '.exe' not exist then use app_path - if(access(buf, F_OK) != 0) + if (access(buf, F_OK) != 0) argv[0] = strdup(app_path); else argv[0] = strdup(buf); + new_argv = __add_arg(kb, argv, &argc, DLP_K_DEBUG_ARG); new_argv[0] = strdup(PATH_GDBSERVER); argv = new_argv; } /* valgrind */ - else if (strncmp(str_array[i], SDK_VALGRIND - , strlen(str_array[i])) == 0) - { + else if (strncmp(str_array[i], SDK_VALGRIND, strlen(str_array[i])) == 0) { new_argv = __add_arg(kb, argv, &argc , DLP_K_VALGRIND_ARG); new_argv[0] = strdup(PATH_VALGRIND); argv = new_argv; } /* unit test */ - else if (strncmp(str_array[i], SDK_UNIT_TEST - , strlen(str_array[i])) == 0) - { + else if (strncmp(str_array[i], SDK_UNIT_TEST, strlen(str_array[i])) == 0) { new_argv = __add_arg(kb, argv, &argc , DLP_K_UNIT_TEST_ARG); argv = new_argv; } + /* attach */ + else if (strncmp(str_array[i], "ATTACH", strlen(str_array[i])) == 0) { + new_argv = __add_arg(kb, argv, &argc, DLP_K_ATTACH_ARG); + new_argv[0] = strdup(PATH_GDBSERVER); + argv = new_argv; + } } *margc = argc; @@ -748,21 +771,6 @@ static app_info_from_db *_get_app_info_from_bundle_by_pkgname( return menu_info; } -/** - * free after use it - */ -int get_native_appid(const char* app_path, char** appid) { - int rc = smack_lgetlabel(app_path, appid, SMACK_LABEL_ACCESS); - - if (rc != 0 || *appid == NULL) { - _E("smack_lgetlabel fail"); - return -1; - } - - _D("get_appid return : %s", *appid); - return 0; -} - int apply_smack_rules(const char* subject, const char* object , const char* access_type) { @@ -889,7 +897,7 @@ int __adjust_process_capability(int sv) return 0; } - + if (sv == CAPABILITY_SET_INHERITABLE) { h.pid = getpid(); if (capset(&h, inh_d) < 0) { @@ -910,7 +918,7 @@ int __adjust_file_capability(const char * path) return 0; } -int __prepare_fork(bundle *kb, char *appid) +int __prepare_fork(bundle *kb, const char *appid) { const char *str = NULL; const char **str_array = NULL; @@ -922,71 +930,70 @@ int __prepare_fork(bundle *kb, char *appid) need_to_set_inh_cap_after_fork=0; poll_outputfile = 0; - if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) { + if (bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) { str_array = bundle_get_str_array(kb, AUL_K_SDK, &len); } else { str = bundle_get_val(kb, AUL_K_SDK); - if(str) { + if (str) { str_array = &str; len = 1; } } - if(str_array == NULL) return 0; + + if (str_array == NULL) + return 0; is_gdbserver_launched = 0; gdbserver_pid = -1; gdbserver_app_pid = -1; for (i = 0; i < len; i++) { - if(str_array[i] == NULL) break; + if (str_array[i] == NULL) + break; + /* gdbserver */ - if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0) - { + if (strncmp(str_array[i], SDK_DEBUG, strlen(str_array[i])) == 0 + || strncmp(str_array[i], "ATTACH", strlen(str_array[i])) == 0) { // because of security issue, prevent debugging(ptrace) for preloaded app and downloaed app - if(pkgmgrinfo_pkginfo_get_pkginfo(appid, &handle) == PMINFO_R_OK) - { - if(pkgmgrinfo_pkginfo_is_preload(handle, &bPreloaded) != PMINFO_R_OK) + if (pkgmgrinfo_pkginfo_get_pkginfo(appid, &handle) == PMINFO_R_OK) { + if (pkgmgrinfo_pkginfo_is_preload(handle, &bPreloaded) != PMINFO_R_OK) return -1; - if(pkgmgrinfo_pkginfo_get_storeclientid(handle, &storeclientid) != PMINFO_R_OK) + if (pkgmgrinfo_pkginfo_get_storeclientid(handle, &storeclientid) != PMINFO_R_OK) return -1; - if(bPreloaded || (storeclientid[0] != '\0')) - { + if (bPreloaded || (storeclientid[0] != '\0')) { _E("debugging is not allowed"); return -1; } } - if(apply_smack_rules("sdbd",appid,"w")) { + if (apply_smack_rules("sdbd",appid,"w")) { _E("smack_accesses_apply fail"); // return -1; } // fixed debug-as fail issue (grant permission to use 10.0.2.2, 10.0.2.16) - if(apply_smack_rules(appid, "system::debugging_network", "rw")) { + if (apply_smack_rules(appid, "system::debugging_network", "rw")) { _E("smack_accesses_apply fail"); } - if(apply_smack_rules("system::debugging_network", appid, "w")) { + + if (apply_smack_rules("system::debugging_network", appid, "w")) { _E("smack_accesses_apply fail"); } // FIXME: set gdbfolder to 755 also - if(dlp_chmod(PATH_GDBSERVER - , S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP - |S_IROTH|S_IXOTH - , 1)) - { + if (dlp_chmod(PATH_GDBSERVER, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, 1)) { _D("unable to set 755 to %s", PATH_GDBSERVER); } + __adjust_file_capability(PATH_GDBSERVER); need_to_set_inh_cap_after_fork++; is_gdbserver_launched++; } /* valgrind */ - else if (strncmp(str_array[i], SDK_VALGRIND - , strlen(str_array[i])) == 0) - { + else if (strncmp(str_array[i], SDK_VALGRIND, strlen(str_array[i])) == 0) { if (__prepare_valgrind_outputfile(kb) == -1) return -1; + __adjust_file_capability(PATH_MEMCHECK); } } @@ -1000,45 +1007,45 @@ void __waiting_outputfile() int wait_count = 0; while(poll_outputfile && wait_count<10) { /* valgrind log file */ - if( (poll_outputfile & POLL_VALGRIND_LOGFILE) - && (access(PATH_VALGRIND_LOGFILE,F_OK)==0) ) - { + if ((poll_outputfile & POLL_VALGRIND_LOGFILE) + && (access(PATH_VALGRIND_LOGFILE,F_OK)==0)) { __chmod_chsmack_toread(PATH_VALGRIND_LOGFILE); poll_outputfile &= ~POLL_VALGRIND_LOGFILE; } /* valgrind xml file */ - if( (poll_outputfile & POLL_VALGRIND_XMLFILE) - && (access(PATH_VALGRIND_XMLFILE,F_OK)==0) ) - { + if ((poll_outputfile & POLL_VALGRIND_XMLFILE) + && (access(PATH_VALGRIND_XMLFILE,F_OK)==0)) { __chmod_chsmack_toread(PATH_VALGRIND_XMLFILE); poll_outputfile &= ~POLL_VALGRIND_XMLFILE; } - - if(poll_outputfile) { + + if (poll_outputfile) { _D("-- now wait for creating the file --"); usleep(50 * 1000); /* 50ms sleep*/ wait_count++; } } - if(wait_count==10) _E("faild to waiting"); + if (wait_count==10) + _E("faild to waiting"); + return; } int __stdout_stderr_redirection(int defpid) { char defpath[UNIX_PATH_MAX]; - int deffd, result=0; + int deffd, result = 0; /* stdout */ snprintf(defpath, UNIX_PATH_MAX, "/proc/%d/fd/1", defpid); deffd = open(defpath,O_WRONLY); - if(deffd < 0) { + if (deffd < 0) { _E("opening caller(%d) stdout failed due to %s" , defpid, strerror(errno)); result++; - }else{ + } else { dup2(deffd, 1); close(deffd); } @@ -1046,11 +1053,11 @@ int __stdout_stderr_redirection(int defpid) /* stderr */ snprintf(defpath, UNIX_PATH_MAX, "/proc/%d/fd/2", defpid); deffd = open(defpath,O_WRONLY); - if(deffd < 0) { + if (deffd < 0) { _E("opening caller(%d) stderr failed due to %s" , defpid,strerror(errno)); result+=2; - }else{ + } else { dup2(deffd, 2); close(deffd); } @@ -1072,7 +1079,6 @@ void __launchpad_main_loop(int main_fd) int is_real_launch = 0; char sock_path[UNIX_PATH_MAX] = {0,}; - char * appid = NULL; pkt = __app_recv_raw(main_fd, &clifd, &cr); if (!pkt) { @@ -1104,28 +1110,19 @@ void __launchpad_main_loop(int main_fd) goto end; } if (app_path[0] != '/') { - _D("app_path is not absolute path"); + _D("app_path is not absolute path", app_path); goto end; } - { - int rc = get_native_appid(app_path,&appid); - if(rc!=0 || appid==NULL) { - _E("unable to get native appid"); - if(appid){ - free(appid); - appid = NULL; - } - goto end; - } - } + debuggee_appid = bundle_get_val(kb, AUL_K_PKGID); __modify_bundle(kb, cr.pid, menu_info, pkt->cmd); pkg_name = _get_pkgname(menu_info); PERF("get package information & modify bundle done"); - if(__prepare_fork(kb,appid) == -1) goto end; + if (__prepare_fork(kb, debuggee_appid) == -1) + goto end; pid = fork(); if (pid == 0) { @@ -1166,14 +1163,12 @@ void __launchpad_main_loop(int main_fd) exit(-1); } - if(is_gdbserver_launched) { - char buf[MAX_LOCAL_BUFSZ]; - + if (is_gdbserver_launched) { usleep(100 * 1000); /* 100ms sleep */ - snprintf(buf, MAX_LOCAL_BUFSZ, "%s.exe", app_path); - gdbserver_app_pid = __proc_iter_cmdline(NULL, buf); - if(gdbserver_app_pid == -1) { + gdbserver_app_pid = __proc_iter_cmdline(NULL, (void *)app_path); + + if (gdbserver_app_pid == -1) { _E("faild to get app pid"); } else { gdbserver_pid = pid; @@ -1184,7 +1179,7 @@ void __launchpad_main_loop(int main_fd) _D("==> real launch pid : %d %s\n", pid, app_path); is_real_launch = 1; - end: +end: __send_result_to_caller(clifd, pid); if (pid > 0) { @@ -1203,8 +1198,6 @@ void __launchpad_main_loop(int main_fd) bundle_free(kb); if (pkt != NULL) free(pkt); - if (appid != NULL) - free(appid); /* Active Flusing for Daemon */ if (initialized > AUL_POLL_CNT) { @@ -1216,6 +1209,26 @@ void __launchpad_main_loop(int main_fd) if(poll_outputfile) __waiting_outputfile(); } +#ifdef _APPFW_FEATURE_SOCKET_ACTIVATION +_static_ int __create_sock_activation(void) +{ + int fd = -1; + int listen_fds; + + listen_fds = sd_listen_fds(0); + if (listen_fds == 1) { + fd = SD_LISTEN_FDS_START + 0; + return fd; + } else if (listen_fds > 1) { + _E("Too many fild descriptors received."); + return -1; + } else { + _E("There is no socket stream"); + return -1; + } +} +#endif + int __launchpad_pre_init(int argc, char **argv) { int fd; @@ -1231,12 +1244,20 @@ int __launchpad_pre_init(int argc, char **argv) } _D("launchpad cmdline = %s", launchpad_cmdline); +#ifdef _APPFW_FEATURE_SOCKET_ACTIVATION /* create launchpad sock */ - fd = __create_server_sock(DEBUG_LAUNCHPAD_PID); + fd = __create_sock_activation(); if (fd < 0) { - _E("server sock error"); - return -1; + _D("Create server socket without socket activation"); +#endif + fd = __create_server_sock(DEBUG_LAUNCHPAD_PID); + if (fd < 0) { + _E("server sock error"); + return -1; + } +#ifdef _APPFW_FEATURE_SOCKET_ACTIVATION } +#endif __preload_init(argc, argv); @@ -1247,7 +1268,7 @@ int __launchpad_pre_init(int argc, char **argv) int __launchpad_post_init() { - /* Setting this as a global variable to keep track + /* Setting this as a global variable to keep track of launchpad poll cnt */ /* static int initialized = 0;*/ @@ -1287,7 +1308,7 @@ int main(int argc, char **argv) if (poll(pfds, POLLFD_MAX, -1) < 0) continue; - /* init with concerning X & EFL (because of booting + /* init with concerning X & EFL (because of booting sequence problem)*/ if (__launchpad_post_init() < 0) { _E("launcpad post init failed"); diff --git a/src/sigchild.h b/src/sigchild.h index 900ebde..8f1bf3c 100755 --- a/src/sigchild.h +++ b/src/sigchild.h @@ -23,6 +23,7 @@ #include #include #include "app_signal.h" +#include "fileutils.h" static struct sigaction old_sigchild; static DBusConnection *bus = NULL; diff --git a/src/simple_util.c b/src/simple_util.c index d2a891d..90e90fb 100755 --- a/src/simple_util.c +++ b/src/simple_util.c @@ -86,7 +86,8 @@ int __proc_iter_cmdline( void *priv) { DIR *dp; - struct dirent *dentry; + struct dirent dentry; + struct dirent *result = NULL; int pid; int ret; char buf[MAX_LOCAL_BUFSZ]; @@ -99,11 +100,11 @@ int __proc_iter_cmdline( if (iterfunc == NULL) iterfunc = __find_pid_by_cmdline; - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) + while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) { + if (!isdigit(dentry.d_name[0])) continue; - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name); + snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry.d_name); ret = __read_proc(buf, buf, sizeof(buf)); if (ret <= 0) continue; @@ -111,10 +112,10 @@ int __proc_iter_cmdline( /* support app launched by shell script*/ if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) pid = - iterfunc(dentry->d_name, &buf[BINSH_SIZE + 1], + iterfunc(dentry.d_name, &buf[BINSH_SIZE + 1], priv); else - pid = iterfunc(dentry->d_name, buf, priv); + pid = iterfunc(dentry.d_name, buf, priv); if (pid > 0) { closedir(dp); @@ -128,7 +129,7 @@ int __proc_iter_cmdline( char *__proc_get_cmdline_bypid(int pid) { - char buf[MAX_LOCAL_BUFSZ]; + char buf[MAX_LOCAL_BUFSZ] = {0}; int ret; snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); @@ -145,7 +146,7 @@ char *__proc_get_cmdline_bypid(int pid) static inline int __get_pgid_from_stat(int pid) { - char buf[MAX_LOCAL_BUFSZ]; + char buf[MAX_LOCAL_BUFSZ] = {0}; char *str = NULL; int ret; int i; @@ -171,7 +172,7 @@ static inline int __get_pgid_from_stat(int pid) } } - if ((count == PROC_STAT_GID_POS) && (str)) + if (count == PROC_STAT_GID_POS && str) pid = atoi(str); else pid = -1; @@ -183,7 +184,8 @@ int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv), void *priv) { DIR *dp; - struct dirent *dentry; + struct dirent dentry; + struct dirent *result = NULL; int _pgid; int ret = -1; @@ -192,13 +194,13 @@ int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv), return -1; } - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) + while (readdir_r(dp, &dentry, &result) == 0 && result != NULL) { + if (!isdigit(dentry.d_name[0])) continue; - _pgid = __get_pgid_from_stat(atoi(dentry->d_name)); + _pgid = __get_pgid_from_stat(atoi(dentry.d_name)); if (pgid == _pgid) { - ret = iterfunc(atoi(dentry->d_name), priv); + ret = iterfunc(atoi(dentry.d_name), priv); if (ret >= 0) break; }