Wait for reexec to finish when fileOutput is nil

Currently, we're not cleanup up after ourselves when fileOutput is nil.
This patch fixes that.

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>
This commit is contained in:
Jonathan Dieter 2020-08-11 15:47:32 +01:00
parent ca4423e94d
commit 0cd2f2d974
1 changed files with 10 additions and 0 deletions

View File

@ -233,6 +233,11 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
if pid < 0 {
return false, -1, errors.Errorf("cannot re-exec process")
}
defer func() {
if retErr != nil {
C.reexec_in_user_namespace_wait(pidC, 0)
}
}()
uids, gids, err := GetConfiguredMappings()
if err != nil {
@ -294,6 +299,11 @@ func becomeRootInUserNS(pausePid, fileToRead string, fileOutput *os.File) (_ boo
}
if fileOutput != nil {
ret := C.reexec_in_user_namespace_wait(pidC, 0)
if ret < 0 {
return false, -1, errors.New("error waiting for the re-exec process")
}
return true, 0, nil
}