Change in pysim[master]: serial: don't crash if the device does not exist

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Thu Feb 25 22:05:57 UTC 2021


fixeria has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/23029 )

Change subject: serial: don't crash if the device does not exist
......................................................................

serial: don't crash if the device does not exist

The most common reason for pySim to crash is when it is executed without
commandline parameters. Then pySim will expect a serial reader on
/dev/ttyUSB0 since this is the default. Lets check if /dev/ttyUSB0 even
exists before trying to open it.

Change-Id: I7545c728b531e9a796eee8f80f0b08d4097f8399
---
M pySim/transport/serial.py
1 file changed, 3 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, approved



diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index 61195e0..b841b3e 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -25,6 +25,7 @@
 
 import serial
 import time
+import os.path
 
 from pySim.exceptions import NoCardError, ProtocolError
 from pySim.transport import LinkBase
@@ -34,6 +35,8 @@
 class SerialSimLink(LinkBase):
 
 	def __init__(self, device='/dev/ttyUSB0', baudrate=9600, rst='-rts', debug=False):
+		if not os.path.exists(device):
+			raise ValueError("device file %s does not exist -- abort" % device)
 		self._sl = serial.Serial(
 				port = device,
 				parity = serial.PARITY_EVEN,

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23029
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I7545c728b531e9a796eee8f80f0b08d4097f8399
Gerrit-Change-Number: 23029
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
Gerrit-CC: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210225/5211c4bb/attachment.htm>


More information about the gerrit-log mailing list