summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-15 01:47:58 +0200
committerhut <hut@lavabit.com>2012-08-15 01:47:58 +0200
commit413c887bf405265d062516070d6ba3800b1293c0 (patch)
tree478d55a0cb048f52510fa894f4b9d7573ec642d5 /ranger
parentb2b1c1024a8cff34690e74292b8132b2cf6fa69b (diff)
downloadranger-413c887bf405265d062516070d6ba3800b1293c0.tar.gz
ext.popen_forked: tweak mechanism
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/popen_forked.py23
-rwxr-xr-xranger/ext/rifle.py23
2 files changed, 22 insertions, 24 deletions
diff --git a/ranger/ext/popen_forked.py b/ranger/ext/popen_forked.py
index 0dd52252..10aab83c 100644
--- a/ranger/ext/popen_forked.py
+++ b/ranger/ext/popen_forked.py
@@ -8,19 +8,16 @@ def Popen_forked(*args, **kwargs):
 	"""
 	Forks process and runs Popen with the given args and kwargs.
 
-	If os.fork() is not supported, runs Popen without forking and returns the
-	process object returned by Popen.
-	Otherwise, returns None.
+	Returns True if forking succeeded, otherwise False.
 	"""
 	try:
 		pid = os.fork()
-	except:
-		# fall back to not forking if os.fork() is not supported
-		return subprocess.Popen(*args, **kwargs)
-	else:
-		if pid == 0:
-			os.setsid()
-			kwargs['stdin'] = open(os.devnull, 'r')
-			kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w')
-			subprocess.Popen(*args, **kwargs)
-			os._exit(0)
+	except OSError:
+		return False
+	if pid == 0:
+		os.setsid()
+		kwargs['stdin'] = open(os.devnull, 'r')
+		kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w')
+		subprocess.Popen(*args, **kwargs)
+		os._exit(0)
+	return True
diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py
index 55a81df0..e0f0eb1b 100755
--- a/ranger/ext/rifle.py
+++ b/ranger/ext/rifle.py
@@ -72,19 +72,20 @@ try:
 	from ranger.ext.popen_forked import Popen_forked
 except ImportError:
 	def Popen_forked(*args, **kwargs):
-		"""Forks process and runs Popen with the given args and kwargs."""
+		"""
+		Forks process and runs Popen with the given args and kwargs.
+		"""
 		try:
 			pid = os.fork()
-		except:
-			# fall back to not forking if os.fork() is not supported
-			return Popen(*args, **kwargs)
-		else:
-			if pid == 0:
-				os.setsid()
-				kwargs['stdin'] = open(os.devnull, 'r')
-				kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w')
-				Popen(*args, **kwargs)
-				os._exit(0)
+		except OSError:
+			return False
+		if pid == 0:
+			os.setsid()
+			kwargs['stdin'] = open(os.devnull, 'r')
+			kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w')
+			subprocess.Popen(*args, **kwargs)
+			os._exit(0)
+		return True
 
 
 def _is_terminal():