Skip to content

Conversation

@malensek
Copy link
Contributor

This PR adds basic shell script support to FogOS.

Modifications:

  • exec.c now looks for #!, determines script interpreter, and runs the interpreter with the script name set to argv[1]
  • sh.c will read commands from a script file passed in on argv[1] and ignores #commented commands

Limitations:

  • Does not support arguments to the script interpreter
  • Comment support is basic and does not support comments in the middle of a command or with whitespace prefixed

@malensek
Copy link
Contributor Author

I will review this pull request!

@rnayakusf
Copy link

I can review this.

@rnayakusf
Copy link

rnayakusf commented Sep 28, 2024

This is a very useful addition to the operating system, and extremely useful for automation and testing. It's fairly easy to understand (once you wrap your head around inodes). I made some scripts to test and they seem mostly robust. Mostly.

I'm happy to announce that I found a serious bug allowing for the execution of commands in comments. Anything after 100 characters is treated like a new line. As such:

#!/sh                                                                                              /echo This is supposed to be commented

results in text being displayed.

Since the buffer to check for an interpreter is 128 bytes while the buffer for sh lines is 100, running a script directly can yield different results than running it as an argument to sh. For example:

#!/./././././././././././././././././././././././././././././././././././././././././././././././././rm /init
/echo You have been pwned

deletes the script if run directly but renders the OS unbootable if ran with sh.

For positive news, I tried making a fork bomb since scripting makes it easier, but it failed to fork and pipe after a few recursions, allowing init to avoid an unfortunate death.

High Level Checks:

  • PR fully resolves the task/issue
  • Does the PR have tests?
  • Does the PR follow project code formatting standards?
  • Does the OS still compile and run?
  • Is documentation included? (The comments help describe the new functionality)

Code Checks:

  • Does the code achieve its intended purpose?
  • Were all edge cases considered?
  • Is the code organized and maintainable?
  • Does the code maintain the same level of performance? (no performance regressions)

Suggestions

  • Fix the comment bug (strchr?). The fix can then be extrapolated to allow for mid-line comments.
  • Add a man page on scripting syntax.

Future Project 1 ideas

  • Add control flow logic to sh (in conjunction with Add "test" Command #77)
  • Add a way to short-circuit scripts if something fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants