Merge branch 'syslog-sysselect-cleanup' into 'master'

syslog and sys_select header cleanup

See merge request redox-os/relibc!1059
This commit is contained in:
Jeremy Soller
2026-03-01 11:00:11 -07:00
6 changed files with 54 additions and 56 deletions
+42 -41
View File
@@ -42,6 +42,7 @@ pub struct fd_set {
pub fds_bits: bitset,
}
#[allow(clippy::needless_update)]
pub fn select_epoll(
nfds: c_int,
readfds: Option<&mut fd_set>,
@@ -71,53 +72,53 @@ pub fn select_epoll(
for fd in 0..nfds {
let mut events = 0;
if let Some(ref fd_set) = read_bitset {
if fd_set.contains(fd as usize) {
events |= EPOLLIN;
}
if let Some(ref fd_set) = read_bitset
&& fd_set.contains(fd as usize)
{
events |= EPOLLIN;
}
if let Some(ref fd_set) = write_bitset {
if fd_set.contains(fd as usize) {
events |= EPOLLOUT;
}
if let Some(ref fd_set) = write_bitset
&& fd_set.contains(fd as usize)
{
events |= EPOLLOUT;
}
if let Some(ref fd_set) = except_bitset {
if fd_set.contains(fd as usize) {
events |= EPOLLERR;
}
if let Some(ref fd_set) = except_bitset
&& fd_set.contains(fd as usize)
{
events |= EPOLLERR;
}
if events > 0 {
let mut event = epoll_event {
events,
data: epoll_data { fd },
..Default::default()
..Default::default() // clippy lint, _pad field on redox but not linux
};
if unsafe { epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) } < 0 {
if unsafe { epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &raw mut event) } < 0 {
if platform::ERRNO.get() == errno::EPERM {
not_epoll += 1;
} else {
return -1;
}
} else {
if let Some(ref mut fd_set) = read_bitset {
if fd_set.contains(fd as usize) {
fd_set.remove(fd as usize);
}
if let Some(ref mut fd_set) = read_bitset
&& fd_set.contains(fd as usize)
{
fd_set.remove(fd as usize);
}
if let Some(ref mut fd_set) = write_bitset {
if fd_set.contains(fd as usize) {
fd_set.remove(fd as usize);
}
if let Some(ref mut fd_set) = write_bitset
&& fd_set.contains(fd as usize)
{
fd_set.remove(fd as usize);
}
if let Some(ref mut fd_set) = except_bitset {
if fd_set.contains(fd as usize) {
fd_set.remove(fd as usize);
}
if let Some(ref mut fd_set) = except_bitset
&& fd_set.contains(fd as usize)
{
fd_set.remove(fd as usize);
}
}
}
@@ -153,23 +154,23 @@ pub fn select_epoll(
let fd = unsafe { event.data.fd };
// TODO: Error status when fd does not match?
if fd >= 0 && fd < FD_SETSIZE as c_int {
if event.events & EPOLLIN > 0 {
if let Some(ref mut fd_set) = read_bitset {
fd_set.insert(fd as usize);
count += 1;
}
if event.events & EPOLLIN > 0
&& let Some(ref mut fd_set) = read_bitset
{
fd_set.insert(fd as usize);
count += 1;
}
if event.events & EPOLLOUT > 0 {
if let Some(ref mut fd_set) = write_bitset {
fd_set.insert(fd as usize);
count += 1;
}
if event.events & EPOLLOUT > 0
&& let Some(ref mut fd_set) = write_bitset
{
fd_set.insert(fd as usize);
count += 1;
}
if event.events & EPOLLERR > 0 {
if let Some(ref mut fd_set) = except_bitset {
fd_set.insert(fd as usize);
count += 1;
}
if event.events & EPOLLERR > 0
&& let Some(ref mut fd_set) = except_bitset
{
fd_set.insert(fd as usize);
count += 1;
}
}
}
+1 -1
View File
@@ -54,7 +54,7 @@ impl LogSink for LogFile {
if unsafe {
connect(
log_fd,
&raw const log_addr as *const sockaddr,
(&raw const log_addr).cast::<sockaddr>(),
size_of::<sockaddr_un>() as u32,
) < 0
} {
+2 -2
View File
@@ -117,8 +117,8 @@ impl<L: LogSink> LogParams<L> {
fprintf(
stderr,
c"%s: %s".as_ptr(),
self.ident.as_ptr() as *const c_char,
buffer[prefix..].as_ptr() as *const c_char,
self.ident.as_ptr().cast::<c_char>(),
buffer[prefix..].as_ptr().cast::<c_char>(),
);
}
}
+7 -7
View File
@@ -85,10 +85,10 @@ pub const extern "C" fn LOG_MASK(p: c_int) -> c_int {
pub extern "C" fn setlogmask(mask: c_int) -> c_int {
let mut params = LOGGER.lock();
let old = params.mask.bits();
if mask != 0 {
if let Some(mask) = params.mask.with_mask(mask) {
params.mask = mask;
}
if mask != 0
&& let Some(mask) = params.mask.with_mask(mask)
{
params.mask = mask;
}
old
}
@@ -110,9 +110,9 @@ pub unsafe extern "C" fn openlog(ident: *const c_char, opt: c_int, facility: c_i
);
// Ensure log is ready to write now instead of checking on the first message.
if conf.contains(logger::Config::NoDelay) {
if let Ok(()) = params.open_logger() {}; // TODO handle error
}
if conf.contains(logger::Config::NoDelay)
&& let Ok(()) = params.open_logger()
{}; // TODO handle error
}
/// See <https://www.man7.org/linux/man-pages/man3/vsyslog.3.html>.
+1 -1
View File
@@ -42,7 +42,7 @@ pub unsafe extern "C" fn ftime(tp: *mut timeb) -> c_int {
// SAFETY: tv and tz are created above, and thus will coerce to valid
// pointers.
if unsafe { gettimeofday(&mut tv, &mut tz) } < 0 {
if unsafe { gettimeofday(&raw mut tv, &raw mut tz) } < 0 {
return -1;
}
+1 -4
View File
@@ -73,10 +73,7 @@ impl Cond {
let relative = match clock_id {
// FUTEX expect monotonic clock
CLOCK_MONOTONIC => timeout.clone(),
CLOCK_REALTIME => match timespec_realtime_to_monotonic(timeout.clone()) {
Ok(relative) => relative,
Err(err) => return Err(err),
},
CLOCK_REALTIME => timespec_realtime_to_monotonic(timeout.clone())?,
_ => return Err(Errno(EINVAL)),
};