diff options
author | Zyad A. Ali <zyad.ali.me@gmail.com> | 2021-06-02 15:33:36 +0200 |
---|---|---|
committer | Zyad A. Ali <zyad.ali.me@gmail.com> | 2021-07-13 22:12:02 +0200 |
commit | 084aa4fa51b74b426cf1bc0e1347624b2b516bcd (patch) | |
tree | 9e989661da3245a2f1cbc0dc6a59faf954317cb5 | |
parent | 7eae6402c111323cd6e92e0499dfa12cf2554d1a (diff) |
Implement Registry.Remove.
Remove implements the behaviour or msgctl(IPC_RMID).
Updates #135
-rw-r--r-- | pkg/sentry/kernel/msgqueue/BUILD | 1 | ||||
-rw-r--r-- | pkg/sentry/kernel/msgqueue/msgqueue.go | 25 |
2 files changed, 24 insertions, 2 deletions
diff --git a/pkg/sentry/kernel/msgqueue/BUILD b/pkg/sentry/kernel/msgqueue/BUILD index 4114ee45a..e4305fead 100644 --- a/pkg/sentry/kernel/msgqueue/BUILD +++ b/pkg/sentry/kernel/msgqueue/BUILD @@ -26,7 +26,6 @@ go_library( "//pkg/abi/linux", "//pkg/context", "//pkg/errors/linuxerr", - "//pkg/log", "//pkg/sentry/fs", "//pkg/sentry/kernel/auth", "//pkg/sentry/kernel/ipc", diff --git a/pkg/sentry/kernel/msgqueue/msgqueue.go b/pkg/sentry/kernel/msgqueue/msgqueue.go index 0e2d996a8..5f7f35cd3 100644 --- a/pkg/sentry/kernel/msgqueue/msgqueue.go +++ b/pkg/sentry/kernel/msgqueue/msgqueue.go @@ -67,6 +67,11 @@ type Queue struct { // mu protects all the fields below. mu sync.Mutex `state:"nosave"` + // dead is set to true when a queue is removed from the registry and should + // not be used. Operations on the queue should check dead, and return + // EIDRM if set to true. + dead bool + // obj defines basic fields that should be included in all SysV IPC objects. obj *ipc.Object @@ -170,6 +175,17 @@ func (r *Registry) newQueueLocked(ctx context.Context, key ipc.Key, creator fs.F return q, nil } +// Remove removes the queue with specified ID. All waiters (readers and +// writers) and writers will be awakened and fail. Remove will return an error +// if the ID is invalid, or the the user doesn't have privileges. +func (r *Registry) Remove(id ipc.ID, creds *auth.Credentials) error { + r.mu.Lock() + defer r.mu.Unlock() + + r.reg.Remove(id, creds) + return nil +} + // Lock implements ipc.Mechanism.Lock. func (q *Queue) Lock() { q.mu.Lock() @@ -187,6 +203,13 @@ func (q *Queue) Object() *ipc.Object { return q.obj } -// Destroy implements ipc.Mechanism.Destroy. It's yet to be implemented. +// Destroy implements ipc.Mechanism.Destroy. func (q *Queue) Destroy() { + q.dead = true + + // Notify waiters. Senders and receivers will try to run, and return an + // error (EIDRM). Waiters should remove themselves from the queue after + // waking up. + q.senders.Notify(waiter.EventOut) + q.receivers.Notify(waiter.EventIn) } |