Fix permissions, daemonize
This commit is contained in:
Generated
+3
-1
@@ -7,7 +7,7 @@ dependencies = [
|
||||
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_event 0.1.0 (git+https://github.com/redox-os/event.git)",
|
||||
"redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smoltcp 0.4.0",
|
||||
"smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -328,6 +328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/batonius/smoltcp.git?branch=default_route#253a14b425fa77ddfe096352cf3d8d6a9dbcafbc"
|
||||
dependencies = [
|
||||
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -477,6 +478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43"
|
||||
"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f"
|
||||
"checksum scopeguard 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c79eb2c3ac4bc2507cda80e7f3ac5b88bd8eae4c0914d5663e6a8933994be918"
|
||||
"checksum smoltcp 0.4.0 (git+https://github.com/batonius/smoltcp.git?branch=default_route)" = "<none>"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520"
|
||||
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
|
||||
|
||||
+1
-1
@@ -41,4 +41,4 @@ features = ["release_max_level_off"]
|
||||
git = "https://github.com/batonius/smoltcp.git"
|
||||
branch = "default_route"
|
||||
default-features = false
|
||||
features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"]
|
||||
features = ["std", "log", "socket-raw", "socket-udp", "socket-tcp"]
|
||||
|
||||
+7
-10
@@ -25,12 +25,6 @@ mod port_set;
|
||||
fn run() -> Result<()> {
|
||||
use syscall::flag::*;
|
||||
|
||||
logger::init_logger();
|
||||
|
||||
// if unsafe { syscall::clone(0).unwrap() } != 0 {
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
trace!("opening network:");
|
||||
let network_fd = syscall::open("network:", O_RDWR | O_NONBLOCK)
|
||||
.map_err(|e| Error::from_syscall_error(e, "failed to open network:"))?
|
||||
@@ -126,9 +120,12 @@ fn run() -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = run() {
|
||||
error!("smoltcpd: {}", err);
|
||||
process::exit(1);
|
||||
if unsafe { syscall::clone(0).unwrap() } == 0 {
|
||||
logger::init_logger();
|
||||
|
||||
if let Err(err) = run() {
|
||||
error!("smoltcpd: {}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ impl Smolnetd {
|
||||
fn poll(&mut self) -> Result<()> {
|
||||
let timestamp = self.get_timestamp();
|
||||
// trace!("Poll {}", timestamp);
|
||||
self.iface
|
||||
.poll(&mut *self.socket_set.borrow_mut(), timestamp)
|
||||
.expect("poll error");
|
||||
if let Err(err) = self.iface.poll(&mut *self.socket_set.borrow_mut(), timestamp) {
|
||||
error!("poll error: {}", err);
|
||||
}
|
||||
self.notify_sockets()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ use std::ops::DerefMut;
|
||||
use syscall::data::TimeSpec;
|
||||
use syscall;
|
||||
|
||||
use super::Smolnetd;
|
||||
use port_set::PortSet;
|
||||
|
||||
pub type TcpScheme = SocketScheme<TcpSocket<'static>>;
|
||||
@@ -109,7 +108,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> {
|
||||
let remote_endpoint = parse_endpoint(parts.next().unwrap_or(""));
|
||||
let mut local_endpoint = parse_endpoint(parts.next().unwrap_or(""));
|
||||
|
||||
if local_endpoint.port <= 1024 && uid != 0 {
|
||||
if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 {
|
||||
return Err(syscall::Error::new(syscall::EACCES));
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> {
|
||||
let remote_endpoint = parse_endpoint(parts.next().unwrap_or(""));
|
||||
let mut local_endpoint = parse_endpoint(parts.next().unwrap_or(""));
|
||||
|
||||
if local_endpoint.port <= 1024 && uid != 0 {
|
||||
if local_endpoint.port > 0 && local_endpoint.port <= 1024 && uid != 0 {
|
||||
return Err(syscall::Error::new(syscall::EACCES));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user