[PROTO] add FD_API_RELEASE event 66/27566/6
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Tue, 16 Sep 2014 07:35:36 +0000 (11:35 +0400)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Thu, 25 Sep 2014 07:18:28 +0000 (00:18 -0700)
now:
14)FD_API_LOCK_START   event before original lock call
15)FD_API_LOCK_END     event after original lock call
16)FD_API_LOCK_RELEASE event after original unlock call

Change-Id: I8a44a8668fef77879b3af7b5eac1aba3af881766
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
helper/libdaprobe.c
include/binproto.h
include/daprobe.h
include/probeinfo.h
probe_file/da_io.h
probe_file/da_io_posix.c

index bad63c8..5c57af2 100755 (executable)
@@ -780,6 +780,9 @@ int preBlockBegin(const void *caller, bool bFiltering, enum DaOptions option)
 {
        bool opt_nofilt;
 
+       if (gTraceInfo.socket.daemonSock == -1)
+               return 0;
+
        if(gProbeBlockCount != 0 || gProbeDepth != 0)
                return 0;
 
index d3be6d1..a1864ca 100644 (file)
@@ -512,6 +512,12 @@ static char __attribute__((used)) *pack_ret(char *to, char ret_type, ...)
        }                                                               \
        errno = (newerrno != 0) ? newerrno : olderrno
 
+#define POST_PACK_PROBEBLOCK_ADD_END()                                 \
+               preBlockEnd();                                          \
+       }                                                               \
+       errno = (newerrno != 0) ? newerrno : olderrno
+
+
 /* int main(int argc, char **argv) */
 /* { */
 /*     char buf[1024]; */
index a16d3bd..552ab42 100644 (file)
@@ -188,7 +188,7 @@ typedef struct {
        int blockresult = 0;            \
        bool bfiltering = true;         \
        DECLARE_ERRNO_VARS;             \
-       int __attribute__((unused)) ret
+       int __attribute__((unused)) ret = 0
 
 // declare variable for standard api (not tizen related api) without ret
 #define DECLARE_VARIABLE_STANDARD_NORET                \
index 5700442..acb2a93 100755 (executable)
@@ -88,6 +88,7 @@ extern "C"{
 #define                FD_API_MANAGE                   12
 #define                FD_API_LOCK_START               14
 #define                FD_API_LOCK_END                 15
+#define                FD_API_LOCK_RELEASE             16
 
 
 #define                SOCKET_API_FD_OPEN              0
index 2fe8264..06c9a88 100755 (executable)
  * Watch out when reusing it somewhere else
  */
 #define AFTER_PACK_ORIGINAL_FD(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...)       \
+do {                                                                                           \
        POST_PACK_PROBEBLOCK_BEGIN();                                                           \
        _fstatret = fstat(FD, &_statbuf);                                                       \
        if (stat_regular_or_socket_p(&_statbuf)) {                                              \
                PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                            \
                POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE);                              \
        }                                                                                       \
-       POST_PACK_PROBEBLOCK_END()
+       POST_PACK_PROBEBLOCK_END();                                                             \
+} while(0)
+
+#define AFTER_PACK_ORIGINAL_FD_MIDDLE(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...)        \
+do {                                                                                           \
+       POST_PACK_PROBEBLOCK_BEGIN();                                                           \
+       _fstatret = fstat(FD, &_statbuf);                                                       \
+       if (stat_regular_or_socket_p(&_statbuf)) {                                              \
+               PREPARE_LOCAL_BUF();                                                            \
+               PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);        \
+               PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                            \
+               POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, FD, APITYPE);                              \
+       }                                                                                       \
+       POST_PACK_PROBEBLOCK_ADD_END();                                                         \
+} while(0)
 
 #define AFTER_PACK_ORIGINAL_NOFD(API_ID, RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...) \
+do {                                                                                   \
        POST_PACK_PROBEBLOCK_BEGIN();                                                   \
        PREPARE_LOCAL_BUF();                                                            \
        PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);        \
        PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                            \
        POST_PACK_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE);                                \
-       POST_PACK_PROBEBLOCK_END()
+       POST_PACK_PROBEBLOCK_END();                                                     \
+} while(0)
 
 #define AFTER_PACK_ORIGINAL_FILEP(API_ID, RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...) \
+do {                                                                                   \
        POST_PACK_PROBEBLOCK_BEGIN();                                                   \
        GET_FD_FROM_FILEP(FILEP);                                                       \
        if(_fd != -1) {                                                                 \
        PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);        \
        PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                            \
        POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE);                             \
