Bug 232908 - mqueue.h needs to include fcntl.h
Summary: mqueue.h needs to include fcntl.h
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Conrad Meyer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-02 12:12 UTC by jphartmann
Modified: 2018-11-03 00:48 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jphartmann 2018-11-02 12:12:39 UTC
If the source file that includes mqueue.h does no other UNIX I/O, O_RDWR is likely undeclared.  Manually including fcntl.h fixes the compiler error.

mq.c: In function 'openqueue':
mq.c:41:35: error: 'O_RDWR' undeclared (first use in this function); did you mean '__SWR'?
    mq->handle = mq_open(mq->name, O_RDWR | O_CREAT, 0600, &att);

Apologies if this is reported in the wrong place.  I am not aware of having installed any package to obtain the message queueing service, so base system seems appropriate.
Comment 1 jphartmann 2018-11-02 12:16:17 UTC
In case it matters, I use gcc, as installed by

pkg install gcc
Comment 2 Yuri Pankov freebsd_committer freebsd_triage 2018-11-02 12:51:47 UTC
Strictly speaking, mqueue.h doesn't need any of the symbols defined in fcntl.h, so "need" wording is not entirely correct.  OTOH, other systems seem to include fcntl.h in mqueue.h, and POSIX explicitly states that it's allowed:

Inclusion of the <mqueue.h> header may make visible symbols defined in the headers <fcntl.h>, <signal.h>, and <time.h>.
Comment 3 jphartmann 2018-11-02 12:55:25 UTC
Point taken about whether fcntl.h needs to be included or not.  If not, the man page should show the required #include.
Comment 4 jphartmann 2018-11-02 12:56:45 UTC
Perhaps the point is moot after all.  I get errno 78 opening the queue now that I managed to compile the code.  This is my trace of the failing open:

mq_open /stxready error 78: Function not implemented

Of course, it would help if I could know what exactly is not implemented.  The man page does not offer any insight, nor does it mention the error ENOSYS, but of course, that could be a case of left hand and right hand.

I do link with -lrt:

gcc -o obj/FreeBSD.amd64/cdlist obj/FreeBSD.amd64/cdlist.o obj/FreeBSD.amd64/amix.o obj/FreeBSD.amd64/curs.o obj/FreeBSD.amd64/dirl.o obj/FreeBSD.amd64/dirpaint.o obj/FreeBSD.amd64/dmenu.o obj/FreeBSD.amd64/menu.o obj/FreeBSD.amd64/pl.o obj/FreeBSD.amd64/sched.o obj/FreeBSD.amd64/st.o obj/FreeBSD.amd64/cdlist_opts.o obj/FreeBSD.amd64/cdlist_enum.o  jlinktime.c -L../playlist/obj/FreeBSD.amd64 -lXCurses -lmenu -lplaylist -lrt -lpthread -lasound -lj -L/home/john/lib -L/usr/local/lib
Comment 5 Brooks Davis freebsd_committer freebsd_triage 2018-11-02 14:55:24 UTC
You need to have P1003_1B_MQUEUE in your kernel or load the mqueuefs module to enable support.

Per the actual PR subject, we should project just include fcntl.h in mqueue.h.  Header pollution seems not worth worrying about in this rarely used framework, especially since posix explicitly allows it.
Comment 6 jphartmann 2018-11-02 15:11:33 UTC
Thanks.  Loading the module fixed this for me.  

How would I have known that I need to load the kernel module?
Comment 7 Conrad Meyer freebsd_committer freebsd_triage 2018-11-02 15:35:51 UTC
(In reply to jphartmann from comment #6)
man mq_open:

NOTES
...
     Please see the mqueuefs(5) man page for instructions on loading the
     module or compiling the service into the kernel.

man mqueuefs:

SYNOPSIS
     To link into kernel:

     options P1003_1B_MQUEUE

     To load as a kernel loadable module:

           kldload mqueuefs
Comment 8 jphartmann 2018-11-02 18:04:03 UTC
Thanks.  

I'll keep an eye open for those man 5 pages in future.

As far as I am concerned, this issue can be closed.
Comment 9 Nathan 2018-11-02 22:23:37 UTC
(In reply to jphartmann from comment #8)
You can close this bug yourself, since you are the original reporter