-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for mq_notify() on Linux #2467
base: master
Are you sure you want to change the base?
Conversation
#[cfg(target_os = "linux")] | ||
pub fn mq_notify(mqdes: &MqdT, notify: SigEvent) -> Result<()> { | ||
let sig_event = notify.sigevent(); | ||
let res = unsafe { libc::syscall(libc::SYS_mq_notify, mqdes.0, &sig_event as *const libc_sigevent) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the Linux manual, glibc has provided a library wrapper for this syscall, we should prefer to use that. If the symbol is not exposed by the libc crate, we should add it there first (to the libc-0.2
branch), and then we adjust the dependency and add it on the Nix side.
/// See also [`mq_notify(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_notify.html) | ||
#[cfg(target_os = "linux")] | ||
pub fn mq_notify(mqdes: &MqdT, notify: SigEvent) -> Result<()> { | ||
let sig_event = notify.sigevent(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.sigevent()
would copy the underlying structure, we can use as_mut_ptr()
to get the pointer directly.
Update: Just found this function returns a mutable pointer, which is not needed by this PR, looks like we need to add an as_ptr()
function, which should be implemented in a way similar to how as_mut_ptr()
was implemented.
/// | ||
/// See also [`mq_notify(2)`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_notify.html) | ||
#[cfg(target_os = "linux")] | ||
pub fn mq_notify(mqdes: &MqdT, notify: SigEvent) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we taking notify
by value?
let _ = nix::mqueue::mq_unlink(mq_name); | ||
let r0 = mq_open(mq_name, oflag0, mode, Some(&attr)); | ||
if let Err(Errno::ENOSYS) = r0 { | ||
println!("message queues not supported or module not loaded?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the skip!()
macro provided in test/common/mod.rs
, which uses io::stderr()
directly to ensure it won't be captured by cargo test
so that the message will always be printed:
skip!("test_mq_send_receive_notify: message queues not supported or module not loaded, skipping test")
What does this PR do
This PR adds support for the
mq_notify()
API that allows a process to register for POSIX message queue notifications.Checklist:
CONTRIBUTING.md