1.1 --- a/libfsserver/lib/directories/directory_resource.cc Sun Mar 26 01:36:53 2023 +0100
1.2 +++ b/libfsserver/lib/directories/directory_resource.cc Sun Mar 26 01:52:16 2023 +0100
1.3 @@ -52,7 +52,12 @@
1.4 appropriate. */
1.5
1.6 void DirectoryResource::close()
1.7 -{
1.8 +{
1.9 + /* Notify other users of the file and unsubscribe. */
1.10 +
1.11 + _provider->notify_others(_notifier, NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL);
1.12 + unsubscribe();
1.13 +
1.14 /* Detach the resource, potentially removing the file provider. */
1.15
1.16 _provider->registry()->detach(fileid, _provider);
1.17 @@ -125,15 +130,27 @@
1.18
1.19 long DirectoryResource::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
1.20 {
1.21 + /* A single notifier is recorded so that it may be unsubscribed when the
1.22 + directory is closed. */
1.23 +
1.24 + unsubscribe();
1.25 +
1.26 _notifier = notifier;
1.27 - return _provider->subscribe(notifier, flags);
1.28 + return _provider->subscribe(_notifier, flags);
1.29 }
1.30
1.31 /* Unsubscribe from notifications. */
1.32
1.33 -long DirectoryResource::unsubscribe(l4_cap_idx_t notifier)
1.34 +long DirectoryResource::unsubscribe()
1.35 {
1.36 - return _provider->unsubscribe(notifier);
1.37 + if (l4_is_valid_cap(_notifier))
1.38 + {
1.39 + long err = _provider->unsubscribe(_notifier);
1.40 + _notifier = L4_INVALID_CAP;
1.41 + return err;
1.42 + }
1.43 + else
1.44 + return L4_EOK;
1.45 }
1.46
1.47 // vim: tabstop=4 expandtab shiftwidth=4