fix: problems caused when uid is 0
This commit is contained in:
parent
96a32f5038
commit
47568051bf
2 changed files with 8 additions and 8 deletions
|
@ -83,7 +83,7 @@ type Metadata struct {
|
||||||
AddrType int `json:"-"`
|
AddrType int `json:"-"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
DNSMode DNSMode `json:"dnsMode"`
|
DNSMode DNSMode `json:"dnsMode"`
|
||||||
Uid int32 `json:"uid"`
|
Uid *int32 `json:"uid"`
|
||||||
Process string `json:"process"`
|
Process string `json:"process"`
|
||||||
ProcessPath string `json:"processPath"`
|
ProcessPath string `json:"processPath"`
|
||||||
}
|
}
|
||||||
|
@ -101,10 +101,10 @@ func (m *Metadata) SourceDetail() string {
|
||||||
return fmt.Sprintf("[%s]", ClashName)
|
return fmt.Sprintf("[%s]", ClashName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Process != "" && m.Uid != 0 {
|
if m.Process != "" && m.Uid != nil {
|
||||||
return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, m.Uid)
|
return fmt.Sprintf("%s(%s, uid=%d)", m.SourceAddress(), m.Process, *m.Uid)
|
||||||
} else if m.Uid != 0 {
|
} else if m.Uid != nil {
|
||||||
return fmt.Sprintf("%s(%d)", m.SourceAddress(), m.Uid)
|
return fmt.Sprintf("%s(%d)", m.SourceAddress(), *m.Uid)
|
||||||
} else if m.Process != "" {
|
} else if m.Process != "" {
|
||||||
return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process)
|
return fmt.Sprintf("%s(%s)", m.SourceAddress(), m.Process)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -72,10 +72,10 @@ func (u *Uid) Match(metadata *C.Metadata) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var uid int32
|
var uid int32
|
||||||
if metadata.Uid != 0 {
|
if metadata.Uid != nil {
|
||||||
uid = metadata.Uid
|
uid = *metadata.Uid
|
||||||
} else if uid, err = process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil {
|
} else if uid, err = process.FindUid(metadata.NetWork.String(), metadata.SrcIP, srcPort); err == nil {
|
||||||
metadata.Uid = uid
|
metadata.Uid = &uid
|
||||||
} else {
|
} else {
|
||||||
log.Warnln("[UID] could not get uid from %s", metadata.String())
|
log.Warnln("[UID] could not get uid from %s", metadata.String())
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue