Skip to content

Commit

Permalink
failed attempt to fix shutdown code path
Browse files Browse the repository at this point in the history
  • Loading branch information
david415 committed Jan 28, 2015
1 parent bba2b69 commit 3c105dd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions attack_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (a *AttackJsonLogger) Publish(report *AttackReport) {
}

func (a *AttackJsonLogger) Close() {
log.Print("closing attack json logger\n")
var err error

err = a.BufWriter.Flush()
Expand Down
8 changes: 8 additions & 0 deletions inquisition.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func NewConnection() *Connection {

func (c *Connection) Close() {
c.AttackLogger.Close()
c.PacketLogger.Close()
}

// PacketLoggerWrite writes the specified raw packet to the raw packet log.
Expand Down Expand Up @@ -631,6 +632,13 @@ func NewConnTracker() *ConnTracker {
}
}

func (c *ConnTracker) Close() {
for k, v := range c.flowAMap {
log.Printf("ConnTracker: closing %s\n", k.String())
v.Close()
}
}

// Has returns true if the given TcpIpFlow is a key in our
// either of flowAMap or flowBMap
func (c *ConnTracker) Has(key TcpIpFlow) bool {
Expand Down
27 changes: 25 additions & 2 deletions pcap_loggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"code.google.com/p/gopacket/layers"
"code.google.com/p/gopacket/pcapgo"
"fmt"
"log"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -90,6 +91,10 @@ func NewPcapLogger(dir string, flow TcpIpFlow) *PcapLogger {
}

func (p *PcapLogger) WritePacket(packet []byte) {
p.writeChan <- packet
}

func (p *PcapLogger) HandleWrite(packet []byte) {
err := p.writer.WritePacket(gopacket.CaptureInfo{
Timestamp: time.Now(),
CaptureLength: len(packet),
Expand All @@ -101,9 +106,27 @@ func (p *PcapLogger) WritePacket(packet []byte) {
}

func (p *PcapLogger) Close() {
log.Print("closing pcap logger\n")
var err error

p.closeChan <- true
close(p.writeChan)
close(p.closeChan)
p.fileHandle.Close()

p.bufWriter.Flush()
if err != nil {
panic(err)
}

err = p.fileHandle.Sync()
if err != nil {
panic(err)
}

err = p.fileHandle.Close()
if err != nil {
panic(err)
}
}

func (p *PcapLogger) StartWriter() {
Expand All @@ -116,7 +139,7 @@ func (p *PcapLogger) startWriter() {
case <-p.closeChan:
return
case packetBytes := <-p.writeChan:
p.WritePacket(packetBytes)
p.HandleWrite(packetBytes)
}
}
}
4 changes: 3 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func (b *HoneyBadgerService) Start() {

// Stop the HoneyBadgerService
func (b *HoneyBadgerService) Stop() {
b.stopChan <- true
b.stopDecodeChan <- true
b.stopChan <- true
close(b.stopChan)
close(b.rawPacketChan)
close(b.stopDecodeChan)

b.connTracker.Close()
}

// startDecodingTcp calls decodeTcp in a new goroutine...
Expand Down

0 comments on commit 3c105dd

Please sign in to comment.