-       POST_PACK_PROBEBLOCK_END()
+       POST_PACK_PROBEBLOCK_END();                                                     \
+} while(0)
 
 /*!
  * Macros {BEFORE,AFTER}_ORIGINAL_START_END_FD only used in {p,v,}{read,write}
@@ -175,10 +194,10 @@ static inline bool stat_regular_or_socket_p(struct stat *buf)
                PACK_RESOURCE(0, FD, APITYPE, _filesize, _filepath);                            \
                FLUSH_LOCAL_BUF();                                                              \
        }                                                               \
-       PRE_PROBEBLOCK_END();
-
+       PRE_PROBEBLOCK_END();                                                           \
 
 #define AFTER_ORIGINAL_START_END_FD(API_ID, RTYPE, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...)          \
+do {                                                                   \
        POST_PACK_PROBEBLOCK_BEGIN();                                   \
        setProbePoint(&probeInfo);                                      \
        _fstatret = fstat(FD, &_statbuf);                               \
@@ -189,7 +208,8 @@ static inline bool stat_regular_or_socket_p(struct stat *buf)
                PACK_RESOURCE(SIZE, FD, APITYPE, _filesize, _filepath); \
                FLUSH_LOCAL_BUF();                                                              \
        }                                                               \
-       POST_PACK_PROBEBLOCK_END();
+       POST_PACK_PROBEBLOCK_END();                                                             \
+} while(0)
 
 
 
@@ -219,15 +239,18 @@ static inline bool stat_regular_or_socket_p(struct stat *buf)
        PRE_PROBEBLOCK_END()
 
 #define AFTER_ORIGINAL_START_END_NOFD(API_ID, RTYPE, RVAL, SIZE, APITYPE, INPUTFORMAT, ...)    \
+do {                                                                                           \
        POST_PACK_PROBEBLOCK_BEGIN();                                                           \
        setProbePoint(&probeInfo);                                                              \
        PREPARE_LOCAL_BUF();                                                                    \
        PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);                \
        PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                                    \
        POST_PACK_PROBEBLOCK_MIDDLE_NOFD(SIZE, APITYPE);                                        \
-       POST_PACK_PROBEBLOCK_END()
+       POST_PACK_PROBEBLOCK_END();                                                             \
+} while(0)
 
 #define AFTER_ORIGINAL_START_END_FILEP(API_ID, RTYPE, RVAL, SIZE, FILEP, APITYPE, INPUTFORMAT, ...)    \
+do {                                                                                           \
        POST_PACK_PROBEBLOCK_BEGIN();                                                           \
        setProbePoint(&probeInfo);                                                              \
        GET_FD_FROM_FILEP(FILEP);                                                               \
@@ -238,7 +261,8 @@ static inline bool stat_regular_or_socket_p(struct stat *buf)
        PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);                \
        PACK_COMMON_END(RTYPE, RVAL, newerrno, blockresult);                                    \
        POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE);                                     \
-       POST_PACK_PROBEBLOCK_END()
+       POST_PACK_PROBEBLOCK_END();                                                             \
+} while(0)
 
 
 static inline ssize_t get_fd_filesize(int fd)
index ae10dad..7b7b675 100755 (executable)
@@ -400,11 +400,14 @@ ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
 // *****************************************************************
 // File Attributes APIs
 // *****************************************************************
-
 int fcntl(int fd, int cmd, ...)
 {
        static int (*fcntlp)(int fd, int cmd, ...);
        int arg = 0, api_type = FD_API_OTHER;
+       int64_t start = 0;
+       int64_t len = 0;
+       int type = 0;
+       int whence = 0;
 
        BEFORE_ORIGINAL_FILE(fcntl, LIBC);
 
@@ -413,14 +416,12 @@ int fcntl(int fd, int cmd, ...)
        arg = va_arg(argl, int);
        va_end(argl);
 
-       ret = fcntlp(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;
+               type = flock->l_type;
+               whence = flock->l_whence;
+               start = flock->l_start;
+               len = flock->l_len;
 
                switch (type) {
                case F_RDLCK:
@@ -428,15 +429,32 @@ int fcntl(int fd, int cmd, ...)
                        api_type = FD_API_LOCK_START;
                        break;
                case F_UNLCK:
-                       api_type = FD_API_LOCK_END;
+                       api_type = FD_API_LOCK_RELEASE;
                        break;
                }
+       }
 
+       /* before lock event */
+       if (api_type == FD_API_LOCK_START)
+               AFTER_PACK_ORIGINAL_FD_MIDDLE(API_ID_fcntl,
+                                             'd', ret, 0, fd, api_type,
+                                             "ddddxx", fd, cmd, type,
+                                             whence, start, len);
+
+       /* call original lock function */
+       ret = fcntlp(fd, cmd, arg);
+
+       /* after lock event */
+       if (api_type != FD_API_OTHER) {
+               if (api_type == FD_API_LOCK_START)
+                       api_type = FD_API_LOCK_END;
+               /* pack FD_API_LOCK_END or FD_API_UNLOCK events */
                AFTER_PACK_ORIGINAL_FD(API_ID_fcntl,
                                       'd', ret, 0, fd, api_type,
                                       "ddddxx", fd, cmd, type,
                                       whence, start, len);
        } else {
+               /* pack FD_API_OTHER */
                AFTER_PACK_ORIGINAL_FD(API_ID_fcntl,
                                       'd', ret, 0, fd, api_type,
                                       "ddd", fd, cmd, arg);