feat:firewalld和ufw同时存在时,不进行操作 (#6688)

Co-authored-by: zengzz01 <zengzz01@mingyuanyun.com>
This commit is contained in:
zzz 2024-10-11 18:03:33 +08:00 committed by GitHub
parent 5374afb226
commit 175b7b89e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,10 +29,17 @@ type FirewallClient interface {
}
func NewFirewallClient() (FirewallClient, error) {
if _, err := os.Stat("/usr/sbin/firewalld"); err == nil {
_, firewalldErr := os.Stat("/usr/sbin/firewalld")
_, ufwErr := os.Stat("/usr/sbin/ufw")
if firewalldErr == nil && ufwErr == nil {
return nil, buserr.New("firewalld and ufw both found, only one firewall should be active")
}
if firewalldErr == nil {
return client.NewFirewalld()
}
if _, err := os.Stat("/usr/sbin/ufw"); err == nil {
if ufwErr == nil {
return client.NewUfw()
}
return nil, buserr.New(constant.ErrFirewall)