aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-02-11 14:05:00 +0100
committerAdrian Kummerlaender2016-02-11 14:05:00 +0100
commitb9f79c106295f2f2589b92b17f60711a43bfbbce (patch)
tree41d5ab1c9adb61fce36b06d8e2c28adc3a228235
parent5ea3620b2fb39ee9408d93fd6cd214d557d42a7f (diff)
downloadchange-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
-rw-r--r--src/change_log.cc34
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);