##// END OF EJS Templates
rust-chg: add state machine to handle "runcommand" request with cHg extension...
rust-chg: add state machine to handle "runcommand" request with cHg extension This is modeled after tokio-hglib's RunCommand state to support the "S" channel message.

File last commit:

r40009:ba447b83 default
r40011:571d8eb3 default
Show More
procutil.rs
38 lines | 1.1 KiB | application/rls-services+xml | RustLexer
Yuya Nishihara
rust-chg: add wrapper around C function
r40006 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! Low-level utility for signal and process handling.
Yuya Nishihara
rust-chg: add low-level function to set pager fd blocking...
r40009 use libc::{self, c_int, size_t, ssize_t};
Yuya Nishihara
rust-chg: add wrapper around C function
r40006 use std::io;
use std::os::unix::io::RawFd;
#[link(name = "procutil", kind = "static")]
extern "C" {
// sendfds.c
fn sendfds(sockfd: c_int, fds: *const c_int, fdlen: size_t) -> ssize_t;
}
Yuya Nishihara
rust-chg: add low-level function to set pager fd blocking...
r40009 /// Changes the given fd to blocking mode.
pub fn set_blocking_fd(fd: RawFd) -> io::Result<()> {
let flags = unsafe { libc::fcntl(fd, libc::F_GETFL) };
if flags < 0 {
return Err(io::Error::last_os_error());
}
let r = unsafe { libc::fcntl(fd, libc::F_SETFL, flags & !libc::O_NONBLOCK) };
if r < 0 {
return Err(io::Error::last_os_error())
}
Ok(())
}
Yuya Nishihara
rust-chg: add wrapper around C function
r40006 /// Sends file descriptors via the given socket.
pub fn send_raw_fds(sock_fd: RawFd, fds: &[RawFd]) -> io::Result<()> {
let r = unsafe { sendfds(sock_fd, fds.as_ptr(), fds.len() as size_t) };
if r < 0 {
return Err(io::Error::last_os_error());
}
Ok(())
}