From: Tobias Brunner Date: Tue, 18 Apr 2023 13:52:23 +0000 (+0200) Subject: watcher: Log when watched FDs are added, removed or updated X-Git-Tag: 5.9.11rc1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34e9cdbcace1da1832d74bff534af6b95b73b612;p=thirdparty%2Fstrongswan.git watcher: Log when watched FDs are added, removed or updated --- diff --git a/src/libstrongswan/processing/watcher.c b/src/libstrongswan/processing/watcher.c index d0df2ddb35..c4d11e9fc6 100644 --- a/src/libstrongswan/processing/watcher.c +++ b/src/libstrongswan/processing/watcher.c @@ -220,6 +220,8 @@ static void notify_end(notify_data_t *data) { private_watcher_t *this = data->this; entry_t *entry, *prev = NULL; + watcher_event_t updated = 0; + bool removed = FALSE; /* reactivate the disabled entry */ this->mutex->lock(this->mutex); @@ -230,9 +232,11 @@ static void notify_end(notify_data_t *data) if (!data->keep) { entry->events &= ~data->event; + updated = entry->events; if (!entry->events) { remove_entry(this, entry, prev); + removed = TRUE; break; } } @@ -243,6 +247,23 @@ static void notify_end(notify_data_t *data) this->condvar->broadcast(this->condvar); update_and_unlock(this); + if (removed) + { + DBG3(DBG_JOB, "removed fd %d[%s%s%s] from watcher after callback", data->fd, + data->event & WATCHER_READ ? "r" : "", + data->event & WATCHER_WRITE ? "w" : "", + data->event & WATCHER_EXCEPT ? "e" : ""); + } + else if (updated) + { + DBG3(DBG_JOB, "updated fd %d[%s%s%s] to %d[%s%s%s] after callback", data->fd, + (updated | data->event) & WATCHER_READ ? "r" : "", + (updated | data->event) & WATCHER_WRITE ? "w" : "", + (updated | data->event) & WATCHER_EXCEPT ? "e" : "", data->fd, + updated & WATCHER_READ ? "r" : "", + updated & WATCHER_WRITE ? "w" : "", + updated & WATCHER_EXCEPT ? "e" : ""); + } free(data); } @@ -498,6 +519,11 @@ METHOD(watcher_t, add, void, .data = data, ); + DBG3(DBG_JOB, "adding fd %d[%s%s%s] to watcher", fd, + events & WATCHER_READ ? "r" : "", + events & WATCHER_WRITE ? "w" : "", + events & WATCHER_EXCEPT ? "e" : ""); + this->mutex->lock(this->mutex); add_entry(this, entry); if (this->state == WATCHER_STOPPED) @@ -519,7 +545,7 @@ METHOD(watcher_t, remove_, void, private_watcher_t *this, int fd) { entry_t *entry, *prev = NULL; - bool found = FALSE; + watcher_event_t found = 0; this->mutex->lock(this->mutex); while (TRUE) @@ -536,8 +562,8 @@ METHOD(watcher_t, remove_, void, is_in_callback = TRUE; break; } + found |= entry->events; entry = remove_entry(this, entry, prev); - found = TRUE; continue; } prev = entry; @@ -552,6 +578,11 @@ METHOD(watcher_t, remove_, void, if (found) { update_and_unlock(this); + + DBG3(DBG_JOB, "removed fd %d[%s%s%s] from watcher", fd, + found & WATCHER_READ ? "r" : "", + found & WATCHER_WRITE ? "w" : "", + found & WATCHER_EXCEPT ? "e" : ""); } else {