Git Product home page Git Product logo

mesabox's Introduction

MesaBox

Build Status License Coverage Status

MesaBox is a collection of core system utilities written in Rust for Unix-like systems.

Like the well-known BusyBox and Toybox sets of utilities popular on embedded devices, MesaBox seeks to provide a fully functioning command-line environment (unlike uutils, which just seeks to reimplement the GNU coreutils).

Completion Status

As the project has just begun many utilities have yet to be implemented. If something in the table below seems interesting, feel free to take a stab at it. If it seems like something that should be in the table is missing, make sure to open an issue. Take a look at CONTRIBUTING.md for more details.

Utility Type Status
arch GNU Complete
base32 GNU Complete
base64 GNU Complete
yes GNU Complete
getty Login Simple Version
tar LSB Beginning Stages
ping Networking Simple Version
cat POSIX/GNU Complete
chmod POSIX/GNU Mostly Complete
(missing --reference)
head POSIX/GNU Complete
echo POSIX Complete
init POSIX Simple Version
sh POSIX Significant Progress
sleep POSIX Complete

Maintainer

License

MesaBox is provided under the 3-Clause BSD license (please see LICENSE for more details).

mesabox's People

Contributors

arcterus avatar mssun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mesabox's Issues

Drop actual_path?

I am considering removing util::actual_path() and just making all the utilities assume that the current working directory that we should operate in is the current working directory of the binary. The original point of util::actual_path() was to support the testing framework, but we won't need it for that once #24 is merged.

I can see it still being useful in some cases where mesabox is used as a library within another program as it allows operating in different directories without modifying the arguments or changing the host program's current working directory (which could be problematic if that program were to be multi-threaded). At the same time, removing util::actual_path() makes the utilities simpler and reduces the number of allocations we need to perform.

sh: implement tilde expansion

We should be doing:

  1. tilde expansion (this, based on the value of $HOME), parameter expansion, command substitution, and arithmetic expansion
  2. field splitting
  3. pathname expansion (i.e. globbing)
  4. quote removal (not sure if this needs to be handled explicitly or if Word::SingleQuote and Word::DoubleQuote are good enough

loginutils/getty issues

Firstly, getty shouldn't just panic on failure (it should instead return Results like the other utilities). Because of how getty affects the state of the system, I think the execve() call may be alright though.

getty should not be hard-coded to call /bin/ion. It should instead take an argument specifying what TTY to take control of and what program to start on said TTY (the current values can serve as defaults, however). We may want to implement gettytab or something similar as well.

sh: switch to LALRPOP?

I would vastly prefer to use something like LALRPOP or pest instead of nom, but right now neither support arbitrary bytes as input. There is this issue for LALRPOP and this one for pest that deal with that problem, but I'm not sure if it's fine to just say that invalid UTF-8 paths can't be given directly as arguments for now (they'd still work if a glob was given where the expanded part was invalid UTF-8). Switching to either LALRPOP or pest should help improve the error messages and make it simpler to fix some of the current parsing issues.

As a side note, this is actually the same issue that prevented me from just using pest in the first place.

Differences between shells

I'm probably gonna use this issue to document differences that I've noticed between our shell and other shells, so it'll be edited/added to over time.

shift in function

Input

fn() { shift; echo hello; }
fn

Results

mesabox

illegal number "1"
hello

bash

hello

zsh

fn:shift: shift count must be <= $#
hello

dash

Notice that dash does not print hello at all. I didn't notice this in the specification, so I'm not actually sure if this is correct behavior (other built-ins like trap let the function continue normally).

dash: 1: shift: can't shift that many

CI/Testing issues

test_chmod::test_chmod_ugoa seems to fail sometimes on Rust 1.26 for some reason. Additionally, the sleep tests can easily fail if the system takes too long to wake from sleep (or if threads take too long to spawn).

Add a wrapper for splice()

On Linux, we should try to use splice() rather than the standard read/write stuff for operations involving pipes. This mostly affects sh.

Finish tar

Because we use tar-rs, we will have this issue at the moment.

The above has been fixed, so it will no longer be an issue when using an up-to-date version of tar-rs.

NonZero types

We should see if there's anywhere where the new NonZero types would work/benefit us.

Do we have a guideline for handling error?

Hi,
I'm trying to contribute some code but get stuck in error handling.

One example I found for returning error is below. However, the progname and err are both None, which seems not very helpful.

Err(MesaError {
exitcode: exitcode,
progname: None,
err: None,
})

Another example I found is below. This line is quite difficult to understand for new contributors.

None => Err(failure::err_msg(format!("invalid hostname: {}", hostname_os.to_string_lossy())).compat())?,

Could you give some guildeline for error handling in mesabox?

Man page generation

We need to decide what documentation system to use. I assume we want support for man pages, which means we can either roll our own generator (like in ripgrep, which, last I checked, first generates an AsciiDoc file in build.rs) or use something like Sphinx, which is used in uutils/coreutils.

sh: split based on the value of IFS

