From fe2b66ed1547663aa353bfb05763305fbcdea88b Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 11 Oct 2020 20:26:23 +0300 Subject: Add dummy SIGINT handler --- Cargo.lock | 11 ++++++++++- Cargo.toml | 8 ++++++-- LICENSE.md | 23 +++++++++++++++++++++++ src/main.rs | 26 +++++++++++++++----------- src/prompt.rs | 2 +- src/user.rs | 1 - 6 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 LICENSE.md diff --git a/Cargo.lock b/Cargo.lock index 714dcaf..da0c46e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "rshell" +name = "libc" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" + +[[package]] +name = "rs" version = "0.1.0" +dependencies = [ + "libc", +] diff --git a/Cargo.toml b/Cargo.toml index 933b672..9859720 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,13 @@ [package] -name = "rshell" +name = "rs" version = "0.1.0" authors = ["Aqua-sama "] +license = "BSD-2-Clause" edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +# See more keys and their definitions at +# https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +libc = "0.2" + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c0a3081 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +Copyright (c) 2020 aqua@iserlohn-fortress.net + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + diff --git a/src/main.rs b/src/main.rs index 403fd33..01e5fbd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,26 @@ -use std::process::Command; -use std::process::Stdio; +use std::process::{Command, Stdio}; mod builtins; mod prompt; +fn sigint_handler(dummy: i32) { + println!("sigint_handler: {}", dummy); +} + fn main() { + + unsafe { + // capture Ctrl+C (SIGINT) + libc::signal(libc::SIGINT, sigint_handler as libc::sighandler_t); + } + match std::fs::read_to_string("/etc/motd") { - Ok(motd) => println!("{}", motd), + Ok(motd) => print!("{}", motd), Err(_) => {} } - let prompt = match prompt::Prompt::new() { - Ok(p) => p, - Err(e) => panic!(e), - }; - let mut cwd = match std::env::current_dir() { - Ok(p) => p, - Err(e) => panic!(e), - }; + let prompt = prompt::Prompt::new().unwrap(); + let mut cwd = std::env::current_dir().unwrap(); loop { prompt.print(&cwd); @@ -91,4 +94,5 @@ fn main() { } } } // loop + } diff --git a/src/prompt.rs b/src/prompt.rs index 40c96cc..acb11e4 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -14,7 +14,7 @@ impl Prompt { let hostname = user::hostname()?; let ready = if username == "root" { "#" } else { "$" }.to_owned(); - let ps1 = match std::env::var("PS1") { + let ps1 = match std::env::var("PRMOPT") { Ok(val) => val, Err(_) => String::from(" {USER}@{HOST} [{PWD}]\n{$} "), } diff --git a/src/user.rs b/src/user.rs index fedf12b..9744928 100644 --- a/src/user.rs +++ b/src/user.rs @@ -46,4 +46,3 @@ fn test_username() { }; assert_eq!(username__, username().unwrap()); } - -- cgit v1.2.1