aboutsummaryrefslogtreecommitdiff
path: root/libports
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-05-26 17:42:07 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-10 22:11:59 +0200
commit8db6b70ab6a64ea9b0ac313f2816131a046fbd76 (patch)
tree37d9c54335e800f4743725fe9633662f49ddc481 /libports
parent3e62adfb214090de7ad531d3aa68570aae92f9ec (diff)
downloadhurd-8db6b70ab6a64ea9b0ac313f2816131a046fbd76.tar.gz
hurd-8db6b70ab6a64ea9b0ac313f2816131a046fbd76.tar.bz2
hurd-8db6b70ab6a64ea9b0ac313f2816131a046fbd76.zip
libports: Treat no-senders notifications as a hint
No-senders notifications are directed to the port that no longer has any senders left. Since any client can easily spoof such a notification, we have to treat the notification as just a hint and verify whether there are, in fact, any senders, and only call ports_no_senders () if there actually are none left.
Diffstat (limited to 'libports')
-rw-r--r--libports/notify-no-senders.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/libports/notify-no-senders.c b/libports/notify-no-senders.c
index 55aa853f..cf0b386a 100644
--- a/libports/notify-no-senders.c
+++ b/libports/notify-no-senders.c
@@ -1,8 +1,9 @@
/* No sender notification
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright (C) 1995, 2021 Free Software Foundation, Inc.
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Written by Miles Bader <miles@gnu.ai.mit.edu>,
+ and Sergey Bugaev <bugaevc@gmail.com>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -23,10 +24,24 @@
error_t
ports_do_mach_notify_no_senders (struct port_info *pi,
- mach_port_mscount_t count)
+ mach_port_mscount_t count)
{
+ error_t err;
+ mach_port_status_t stat;
+
if (!pi)
return EOPNOTSUPP;
- ports_no_senders (pi, count);
+
+ /* Treat the notification as a hint, since it might not be coming from the
+ kernel. We now check if there are indeed no more senders left. */
+ err = mach_port_get_receive_status (mach_task_self (),
+ pi->port_right, &stat);
+ if (err)
+ return err;
+
+ if (stat.mps_srights)
+ return EAGAIN;
+
+ ports_no_senders (pi, stat.mps_mscount);
return 0;
}