[Title] apply smack rule in debug attach
authorho.namkoong <ho.namkoong@samsung.com>
Sun, 23 Jun 2013 07:58:50 +0000 (16:58 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Sun, 23 Jun 2013 07:58:50 +0000 (16:58 +0900)
[Type]
[Module]
[Priority]
[CQ#]
[Redmine#] 9670
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: Icb4d91d96647ed89286f43c3ed5f6f42dabe0387

src/sdb.c
src/sdktools.c
src/sdktools.h

index 4c3c877..01a8928 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -1037,31 +1037,6 @@ static void execute_required_process() {
     pclose(pre_proc_file);
 
     system("/usr/bin/debug_launchpad_preloading_preinitializing_daemon &");
-
-//    pid_t pid = fork();
-//
-//    switch (pid) {
-//        case -1:
-//            D("fork failed\n");
-//            break;
-//        case 0:
-//            if(setsid() == -1) {
-//                D("Fail to set session id of debug launchpad daemon\n");
-//                exit(1);
-//            }
-//            if(chdir("/") < 0) {
-//                D("Fail debug launchpad daemon to chdir\n");
-//                exit(1);
-//            }
-//            execl("/usr/bin/debug_launchpad_preloading_preinitializing_daemon", "debug_launchpad_preloading_preinitializing_daemon", NULL);
-//            D("exec failed\n");
-//            exit(1);
-//            break;
-//        default:
-//            required_pid = pid;
-//            break;
-//    }
-
 }
 
 static void init_sdk_requirements() {
index 7d2f739..4bb5237 100644 (file)
@@ -213,8 +213,53 @@ int exec_app_standalone(const char* path) {
         if (flag == 0) {
             // TODO: check evn setting
         }
+
+        if(!strcmp(tokens[i], SDK_LAUNCH_PATH)) {
+            int debug = 0;
+            int pid = 0;
+            char* pkg_id = NULL;
+            char* executable = NULL;
+            ++i;
+            while( i < cnt ) {
+                if(!strcmp(tokens[i], "-attach")) {
+                    if(++i < cnt) {
+                        char* pid_pattern = "[1-9][0-9]{2,5}";
+                        if (regcmp(pid_pattern, tokens[i])) {
+                            pid = atoi(tokens[i]);
+                        }
+                    }
+                }
+                else if(!strcmp(tokens[i], "-p")) {
+                    if(++i < cnt) {
+                        pkg_id = tokens[i];
+                    }
+                }
+                else if(!strcmp(tokens[i], "-e")) {
+                    if(++i < cnt) {
+                        executable = tokens[i];
+                    }
+                }
+                i++;
+            }
+            if(pid > 0) {
+                char cmdline[128];
+                if (pid) {
+                    snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
+                    int fd = unix_open(cmdline, O_RDONLY);
+                    if (fd > 0) {
+                        if(read_line(fd, cmdline, sizeof(cmdline))) {
+                            if (set_smack_rules_for_gdbserver(cmdline, 1)) {
+                                ret = 1;
+                            }
+                        }
+                        sdb_close(fd);
+                    }
+                }
+            }
+            break;
+        }
         // TODO: i length check
-        if (!strcmp(tokens[i], GDBSERVER_PATH) || !strcmp(tokens[i], GDBSERVER_PLATFORM_PATH)) { //gdbserver :11 --attach 2332 (cnt=4,)
+        else if (!strcmp(tokens[i], GDBSERVER_PATH) || !strcmp(tokens[i], GDBSERVER_PLATFORM_PATH)) { //gdbserver :11 --attach 2332 (cnt=4,)
             char *gdb_attach_arg_pattern = "^:[1-9][0-9]{2,5} \\-\\-attach [1-9][0-9]{2,5}$";
             int argcnt = cnt-i-1;
             if (argcnt == 3 && !strcmp("--attach", tokens[i+2])) {
index 881f122..2c491af 100644 (file)
@@ -23,6 +23,7 @@ struct arg_permit_rule
 };
 
 
+#define SDK_LAUNCH_PATH                 "/usr/sbin/sdk_launch"
 #define APP_INSTALL_PATH_PREFIX1                "/opt/apps"
 #define APP_INSTALL_PATH_PREFIX2                "/opt/usr/apps"
 #define GDBSERVER_PATH                          "/home/developer/sdk_tools/gdbserver/gdbserver"