[PROTO] Send probes from {r,v,}{read,write} only for socket and reg files
authorDmitry Bogatov <d.bogatov@samsung.com>
Fri, 20 Sep 2013 09:53:27 +0000 (13:53 +0400)
committerDmitry Bogatov <d.bogatov@samsung.com>
Fri, 20 Sep 2013 11:20:43 +0000 (15:20 +0400)
See-also: 02637c31710324818e36a0455c6f79c0def786ea
Change-Id: I66760615a24c02e2ae7054dcc745db0d3ab7341d
Signed-off-by: Dmitry Bogatov <d.bogatov@samsung.com>
probe_file/da_io.h

index a32390f..3b34d9c 100755 (executable)
        POST_PACK_PROBEBLOCK_MIDDLE_FD(SIZE, _fd, APITYPE);                             \
        POST_PACK_PROBEBLOCK_END()
 
+/*!
+ * Macros {BEFORE,AFTER}_ORIGINAL_START_END_FD only used in {p,v,}{read,write}
+ * in which we should log only about files and sockets. Given this lucky
+ * coincidence we can implement this login in macros. As such, they should not
+ * be used in functions for which this logic do not apply.
+ */
+static inline bool stat_regular_or_socket_p(struct stat *buf)
+{
+  return S_ISREG(buf->st_mode) || S_ISSOCK(buf->st_mode);
+}
+#define BEFORE_ORIGINAL_START_END_FD(API_ID, FUNCNAME, LIBNAME, FD, APITYPE, INPUTFORMAT, ...) \
+       DECLARE_VARIABLE_FD;                                                                    \
+       GET_REAL_FUNC(FUNCNAME, LIBNAME);                                                       \
+       PRE_PROBEBLOCK_BEGIN();                                                                 \
+       _fstatret = fstat(FD, &_statbuf);                                                       \
+       if (stat_regular_or_socket_p(&_statbuf)) {                                              \
+               DEFINE_FILESIZE_FD(fd);                                                         \
+               PREPARE_LOCAL_BUF();                                                            \
+               PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);        \
+               PACK_COMMON_END(0, 0, blockresult);                                             \
+               PACK_RESOURCE(0, FD, APITYPE, _filesize, _filepath);                            \
+               FLUSH_LOCAL_BUF();                                                              \
+               PRE_PROBEBLOCK_END();                                                           \
+       }
 
-// ==================================================================
-// START_END macro for file
-// ==================================================================
 
-#define BEFORE_ORIGINAL_START_END_FD(API_ID, FUNCNAME, LIBNAME, FD, APITYPE, INPUTFORMAT, ...) \
-       DECLARE_VARIABLE_FD;                                                            \
-       GET_REAL_FUNC(FUNCNAME, LIBNAME);                                               \
-       PRE_PROBEBLOCK_BEGIN();                                                         \
-       _fstatret = fstat(FD, &_statbuf);                                               \
-       DEFINE_FILESIZE_FD(fd);                                                         \
-       PREPARE_LOCAL_BUF();                                                            \
-       PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);        \
-       PACK_COMMON_END(0, 0, blockresult);                                             \
-       PACK_RESOURCE(0, FD, APITYPE, _filesize, _filepath);                            \
-       FLUSH_LOCAL_BUF();                                                              \
-       PRE_PROBEBLOCK_END()
+#define AFTER_ORIGINAL_START_END_FD(API_ID, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...)         \
+       POST_PACK_PROBEBLOCK_BEGIN();                                                           \
+       setProbePoint(&probeInfo);                                                              \
+       _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(RVAL, newerrno, blockresult);                                   \
+               PACK_RESOURCE(SIZE, FD, APITYPE, _filesize, _filepath);                         \
+               FLUSH_LOCAL_BUF();                                                              \
+               POST_PACK_PROBEBLOCK_END();                                                     \
+       }
 
 #define BEFORE_ORIGINAL_START_END_NOFD(API_ID, FUNCNAME, LIBNAME, APITYPE, INPUTFORMAT, ...)   \
        DECLARE_VARIABLE_FD;                                                            \
        POST_PACK_PROBEBLOCK_MIDDLE_FD(0, _fd, APITYPE);                                        \
        PRE_PROBEBLOCK_END()
 
-#define AFTER_ORIGINAL_START_END_FD(API_ID, RVAL, SIZE, FD, APITYPE, INPUTFORMAT, ...)         \
-       POST_PACK_PROBEBLOCK_BEGIN();                                                           \
-       setProbePoint(&probeInfo);                                                              \
-       _fstatret = fstat(FD, &_statbuf);                                                       \
-       PREPARE_LOCAL_BUF();                                                                    \
-       PACK_COMMON_BEGIN(MSG_PROBE_RESOURCE, API_ID, INPUTFORMAT, __VA_ARGS__);                \
-       PACK_COMMON_END(RVAL, newerrno, blockresult);                                           \
-       PACK_RESOURCE(SIZE, FD, APITYPE, _filesize, _filepath);                                 \
-       FLUSH_LOCAL_BUF();                                                                      \
-       POST_PACK_PROBEBLOCK_END()
-
 #define AFTER_ORIGINAL_START_END_NOFD(API_ID, RVAL, SIZE, APITYPE, INPUTFORMAT, ...)           \
        POST_PACK_PROBEBLOCK_BEGIN();                                                           \
        setProbePoint(&probeInfo);                                                              \