mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
window: fix various problems, cleanup
with window -m, properly remove the old wsys from /dev before binding new window to it, so the original window wont leak into the new namespace. do not pass -pid when $wsys does not refer to a local running rio. cleanup environment before running sub-process. set window label consistentently no matter if -m is used or not.
This commit is contained in:
parent
1059da0066
commit
221129dc30
1 changed files with 87 additions and 83 deletions
170
rc/bin/window
170
rc/bin/window
|
@ -1,100 +1,104 @@
|
||||||
#!/bin/rc
|
#!/bin/rc
|
||||||
# window [many options] cmd [arg...] - create new window and run cmd in it
|
# window [many options] cmd [arg...] - create new window and run cmd in it
|
||||||
rfork e
|
rfork e
|
||||||
fn checkwsys{
|
|
||||||
if(~ $wsys ''){
|
|
||||||
echo 'window: $wsys not defined'
|
|
||||||
exit bad
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# original version used mount to do the work
|
cmd=()
|
||||||
fn oldway{
|
spec=()
|
||||||
switch($#*){
|
wdir=()
|
||||||
case 0 1
|
wpid=()
|
||||||
echo usage: window '''minx miny maxx maxy''' cmd args ...
|
mflag=()
|
||||||
exit usage
|
xflag=()
|
||||||
}
|
argv0=$0
|
||||||
|
|
||||||
checkwsys
|
|
||||||
|
|
||||||
dir = /mnt/wsys
|
|
||||||
srv = $wsys
|
|
||||||
|
|
||||||
rfork ne
|
|
||||||
{
|
|
||||||
if(x=`{cat /dev/ppid}; mount $srv $dir N`{{echo $x $1 }| sed 's/^ //g;s/ +/,/g'}){
|
|
||||||
shift
|
|
||||||
bind -b $dir /dev
|
|
||||||
echo -n `{basename $1} > /dev/label >[2] /dev/null
|
|
||||||
exec $* < /dev/cons > /dev/cons >[2] /dev/cons
|
|
||||||
}
|
|
||||||
}&
|
|
||||||
}
|
|
||||||
|
|
||||||
# if argument is of form '100 100 200 200' or '100,100,200,200' use old way
|
|
||||||
if(~ $1 *[0-9][' ,'][0-9]*){
|
if(~ $1 *[0-9][' ,'][0-9]*){
|
||||||
oldway $*
|
# old syntax: '100 100 200 200' or '100,100,200,200'
|
||||||
exit
|
spec=(-r `{echo $1 | sed 's/,/ /g'})
|
||||||
|
shift
|
||||||
|
mflag=1
|
||||||
}
|
}
|
||||||
|
if not {
|
||||||
# geometry parameters are:
|
while(~ $1 -* && ~ $#xflag 0)
|
||||||
# -r 0 0 100 100
|
switch($1){
|
||||||
# -dx n
|
case -hide -scroll -noscroll
|
||||||
# -dy n
|
spec=($spec $1)
|
||||||
# -minx n
|
shift
|
||||||
# -miny n
|
case -dx -dy -minx -miny -maxx -maxy
|
||||||
# -maxx n
|
spec=($spec $1 $2)
|
||||||
# -maxy n
|
shift 2
|
||||||
# where n can be a number, to set the value, or +number or -number to change it
|
case -r
|
||||||
|
spec=($spec $1 $2 $3 $4 $5)
|
||||||
# find wctl file
|
shift 5
|
||||||
fn getwctl{
|
case -cd
|
||||||
if(~ $wctl ''){
|
wdir=$2
|
||||||
if(test -f /dev/wctl) echo /dev/wctl
|
shift 2
|
||||||
if not if(test -f /mnt/term/dev/wctl) echo /mnt/term/dev/wctl
|
case -pid
|
||||||
if not if(~ $service cpu) echo /mnt/term/srv/riowctl.*.*
|
wpid=$2
|
||||||
if not {
|
shift 2
|
||||||
echo window: '$wctl' not defined >[1=2]
|
case -m
|
||||||
|
mflag=1
|
||||||
|
shift
|
||||||
|
case -x
|
||||||
|
xflag=1
|
||||||
|
shift
|
||||||
|
case *
|
||||||
|
echo usage: $argv0 '[ -m ] [ -r minx miny maxx maxy ]' \
|
||||||
|
'[ -dx n ] [ -dy n ] [ -minx n ] [ -miny n ] [ -maxx n ] [ -maxy n ]' \
|
||||||
|
'[ -cd dir ] [ -hide ] [ -scroll ] [ -noscroll ] [ cmd arg ... ]' >[1=2]
|
||||||
exit usage
|
exit usage
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if not echo $wctl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# use mount to make local window
|
if(~ $#* 0) cmd=rc
|
||||||
if(~ $1 -m){
|
if not cmd=$*
|
||||||
shift
|
|
||||||
|
if(~ $#xflag 1){
|
||||||
|
echo -n `{basename $cmd(1)} >/dev/label >[2]/dev/null
|
||||||
|
rm -f /env/^(cmd spec wdir wpid mflag xflag argv0)
|
||||||
|
exec $cmd
|
||||||
|
exit exec
|
||||||
|
}
|
||||||
|
|
||||||
|
if(~ $#mflag 1) {
|
||||||
|
if(~ $wsys ''){
|
||||||
|
echo $argv0: '$wsys' not defined >[1=2]
|
||||||
|
exit bad
|
||||||
|
}
|
||||||
|
|
||||||
checkwsys
|
|
||||||
|
|
||||||
dir = /mnt/wsys
|
|
||||||
srv = $wsys
|
|
||||||
rfork ne
|
|
||||||
{
|
{
|
||||||
unmount /mnt/acme /dev >[2]/dev/null
|
rfork n
|
||||||
if(mount $srv $dir 'new -pid '^`{cat /dev/ppid}^' '$"*){
|
|
||||||
bind -b $dir /dev
|
if(~ $wsys /srv/*){
|
||||||
# toss geometry parameters to find command
|
if(~ $#wpid 0)
|
||||||
while(~ $1 -*)
|
wpid=`{cat /dev/ppid}
|
||||||
switch($1){
|
spec=($spec -pid $wpid)
|
||||||
case -dx -dy -minx -miny -maxx -maxy
|
}
|
||||||
shift 2
|
if(~ $#wdir 0){
|
||||||
case -r
|
wdir=`{pwd}
|
||||||
shift 5
|
}
|
||||||
case -scroll
|
if not {
|
||||||
shift
|
builtin cd $wdir
|
||||||
case -noscroll
|
}
|
||||||
shift
|
spec=($spec -cd $wdir)
|
||||||
case -hide
|
|
||||||
shift
|
{unmount /mnt/acme /dev; unmount $wsys /dev} >[2]/dev/null
|
||||||
}
|
if(mount $wsys /mnt/wsys 'new '$"spec){
|
||||||
if(~ $#* 0) cmd = rc
|
bind -b /mnt/wsys /dev
|
||||||
if not cmd = $*
|
exec $argv0 -x $cmd </dev/cons >/dev/cons >[2]/dev/cons
|
||||||
echo -n `{basename $cmd(1)} > /dev/label >[2] /dev/null
|
|
||||||
exec $cmd < /dev/cons > /dev/cons >[2] /dev/cons
|
|
||||||
}
|
}
|
||||||
}&
|
}&
|
||||||
}
|
}
|
||||||
|
if not {
|
||||||
|
if(~ $wctl ''){
|
||||||
|
if(test -f /dev/wctl) wctl=/dev/wctl
|
||||||
|
if not if(test -f /mnt/term/dev/wctl) wctl=/mnt/term/dev/wctl
|
||||||
|
if not if(test -r /mnt/term/env/wctl) wctl=/mnt/term^`{cat /mnt/term/env/wctl}
|
||||||
|
if not {
|
||||||
|
echo $argv0: '$wctl' not defined >[1=2]
|
||||||
|
exit bad
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if not echo new -cd `{pwd} $* >> `{getwctl}
|
if(! ~ $#wdir 0)
|
||||||
|
spec=($spec -cd $wdir)
|
||||||
|
echo new $spec $argv0 -x $cmd >>$wctl
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue