diff options
author | Lasse Dalegaard <dalegaard@gmail.com> | 2021-03-01 15:49:18 +0000 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-03-01 12:59:33 -0500 |
commit | e0db9f3a6ec5caf619cba2e693be1b155df052f4 (patch) | |
tree | f0b80e3a6ba707b967b7f8a06e49fb8277931246 /klippy | |
parent | 1b989b81e0be596d6b61599c8bce0d8a21c606ee (diff) | |
download | kutter-e0db9f3a6ec5caf619cba2e693be1b155df052f4.tar.gz kutter-e0db9f3a6ec5caf619cba2e693be1b155df052f4.tar.xz kutter-e0db9f3a6ec5caf619cba2e693be1b155df052f4.zip |
serialhdl: prevent creation of controlling tty
When `serialhdl` opens a terminal device it must prevent the device from
becoming the controlling terminal of `klippy`, as such a terminal will
send additional messages to the session leader, e.g. a SIGHUP, which
would kill `klippy`. See e.g. #3981.
pySerial already does this, but for e.g. `klipper_mcu` we were not doing
this ourselves.
On Linux a process must set `O_NOCTTY` when opening any file that could
potentially be a terminal device, to avoid this.
Earlier process daemonization tools prevent this from being an issue by
double forking, but under `systemd` a process must take steps to avoid
opening a controlling terminal.
Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r-- | klippy/serialhdl.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index e9c645d0..9ef39dfd 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -3,7 +3,7 @@ # Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. -import logging, threading +import logging, threading, os import serial import msgproto, chelper, util @@ -91,7 +91,8 @@ class SerialReader: self.ser.rts = self.rts self.ser.open() else: - self.ser = open(self.serialport, 'rb+', buffering=0) + fd = os.open(self.serialport, os.O_RDWR | os.O_NOCTTY) + self.ser = os.fdopen(fd, 'rb+', 0) except (OSError, IOError, serial.SerialException) as e: logging.warn("Unable to open port: %s", e) self.reactor.pause(connect_time + 5.) |