Skip to content

Commit 76c6073

Browse files
committed
Expose uinput file descriptor on Device
This is useful for dropping root privileges (setuid)
1 parent 1c37e30 commit 76c6073

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class Device(object):
162162
"""
163163

164164
def __init__(self, events, name="python-uinput",
165-
bustype=0, vendor=0, product=0, version=0):
165+
bustype=0, vendor=0, product=0, version=0, fd=None):
166166
self.__events = events
167167
self.__uinput_fd = -1
168168
self.__name = name.encode()
@@ -172,7 +172,7 @@ def __init__(self, events, name="python-uinput",
172172
user_dev.id.vendor = vendor
173173
user_dev.id.product = product
174174
user_dev.id.version = version
175-
self.__uinput_fd = _libsuinput.suinput_open()
175+
self.__uinput_fd = fd or self.create_uinput_fd()
176176
for ev_spec in self.__events:
177177
ev_type, ev_code = ev_spec[:2]
178178
_libsuinput.suinput_enable_event(self.__uinput_fd, ev_type, ev_code)
@@ -185,6 +185,10 @@ def __init__(self, events, name="python-uinput",
185185

186186
_libsuinput.suinput_create(self.__uinput_fd, ctypes.pointer(user_dev))
187187

188+
@staticmethod
189+
def create_uinput_fd():
190+
return _libsuinput.suinput_open()
191+
188192
def syn(self):
189193
"""Fire all emitted events.
190194

0 commit comments

Comments
 (0)