ref: b7af62b250e5dff30320a181ca9d53ab5a7c276d
parent: d1540c7f666e3c5d636b48c956b444205b50502d
author: henesy <devnull@localhost>
date: Fri Aug 2 14:59:56 EDT 2019
update os(1) to have -C and -D flags - runs in cwd inside Inferno by default - flags can toggle this off ;; update os(1) manual
--- a/appl/cmd/os.b
+++ b/appl/cmd/os.b
@@ -8,6 +8,8 @@
include "string.m";
str: String;
+include "lists.m";
+
include "env.m";
env: Env;
@@ -38,26 +40,40 @@
fail(sys->sprint("cannot load %s: %r", Arg->PATH));
arg->init(args);
- arg->setusage("os [-rc] [-d dir] [-m mount] [-n] [-N nice] [-b] command [arg...]");
+ arg->setusage("os [-DrcCbn] [-d dir] [-m mount] [-N nice] command [arg...]");
+ emuroot := env->getenv("emuroot");
+
+ debug := 0;
nice := 0;
nicearg: string;
workdir:= "";
mntpoint := "";
foreground := 1;
- rooted := 0;
- usecwd := 0;
+ convpaths := 1;
+ # Root ourselves in the of our cwd inside of Inferno by default
+ rooted := 1;
+ usecwd := 1;
+
while((opt := arg->opt()) != 0) {
case opt {
+ 'D' =>
+ # Turn on debugging
+ debug = 1;
'r' =>
- rooted = 1;
+ # Don't root at Inferno /
+ rooted = 0;
'c' =>
- # Since the cwd is rooted, we set rooted flag
- rooted = 1;
- usecwd = 1;
+ # Don't use cwd - will run at Inferno / if -r isn't set
+ usecwd = 0;
+ 'C' =>
+ # Don't convert arguments starting with / to $emuroot^/$arg
+ convpaths = 0;
'd' =>
workdir = arg->earg();
+ usecwd = 0;
+ rooted = 0;
'm' =>
mntpoint = arg->earg();
'n' =>
@@ -72,7 +88,7 @@
}
}
args = arg->argv();
- if (args == nil)
+ if(args == nil)
arg->usage();
arg = nil;
@@ -99,14 +115,43 @@
if(nice && sys->fprint(cfd, "nice%s", nicearg) < 0)
sys->fprint(sys->fildes(2), "os: warning: can't set nice priority: %r\n");
+ # Convert arguments beginning with / to $emuroot^/$arg
+ if(convpaths && len args > 1){
+ lists := load Lists Lists->PATH;
+ if(lists == nil)
+ raise "cannot load lists";
+
+ nargs: list of string;
+ argv0 := hd args;
+ args = tl args;
+
+ for(; args != nil; args = tl args){
+ a := hd args;
+ if(a[0] == '/')
+ a = emuroot + a;
+
+ nargs = a :: nargs;
+ }
+
+ args = lists->reverse(nargs);
+ args = argv0 :: args;
+ }
+
+ if(debug){
+ sys->fprint(sys->fildes(2), "Args to cmd:\n");
+ for(argv := args; argv != nil; argv = tl argv)
+ sys->fprint(sys->fildes(2), "\t%s\n", hd argv);
+ }
+
if(usecwd)
workdir = wd->init();
- if(rooted){
- # If $emuroot is not set, don't care, directory is checked below
- emuroot := env->getenv("emuroot");
+ # If $emuroot is not set, don't care, directory is checked below
+ if(rooted)
workdir = emuroot + workdir;
- }
+
+ if(debug)
+ sys->fprint(sys->fildes(2), "Workdir = %s\n", workdir);
if(workdir != nil && sys->fprint(cfd, "dir %s", workdir) < 0)
fail(sys->sprint("cannot set cwd %q: %r", workdir));
--- a/man/1/os
+++ b/man/1/os
@@ -6,17 +6,13 @@
.br
.B os
[
-.B -rc
+.B -DrcCbn
] [
-.B -b
-] [
.B -m
.I mountpoint
] [
.BI -d " dir"
] [
-.B -n
-] [
.BI -N " level"
]
.I cmd
@@ -29,7 +25,17 @@
.IR cmd (3)
device to execute a command,
.IR cmd ,
-on a host system.
+on a host system. By default, the current working directory of the calling process inside Inferno
+is used as the
+.I cmd
+working directory and
+.B $emuroot
+is prepended to
+.I cmd
+arguments beginning with the
+.I /
+character.
+
If the
.B -m
option is given,
@@ -50,19 +56,29 @@
.B -r
option is specified,
.B $emuroot
-will be prepended to the operating directory, which may include
-.I dir
-if specified. If the
+will not be prepended to the working directory. If the
.B -c
-option is specified, the current working directory will be used for execution, setting
-the
+option is specified, the current working directory will not be used for execution. If the
.B -r
-option in the process.
+and
+.B -d
+options are not set, then the Inferno root directory will be used as the working directory.
Note that the
-.B -c
-option overrides the
.B -d
-option.
+option overrides the
+.B -r
+and
+.B -c
+options. The
+.B -C
+option disables the prepending of
+.B $emuroot
+to arguments to
+.I cmd
+beginning with the
+.I /
+character.
+
The standard output and standard error of the command appear on the standard output
and standard error streams of the
.I os