1.1 --- a/libfsclient/lib/src/notifier.cc Fri Mar 11 22:16:00 2022 +0100
1.2 +++ b/libfsclient/lib/src/notifier.cc Sun Mar 13 01:24:40 2022 +0100
1.3 @@ -30,6 +30,7 @@
1.4
1.5 #include "notification_client.h"
1.6 #include "notifier.h"
1.7 +#include "notifier_peer_client.h"
1.8
1.9
1.10
1.11 @@ -192,20 +193,33 @@
1.12 std::unique_lock<std::mutex> state_guard(_state_lock);
1.13
1.14 FileNotificationState &state = file_state(file, true);
1.15 + long err;
1.16
1.17 /* Create a notification endpoint, if necessary. */
1.18
1.19 if (state.is_null())
1.20 {
1.21 - long err = ipc_server_new_for_thread(&state.endpoint, file, _thread);
1.22 + err = ipc_server_new_for_thread(&state.endpoint, file, _thread);
1.23
1.24 if (err)
1.25 return err;
1.26 }
1.27
1.28 + /* Subscribe, sending the notification endpoint and obtaining a peer endpoint
1.29 + for unsubscribing. */
1.30 +
1.31 client_Notification notify(file->ref);
1.32
1.33 - return notify.subscribe(state.endpoint, flags);
1.34 + err = notify.subscribe(state.endpoint, flags, &state.peer);
1.35 +
1.36 + if (err)
1.37 + {
1.38 + ipc_cap_free_um(state.endpoint);
1.39 + _state.erase(file);
1.40 + return err;
1.41 + }
1.42 +
1.43 + return L4_EOK;
1.44 }
1.45
1.46 /* Unsubscribe from notification events on a file. */
1.47 @@ -221,6 +235,15 @@
1.48 if (state.is_null())
1.49 return -L4_EINVAL;
1.50
1.51 + /* Unsubscribe via the peer endpoint. */
1.52 +
1.53 + client_NotifierPeer peer(state.peer);
1.54 +
1.55 + peer.unsubscribe();
1.56 +
1.57 + ipc_cap_free_um(state.endpoint);
1.58 + ipc_cap_free_um(state.peer);
1.59 +
1.60 _state.erase(file);
1.61
1.62 /* Remove the lock for updating file state. */