Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Aug 16, 2023
1 parent 48e3def commit df69a05
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/resetter/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *Resetter) Terminate(ctx context.Context, shower progresser.Shower, envR
}
}
log.Println("[NFO] exiting shell singleton")
s.signal("###:exit:", "")
s.signal(comExit, "")
return
}

Expand Down Expand Up @@ -241,12 +241,12 @@ func (s *Resetter) exec(ctx context.Context, shower progresser.Shower, envRead m
s.rcoms = make(chan uint8)
coms := newlinesWriter(func(data []byte) {
if n := len(data); n > 0 {
if x := bytes.TrimPrefix(data, []byte("###:exitcode:")); n != len(x) {
if x := bytes.TrimPrefix(data, []byte(comExitcode)); n != len(x) {
if y, err := strconv.ParseInt(string(x), 10, 8); err == nil {
s.rcoms <- uint8(y)
}
}
if x := bytes.TrimPrefix(data, []byte("###:unexpected:")); n != len(x) {
if x := bytes.TrimPrefix(data, []byte(comUnexpected)); n != len(x) {
log.Printf("[ERR] unexpected rcoms: %s", x)
}
}
Expand All @@ -263,7 +263,7 @@ func (s *Resetter) exec(ctx context.Context, shower progresser.Shower, envRead m
}
return
}
if x := bytes.TrimPrefix(data, []byte("###:exitcode:")); n != len(x) {
if x := bytes.TrimPrefix(data, []byte(comExitcode)); n != len(x) {
return
}
shower.Printf("%s", data)
Expand All @@ -281,7 +281,7 @@ func (s *Resetter) exec(ctx context.Context, shower progresser.Shower, envRead m
}
return
}
if x := bytes.TrimPrefix(data, []byte("###:exitcode:")); n != len(x) {
if x := bytes.TrimPrefix(data, []byte(comExitcode)); n != len(x) {
return
}
shower.Errorf("%s", data)
Expand Down Expand Up @@ -318,6 +318,11 @@ func (s *Resetter) exec(ctx context.Context, shower progresser.Shower, envRead m
const (
stdeitherPrefixSkip = "+ "
stdeitherPrefixDropPrefix = "++ "
comPrefix = "###:" //FIXME: pick from random alnum at first run
comExec = comPrefix + "exec:"
comExit = comPrefix + "exit:"
comExitcode = comPrefix + "exitcode:"
comUnexpected = comPrefix + "unexpected:"
)

func writeMainScript(name string, paths []string) (err error) {
Expand All @@ -336,9 +341,9 @@ trap 'rm -f "`+strings.Join(append(paths, name), `" "`)+`"' EXIT
while read -r x; do
case "$x" in
'###:exec:'*) x=${x:9} ;;
'###:exit:') exit 0 ;;
*) echo "###:unexpected:$x" && exit 42 ;;
'`+comExec+`'*) x=${x:9} ;;
'`+comExit+`') exit 0 ;;
*) echo "`+comUnexpected+`$x" && exit 42 ;;
esac
if ! script=$(cat "$x"); then
Expand All @@ -353,7 +358,7 @@ while read -r x; do
fi
source "$x"
echo "###:exitcode:$?"
echo "`+comExitcode+`$?"
done
`)
return
Expand Down Expand Up @@ -401,7 +406,7 @@ func (s *Resetter) signal(verb, param string) {
func (s *Resetter) execEach(ctx context.Context, cmd shellCmd) (err error) {
start := time.Now()

s.signal("###:exec:", s.scriptsPaths[cmd])
s.signal(comExec, s.scriptsPaths[cmd])
log.Println("[DBG] sent processing signal to shell singleton:", s.scriptsPaths[cmd])

select {
Expand Down

0 comments on commit df69a05

Please sign in to comment.