Skip to content

Commit eb51149

Browse files
authored
Merge pull request #94 from openssh-rust/rust-1.63
Use Rust 1.63's `OwnedFd`
2 parents b23a8a6 + 7bdc576 commit eb51149

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

.github/workflows/msrv.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
- uses: actions-rs/toolchain@v1
2323
with:
2424
profile: minimal
25-
toolchain: 1.56.1
25+
toolchain: 1.63.0
2626
override: true
2727
- uses: actions/checkout@v2
28-
- name: cargo +1.56.1 check
28+
- name: cargo +1.63.0 check
2929
uses: actions-rs/cargo@v1
3030
with:
3131
command: check

.github/workflows/style.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
profile: minimal
3030
toolchain: ${{ matrix.toolchain }}
3131
components: rustfmt, clippy
32+
override: true
3233
- uses: actions/checkout@v2
3334
- name: cargo fmt --check
3435
uses: actions-rs/cargo@v1

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
with:
2828
profile: minimal
2929
toolchain: ${{ matrix.toolchain }}
30+
override: true
3031
- uses: actions/checkout@v2
3132
- run: |
3233
# Wait for startup of openssh-server

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "openssh"
33
version = "0.9.6"
44
authors = ["Jon Gjengset <jon@thesquareplanet.com>"]
55
edition = "2021"
6-
rust-version = "1.56.1"
6+
rust-version = "1.63.0"
77
license = "MIT OR Apache-2.0"
88

99
readme = "README.md"
@@ -44,9 +44,6 @@ thiserror = "1.0.30"
4444
tokio = { version = "1", features = [ "process", "io-util", "macros" ] }
4545
tokio-pipe = "0.2.8"
4646

47-
libc = "0.2.112"
48-
io-lifetimes = "0.7"
49-
5047
once_cell = "1.8.0"
5148
dirs = "4.0.0"
5249

src/changelog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::*;
44
/// TODO: RENAME THIS INTO THE NEXT VERSION BEFORE RELEASE
55
///
66
/// ## Added
7+
/// - `impl From<std::os::unix::io::OwnedFd> for Stdio`
78
/// ## Changed
89
/// ## Removed
910
#[doc(hidden)]
@@ -32,8 +33,7 @@ pub mod v0_9_5 {}
3233
/// ## Added
3334
/// - [`Session::resume`]
3435
/// - [`Session::resume_mux`]
35-
/// - [`Session::leak`]
36-
/// - [`Session::force_terminate`]
36+
/// - [`Session::detach`]
3737
pub mod v0_9_3 {}
3838

3939
/// ## Changed

src/stdio.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,14 @@ use super::Error;
33
#[cfg(feature = "native-mux")]
44
use super::native_mux_impl;
55

6-
use io_lifetimes::OwnedFd;
76
use std::fs::File;
87
use std::io;
9-
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
8+
use std::os::unix::io::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
109
use std::pin::Pin;
1110
use std::process;
1211
use std::task::{Context, Poll};
1312
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1413

15-
pub(crate) unsafe fn dup(raw_fd: RawFd) -> Result<OwnedFd, Error> {
16-
let res = libc::dup(raw_fd);
17-
if res == -1 {
18-
Err(Error::ChildIo(io::Error::last_os_error()))
19-
} else {
20-
// safety: dup returns a valid fd on success.
21-
Ok(OwnedFd::from_raw_fd(res))
22-
}
23-
}
24-
2514
#[derive(Debug)]
2615
pub(crate) enum StdioImpl {
2716
/// Read/Write to /dev/null
@@ -75,6 +64,12 @@ impl From<Stdio> for process::Stdio {
7564
}
7665
}
7766

67+
impl From<OwnedFd> for Stdio {
68+
fn from(fd: OwnedFd) -> Self {
69+
Self(StdioImpl::Fd(fd))
70+
}
71+
}
72+
7873
macro_rules! impl_from_for_stdio {
7974
($type:ty) => {
8075
impl From<$type> for Stdio {
@@ -145,7 +140,13 @@ macro_rules! impl_from_impl_child_io {
145140
let fd = arg.as_raw_fd();
146141

147142
// safety: arg.as_raw_fd() is guaranteed to return a valid fd.
148-
let fd = unsafe { dup(fd) }?.into_raw_fd();
143+
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
144+
145+
let fd = fd
146+
.try_clone_to_owned()
147+
.map_err(Error::ChildIo)?
148+
.into_raw_fd();
149+
149150
<$inner>::from_raw_fd_checked(fd)
150151
.map(Self)
151152
.map_err(Error::ChildIo)

0 commit comments

Comments
 (0)