We should be doing:

  1. tilde expansion, parameter expansion, command substitution, and arithmetic expansion
  2. field splitting (this, based on the value of $IFS)
  3. pathname expansion (i.e. globbing)
  4. quote removal (not sure if this needs to be handled explicitly or if Word::SingleQuote and Word::DoubleQuote are good enough

Remove build targets

We can probably remove the 1.26.2 targets on ARM, as if they work on x86_64 they'll likely work on ARM (we don't do much architecture-specific stuff at the moment). We can also probably combine the formatting target with the normal stable Linux target.

The first two tests are blocking for over 60 seconds in Travis

I don't know why the first tests are always blocking for over 60 seconds. However, after the blocking issue, all testcases can be run without any problem.

test gnu::arch::test_x86_64 ... test gnu::arch::test_x86_64 has been running for over 60 seconds
test gnu::base32::test_decode ... test gnu::base32::test_decode has been running for over 60 seconds

Code coverage

Switching from tarpaulin to kcov did not fix the issue as the problem (needing to disable ASLR) is inherent to the approach used by both tools. It seems like we either need to relax the Docker permissions or wait until rustc can emit coverage information (or use something other than Drone for CI).

For the time being I will continue to allow the build to succeed when the run-kcov.sh script fails.

init: Is init a POSIX utility?

I didn't find init in the POSIX standard (http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html).

How about treat init itself as a "type"/"feature" (similar with "POSIX", "Netowrking", etc)?.

Also, I am trying to compile mesabox in OS X (x86_64-apple-darwin). init (in "posix" feature) and getty (in "loginutils" feature) are not compatible with OSX (which are not designed and supposed to work in OSX). Therefore, for people who want to use it in OSX can simply exclude "init" and "loginutils" feature.

Anyway, I don't think supporting OSX is the first priority.

Bindings for calling from C

It would be nice to be able to call the utilities from C code. We might limit the user to providing raw file descriptors/raw handles as there's no way to have generic bindings. We could also expose RawObject and have the user give those to the interface so we don't need to worry about the platform differences.

We should look at using cbindgen, but if our interface is small enough it might just be easier to maintain it by hand.

Tokenize input prior to parsing

Due to parsing directly on the input, we have a few issues where stuff like forx iny; do echo $x; done will functions the same as for x in y; do echo $x; done. Tokenizing the input should fix this issue.

Implement && and ||

This should be very easy. All we need to do is check the exit codes returned from execute().

Issues with using the utils as shell built-ins

Given that I am planning on using all the mesabox utilities as built-ins for the shell, I thought I would use this issue to categorize any issues that come up.

One issue that I don't know how to solve until OOM can panic (instead of aborting) is that if one of the built-in utilities encounters an OOM error the entire shell will abort. Clearly, this is not intended behavior, so we should be careful with how much memory we allocate until OOM can panic (in which case we will just need to catch_unwind() the built-ins or something to make sure they don't crash the entire shell.

Test coverage is not accurate

Everything works well except for files/functions under shell. I don't why the integration test cases for shell will not emit hit counts. Therefore, the test coverage for posix/sh is not accurate.

`cargo fmt` does very little

Because all the utilities are included dynamically using macros, cargo fmt only formats the stuff like src/setup.rs and src/util.rs.

I also think we should configure the formatting, as sometimes the output looks worse/is harder to read than the input with the current settings.

posix/sh: parser accepts invalid input

For some reason the parser accepts echo hi | echo hello (echo hi; cat) | cat, which causes hello to be displayed on stdout. Based on testing, it seems to stop parsing when it sees the (echo hi; cat) part.

Better format for error messages

The current error messages are not consistent and nested together. We should have a better error message format.

mesabox head:

$ ./target/debug/mesabox head -c - tests/fixtures/head/lorem_ipsum.txt
head: error: Invalid value for '--bytes <NUMBER>': '-' is not a number or is too large

mesabox cat:

$ ./target/debug/mesabox cat fdsfs
cat: fdsfs: No such file or directory (os error 2)
cat: encountered 1 error(s)

Some examples for reference:

GNU coreutils:

$ head -c - tests/fixtures/head/lorem_ipsum.txt
head: invalid number of bytes: ‘’

BSD (OS X):

$ head -c - tests/fixtures/head/lorem_ipsum.txt
head: illegal byte count -- -

BusyBox:

$ ./busybox head -c - busybox_unstripped.out
head: invalid number ''

Cargo:

$ cargo build --release sss
error: Found argument 'sss' which wasn't expected, or isn't valid in this context

USAGE:
    cargo build --release

For more information try --help

Implement globbing

We cannot use the globwalk crate as it does not support globbing for parent directories (i.e. paths like ../../* won't work). We will probably need to roll our own directory walker, either by using globset or modifying glob to support OsStrings.

Implement piping

The relevant sections are mostly in src/posix/sh/command.rs. We can't just use ChildStdin/ChildStdout/ChildStderr because we need to support other file descriptors as well, so we need to create the pipes manually using nix.

EDIT: dunno why I wrote the above, but ChildStdout should be passed into the next command as its stdin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.