Merge "[Bugfix][T106BUG-512][POWER]cant create wakelcok repeatly"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/files/lynq-qser-autosuspend-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/files/lynq-qser-autosuspend-demo.cpp
index fbaa297..b0c2330 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/files/lynq-qser-autosuspend-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-autosuspend-demo/files/lynq-qser-autosuspend-demo.cpp
@@ -65,7 +65,7 @@
     {
         if(strlen(lock_status.lock_name[i]) != 0)
         {
-            printf("fd: %d lock_name:%s strlen:%d\n", i, lock_status.lock_name[i], strlen(lock_status.lock_name[i]));
+            printf("fd: %d lock_name:%s strlen:%d, pid=%d\n", i, lock_status.lock_name[i], strlen(lock_status.lock_name[i]), lock_status.lock_pid[i]);
         }
     }
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/include/lynq-qser-autosuspend.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/include/lynq-qser-autosuspend.h
index 5d3966a..5d4b91d 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/include/lynq-qser-autosuspend.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/include/lynq-qser-autosuspend.h
@@ -53,6 +53,7 @@
 typedef struct
 {
     char lock_name[MAX_LOCK_NUM][64];
+    int lock_pid[MAX_LOCK_NUM];
 } LOCK_TABLE;
 
 int read_lock_table(void);
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
index 260dcb6..bb659ef 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-autosuspend/lynq-qser-autosuspend.cpp
@@ -8,7 +8,6 @@
 #include <pthread.h>
 #include <unistd.h>
 
-
 #include <lynq_autosuspend.h>
 #include "lynq-qser-autosuspend.h"
 #include "liblog/lynq_deflog.h"
@@ -145,11 +144,20 @@
     return 0;
 }
 
+int check_pid(int pid)
+{
+    char cmd1[64];
+    int ret = -1;
+    sprintf(cmd1, "ps -ef |awk '{print $1}'|grep \"^%d$\"", pid);
+    ret = system(cmd1);
+    return ret;
+}
 
 int check_lock(char *name)
 {
     int j;
     int num;
+    int ret=-1;
     for(j=0;j<MAX_LOCK_NUM;j++)
     {
         if(strcmp(lock_status.lock_name[j], name) == 0)
@@ -161,7 +169,18 @@
 
     if(j < MAX_LOCK_NUM)
     {
-        return num;
+        ret = check_pid(lock_status.lock_pid[j]);
+        if(!ret)
+        {
+            LYINFLOG("the pid is exist\n");
+            num = MAX_LOCK_NUM+1;
+            return num;
+        }
+        else
+        {
+            LYINFLOG("the pid is not exist\n");
+            return num;
+        }
     }
 
     return -1;
@@ -174,15 +193,15 @@
     int i = 0;
     int num;
     int check_flag;
-    
-    LYINFLOG("name:%s\n", name);
+    int pid;
+
     ret = read_lock_table();
     LYINFLOG("read_lock_table ret = %d\n", ret);
     if(ret <0)
     {
         return ret;
     }
-
+    pid = getpid();
     check_flag = check_lock(name);
 
     if(check_flag < 0)
@@ -192,7 +211,8 @@
             if(strlen(lock_status.lock_name[i]) == 0)
             {
                 strcpy(lock_status.lock_name[i], name);
-                LYINFLOG("lock_name[%d] %s\n", i, lock_status.lock_name[i]);
+                lock_status.lock_pid[i] = pid;
+                LYINFLOG("lock_name[%d] %s, lock_pid = %d\n", i, lock_status.lock_name[i], pid);
                 break;
             }
         }
@@ -205,10 +225,15 @@
             num = i;
         }
     }
-    else
+    else if(check_flag > MAX_LOCK_NUM)
     {
         return E_LOCK_EXIST;
     }
+    else
+    {
+        num = check_flag;
+        lock_status.lock_pid[num] = pid;
+    }
 
     LYINFLOG("num = %d\n", num);
     ret = save_lock_table();
@@ -225,6 +250,7 @@
     int i;
     ret = read_lock_table();
     memset(lock_status.lock_name[fd], 0, sizeof(lock_status.lock_name[fd]));
+    lock_status.lock_pid[fd] = -1;
     ret = save_lock_table();
     return ret;
 }