Skip to content

Commit 8acd96f

Browse files
greatgitsbyclaude
andcommitted
esim: hold filesystem lock during AtClient echo disable
When multiple processes create TiciLPA simultaneously, each AtClient sends ATE0 to the serial port during init without holding any lock. This can inject into the serial stream while another process is mid-command, causing timeouts. Hold the filesystem lock during _disable_echo to serialize init across processes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 698fcc5 commit 8acd96f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

system/hardware/tici/lpa.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
MM = "org.freedesktop.ModemManager1"
3434
MM_MODEM = MM + ".Modem"
3535
ES10X_MSS = 120
36+
LOCK_FILE = '/tmp/.lpa.lock'
3637
DEBUG = True
3738

3839
# TLV Tags
@@ -128,7 +129,13 @@ def __init__(self, device: str, baud: int, timeout: float, debug: bool) -> None:
128129
self._use_dbus = False
129130
try:
130131
self._serial = serial.Serial(device, baudrate=baud, timeout=timeout)
131-
self._disable_echo()
132+
fd = os.open(LOCK_FILE, os.O_CREAT | os.O_RDWR)
133+
try:
134+
fcntl.flock(fd, fcntl.LOCK_EX)
135+
self._disable_echo()
136+
finally:
137+
fcntl.flock(fd, fcntl.LOCK_UN)
138+
os.close(fd)
132139
if self.debug:
133140
print("AtClient: using serial transport", file=sys.stderr)
134141
except (serial.SerialException, PermissionError, OSError) as e:
@@ -692,7 +699,6 @@ def set_profile_nickname(client: AtClient, iccid: str, nickname: str) -> None:
692699

693700

694701
MM_DEVICE_UID = '/sys/devices/platform/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb1/1-1'
695-
LOCK_FILE = '/tmp/.lpa.lock'
696702

697703

698704
class TiciLPA(LPABase):

0 commit comments

Comments
 (0)