Skip to content

Commit

Permalink
Detach from tty to prevent any packages thinking they have
Browse files Browse the repository at this point in the history
interactive input.
  • Loading branch information
Ealdwulf committed Mar 14, 2018
1 parent 76bc705 commit 1434aff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/kano-updater-internal
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ from kano_updater.progress import CLIProgress, Relaunch
from kano_updater.status import UpdaterStatus
from kano_updater.utils import make_low_prio, is_running, \
remove_pid_file, pause_notifications, resume_notifications, show_kano_dialog, \
run_bg, enable_power_button, disable_power_button, verify_kit_is_plugged
run_bg, enable_power_button, disable_power_button, verify_kit_is_plugged, \
detach_from_tty
from kano_updater.return_codes import RC, RCState
import kano_updater.priority as Priority

Expand Down Expand Up @@ -175,6 +176,9 @@ def main():
msg = _('Administrator priviledges are required to perform this operation')
enforce_root(u"{}: {}".format(_('ERROR'), msg))

# detach from tty to avoid packages trying to run interactive commands
detach_from_tty()

args = docopt.docopt(__doc__, version=str(get_target_version()))
_g_gui_mode = args['--gui']

Expand Down
14 changes: 14 additions & 0 deletions kano_updater/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import signal
import re
import subprocess
import fcntl
import termios

from kano.logging import logger
from kano.utils.shell import run_cmd, run_bg, run_cmd_log
Expand Down Expand Up @@ -577,3 +579,15 @@ def verify_kit_is_plugged():
).run()

return is_plugged and not is_battery_


def detach_from_tty():
"""
Detach from controlling tty
"""
try:
myTTY = os.open("/dev/tty",os.O_RDWR)
fcntl.ioctl(myTTY, termios.TIOCNOTTY, 0)
os.close(myTTY)
except:
logger.error("Failed to close controlling terminal")

0 comments on commit 1434aff

Please sign in to comment.