diff options
author | Adrian Kummerlaender | 2016-02-11 14:05:00 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-02-11 14:05:00 +0100 |
commit | b9f79c106295f2f2589b92b17f60711a43bfbbce (patch) | |
tree | 41d5ab1c9adb61fce36b06d8e2c28adc3a228235 /src | |
parent | 5ea3620b2fb39ee9408d93fd6cd214d557d42a7f (diff) | |
download | change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar.gz change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar.bz2 change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar.lz change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar.xz change-b9f79c106295f2f2589b92b17f60711a43bfbbce.tar.zst change-b9f79c106295f2f2589b92b17f60711a43bfbbce.zip |
Extract file descriptor filter logic
Diffstat (limited to 'src')
-rw-r--r-- | src/change_log.cc | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/change_log.cc b/src/change_log.cc index c8dd8a1..a6f1437 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -12,6 +12,16 @@ static std::unique_ptr<utility::FileDescriptorGuard> fd_guard; static std::unique_ptr<utility::Logger> logger; static std::unique_ptr<tracking::ChangeTracker> tracker; +void track_write(const int fd) { + if ( fd != *fd_guard && utility::is_regular_file(fd) ) { + const std::string file_name{ utility::get_file_name(fd) }; + + if ( !tracker->is_tracked(file_name) ) { + tracker->track(file_name); + } + } +} + void init() __attribute__ ((constructor)); void init() { if ( getenv("CHANGE_LOG_TARGET") != NULL ) { @@ -33,25 +43,13 @@ void init() { } ssize_t write(int fd, const void* buffer, size_t count) { - if ( fd != *fd_guard && utility::is_regular_file(fd) ) { - const std::string file_name{ utility::get_file_name(fd) }; - - if ( !tracker->is_tracked(file_name) ) { - tracker->track(file_name); - } - } + track_write(fd); return actual::write(fd, buffer, count); } ssize_t writev(int fd, const iovec* iov, int iovcnt) { - if ( fd != *fd_guard && utility::is_regular_file(fd) ) { - const std::string file_name{ utility::get_file_name(fd) }; - - if ( !tracker->is_tracked(file_name) ) { - tracker->track(file_name); - } - } + track_write(fd); return actual::writev(fd, iov, iovcnt); } @@ -91,12 +89,8 @@ int unlinkat(int dirfd, const char* path, int flags) { } void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { - if ( ( prot & PROT_WRITE ) && utility::is_regular_file(fd) ) { - const std::string file_name{ utility::get_file_name(fd) }; - - if ( !tracker->is_tracked(file_name) ) { - tracker->track(file_name); - } + if ( prot & PROT_WRITE ) { + track_write(fd); } return actual::mmap(addr, length, prot, flags, fd, offset); |