topic_monitor to migrate from wperror to perror

This avoids needing to use the ffi
This commit is contained in:
ridiculousfish 2023-07-03 14:05:42 -07:00
parent 15361f62ed
commit 35f8f421fe

View file

@ -24,8 +24,8 @@ use crate::fd_readable_set::fd_readable_set_t;
use crate::fds::{self, AutoClosePipes};
use crate::ffi::{self as ffi, c_int};
use crate::flog::{FloggableDebug, FLOG};
use crate::wchar::{widestrs, wstr, WString};
use crate::wchar_ffi::wcharz;
use crate::wchar::WString;
use crate::wutil::perror;
use nix::errno::Errno;
use nix::unistd;
use std::cell::UnsafeCell;
@ -88,7 +88,6 @@ pub fn all_topics() -> [topic_t; 3] {
[topic_t::sighupint, topic_t::sigchld, topic_t::internal_exit]
}
#[widestrs]
impl generation_list_t {
pub fn new() -> Self {
Self::default()
@ -225,14 +224,13 @@ impl binary_semaphore_t {
}
/// Release a waiting thread.
#[widestrs]
pub fn post(&self) {
// Beware, we are in a signal handler.
if self.sem_ok_ {
let res = unsafe { libc::sem_post(self.sem_.get()) };
// sem_post is non-interruptible.
if res < 0 {
self.die("sem_post"L);
self.die("sem_post");
}
} else {
// Write exactly one byte.
@ -247,14 +245,13 @@ impl binary_semaphore_t {
break;
}
if !success {
self.die("write"L);
self.die("write");
}
}
}
/// Wait for a post.
/// This loops on EINTR.
#[widestrs]
pub fn wait(&self) {
if self.sem_ok_ {
let mut res;
@ -267,7 +264,7 @@ impl binary_semaphore_t {
}
// Other errors here are very unexpected.
if res < 0 {
self.die("sem_wait"L);
self.die("sem_wait");
}
} else {
let fd = self.pipes_.read.fd();
@ -288,14 +285,14 @@ impl binary_semaphore_t {
if amt.is_err()
&& (amt.err() != Some(Errno::EINTR) && amt.err() != Some(Errno::EAGAIN))
{
self.die("read"L);
self.die("read");
}
}
}
}
pub fn die(&self, msg: &wstr) {
ffi::wperror(wcharz!(msg));
pub fn die(&self, msg: &str) {
perror(msg);
panic!("die");
}
}