From 16f8738bffd2fedc0c54fe665f91852dfb5a80b4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 2 Jan 2018 21:51:52 -0700 Subject: [PATCH 01/24] Initial commit --- Cargo.lock | 101 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 ++++ src/main.rs | 28 ++++++++++++ src/scheme.rs | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 src/scheme.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000000..cce61a7152 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,101 @@ +[[package]] +name = "chrono" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "logd" +version = "0.1.0" +dependencies = [ + "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_syscall" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "time" +version = "0.1.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" +"checksum num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4083e14b542ea3eb9b5f33ff48bd373a92d78687e74f4cc0a30caeb754f0ca" +"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" +"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" +"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070" +"checksum redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "07b8f011e3254d5a9b318fde596d409a0001c9ae4c6e7907520c2eaa4d988c99" +"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000000..254793e59a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "logd" +version = "0.1.0" +authors = ["Jeremy Soller "] + +[dependencies] +chrono = "0.4" +redox_syscall = "0.1" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000000..23075de782 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,28 @@ +extern crate chrono; +extern crate syscall; + +use syscall::data::Packet; +use syscall::scheme::SchemeMut; +use std::fs::File; +use std::io::{Read, Write}; +use scheme::LogScheme; + +mod scheme; + +fn main() { + if unsafe { syscall::clone(0).unwrap() } == 0 { + let mut socket = File::create(":log").expect("logd: failed to create log scheme"); + let mut scheme = LogScheme::new(); + + syscall::setrens(0, 0).expect("logd: failed to enter null namespace"); + + loop { + let mut packet = Packet::default(); + socket.read(&mut packet).expect("logd: failed to read events from log scheme"); + + scheme.handle(&mut packet); + + socket.write(&packet).expect("logd: failed to write responses to log scheme"); + } + } +} diff --git a/src/scheme.rs b/src/scheme.rs new file mode 100644 index 0000000000..424e410824 --- /dev/null +++ b/src/scheme.rs @@ -0,0 +1,124 @@ +use chrono::Local; +use std::collections::BTreeMap; +use std::io::{self, Write}; +use syscall::error::*; +use syscall::scheme::SchemeMut; + +pub struct LogHandle { + context: Box<[u8]>, + buf: Vec, +} + +pub struct LogScheme { + next_id: usize, + handles: BTreeMap, +} + +impl LogScheme { + pub fn new() -> Self { + LogScheme { + next_id: 0, + handles: BTreeMap::new(), + } + } +} + +impl SchemeMut for LogScheme { + fn open(&mut self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result { + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, LogHandle { + context: path.to_vec().into_boxed_slice(), + buf: Vec::new() + }); + + Ok(id) + } + + fn dup(&mut self, _id: usize, buf: &[u8]) -> Result { + if ! buf.is_empty() { + return Err(Error::new(EINVAL)); + } + + Ok(0) + } + + fn read(&mut self, id: usize, _buf: &mut [u8]) -> Result { + let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + // TODO + + Ok(0) + } + + fn write(&mut self, id: usize, buf: &[u8]) -> Result { + let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; + + let mut stdout = io::stdout(); + + let mut i = 0; + while i < buf.len() { + let b = buf[i]; + + if handle.buf.is_empty() { + let timestamp = Local::now(); + let _ = write!(handle.buf, "{}", timestamp.format("%F %T.%f")); + handle.buf.extend_from_slice(&handle.context); + handle.buf.extend_from_slice(b": "); + } + + handle.buf.push(b); + + if b == b'\n' { + let _ = stdout.write(&handle.buf); + let _ = stdout.flush(); + + handle.buf.clear(); + } + + i += 1; + } + + Ok(i) + } + + fn fcntl(&mut self, id: usize, _cmd: usize, _arg: usize) -> Result { + let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + Ok(0) + } + + fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { + let handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + let scheme_path = b"log:"; + + let mut i = 0; + while i < buf.len() && i < scheme_path.len() { + buf[i] = scheme_path[i]; + i += 1; + } + + let mut j = 0; + while i < buf.len() && j < handle.context.len() { + buf[i] = handle.context[j]; + i += 1; + j += 1; + } + + Ok(i) + } + + fn fsync(&mut self, id: usize) -> Result { + let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + + Ok(0) + } + + fn close(&mut self, id: usize) -> Result { + self.handles.remove(&id).ok_or(Error::new(EBADF))?; + + Ok(0) + } +} From b9ca3b7ce8c8d4217bfe87c705a573e3cf0a6825 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 2 Jan 2018 21:52:28 -0700 Subject: [PATCH 02/24] Fix time format --- src/scheme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scheme.rs b/src/scheme.rs index 424e410824..a6c3677b72 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -63,7 +63,7 @@ impl SchemeMut for LogScheme { if handle.buf.is_empty() { let timestamp = Local::now(); - let _ = write!(handle.buf, "{}", timestamp.format("%F %T.%f")); + let _ = write!(handle.buf, "{}", timestamp.format("%F %T%.f ")); handle.buf.extend_from_slice(&handle.context); handle.buf.extend_from_slice(b": "); } From e57f62b8f56aa1dd01f33905f1b35238cbc9d82f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 14 Oct 2018 19:56:33 -0600 Subject: [PATCH 03/24] Update Cargo.lock --- Cargo.lock | 93 +++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cce61a7152..0f11aa43ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,101 +1,80 @@ [[package]] name = "chrono" -version = "0.4.0" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.34" +version = "0.2.43" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num" -version = "0.1.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.35" +version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-iter" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.1.41" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "redox_syscall" -version = "0.1.33" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.38" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" -version = "0.2.8" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "winapi-build" -version = "0.1.1" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0" -"checksum num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4083e14b542ea3eb9b5f33ff48bd373a92d78687e74f4cc0a30caeb754f0ca" -"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" -"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" -"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070" -"checksum redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "07b8f011e3254d5a9b318fde596d409a0001c9ae4c6e7907520c2eaa4d988c99" -"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" +"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 32ab1a6e9d5ca4da4487d0a2a4d34f698a2ecac1 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Tue, 15 Jan 2019 12:15:22 +0000 Subject: [PATCH 04/24] aarch64-prep: Update Cargo.lock Needed to work with the latest redox_syscall mods. --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f11aa43ab..e72cd866dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,12 +5,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.43" +version = "0.2.47" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -18,7 +18,7 @@ name = "logd" version = "0.1.0" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -36,16 +36,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "redox_syscall" -version = "0.1.40" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.40" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -70,11 +70,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" -"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)" = "48450664a984b25d5b479554c29cc04e3150c97aa4c01da5604a2d4ed9151476" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" -"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" +"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From a9928cf4aa01908e5e2b96da36c6da62a6be9c01 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 23 Apr 2019 14:02:08 -0600 Subject: [PATCH 05/24] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..eb5a316cbd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target From 1752de22bf6f1c89c5dda281c5030e8df87d72a0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 18 Jul 2019 19:46:50 -0600 Subject: [PATCH 06/24] Break on EOF --- Cargo.lock | 2 ++ src/main.rs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e72cd866dd..eb1dfc3fc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "chrono" version = "0.4.6" diff --git a/src/main.rs b/src/main.rs index 23075de782..db15e1b96e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,9 @@ fn main() { loop { let mut packet = Packet::default(); - socket.read(&mut packet).expect("logd: failed to read events from log scheme"); + if socket.read(&mut packet).expect("logd: failed to read events from log scheme") == 0 { + break; + } scheme.handle(&mut packet); From 4a32dfea150e2b20cb770e2f8c66c700c8d58e67 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 19 Oct 2019 20:27:36 -0600 Subject: [PATCH 07/24] Update dependencies --- Cargo.lock | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb1dfc3fc1..9b513f575e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,44 +1,54 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "chrono" -version = "0.4.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.47" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "redox_syscall" -version = "0.1.50" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -46,14 +56,14 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -71,12 +81,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" -"checksum libc 0.2.47 (registry+https://github.com/rust-lang/crates.io-index)" = "48450664a984b25d5b479554c29cc04e3150c97aa4c01da5604a2d4ed9151476" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2" +"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" +"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From efa48434b439d9e67df41fec24ac0629d720cdfd Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 25 May 2020 07:40:16 -0600 Subject: [PATCH 08/24] Update time to 0.1.43 --- Cargo.lock | 42 ++++++++++++++++++++---------------------- Cargo.toml | 4 ++-- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b513f575e..44d0da07ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,48 +2,47 @@ # It is not intended for manual editing. [[package]] name = "autocfg" -version = "0.1.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chrono" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.65" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.41" +version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -53,11 +52,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -81,13 +79,13 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" -"checksum chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" -"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" -"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" -"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" +"checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" +"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" -"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 254793e59a..5f71581438 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["Jeremy Soller "] [dependencies] -chrono = "0.4" -redox_syscall = "0.1" +chrono = "0.4.11" +redox_syscall = "0.1.56" From 293f4fb9885fffe9fdb59e03fca7897a34a8a649 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 2 Aug 2020 16:04:17 -0600 Subject: [PATCH 09/24] Update redox_syscall --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44d0da07ce..90082eba8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ name = "logd" version = "0.1.0" dependencies = [ "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -47,7 +47,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -84,7 +84,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" "checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" "checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" From 16e40646244877ffc56973eb82330316fcc983c7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 19 Jan 2021 11:24:59 -0700 Subject: [PATCH 10/24] Update redox_syscall --- Cargo.lock | 78 ++++++++++++++++++++++++++++++++--------------------- Cargo.toml | 2 +- src/main.rs | 3 ++- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90082eba8d..cc42ae0a07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,66 +2,82 @@ # It is not intended for manual editing. [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bitflags" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.70" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-integer" -version = "0.1.42" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "time" -version = "0.1.43" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -79,13 +95,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" -"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" -"checksum libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f" -"checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" -"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" -"checksum redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)" = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +"checksum libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)" = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +"checksum num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +"checksum num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +"checksum redox_syscall 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +"checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +"checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 5f71581438..dfc22e0d07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Jeremy Soller "] [dependencies] chrono = "0.4.11" -redox_syscall = "0.1.56" +redox_syscall = "0.2.4" diff --git a/src/main.rs b/src/main.rs index db15e1b96e..0fcc1c0416 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ extern crate chrono; extern crate syscall; use syscall::data::Packet; +use syscall::flag::CloneFlags; use syscall::scheme::SchemeMut; use std::fs::File; use std::io::{Read, Write}; @@ -10,7 +11,7 @@ use scheme::LogScheme; mod scheme; fn main() { - if unsafe { syscall::clone(0).unwrap() } == 0 { + if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { let mut socket = File::create(":log").expect("logd: failed to create log scheme"); let mut scheme = LogScheme::new(); From bee08cbdf10560649d31f4ce6be361b717542298 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 28 Apr 2021 20:42:59 -0600 Subject: [PATCH 11/24] Update dependencies --- Cargo.lock | 14 +++++++------- Cargo.toml | 4 ++-- src/scheme.rs | 13 +++++++------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc42ae0a07..f6880932c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,7 +15,7 @@ name = "chrono" version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", @@ -24,7 +24,7 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.82" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -32,7 +32,7 @@ name = "logd" version = "0.1.0" dependencies = [ "chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -54,7 +54,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -65,7 +65,7 @@ name = "time" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)", "wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -98,10 +98,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -"checksum libc 0.2.82 (registry+https://github.com/rust-lang/crates.io-index)" = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +"checksum libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)" = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" "checksum num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" "checksum num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -"checksum redox_syscall 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +"checksum redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" "checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" "checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" "checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" diff --git a/Cargo.toml b/Cargo.toml index dfc22e0d07..4a4cb14f2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["Jeremy Soller "] [dependencies] -chrono = "0.4.11" -redox_syscall = "0.2.4" +chrono = "0.4.19" +redox_syscall = "0.2.7" diff --git a/src/scheme.rs b/src/scheme.rs index a6c3677b72..b12d46a746 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -5,7 +5,7 @@ use syscall::error::*; use syscall::scheme::SchemeMut; pub struct LogHandle { - context: Box<[u8]>, + context: Box, buf: Vec, } @@ -24,12 +24,12 @@ impl LogScheme { } impl SchemeMut for LogScheme { - fn open(&mut self, path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result { + fn open(&mut self, path: &str, _flags: usize, _uid: u32, _gid: u32) -> Result { let id = self.next_id; self.next_id += 1; self.handles.insert(id, LogHandle { - context: path.to_vec().into_boxed_slice(), + context: path.to_string().into_boxed_str(), buf: Vec::new() }); @@ -64,7 +64,7 @@ impl SchemeMut for LogScheme { if handle.buf.is_empty() { let timestamp = Local::now(); let _ = write!(handle.buf, "{}", timestamp.format("%F %T%.f ")); - handle.buf.extend_from_slice(&handle.context); + handle.buf.extend_from_slice(handle.context.as_bytes()); handle.buf.extend_from_slice(b": "); } @@ -101,8 +101,9 @@ impl SchemeMut for LogScheme { } let mut j = 0; - while i < buf.len() && j < handle.context.len() { - buf[i] = handle.context[j]; + let context_bytes = handle.context.as_bytes(); + while i < buf.len() && j < context_bytes.len() { + buf[i] = context_bytes[j]; i += 1; j += 1; } From 6e5c133b17b52c2de665c3b84d500f70e508aafd Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 17 Jun 2021 14:34:55 +0200 Subject: [PATCH 12/24] Update syscall. --- Cargo.lock | 62 ++++++++++++++++++++++++++---------------------------- Cargo.toml | 2 +- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6880932c8..b51538e5f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,106 +4,104 @@ name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "chrono" version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ - "libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)", - "num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "num-integer", + "num-traits", + "time", + "winapi", ] [[package]] name = "libc" -version = "0.2.94" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono", + "redox_syscall", ] [[package]] name = "num-integer" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "num-traits", ] [[package]] name = "num-traits" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", ] [[package]] name = "redox_syscall" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", ] [[package]] name = "time" version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)", - "wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "wasi", + "winapi", ] [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -"checksum libc 0.2.94 (registry+https://github.com/rust-lang/crates.io-index)" = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" -"checksum num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -"checksum num-traits 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -"checksum redox_syscall 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" -"checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -"checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 4a4cb14f2b..9f364ea931 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Jeremy Soller "] [dependencies] chrono = "0.4.19" -redox_syscall = "0.2.7" +redox_syscall = "0.2.9" From 70cb1051cb04c0dcc04163073b4a352939641956 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 14 Feb 2022 10:37:56 -0700 Subject: [PATCH 13/24] Support multiple outputs and fix dup --- src/main.rs | 71 +++++++++++++++++++++++++++++++++++++++------------ src/scheme.rs | 34 ++++++++++++++++++------ 2 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0fcc1c0416..2c241fddf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,28 +4,65 @@ extern crate syscall; use syscall::data::Packet; use syscall::flag::CloneFlags; use syscall::scheme::SchemeMut; -use std::fs::File; +use std::env; +use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; +use std::os::unix::io::{FromRawFd, RawFd}; +use std::process; use scheme::LogScheme; mod scheme; -fn main() { - if unsafe { syscall::clone(CloneFlags::empty()).unwrap() } == 0 { - let mut socket = File::create(":log").expect("logd: failed to create log scheme"); - let mut scheme = LogScheme::new(); - - syscall::setrens(0, 0).expect("logd: failed to enter null namespace"); - - loop { - let mut packet = Packet::default(); - if socket.read(&mut packet).expect("logd: failed to read events from log scheme") == 0 { - break; - } - - scheme.handle(&mut packet); - - socket.write(&packet).expect("logd: failed to write responses to log scheme"); +fn daemon(mut write: File) { + let mut files = Vec::new(); + for arg in env::args().skip(1) { + eprintln!("logd: opening {:?}", arg); + match OpenOptions::new().write(true).open(&arg) { + Ok(file) => files.push(file), + Err(err) => eprintln!("logd: failed to open {:?}: {:?}", arg, err), } } + + let mut socket = File::create(":log").expect("logd: failed to create log scheme"); + + syscall::setrens(0, 0).expect("logd: failed to enter null namespace"); + + eprintln!("logd: ready for logging on log:"); + + write.write(&[0]).expect("logd: failed to write to pipe"); + + let mut scheme = LogScheme::new(files); + + loop { + let mut packet = Packet::default(); + if socket.read(&mut packet).expect("logd: failed to read events from log scheme") == 0 { + break; + } + + scheme.handle(&mut packet); + + socket.write(&packet).expect("logd: failed to write responses to log scheme"); + } +} + +fn main() { + let mut pipes = [0; 2]; + syscall::pipe2(&mut pipes, 0).expect("logd: failed to create pipe"); + + let mut read = unsafe { File::from_raw_fd(pipes[0] as RawFd) }; + let write = unsafe { File::from_raw_fd(pipes[1] as RawFd) }; + + let pid = unsafe { syscall::clone(CloneFlags::empty()).expect("logd: failed to fork") }; + if pid == 0 { + drop(read); + + daemon(write); + } else { + drop(write); + + let mut res = [0]; + read.read(&mut res).expect("logd: failed to read from pipe"); + + process::exit(res[0] as i32); + } } diff --git a/src/scheme.rs b/src/scheme.rs index b12d46a746..e94082c28e 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -1,6 +1,7 @@ use chrono::Local; use std::collections::BTreeMap; -use std::io::{self, Write}; +use std::fs::File; +use std::io::Write; use syscall::error::*; use syscall::scheme::SchemeMut; @@ -11,13 +12,15 @@ pub struct LogHandle { pub struct LogScheme { next_id: usize, + files: Vec, handles: BTreeMap, } impl LogScheme { - pub fn new() -> Self { + pub fn new(files: Vec) -> Self { LogScheme { next_id: 0, + files, handles: BTreeMap::new(), } } @@ -36,12 +39,25 @@ impl SchemeMut for LogScheme { Ok(id) } - fn dup(&mut self, _id: usize, buf: &[u8]) -> Result { + fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result { if ! buf.is_empty() { return Err(Error::new(EINVAL)); } - Ok(0) + let context = { + let handle = self.handles.get(&old_id).ok_or(Error::new(EBADF))?; + handle.context.clone() + }; + + let id = self.next_id; + self.next_id += 1; + + self.handles.insert(id, LogHandle { + context, + buf: Vec::new() + }); + + Ok(id) } fn read(&mut self, id: usize, _buf: &mut [u8]) -> Result { @@ -55,24 +71,26 @@ impl SchemeMut for LogScheme { fn write(&mut self, id: usize, buf: &[u8]) -> Result { let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; - let mut stdout = io::stdout(); - let mut i = 0; while i < buf.len() { let b = buf[i]; + /*TODO: do we want to log timestampts too? if handle.buf.is_empty() { let timestamp = Local::now(); let _ = write!(handle.buf, "{}", timestamp.format("%F %T%.f ")); handle.buf.extend_from_slice(handle.context.as_bytes()); handle.buf.extend_from_slice(b": "); } + */ handle.buf.push(b); if b == b'\n' { - let _ = stdout.write(&handle.buf); - let _ = stdout.flush(); + for file in self.files.iter_mut() { + let _ = file.write(&handle.buf); + let _ = file.flush(); + } handle.buf.clear(); } From 98d6f67d41e57539653cde42788cd9df4d8f473e Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 25 Mar 2022 15:10:04 +0100 Subject: [PATCH 14/24] Update syscall --- Cargo.lock | 18 ++++++++++-------- Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b51538e5f0..ad24f664b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,16 +1,18 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "chrono" @@ -27,9 +29,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.97" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "logd" @@ -60,9 +62,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index 9f364ea931..dd4fdf370f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Jeremy Soller "] [dependencies] chrono = "0.4.19" -redox_syscall = "0.2.9" +redox_syscall = "0.2.12" From 8bb6986dbca25c6ef39bf6dea51ddb8600830b4d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 19 Apr 2022 18:18:20 -0600 Subject: [PATCH 15/24] Use requesting process's PID to ensure output is not jumbled --- src/main.rs | 1 + src/scheme.rs | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2c241fddf2..9ac1971a10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,7 @@ fn daemon(mut write: File) { break; } + scheme.current_pid = packet.pid; scheme.handle(&mut packet); socket.write(&packet).expect("logd: failed to write responses to log scheme"); diff --git a/src/scheme.rs b/src/scheme.rs index e94082c28e..bff6ee3b2e 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -7,13 +7,14 @@ use syscall::scheme::SchemeMut; pub struct LogHandle { context: Box, - buf: Vec, + bufs: BTreeMap>, } pub struct LogScheme { next_id: usize, files: Vec, handles: BTreeMap, + pub current_pid: usize, } impl LogScheme { @@ -22,6 +23,7 @@ impl LogScheme { next_id: 0, files, handles: BTreeMap::new(), + current_pid: 0, } } } @@ -33,7 +35,7 @@ impl SchemeMut for LogScheme { self.handles.insert(id, LogHandle { context: path.to_string().into_boxed_str(), - buf: Vec::new() + bufs: BTreeMap::new(), }); Ok(id) @@ -54,7 +56,7 @@ impl SchemeMut for LogScheme { self.handles.insert(id, LogHandle { context, - buf: Vec::new() + bufs: BTreeMap::new(), }); Ok(id) @@ -71,28 +73,30 @@ impl SchemeMut for LogScheme { fn write(&mut self, id: usize, buf: &[u8]) -> Result { let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; + let handle_buf = handle.bufs.entry(self.current_pid).or_insert_with(|| Vec::new()); + let mut i = 0; while i < buf.len() { let b = buf[i]; /*TODO: do we want to log timestampts too? - if handle.buf.is_empty() { + if handle_buf.is_empty() { let timestamp = Local::now(); - let _ = write!(handle.buf, "{}", timestamp.format("%F %T%.f ")); - handle.buf.extend_from_slice(handle.context.as_bytes()); - handle.buf.extend_from_slice(b": "); + let _ = write!(handle_buf, "{}", timestamp.format("%F %T%.f ")); + handle_buf.extend_from_slice(handle.context.as_bytes()); + handle_buf.extend_from_slice(b": "); } */ - handle.buf.push(b); + handle_buf.push(b); if b == b'\n' { for file in self.files.iter_mut() { - let _ = file.write(&handle.buf); + let _ = file.write(&handle_buf); let _ = file.flush(); } - handle.buf.clear(); + handle_buf.clear(); } i += 1; @@ -132,11 +136,15 @@ impl SchemeMut for LogScheme { fn fsync(&mut self, id: usize) -> Result { let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; + //TODO: flush remaining data? + Ok(0) } fn close(&mut self, id: usize) -> Result { self.handles.remove(&id).ok_or(Error::new(EBADF))?; + + //TODO: flush remaining data? Ok(0) } From 1991764a0bea9b7809f661a277b1525ac18b0f2c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 19 Apr 2022 18:22:56 -0600 Subject: [PATCH 16/24] Add log context if it is set. Remove timestamp feature --- Cargo.lock | 88 ++------------------------------------------------- Cargo.toml | 1 - src/main.rs | 1 - src/scheme.rs | 9 ++---- 4 files changed, 4 insertions(+), 95 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad24f664b3..d54748f5e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,108 +2,24 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "time", - "winapi", -] - -[[package]] -name = "libc" -version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" - [[package]] name = "logd" version = "0.1.0" dependencies = [ - "chrono", "redox_syscall", ] -[[package]] -name = "num-integer" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" -dependencies = [ - "autocfg", -] - [[package]] name = "redox_syscall" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae183fc1b06c149f0c1793e1eb447c8b04bfe46d48e9e48bfb8d2d7ed64ecf0" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] - -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi", - "winapi", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index dd4fdf370f..1285b4cbfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,4 @@ version = "0.1.0" authors = ["Jeremy Soller "] [dependencies] -chrono = "0.4.19" redox_syscall = "0.2.12" diff --git a/src/main.rs b/src/main.rs index 9ac1971a10..86db8b9ac9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -extern crate chrono; extern crate syscall; use syscall::data::Packet; diff --git a/src/scheme.rs b/src/scheme.rs index bff6ee3b2e..d956b2be19 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -1,4 +1,3 @@ -use chrono::Local; use std::collections::BTreeMap; use std::fs::File; use std::io::Write; @@ -79,14 +78,10 @@ impl SchemeMut for LogScheme { while i < buf.len() { let b = buf[i]; - /*TODO: do we want to log timestampts too? - if handle_buf.is_empty() { - let timestamp = Local::now(); - let _ = write!(handle_buf, "{}", timestamp.format("%F %T%.f ")); + if handle_buf.is_empty() && ! handle.context.is_empty() { handle_buf.extend_from_slice(handle.context.as_bytes()); handle_buf.extend_from_slice(b": "); } - */ handle_buf.push(b); @@ -143,7 +138,7 @@ impl SchemeMut for LogScheme { fn close(&mut self, id: usize) -> Result { self.handles.remove(&id).ok_or(Error::new(EBADF))?; - + //TODO: flush remaining data? Ok(0) From 0b7d6139aea93bebee53bf724214419f96854c01 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 18 Jul 2022 16:20:33 +0200 Subject: [PATCH 17/24] Use redox-daemon --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + src/main.rs | 27 ++++----------------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d54748f5e1..f47a76d1a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,10 +8,27 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + [[package]] name = "logd" version = "0.1.0" dependencies = [ + "redox-daemon", + "redox_syscall", +] + +[[package]] +name = "redox-daemon" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e31c834277709c7ff3eb74959fe62be4b45b1189ba9d41fd3744cd3a9c554f" +dependencies = [ + "libc", "redox_syscall", ] diff --git a/Cargo.toml b/Cargo.toml index 1285b4cbfa..46290dcec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ authors = ["Jeremy Soller "] [dependencies] redox_syscall = "0.2.12" +redox-daemon = "0.1" diff --git a/src/main.rs b/src/main.rs index 86db8b9ac9..2030ef47f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,16 @@ extern crate syscall; use syscall::data::Packet; -use syscall::flag::CloneFlags; use syscall::scheme::SchemeMut; use std::env; use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; -use std::os::unix::io::{FromRawFd, RawFd}; use std::process; use scheme::LogScheme; mod scheme; -fn daemon(mut write: File) { +fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut files = Vec::new(); for arg in env::args().skip(1) { eprintln!("logd: opening {:?}", arg); @@ -28,7 +26,7 @@ fn daemon(mut write: File) { eprintln!("logd: ready for logging on log:"); - write.write(&[0]).expect("logd: failed to write to pipe"); + daemon.ready().expect("logd: failed to notify parent"); let mut scheme = LogScheme::new(files); @@ -43,26 +41,9 @@ fn daemon(mut write: File) { socket.write(&packet).expect("logd: failed to write responses to log scheme"); } + process::exit(0); } fn main() { - let mut pipes = [0; 2]; - syscall::pipe2(&mut pipes, 0).expect("logd: failed to create pipe"); - - let mut read = unsafe { File::from_raw_fd(pipes[0] as RawFd) }; - let write = unsafe { File::from_raw_fd(pipes[1] as RawFd) }; - - let pid = unsafe { syscall::clone(CloneFlags::empty()).expect("logd: failed to fork") }; - if pid == 0 { - drop(read); - - daemon(write); - } else { - drop(write); - - let mut res = [0]; - read.read(&mut res).expect("logd: failed to read from pipe"); - - process::exit(res[0] as i32); - } + redox_daemon::Daemon::new(daemon).expect("logd: failed to daemonize"); } From 734bb9277696fa09cee5f517fc46cc0588cf460c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 22 Aug 2022 08:59:21 -0600 Subject: [PATCH 18/24] Update redox_syscall --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f47a76d1a9..941a94958f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "logd" @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] From 513564a4d373c2aa675fc701ba06921fdae03d82 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 11 Feb 2023 14:42:57 -0700 Subject: [PATCH 19/24] Update libc crate --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 941a94958f..967f273d94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "libc" -version = "0.2.132" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "logd" From ce5de147f3a984d4dcb925acedea194c6c7c4a8f Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 31 Aug 2023 20:54:40 +0200 Subject: [PATCH 20/24] Update dependencies. --- Cargo.lock | 12 ++++++------ Cargo.toml | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 967f273d94..580d448020 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "logd" @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "redox-daemon" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e31c834277709c7ff3eb74959fe62be4b45b1189ba9d41fd3744cd3a9c554f" +checksum = "811fd0d382a70c9e9192166ee794567b65ef34cc7309c86a49b071779ca9b5f3" dependencies = [ "libc", "redox_syscall", @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index 46290dcec7..df273401d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["Jeremy Soller "] [dependencies] -redox_syscall = "0.2.12" -redox-daemon = "0.1" +redox_syscall = "0.3" +redox-daemon = "0.1.1" From a6596f8edb194019c40f9fe3e1ae67d81c12d907 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 16 Nov 2023 13:57:38 +0100 Subject: [PATCH 21/24] Migrate to libredox and redox-scheme. --- Cargo.lock | 73 +++++++++++++++++++++++++++++++++++++++------------ Cargo.toml | 7 +++-- src/main.rs | 26 +++++++----------- src/scheme.rs | 3 ++- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 580d448020..1073984a2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,35 +8,74 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "libc" -version = "0.2.147" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] -name = "logd" -version = "0.1.0" -dependencies = [ - "redox-daemon", - "redox_syscall", -] - -[[package]] -name = "redox-daemon" -version = "0.1.1" +name = "libredox" +version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "811fd0d382a70c9e9192166ee794567b65ef34cc7309c86a49b071779ca9b5f3" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ + "bitflags 2.4.1", "libc", "redox_syscall", ] [[package]] -name = "redox_syscall" -version = "0.3.5" +name = "libredox" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "962b650e6b934f95cec493e1464e0f5cba98dd9ba9ef2b1c42cdfdb7864cab5a" dependencies = [ - "bitflags", + "bitflags 2.4.1", + "libc", + "redox_syscall", +] + +[[package]] +name = "logd" +version = "0.1.0" +dependencies = [ + "libredox 0.0.3", + "redox-daemon", + "redox-scheme", + "redox_syscall", +] + +[[package]] +name = "redox-daemon" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353178b5771a301b9d2b318914ab5dfeb21dd6e65930faedde19248cfceca5a7" +dependencies = [ + "libc", + "libredox 0.0.1", +] + +[[package]] +name = "redox-scheme" +version = "0.1.0" +source = "git+https://gitlab.redox-os.org/redox-os/redox-scheme.git#2c4a85399defee72d25091922450126cdf6130a2" +dependencies = [ + "libredox 0.0.3", + "redox_syscall", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", ] diff --git a/Cargo.toml b/Cargo.toml index df273401d4..a86658c372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,10 @@ name = "logd" version = "0.1.0" authors = ["Jeremy Soller "] +edition = "2021" [dependencies] -redox_syscall = "0.3" -redox-daemon = "0.1.1" +redox_syscall = "0.4.1" +redox-daemon = "0.1.2" +libredox = "0.0.3" +redox-scheme = { git = "https://gitlab.redox-os.org/redox-os/redox-scheme.git" } diff --git a/src/main.rs b/src/main.rs index 2030ef47f0..9559df50f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ -extern crate syscall; - -use syscall::data::Packet; -use syscall::scheme::SchemeMut; use std::env; -use std::fs::{File, OpenOptions}; +use std::fs::{OpenOptions}; use std::io::{Read, Write}; use std::process; -use scheme::LogScheme; +use redox_scheme::{Socket, SignalBehavior}; + +use crate::scheme::LogScheme; mod scheme; @@ -20,9 +18,9 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { } } - let mut socket = File::create(":log").expect("logd: failed to create log scheme"); + let mut socket = Socket::create("log").expect("logd: failed to create log scheme"); - syscall::setrens(0, 0).expect("logd: failed to enter null namespace"); + libredox::call::setrens(0, 0).expect("logd: failed to enter null namespace"); eprintln!("logd: ready for logging on log:"); @@ -30,16 +28,12 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut scheme = LogScheme::new(files); - loop { - let mut packet = Packet::default(); - if socket.read(&mut packet).expect("logd: failed to read events from log scheme") == 0 { - break; - } + while let Some(request) = socket.next_request(SignalBehavior::Restart).expect("logd: failed to read events from log scheme") { + scheme.current_pid = request.context_id(); - scheme.current_pid = packet.pid; - scheme.handle(&mut packet); + let response = request.handle_scheme_mut(&mut scheme); - socket.write(&packet).expect("logd: failed to write responses to log scheme"); + socket.write_responses(&[response], SignalBehavior::Restart).expect("logd: failed to write responses to log scheme"); } process::exit(0); } diff --git a/src/scheme.rs b/src/scheme.rs index d956b2be19..91c6f8f271 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -1,8 +1,9 @@ use std::collections::BTreeMap; use std::fs::File; use std::io::Write; + use syscall::error::*; -use syscall::scheme::SchemeMut; +use redox_scheme::SchemeMut; pub struct LogHandle { context: Box, From e0f930ad72521a61951d0d98cc830373a18ef661 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sat, 7 Sep 2024 00:51:02 +0200 Subject: [PATCH 22/24] Update dependencies, rustfmt, use v2 scheme. --- Cargo.lock | 52 ++++++++++++++++++--------------------------------- Cargo.toml | 6 +++--- src/main.rs | 21 ++++++++++++++------- src/scheme.rs | 37 ++++++++++++++++++++++-------------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1073984a2e..b68d94e1bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,40 +4,23 @@ version = 3 [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libredox" -version = "0.0.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.1", - "libc", - "redox_syscall", -] - -[[package]] -name = "libredox" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "962b650e6b934f95cec493e1464e0f5cba98dd9ba9ef2b1c42cdfdb7864cab5a" -dependencies = [ - "bitflags 2.4.1", + "bitflags", "libc", "redox_syscall", ] @@ -46,7 +29,7 @@ dependencies = [ name = "logd" version = "0.1.0" dependencies = [ - "libredox 0.0.3", + "libredox", "redox-daemon", "redox-scheme", "redox_syscall", @@ -54,28 +37,29 @@ dependencies = [ [[package]] name = "redox-daemon" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "353178b5771a301b9d2b318914ab5dfeb21dd6e65930faedde19248cfceca5a7" +checksum = "7fbdeffdb03cf2961b211a2023e683d71f2c225ea93404da5dc34b0dc94f0341" dependencies = [ "libc", - "libredox 0.0.1", + "libredox", ] [[package]] name = "redox-scheme" -version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/redox-scheme.git#2c4a85399defee72d25091922450126cdf6130a2" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2148c23b7ed5bf1cc3919b4830e4bf2a674a5d3691c619317624ccd78d13a3ac" dependencies = [ - "libredox 0.0.3", + "libredox", "redox_syscall", ] [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] diff --git a/Cargo.toml b/Cargo.toml index a86658c372..ab9f15e31a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Jeremy Soller "] edition = "2021" [dependencies] -redox_syscall = "0.4.1" +redox_syscall = "0.5" redox-daemon = "0.1.2" -libredox = "0.0.3" -redox-scheme = { git = "https://gitlab.redox-os.org/redox-os/redox-scheme.git" } +libredox = "0.1.3" +redox-scheme = "0.2.1" diff --git a/src/main.rs b/src/main.rs index 9559df50f0..11b04c8d41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ +use redox_scheme::{RequestKind, SignalBehavior, Socket, V2}; use std::env; -use std::fs::{OpenOptions}; -use std::io::{Read, Write}; +use std::fs::OpenOptions; use std::process; -use redox_scheme::{Socket, SignalBehavior}; use crate::scheme::LogScheme; @@ -18,7 +17,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { } } - let mut socket = Socket::create("log").expect("logd: failed to create log scheme"); + let socket = Socket::::create("log").expect("logd: failed to create log scheme"); libredox::call::setrens(0, 0).expect("logd: failed to enter null namespace"); @@ -28,12 +27,20 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut scheme = LogScheme::new(files); - while let Some(request) = socket.next_request(SignalBehavior::Restart).expect("logd: failed to read events from log scheme") { + while let Some(request) = socket + .next_request(SignalBehavior::Restart) + .expect("logd: failed to read events from log scheme") + { scheme.current_pid = request.context_id(); - let response = request.handle_scheme_mut(&mut scheme); + let RequestKind::Call(request) = request.kind() else { + continue; + }; - socket.write_responses(&[response], SignalBehavior::Restart).expect("logd: failed to write responses to log scheme"); + let response = request.handle_scheme_mut(&mut scheme); + socket + .write_responses(&[response], SignalBehavior::Restart) + .expect("logd: failed to write responses to log scheme"); } process::exit(0); } diff --git a/src/scheme.rs b/src/scheme.rs index 91c6f8f271..f50ce41769 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -2,8 +2,8 @@ use std::collections::BTreeMap; use std::fs::File; use std::io::Write; -use syscall::error::*; use redox_scheme::SchemeMut; +use syscall::error::*; pub struct LogHandle { context: Box, @@ -33,16 +33,19 @@ impl SchemeMut for LogScheme { let id = self.next_id; self.next_id += 1; - self.handles.insert(id, LogHandle { - context: path.to_string().into_boxed_str(), - bufs: BTreeMap::new(), - }); + self.handles.insert( + id, + LogHandle { + context: path.to_string().into_boxed_str(), + bufs: BTreeMap::new(), + }, + ); Ok(id) } fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result { - if ! buf.is_empty() { + if !buf.is_empty() { return Err(Error::new(EINVAL)); } @@ -54,15 +57,18 @@ impl SchemeMut for LogScheme { let id = self.next_id; self.next_id += 1; - self.handles.insert(id, LogHandle { - context, - bufs: BTreeMap::new(), - }); + self.handles.insert( + id, + LogHandle { + context, + bufs: BTreeMap::new(), + }, + ); Ok(id) } - fn read(&mut self, id: usize, _buf: &mut [u8]) -> Result { + fn read(&mut self, id: usize, _buf: &mut [u8], _offset: u64, _flags: u32) -> Result { let _handle = self.handles.get(&id).ok_or(Error::new(EBADF))?; // TODO @@ -70,16 +76,19 @@ impl SchemeMut for LogScheme { Ok(0) } - fn write(&mut self, id: usize, buf: &[u8]) -> Result { + fn write(&mut self, id: usize, buf: &[u8], _offset: u64, _flags: u32) -> Result { let handle = self.handles.get_mut(&id).ok_or(Error::new(EBADF))?; - let handle_buf = handle.bufs.entry(self.current_pid).or_insert_with(|| Vec::new()); + let handle_buf = handle + .bufs + .entry(self.current_pid) + .or_insert_with(|| Vec::new()); let mut i = 0; while i < buf.len() { let b = buf[i]; - if handle_buf.is_empty() && ! handle.context.is_empty() { + if handle_buf.is_empty() && !handle.context.is_empty() { handle_buf.extend_from_slice(handle.context.as_bytes()); handle_buf.extend_from_slice(b": "); } From 50842448dc672c024f03145404e6ea02f4adb73d Mon Sep 17 00:00:00 2001 From: Andrey Turkin Date: Thu, 18 Jul 2024 13:53:49 +0300 Subject: [PATCH 23/24] Bump dependencies --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b68d94e1bf..2f9ab2c892 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libredox" @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "redox-scheme" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2148c23b7ed5bf1cc3919b4830e4bf2a674a5d3691c619317624ccd78d13a3ac" +checksum = "98d040cfa6370d9c6b1a5987247272f19ea4722f1064e66ad2e077c152b82ea3" dependencies = [ "libredox", "redox_syscall", @@ -57,9 +57,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] From db36d01782a6b9cc7ec995f884f8c1259d79903e Mon Sep 17 00:00:00 2001 From: Ribbon Date: Thu, 9 Jan 2025 12:18:48 +0000 Subject: [PATCH 24/24] Add README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000000..be1f2d5f1b --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# logd + +Log daemon for collecting all log output. + +## How To Contribute + +To learn how to contribute to this system component you need to read the following document: + +- [CONTRIBUTING.md](https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md) + +## Development + +To learn how to do development with this system component inside the Redox build system you need to read the [Build System](https://doc.redox-os.org/book/build-system-reference.html) and [Coding and Building](https://doc.redox-os.org/book/coding-and-building.html) pages. + +### How To Build + +To build this system component you need to download the Redox build system, you can learn how to do it on the [Building Redox](https://doc.redox-os.org/book/podman-build.html) page. + +This is necessary because they only work with cross-compilation to a Redox virtual machine, but you can do some testing from Linux.