Skip to content

Commit

Permalink
Merge pull request #17 from instana/issue_16
Browse files Browse the repository at this point in the history
Fix error checking and add a recover
  • Loading branch information
pglombardo authored Mar 29, 2017
2 parents d7a6c4b + cc534f7 commit 027ddaf
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,32 @@ func (r *fsmS) announceSensor(e *f.Event) {
log.debug("announcing sensor to the agent")

go func(cb func(b bool, from *FromS)) {
defer func() {
if r := recover(); r != nil {
log.debug("Announce recovered:", r)
}
}()

d := &Discovery{PID: os.Getpid()}

d.Name, d.Args = getCommandLine()

var socket net.Conn
if _, err := os.Stat("/proc"); err == nil {
socket, err := net.Dial("tcp", r.agent.host+":42699")
if err != nil {
log.error(err)
}
if addr, err := net.ResolveTCPAddr("tcp", r.agent.host+":42699"); err == nil {
if tcpConn, err := net.DialTCP("tcp", nil, addr); err == nil {
defer tcpConn.Close()

tcpConn := socket.(*net.TCPConn)
f, err := tcpConn.File()
f, err := tcpConn.File()

if err != nil {
log.error(err)
} else {
d.Fd = fmt.Sprintf("%v", f.Fd())
if err != nil {
log.error(err)
} else {
d.Fd = fmt.Sprintf("%v", f.Fd())

link := fmt.Sprintf("/proc/%d/fd/%d", os.Getpid(), f.Fd())
if _, err := os.Stat(link); err == nil {
d.Inode, _ = os.Readlink(link)
link := fmt.Sprintf("/proc/%d/fd/%d", os.Getpid(), f.Fd())
if _, err := os.Stat(link); err == nil {
d.Inode, _ = os.Readlink(link)
}
}
}
}
}
Expand All @@ -162,10 +165,6 @@ func (r *fsmS) announceSensor(e *f.Event) {
&FromS{
PID: strconv.Itoa(int(ret.Pid)),
HostID: ret.HostID})

if socket != nil {
socket.Close()
}
}(cb)
}

Expand Down

0 comments on commit 027ddaf

Please sign in to comment.