Skip to content

Commit 442ae64

Browse files
committed
Add safeties; exception handling
1 parent ac415f4 commit 442ae64

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

instana/fsm.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import socket
34
import subprocess
45
import threading as t
@@ -128,20 +129,24 @@ def announce_sensor(self, e):
128129
pid = os.getpid()
129130
cmdline = []
130131

131-
if os.path.isfile("/proc/self/cmdline"):
132-
with open("/proc/self/cmdline") as cmd:
133-
cmdinfo = cmd.read()
134-
cmdline = cmdinfo.split('\x00')
135-
else:
136-
# Python doesn't provide a reliable method to determine what
137-
# the OS process command line may be. Here we are forced to
138-
# rely on ps rather than adding a dependency on something like
139-
# psutil which requires dev packages, gcc etc...
140-
proc = subprocess.Popen(["ps", "-p", str(pid), "-o", "command"],
141-
stdout=subprocess.PIPE)
142-
(out, err) = proc.communicate()
143-
parts = out.split(b'\n')
144-
cmdline = [parts[1].decode("utf-8")]
132+
try:
133+
if os.path.isfile("/proc/self/cmdline"):
134+
with open("/proc/self/cmdline") as cmd:
135+
cmdinfo = cmd.read()
136+
cmdline = cmdinfo.split('\x00')
137+
else:
138+
# Python doesn't provide a reliable method to determine what
139+
# the OS process command line may be. Here we are forced to
140+
# rely on ps rather than adding a dependency on something like
141+
# psutil which requires dev packages, gcc etc...
142+
proc = subprocess.Popen(["ps", "-p", str(pid), "-o", "command"],
143+
stdout=subprocess.PIPE)
144+
(out, err) = proc.communicate()
145+
parts = out.split(b'\n')
146+
cmdline = [parts[1].decode("utf-8")]
147+
except Exception as err:
148+
cmdline = sys.argv
149+
log.debug(err)
145150

146151
d = Discovery(pid=pid,
147152
name=cmdline[0],

0 commit comments

Comments
 (0)