Skip to content

Commit

Permalink
fix: sshDev 忽略 DoUserProcessKill 产生的 error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Aug 9, 2023
1 parent a185136 commit fd75c7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
14 changes: 6 additions & 8 deletions internal/pkg/sshDev/client/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func DoAccountDelete(logger *log.Entry, username string) error {
return nil
}

func DoUserProcessKill(logger *log.Entry, username string) error {
// DoUserProcessKill 当用户没有进程时,将会产生 error,所以忽略 error
func DoUserProcessKill(logger *log.Entry, username string) {
if err := linux.UserKillAll(username); err != nil {
logger.Errorln("结束用户进程失败:", err)
return err
logger.Warnln("结束用户进程失败:", err)
return
}
logger.Infoln("用户进程已清理")
return nil
}

func LinuxUserPreset(logger *log.Entry, username string) error {
Expand All @@ -45,15 +45,13 @@ func SshAccountSet(account *proto.SshAccount) error {

var err error
if account.IsDel {
if err = DoUserProcessKill(logger, account.Username); err != nil {
return err
}
DoUserProcessKill(logger, account.Username)
if err = DoAccountDelete(logger, account.Username); err != nil {
return err
}
logger.Infoln("用户已删除")
} else if account.IsKill {
_ = DoUserProcessKill(logger, account.Username)
DoUserProcessKill(logger, account.Username)
} else {
ready, exist := accounts[account.Username]
if !exist {
Expand Down
5 changes: 0 additions & 5 deletions pkg/linux/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package linux

import (
"github.com/Mmx233/tool"
"os/exec"
)

Expand All @@ -11,10 +10,6 @@ func UserHomePath(username string) string {
return "/home/" + username
}

func UserExist(username string) (bool, error) {
return tool.File.Exists(UserHomePath(username))
}

func CreateUser(username string) error {
return exec.Command("adduser", "-D", "-s", "/bin/sh", "-G", "common", "-h", UserHomePath(username), username).Run()
}
Expand Down

0 comments on commit fd75c7c

Please sign in to comment.