From 68d189e656f4db1254e04f28ab715da541201f4b Mon Sep 17 00:00:00 2001 From: GUO YANKE Date: Thu, 22 Aug 2024 10:20:34 +0800 Subject: [PATCH] chore: fix typo --- .vscode/settings.json | 6 ++++-- internal/msetups/setup_thp.go | 4 ++-- internal/msetups/setup_zombies.go | 33 ++++++++++++++----------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cf94acf..21fe3cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "charsets", "exem", + "hugepage", "injectenv", "interp", "menv", @@ -15,6 +16,7 @@ "munit", "shellquote", "simplifiedchinese", - "stretchr" + "stretchr", + "webdav" ] -} +} \ No newline at end of file diff --git a/internal/msetups/setup_thp.go b/internal/msetups/setup_thp.go index 0434b10..a74f567 100644 --- a/internal/msetups/setup_thp.go +++ b/internal/msetups/setup_thp.go @@ -31,8 +31,8 @@ func setupTHP(logger mlog.ProcLogger) (err error) { } logger.Printf("current THP configuration: %s", bytes.TrimSpace(buf)) logger.Printf("writing THP configuration: %s", val) - if err = os.WriteFile(controlFileTHP, []byte(val), 644); err != nil { - err = fmt.Errorf("fialed writting THP configuration %s: %s", controlFileTHP, err.Error()) + if err = os.WriteFile(controlFileTHP, []byte(val), 0644); err != nil { + err = fmt.Errorf("failed writing THP configuration %s: %s", controlFileTHP, err.Error()) return } if buf, err = os.ReadFile(controlFileTHP); err != nil { diff --git a/internal/msetups/setup_zombies.go b/internal/msetups/setup_zombies.go index c1db3b8..1e8e173 100644 --- a/internal/msetups/setup_zombies.go +++ b/internal/msetups/setup_zombies.go @@ -19,7 +19,6 @@ func init() { } func setupZombies(log mlog.ProcLogger) (err error) { - // 如果自己不是 PID 1,则不负责清理僵尸进程 if os.Getpid() != 1 { log.Print("minit is not running as PID 1, skipping cleaning up zombies") return @@ -31,11 +30,9 @@ func setupZombies(log mlog.ProcLogger) (err error) { } func runZombieCleaner(log mlog.ProcLogger) { - // SIGCHLD 触发 chSig := make(chan os.Signal, 10) signal.Notify(chSig, syscall.SIGCHLD) - // 周期触发 tk := time.NewTicker(time.Second * 30) var chT <-chan time.Time @@ -60,19 +57,19 @@ func runZombieCleaner(log mlog.ProcLogger) { func cleanZombieProcesses(log mlog.ProcLogger) { var ( err error - pids []int + pIDs []int ) - if pids, err = findZombieProcesses(); err != nil { + if pIDs, err = findZombieProcesses(); err != nil { log.Print("failed checking zombies:", err.Error()) return } - for _, pid := range pids { - go waitZombieProcess(log, pid) + for _, pID := range pIDs { + go waitZombieProcess(log, pID) } } -func findZombieProcesses() (pids []int, err error) { +func findZombieProcesses() (pIDs []int, err error) { var f *os.File if f, err = os.Open("/proc"); err != nil { return @@ -86,25 +83,25 @@ func findZombieProcesses() (pids []int, err error) { if dirname[0] < '0' || dirname[0] > '9' { continue } - var pid int - if pid, err = strconv.Atoi(dirname); err != nil { + var pID int + if pID, err = strconv.Atoi(dirname); err != nil { return } var zombie bool - if zombie, err = checkProcessIsZombie(pid); err != nil { + if zombie, err = checkProcessIsZombie(pID); err != nil { err = nil continue } if zombie { - pids = append(pids, pid) + pIDs = append(pIDs, pID) } } return } -func checkProcessIsZombie(pid int) (zombie bool, err error) { +func checkProcessIsZombie(pID int) (zombie bool, err error) { var buf []byte - if buf, err = os.ReadFile(fmt.Sprintf("/proc/%d/stat", pid)); err != nil { + if buf, err = os.ReadFile(fmt.Sprintf("/proc/%d/stat", pID)); err != nil { return } zombie = checkProcStatIsZombie(buf) @@ -127,17 +124,17 @@ func checkProcStatIsZombie(buf []byte) bool { return buf[0] == 'Z' } -func waitZombieProcess(log mlog.ProcLogger, pid int) { +func waitZombieProcess(log mlog.ProcLogger, pID int) { var err error var ws syscall.WaitStatus for { - _, err = syscall.Wait4(pid, &ws, 0, nil) + _, err = syscall.Wait4(pID, &ws, 0, nil) for syscall.EINTR == err { - _, err = syscall.Wait4(pid, &ws, 0, nil) + _, err = syscall.Wait4(pID, &ws, 0, nil) } if syscall.ECHILD == err { break } } - log.Printf("zombie cleaned %d", pid) + log.Printf("zombie cleaned %d", pID) }