Merge pull request #2744 from fengwang666/nil-bug

runtime: fix nil reference in cleanup rootless user
This commit is contained in:
Fupan Li 2021-09-28 22:43:24 +08:00 committed by GitHub
commit 823818cfbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1024,10 +1024,12 @@ func (q *qemu) cleanupVM() error {
u, err := user.LookupId(strconv.Itoa(int(q.config.Uid)))
if err != nil {
q.Logger().WithError(err).WithField("uid", q.config.Uid).Warn("failed to find the user")
return nil
}
userdelPath, err := pkgUtils.FirstValidExecutable([]string{"/usr/sbin/userdel", "/sbin/userdel", "/bin/userdel"})
if err != nil {
q.Logger().WithError(err).WithField("user", u.Username).Warn("failed to delete the user")
return nil
}
_, err = pkgUtils.RunCommand([]string{userdelPath, "-f", u.Username})
if err != nil {