|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | import socket |
3 | 4 | import subprocess |
4 | 5 | import threading as t |
@@ -128,20 +129,24 @@ def announce_sensor(self, e): |
128 | 129 | pid = os.getpid() |
129 | 130 | cmdline = [] |
130 | 131 |
|
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) |
145 | 150 |
|
146 | 151 | d = Discovery(pid=pid, |
147 | 152 | name=cmdline[0], |
|
0 commit comments