[packages/python-sh] - fix for udev systems without /dev/fd symlink

qboosh qboosh at pld-linux.org
Sun Jan 11 12:49:25 CET 2026


commit 115137af605cd8ce2738fb8dcd13fd2453a34fad
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date:   Sun Jan 11 12:49:17 2026 +0100

    - fix for udev systems without /dev/fd symlink

 python-sh.spec |  2 ++
 sh-udev.patch  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
---
diff --git a/python-sh.spec b/python-sh.spec
index 1d66860..202de35 100644
--- a/python-sh.spec
+++ b/python-sh.spec
@@ -15,6 +15,7 @@ License:	MIT
 Group:		Libraries/Python
 Source0:	https://files.pythonhosted.org/packages/source/s/sh/%{module}-%{version}.tar.gz
 # Source0-md5:	d60498172876f35aef6303a9cbb8eb11
+Patch0:		sh-udev.patch
 URL:		https://pypi.org/project/sh/
 BuildRequires:	rpm-pythonprov
 BuildRequires:	rpmbuild(macros) >= 1.714
@@ -58,6 +59,7 @@ tak, jakby był funkcją.
 
 %prep
 %setup -q -n %{module}-%{version}
+%patch -P0 -p1
 
 %build
 %if %{with python2}
diff --git a/sh-udev.patch b/sh-udev.patch
new file mode 100644
index 0000000..615379f
--- /dev/null
+++ b/sh-udev.patch
@@ -0,0 +1,47 @@
+Some udev-based systems don't have /dev/fd symlink
+--- sh-1.14.3/sh.py.orig	2022-07-18 08:46:38.000000000 +0200
++++ sh-1.14.3/sh.py	2026-01-11 11:33:08.928375012 +0100
+@@ -2065,7 +2065,13 @@ class OProc(object):
+                     pass_fds.update(ca["pass_fds"])
+ 
+                     # don't inherit file descriptors
+-                    inherited_fds = os.listdir("/dev/fd")
++                    try:
++                        inherited_fds = os.listdir("/dev/fd")
++                    except OSError:
++                        # Some systems don't have /dev/fd. Raises OSError in
++                        # Python2, FileNotFoundError on Python3. The latter doesn't
++                        # exist on Python2, but inherits from IOError, which does.
++                        inherited_fds = os.listdir("/proc/self/fd")
+                     inherited_fds = set(int(fd) for fd in inherited_fds) - pass_fds
+                     for fd in inherited_fds:
+                         try:
+--- sh-1.14.3/test.py.orig	2022-07-18 08:46:38.000000000 +0200
++++ sh-1.14.3/test.py	2026-01-11 11:33:48.968592555 +0100
+@@ -614,7 +614,7 @@ print("hi")
+ 
+         py = create_tmp_test("""
+ import os
+-print(len(os.listdir("/dev/fd")))
++print(len(os.listdir("/proc/self/fd")))
+ """)
+         out = python(py.name, _close_fds=False).strip()
+         # pick some number greater than 4, since it's hard to know exactly how many fds will be open/inherted in the
+@@ -638,7 +638,7 @@ print(len(os.listdir("/dev/fd")))
+ 
+         py = create_tmp_test("""
+ import os
+-print(os.listdir("/dev/fd"))
++print(os.listdir("/proc/self/fd"))
+ """)
+         out = python(py.name).strip()
+         self.assertEqual(out, "['0', '1', '2', '3']")
+@@ -661,7 +661,7 @@ print(os.listdir("/dev/fd"))
+ 
+         py = create_tmp_test("""
+ import os
+-print(os.listdir("/dev/fd"))
++print(os.listdir("/proc/self/fd"))
+ """)
+         out = python(py.name, _pass_fds=[last_fd]).strip()
+         inherited = [0, 1, 2, 3, last_fd]
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/python-sh.git/commitdiff/115137af605cd8ce2738fb8dcd13fd2453a34fad



More information about the pld-cvs-commit mailing list