1.1 --- a/libexec/include/exec/process_monitor.h Sun Mar 26 01:36:53 2023 +0100
1.2 +++ b/libexec/include/exec/process_monitor.h Sun Mar 26 01:52:16 2023 +0100
1.3 @@ -42,6 +42,10 @@
1.4 _task = L4_INVALID_CAP, _mapped_task = L4_INVALID_CAP,
1.5 _thread = L4_INVALID_CAP, _mapped_thread = L4_INVALID_CAP;
1.6
1.7 + /* Notification support. */
1.8 +
1.9 + l4_cap_idx_t _notifier = L4_INVALID_CAP;
1.10 +
1.11 public:
1.12 explicit ProcessMonitor();
1.13
1.14 @@ -75,7 +79,7 @@
1.15
1.16 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
1.17
1.18 - virtual long unsubscribe(l4_cap_idx_t notifier);
1.19 + virtual long unsubscribe();
1.20 };
1.21
1.22 /* vim: tabstop=2 expandtab shiftwidth=2
2.1 --- a/libexec/lib/src/process_monitor.cc Sun Mar 26 01:36:53 2023 +0100
2.2 +++ b/libexec/lib/src/process_monitor.cc Sun Mar 26 01:52:16 2023 +0100
2.3 @@ -144,14 +144,24 @@
2.4
2.5 long ProcessMonitor::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
2.6 {
2.7 - return NotificationSupport::subscribe(notifier, flags);
2.8 + unsubscribe();
2.9 +
2.10 + _notifier = notifier;
2.11 + return NotificationSupport::subscribe(_notifier, flags);
2.12 }
2.13
2.14 /* Unsubscribe from notifications. */
2.15
2.16 -long ProcessMonitor::unsubscribe(l4_cap_idx_t notifier)
2.17 +long ProcessMonitor::unsubscribe()
2.18 {
2.19 - return NotificationSupport::unsubscribe(notifier);
2.20 + if (l4_is_valid_cap(_notifier))
2.21 + {
2.22 + long err = NotificationSupport::unsubscribe(_notifier);
2.23 + _notifier = L4_INVALID_CAP;
2.24 + return err;
2.25 + }
2.26 + else
2.27 + return L4_EOK;
2.28 }
2.29
2.30 /* vim: tabstop=2 expandtab shiftwidth=2
3.1 --- a/libfsserver/include/fsserver/directory_resource.h Sun Mar 26 01:36:53 2023 +0100
3.2 +++ b/libfsserver/include/fsserver/directory_resource.h Sun Mar 26 01:52:16 2023 +0100
3.3 @@ -63,7 +63,7 @@
3.4
3.5 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
3.6
3.7 - virtual long unsubscribe(l4_cap_idx_t notifier);
3.8 + virtual long unsubscribe();
3.9 };
3.10
3.11 // vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/libfsserver/include/fsserver/file_pager.h Sun Mar 26 01:36:53 2023 +0100
4.2 +++ b/libfsserver/include/fsserver/file_pager.h Sun Mar 26 01:52:16 2023 +0100
4.3 @@ -83,7 +83,7 @@
4.4
4.5 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
4.6
4.7 - virtual long unsubscribe(l4_cap_idx_t notifier);
4.8 + virtual long unsubscribe();
4.9 };
4.10
4.11 // vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/libfsserver/include/fsserver/pipe_pager.h Sun Mar 26 01:36:53 2023 +0100
5.2 +++ b/libfsserver/include/fsserver/pipe_pager.h Sun Mar 26 01:52:16 2023 +0100
5.3 @@ -77,7 +77,7 @@
5.4
5.5 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
5.6
5.7 - virtual long unsubscribe(l4_cap_idx_t notifier);
5.8 + virtual long unsubscribe();
5.9 };
5.10
5.11 // vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/libfsserver/lib/directories/directory_resource.cc Sun Mar 26 01:36:53 2023 +0100
6.2 +++ b/libfsserver/lib/directories/directory_resource.cc Sun Mar 26 01:52:16 2023 +0100
6.3 @@ -52,7 +52,12 @@
6.4 appropriate. */
6.5
6.6 void DirectoryResource::close()
6.7 -{
6.8 +{
6.9 + /* Notify other users of the file and unsubscribe. */
6.10 +
6.11 + _provider->notify_others(_notifier, NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL);
6.12 + unsubscribe();
6.13 +
6.14 /* Detach the resource, potentially removing the file provider. */
6.15
6.16 _provider->registry()->detach(fileid, _provider);
6.17 @@ -125,15 +130,27 @@
6.18
6.19 long DirectoryResource::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
6.20 {
6.21 + /* A single notifier is recorded so that it may be unsubscribed when the
6.22 + directory is closed. */
6.23 +
6.24 + unsubscribe();
6.25 +
6.26 _notifier = notifier;
6.27 - return _provider->subscribe(notifier, flags);
6.28 + return _provider->subscribe(_notifier, flags);
6.29 }
6.30
6.31 /* Unsubscribe from notifications. */
6.32
6.33 -long DirectoryResource::unsubscribe(l4_cap_idx_t notifier)
6.34 +long DirectoryResource::unsubscribe()
6.35 {
6.36 - return _provider->unsubscribe(notifier);
6.37 + if (l4_is_valid_cap(_notifier))
6.38 + {
6.39 + long err = _provider->unsubscribe(_notifier);
6.40 + _notifier = L4_INVALID_CAP;
6.41 + return err;
6.42 + }
6.43 + else
6.44 + return L4_EOK;
6.45 }
6.46
6.47 // vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/libfsserver/lib/files/file_pager.cc Sun Mar 26 01:36:53 2023 +0100
7.2 +++ b/libfsserver/lib/files/file_pager.cc Sun Mar 26 01:52:16 2023 +0100
7.3 @@ -53,7 +53,7 @@
7.4 /* Notify other users of the file and unsubscribe. */
7.5
7.6 _provider->notify_others(_notifier, NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL);
7.7 - unsubscribe(_notifier);
7.8 + unsubscribe();
7.9
7.10 /* Detach the pager, potentially removing the file provider. */
7.11
7.12 @@ -155,18 +155,24 @@
7.13 /* A single notifier is recorded so that it may be unsubscribed when the
7.14 file is closed. */
7.15
7.16 - if ((notifier != _notifier) && l4_is_valid_cap(_notifier))
7.17 - unsubscribe(_notifier);
7.18 + unsubscribe();
7.19
7.20 _notifier = notifier;
7.21 - return _provider->subscribe(notifier, flags);
7.22 + return _provider->subscribe(_notifier, flags);
7.23 }
7.24
7.25 /* Unsubscribe from notifications. */
7.26
7.27 -long FilePager::unsubscribe(l4_cap_idx_t notifier)
7.28 +long FilePager::unsubscribe()
7.29 {
7.30 - return _provider->unsubscribe(notifier);
7.31 + if (l4_is_valid_cap(_notifier))
7.32 + {
7.33 + long err = _provider->unsubscribe(_notifier);
7.34 + _notifier = L4_INVALID_CAP;
7.35 + return err;
7.36 + }
7.37 + else
7.38 + return L4_EOK;
7.39 }
7.40
7.41 // vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/libfsserver/lib/pipes/pipe_pager.cc Sun Mar 26 01:36:53 2023 +0100
8.2 +++ b/libfsserver/lib/pipes/pipe_pager.cc Sun Mar 26 01:52:16 2023 +0100
8.3 @@ -62,7 +62,7 @@
8.4
8.5 _paging->notify_others(_writing ? PipePaging::WRITER : PipePaging::READER,
8.6 NOTIFY_PEER_CLOSED, NOTIFY_VALUES_NULL);
8.7 - unsubscribe(_notifier);
8.8 + unsubscribe();
8.9
8.10 /* Deallocate the paging coordinator if no other endpoints are active. */
8.11
8.12 @@ -183,22 +183,27 @@
8.13 long PipePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
8.14 {
8.15 /* A single notifier is recorded so that it may be unsubscribed when the
8.16 - file is closed. */
8.17 + endpoint is closed. */
8.18
8.19 - if ((notifier != _notifier) && l4_is_valid_cap(_notifier))
8.20 - unsubscribe(_notifier);
8.21 + unsubscribe();
8.22
8.23 _notifier = notifier;
8.24 -
8.25 return _paging->subscribe(_writing ? PipePaging::WRITER : PipePaging::READER,
8.26 - notifier, flags);
8.27 + _notifier, flags);
8.28 }
8.29
8.30 /* Unsubscribe from notifications. */
8.31
8.32 -long PipePager::unsubscribe(l4_cap_idx_t notifier)
8.33 +long PipePager::unsubscribe()
8.34 {
8.35 - return _paging->unsubscribe(notifier);
8.36 + if (l4_is_valid_cap(_notifier))
8.37 + {
8.38 + long err = _paging->unsubscribe(_notifier);
8.39 + _notifier = L4_INVALID_CAP;
8.40 + return err;
8.41 + }
8.42 + else
8.43 + return L4_EOK;
8.44 }
8.45
8.46 // vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/libnotifier/lib/src/notifier.cc Sun Mar 26 01:36:53 2023 +0100
9.2 +++ b/libnotifier/lib/src/notifier.cc Sun Mar 26 01:52:16 2023 +0100
9.3 @@ -187,6 +187,13 @@
9.4 state.endpoint = server.config()->server;
9.5 }
9.6
9.7 + /* Forbid repeated subscription.
9.8 + NOTE: Could instead rely on being unsubscribed, releasing the existing
9.9 + endpoint. */
9.10 +
9.11 + else
9.12 + return -L4_EEXIST;
9.13 +
9.14 /* Allow this object to be re-entered. This may occur because the subscribe
9.15 operation can cause deferred notifications to be sent back to the
9.16 subscribed notifier and to this object. */
9.17 @@ -218,7 +225,7 @@
9.18
9.19 client_Notification notify(object->base->ref);
9.20
9.21 - notify.unsubscribe(state.endpoint);
9.22 + notify.unsubscribe();
9.23
9.24 return remove_endpoint(object, state.endpoint);
9.25 }
10.1 --- a/libsystypes/idl/notification.idl Sun Mar 26 01:36:53 2023 +0100
10.2 +++ b/libsystypes/idl/notification.idl Sun Mar 26 01:52:16 2023 +0100
10.3 @@ -7,7 +7,8 @@
10.4
10.5 [opcode(23)] void subscribe(in cap notifier, in notify_flags_t flags);
10.6
10.7 - /* Unsubscribe from events. */
10.8 + /* Unsubscribe from events. A notifier cannot be provided since it will be
10.9 + considered distinct from any previously presented for subscription. */
10.10
10.11 - [opcode(24)] void unsubscribe(in cap notifier);
10.12 + [opcode(24)] void unsubscribe();
10.13 };