From 4d31624a69aaacc71e6cbc9e9bb6b2efa137c4ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Sep 2017 18:45:51 +0530 Subject: [PATCH] Better handling of failure to execute child exec() a shell instead so that we are not left with a forked but not execed process --- kitty/child.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kitty/child.py b/kitty/child.py index 6253e316f..50e8dace3 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -2,13 +2,15 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2016, Kovid Goyal -import os import fcntl +import os +import sys from threading import Thread -from .constants import terminfo_dir import kitty.fast_data_types as fast_data_types +from .constants import terminfo_dir + def remove_cloexec(fd): fcntl.fcntl(fd, fcntl.F_SETFD, fcntl.fcntl(fd, fcntl.F_GETFD) & ~fcntl.FD_CLOEXEC) @@ -61,9 +63,13 @@ class Child: try: os.execvp(self.argv[0], self.argv) except Exception as err: + # Report he failure and exec a shell instead so that + # we are not left with a forked but not execed process print('Could not launch:', self.argv[0]) print('\t', err) - input('\nPress Enter to exit:') + print('\nPress Enter to exit:', end=' ') + sys.stdout.flush() + os.execvp('/bin/sh', ['/bin/sh', '-c', 'read w']) else: # master os.close(slave) self.pid = pid