[FEATURE] File analysis: add file lock msg types 11/24111/2
authorVasiliy Ulyanov <v.ulyanov@samsung.com>
Wed, 21 May 2014 06:47:45 +0000 (10:47 +0400)
committerVasiliy Ulyanov <v.ulyanov@samsung.com>
Fri, 18 Jul 2014 09:37:39 +0000 (13:37 +0400)
Change-Id: I731f95f97da0744d66733d610c6d5d061be0e01c
Signed-off-by: Vasiliy Ulyanov <v.ulyanov@samsung.com>
include/probeinfo.h
probe_file/da_io_posix.c

index 258a8fa..5700442 100755 (executable)
@@ -86,6 +86,8 @@ extern "C"{
 #define                FD_API_RECEIVE                  10
 #define                FD_API_OPTION                   11
 #define                FD_API_MANAGE                   12
+#define                FD_API_LOCK_START               14
+#define                FD_API_LOCK_END                 15
 
 
 #define                SOCKET_API_FD_OPEN              0
index 68aa65b..79f7644 100755 (executable)
@@ -226,12 +226,24 @@ int fchown(int fd, uid_t owner, gid_t group)
 int lockf(int fd, int function, off_t size)
 {
        static int (*lockfp)(int fd, int function, off_t size);
+       int api_type = FD_API_PERMISSION;
 
        BEFORE_ORIGINAL_FILE(lockf, LIBC);
        ret = lockfp(fd, function, size);
+
+       switch (function) {
+       case F_LOCK:
+       case F_TLOCK:
+               api_type = FD_API_LOCK_START;
+               break;
+       case F_ULOCK:
+               api_type = FD_API_LOCK_END;
+               break;
+       }
+
        AFTER_PACK_ORIGINAL_FD(API_ID_lockf,
-                                  'd', ret, (unsigned int)size, fd, FD_API_PERMISSION,
-                                  "ddx", fd, function, (uint64_t)(size));
+                              'd', ret, (unsigned int)size, fd, api_type,
+                              "ddx", fd, function, (uint64_t)(size));
        return ret;
 }
 
@@ -380,7 +392,7 @@ ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
 int fcntl(int fd, int cmd, ...)
 {
        static int (*fcntlp)(int fd, int cmd, ...);
-       int arg = 0;
+       int arg = 0, api_type = FD_API_OTHER;
 
        BEFORE_ORIGINAL_FILE(fcntl, LIBC);
 
@@ -391,8 +403,32 @@ int fcntl(int fd, int cmd, ...)
 
        ret = fcntlp(fd, cmd, arg);
 
-       AFTER_PACK_ORIGINAL_FD(API_ID_fcntl,
-                                  'd', ret, 0, fd, FD_API_OTHER, "ddd", fd, cmd, arg);
+       if (cmd == F_SETLK || cmd == F_SETLKW) {
+               struct flock *flock = (struct flock *)arg;
+               int type = flock->l_type;
+               int whence = flock->l_whence;
+               int64_t /*off_t*/ start = flock->l_start;
+               int64_t /*off_t*/ len = flock->l_len;
+
+               switch (type) {
+               case F_RDLCK:
+               case F_WRLCK:
+                       api_type = FD_API_LOCK_START;
+                       break;
+               case F_UNLCK:
+                       api_type = FD_API_LOCK_END;
+                       break;
+               }
+
+               AFTER_PACK_ORIGINAL_FD(API_ID_fcntl,
+                                      'd', ret, 0, fd, api_type,
+                                      "ddddxx", fd, cmd, type,
+                                      whence, start, len);
+       } else {
+               AFTER_PACK_ORIGINAL_FD(API_ID_fcntl,
+                                      'd', ret, 0, fd, api_type,
+                                      "ddd", fd, cmd, arg);
+       }
 
        return ret;
 }