oz-init pid mappings are now properly destroyed as these processes exit.

shw_dev
shw 8 years ago
parent a930fbbce0
commit b567e5ce54

@ -22,7 +22,7 @@ var OzInitPids []OzInitProc = []OzInitProc{}
func addInitPid(pid int, name string) { func addInitPid(pid int, name string) {
fmt.Println("::::::::::: init pid added: ", pid, " -> ", name) fmt.Println("::::::::::: init pid added: ", pid, " -> ", name)
for i := 0; i < len(OzInitPids); i++ { for i := 0; i < len(OzInitPids); i++ {
if OzInitPids[i].Pid == pid { if OzInitPids[i].Pid == pid {
return return
@ -34,6 +34,7 @@ func addInitPid(pid int, name string) {
} }
func removeInitPid(pid int) { func removeInitPid(pid int) {
fmt.Println("::::::::::: removing PID: ", pid)
for i := 0; i < len(OzInitPids); i++ { for i := 0; i < len(OzInitPids); i++ {
if OzInitPids[i].Pid == pid { if OzInitPids[i].Pid == pid {
OzInitPids = append(OzInitPids[:i], OzInitPids[i+1:]...) OzInitPids = append(OzInitPids[:i], OzInitPids[i+1:]...)
@ -174,6 +175,18 @@ func ReceiverLoop(fw *Firewall, c net.Conn) {
addInitPid(initpid, ozname) addInitPid(initpid, ozname)
c.Write([]byte("OK.\n")) c.Write([]byte("OK.\n"))
return return
} else if tokens[0] == "unregister-init" && len(tokens) == 2 {
initp := tokens[1]
initpid, err := strconv.Atoi(initp)
if err != nil {
log.Notice("IPC received invalid oz-init pid: ", initp)
c.Write([]byte("Bad command: init pid was invalid"))
return
}
removeInitPid(initpid)
c.Write([]byte("OK.\n"))
} }
if len(tokens) != 6 { if len(tokens) != 6 {

@ -502,6 +502,7 @@ func findProcessForPacket(pkt *nfqueue.NFQPacket) (*procsnitch.Info, string) {
res := procsnitch.LookupTCPSocketProcessAll(srcip, srcp, dstip, dstp, nil) res := procsnitch.LookupTCPSocketProcessAll(srcip, srcp, dstip, dstp, nil)
if res == nil { if res == nil {
removePids := make([]int, 0)
for i := 0; i < len(OzInitPids); i++ { for i := 0; i < len(OzInitPids); i++ {
data := "" data := ""
@ -511,6 +512,11 @@ fmt.Println("XXX: opening: ", fname)
if err != nil { if err != nil {
fmt.Println("Error reading proc data from ", fname, ": ", err) fmt.Println("Error reading proc data from ", fname, ": ", err)
if err == syscall.ENOENT {
removePids = append(removePids, OzInitPids[i].Pid)
}
continue continue
} else { } else {
data = string(bdata) data = string(bdata)
@ -538,6 +544,11 @@ fmt.Println("XXX: opening: ", fname)
} }
} }
for _, p := range removePids {
removeInitPid(p)
}
} }
return res, optstr return res, optstr

Loading…
Cancel
Save