Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Oct 2016 19:09:03 -0500
From:      Lewis Donzis <lew@perftech.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Jilles Tjoelker <jilles@stack.nl>, deischen@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: mq on kqueue broken after upgrade to FreeBSD 11  
Message-ID:  <AD237AD4-443D-40CF-87B8-622C6D68C1B3@perftech.com>
In-Reply-To: <20161005131412.GF38409@kib.kiev.ua>
References:  <20160930184418.1047afc2@kan> <20161001092515.GW38409@kib.kiev.ua> <20161001201655.GA91457@stack.nl> <20161001210722.GC38409@kib.kiev.ua> <20161001231524.GB91457@stack.nl> <20161002114613.GE38409@kib.kiev.ua> <20161002132242.GA2628@stack.nl> <7A72D37B-6C57-41FE-893F-592235A19D9D@perftech.com> <20161002163708.GG38409@kib.kiev.ua> <95CA96C0-A0F2-46B6-8BEA-E1A923FEC91D@perftech.com> <20161005131412.GF38409@kib.kiev.ua>

index | next in thread | previous in thread | raw e-mail


> On Oct 5, 2016, at 8:14 AM, Konstantin Belousov <kostikbel@gmail.com> wrote:
> 
> On Mon, Oct 03, 2016 at 07:27:54AM -0500, Lewis Donzis wrote:
>> That's a very good point, I hadn't considered those other functions,
>> and it???s clear that an fd is allocated and stored in the mqd_t.
>> But using close() instead of mq_close() wouldn't delete the sigevent
>> or free the memory that was allocated by mq_open(). In other words,
>> I don't understand why you'd ever want/need to use close() on the
>> underlying fd.
> 
> I really have troubles giving any useful interpretation to your question.
> OS provides the kernel service which backs the posix message queue
> implementation in userspace, as a file descriptor.  To release resources
> designated by the file descriptor, it must be closed, as in, close(2)
> must be called.  Librt does this in mq_close(3).
> 
> Why should I need to show a case of using close(2) on kernel mq
> descriptor (perhaps besides librt) ? And how this changes or augments
> the fact that kmq is file descriptor ?

Sorry, perhaps I wasn’t clear.  As I read it, you suggested that you "can and should call close()" on the fd in an mqd_t, and my point was simply that such practice would obviously be bad because it would fail to release resources allocated by mq_open().  So yes, the correct way to close an mqueue is via mq_close(), i.e., we’re not meant to circumvent the librt functions.

The problem is that it’s not exactly clean that we have mq_*() functions for some operations, whereas for others, we’re required to convert the mqd_t to an fd.  Of course, this is no fault of FreeBSD, and perhaps the POSIX folks should have come up with a better way to address this.  For example, they could have specified a portable way to get the underlying fd from an mqd_t and specified what can and cannot be done with the fd.

lew

help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AD237AD4-443D-40CF-87B8-622C6D68C1B3>