Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[close #356]: Block not removed when canceling update #364

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -180,9 +181,16 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
PrintVerboseSimple("[Stage 0] -------- ABSystemRunOperation")

if s.UpgradeLockExists() {
err := errors.New("upgrades are locked, another is running or need a reboot")
PrintVerboseErr("ABSystemRunOperation", 0, err)
return err
if isAbrootRunning() {
PrintVerboseWarn("ABSystemRunOperation", 0, "upgrades are locked, another is running")
return errors.New("upgrades are locked, another is running")
}

err := removeUpgradeLock()
if err != nil {
PrintVerboseErr("ABSystemRunOperation", 0, err)
return err
}
}

err := s.LockUpgrade()
Expand Down Expand Up @@ -949,3 +957,41 @@ func (s *ABSystem) RemoveStageFile() error {
PrintVerboseInfo("ABSystem.RemoveStageFile", "stage file removed")
return nil
}

// isAbrootRunning checks if an instance of the `abroot` command is running
// other than the current process
func isAbrootRunning() bool {
pid := os.Getpid()
procs, err := os.ReadDir("/proc")
if err != nil {
return false
}

for _, file := range procs {
if file.IsDir() {
if _, err := strconv.Atoi(file.Name()); err == nil {
cmdline, err := os.ReadFile("/proc/" + file.Name() + "/cmdline")
exe, exeErr := os.Readlink("/proc/" + file.Name() + "/exe")
if (err == nil && strings.Contains(string(cmdline), "abroot")) || (exeErr == nil && strings.Contains(exe, "abroot")) {
procPid, _ := strconv.Atoi(file.Name())
if procPid != pid {
return true
}
}
}
}
}
return false
}

// removeUpgradeLock removes the lock file, allowing upgrades to proceed
func removeUpgradeLock() error {
err := os.Remove(lockFile)
if err != nil {
PrintVerboseErr("removeUpgradeLock", 0, err)
return err
}

PrintVerboseInfo("removeUpgradeLock", "upgrade lock removed")
return nil
}
Loading