diff --git a/src/inotify.c b/src/inotify.c index 828f7f6..553ba67 100644 --- a/src/inotify.c +++ b/src/inotify.c @@ -96,7 +96,8 @@ void *inotify_gotsig(int sig, siginfo_t *info, void *ucontext) void* inotify_thread(void* arg) { mtp_ctx * ctx; - int i,length; + int i, length; + int send_event_flag; fs_entry * entry; fs_entry * deleted_entry; fs_entry * modified_entry; @@ -144,6 +145,8 @@ void* inotify_thread(void* arg) entry = NULL; do { + send_event_flag = 0; + if ( pthread_mutex_lock( &ctx->inotify_mutex ) ) { PRINT_ERROR( "inotify_thread - pthread_mutex_lock failure !"); @@ -162,7 +165,7 @@ void* inotify_thread(void* arg) { // Send an "ObjectAdded" (0x4002) MTP event message with the entry handle. handle[0] = new_entry->handle; - mtp_push_event( ctx, MTP_EVENT_OBJECT_ADDED, 1, (uint32_t *)&handle ); + send_event_flag = 1; PRINT_DEBUG( "inotify_thread (IN_CREATE): Entry %s created (Handle 0x%.8X)", event->name, new_entry->handle ); } @@ -192,6 +195,11 @@ void* inotify_thread(void* arg) return NULL; } + if( send_event_flag ) + { + mtp_push_event( ctx, MTP_EVENT_OBJECT_ADDED, 1, (uint32_t *)&handle ); + } + }while(entry); } @@ -201,6 +209,8 @@ void* inotify_thread(void* arg) do { + send_event_flag = 0; + if ( pthread_mutex_lock( &ctx->inotify_mutex ) ) { PRINT_ERROR( "inotify_thread - pthread_mutex_lock failure !"); @@ -215,7 +225,7 @@ void* inotify_thread(void* arg) { // Send an "ObjectInfoChanged" (0x4007) MTP event message with the entry handle. handle[0] = modified_entry->handle; - mtp_push_event( ctx, MTP_EVENT_OBJECT_INFO_CHANGED, 1, (uint32_t *)&handle ); + send_event_flag = 1; PRINT_DEBUG( "inotify_thread (IN_MODIFY): Entry %s modified (Handle 0x%.8X)", event->name, modified_entry->handle); } @@ -236,6 +246,11 @@ void* inotify_thread(void* arg) return NULL; } + if( send_event_flag ) + { + mtp_push_event( ctx, MTP_EVENT_OBJECT_INFO_CHANGED, 1, (uint32_t *)&handle ); + } + }while(entry); } @@ -245,6 +260,8 @@ void* inotify_thread(void* arg) do { + send_event_flag = 0; + if ( pthread_mutex_lock( &ctx->inotify_mutex ) ) { PRINT_ERROR( "inotify_thread - pthread_mutex_lock failure !"); @@ -266,7 +283,7 @@ void* inotify_thread(void* arg) // Send an "ObjectRemoved" (0x4003) MTP event message with the entry handle. handle[0] = deleted_entry->handle; - mtp_push_event( ctx, MTP_EVENT_OBJECT_REMOVED, 1, (uint32_t *)&handle ); + send_event_flag = 1; PRINT_DEBUG( "inotify_thread (IN_DELETE): Entry %s deleted (Handle 0x%.8X)", event->name, deleted_entry->handle); } @@ -287,6 +304,10 @@ void* inotify_thread(void* arg) return NULL; } + if( send_event_flag ) + { + mtp_push_event( ctx, MTP_EVENT_OBJECT_REMOVED, 1, (uint32_t *)&handle ); + } }while(entry); } }