fix: problems caused when uid is 0

This commit is contained in:
adlyq 2022-04-28 11:51:40 +08:00
parent 96a32f5038
commit 47568051bf
2 changed files with 8 additions and 8 deletions

View file

@ -83,7 +83,7 @@ type Metadata struct {
AddrType int `json:"-"`
Host string `json:"host"`
DNSMode DNSMode `json:"dnsMode"`
Uid int32 `json:"uid"`
Uid *int32 `json:"uid"`
Process string `json:"process"`
ProcessPath string `json:"processPath"`
}
@ -101,10 +101,10 @@ func (m *Metadata) SourceDetail() string {
return fmt.Sprintf("[%s]", ClashName)
}
if m.Process != "" && m.Uid != 0 {
return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, m.Uid)
} else if m.Uid != 0 {
return fmt.Sprintf("%s(%d)", m.SourceAddress(), m.Uid)
if m.Process != "" && m.Uid != nil {
return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, *m.Uid)
} else if m.Uid != nil {
return fmt.Sprintf("%s(%d)", m.SourceAddress(), *m.Uid)
} else if m.Process != "" {
return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process)
} else {

View file

@ -72,10 +72,10 @@ func (u *Uid) Match(metadata *C.Metadata) bool {
return false
}
var uid int32
if metadata.Uid != 0 {
uid = metadata.Uid
if metadata.Uid != nil {
uid = *metadata.Uid
} else if uid, err = process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil {
metadata.Uid = uid
metadata.Uid = &uid
} else {
log.Warnln("[UID] could not get uid from %s", metadata.String())
return false