[FIX] common app terminates da_manager on stop message 42/29242/6
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 23 Oct 2014 07:05:23 +0000 (11:05 +0400)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 30 Oct 2014 12:35:55 +0000 (15:35 +0300)
Change-Id: Ie1b43066a7b63b8e208b8bb79c51453de436f8b5
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
helper/libdaprobe.c

index 97b1f2e..f633a01 100755 (executable)
@@ -102,11 +102,38 @@ static void _configure(char* configstr)
 
 void application_exit()
 {
-       PRINTMSG("App termination: EXIT(0)");
+       pid_t gpid;
+       FILE *f = NULL;
+       char buf[MAX_PATH_LENGTH];
+       const char manager_name[] = "da_manager";
+
        /* TODO think of another way for correct app termination */
 
-       /* Kill yourself!! */
-       killpg(getpgrp(), SIGKILL);
+       gpid = getpgrp();
+       /* check for parent */
+       snprintf(buf, sizeof(buf), "/proc/%d/cmdline", gpid);
+       f = fopen(buf, "r");
+       if (f != NULL) {
+               fscanf(f, "%s", buf);
+               fclose(f);
+               if (strlen(buf) == strlen(manager_name) &&
+                   strncmp(buf, manager_name, sizeof(manager_name)) == 0) {
+                       /* Luke, I am your father
+                        * da_manager is our parent
+                        * looks like we are common applicaton
+                        */
+                       PRINTMSG("App termination: EXIT(0)");
+                       exit(0);
+               }
+       }
+
+       /* da_manager is not our father
+        * we are native app or already launched.
+        * Will be troubles up there if we are common already launched app!!!
+        * Kill yourself!!
+        */
+       PRINTMSG("App termination: kill all process group");
+       killpg(gpid, SIGKILL);
 }
 
 // create socket to daemon and connect