1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
Description: Tweak code for nix 0.30
Author: Peter Michael Green <plugwash@debian.org>
Index: greetd-0.10.3/greetd/Cargo.toml
===================================================================
--- greetd-0.10.3.orig/greetd/Cargo.toml
+++ greetd-0.10.3/greetd/Cargo.toml
@@ -11,7 +11,7 @@ repository = "https://git.sr.ht/~kennyle
debug = []
[dependencies]
-nix = { version = ">=0.29", features = ["ioctl", "signal", "user", "fs", "mman"] }
+nix = { version = ">=0.30", features = ["ioctl", "signal", "user", "fs", "mman"] }
pam-sys = "0.5.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Index: greetd-0.10.3/greetd/src/terminal/mod.rs
===================================================================
--- greetd-0.10.3.orig/greetd/src/terminal/mod.rs
+++ greetd-0.10.3/greetd/src/terminal/mod.rs
@@ -4,9 +4,11 @@ use crate::error::Error;
use nix::{
fcntl::{open, OFlag},
sys::stat::Mode,
- unistd::{close, dup2, write},
+ unistd::{close, dup2_stdin, dup2_stdout, dup2_stderr, write},
};
use std::{ffi::CStr, os::unix::io::RawFd};
+use std::os::fd::IntoRawFd;
+use std::os::fd::BorrowedFd;
#[allow(dead_code)]
pub enum KdMode {
@@ -66,7 +68,7 @@ impl Terminal {
);
match res {
Ok(fd) => Ok(Terminal {
- fd,
+ fd: fd.into_raw_fd(),
autoclose: true,
}),
Err(e) => return Err(format!("terminal: unable to open: {}", e).into()),
@@ -204,9 +206,10 @@ impl Terminal {
/// Hook up stdin, stdout and stderr of the current process ot this
/// terminal.
pub fn term_connect_pipes(&self) -> Result<(), Error> {
- let res = dup2(self.fd, 0)
- .and_then(|_| dup2(self.fd, 1))
- .and_then(|_| dup2(self.fd, 2));
+ let borrowedfd = unsafe { BorrowedFd::borrow_raw(self.fd) };
+ let res = dup2_stdin(borrowedfd)
+ .and_then(|_| dup2_stdout(borrowedfd))
+ .and_then(|_| dup2_stderr(borrowedfd));
if let Err(v) = res {
Err(format!("terminal: unable to connect pipes: {}", v).into())
Index: greetd-0.10.3/greetd/src/main.rs
===================================================================
--- greetd-0.10.3.orig/greetd/src/main.rs
+++ greetd-0.10.3/greetd/src/main.rs
@@ -11,6 +11,7 @@ use std::os::unix::{
io::{FromRawFd, RawFd},
net::UnixDatagram,
};
+use std::os::fd::BorrowedFd;
use nix::{
fcntl::{fcntl, FcntlArg, FdFlag},
@@ -22,9 +23,10 @@ use crate::{error::Error, session::worke
async fn session_worker_main(config: config::Config) -> Result<(), Error> {
let raw_fd = config.internal.session_worker as RawFd;
- let mut cur_flags = FdFlag::from_bits_retain(fcntl(raw_fd, FcntlArg::F_GETFD)?);
+ let borrowed_fd = unsafe { BorrowedFd::borrow_raw(raw_fd) };
+ let mut cur_flags = FdFlag::from_bits_retain(fcntl(borrowed_fd, FcntlArg::F_GETFD)?);
cur_flags.insert(FdFlag::FD_CLOEXEC);
- fcntl(raw_fd, FcntlArg::F_SETFD(cur_flags))?;
+ fcntl(borrowed_fd, FcntlArg::F_SETFD(cur_flags))?;
let sock = unsafe { UnixDatagram::from_raw_fd(raw_fd) };
worker::main(&sock)
}
Index: greetd-0.10.3/greetd/src/session/interface.rs
===================================================================
--- greetd-0.10.3.orig/greetd/src/session/interface.rs
+++ greetd-0.10.3/greetd/src/session/interface.rs
@@ -100,9 +100,9 @@ impl Session {
UnixDatagram::pair().map_err(|e| format!("could not create pipe: {}", e))?;
let raw_child = childfd.as_raw_fd();
- let mut cur_flags = FdFlag::from_bits_retain(fcntl(raw_child, FcntlArg::F_GETFD)?);
+ let mut cur_flags = FdFlag::from_bits_retain(fcntl(&childfd, FcntlArg::F_GETFD)?);
cur_flags.remove(FdFlag::FD_CLOEXEC);
- fcntl(raw_child, FcntlArg::F_SETFD(cur_flags))?;
+ fcntl(&childfd, FcntlArg::F_SETFD(cur_flags))?;
let cur_exe = std::env::current_exe()?;
let bin = CString::new(cur_exe.to_str().expect("unable to get current exe name"))?;
|