diff options
author | Maxim Devaev <[email protected]> | 2021-12-30 05:44:42 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2021-12-30 05:44:42 +0300 |
commit | f609e857b14986bd8106685a60ae41ab2d1f8657 (patch) | |
tree | e03cc711fd0232976469d76092936a37dd2354ae /kvmd/libc.py | |
parent | 885c14f9e4c1e787f8539fe2bb0e533bdb2caba2 (diff) |
libc module
Diffstat (limited to 'kvmd/libc.py')
-rw-r--r-- | kvmd/libc.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/kvmd/libc.py b/kvmd/libc.py new file mode 100644 index 00000000..f2e3370c --- /dev/null +++ b/kvmd/libc.py @@ -0,0 +1,59 @@ +# ========================================================================== # +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2021 Maxim Devaev <[email protected]> # +# # +# This source file is partially based on python-watchdog module. # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +# ========================================================================== # + + +import ctypes +import ctypes.util + +from ctypes import c_int +from ctypes import c_uint32 +from ctypes import c_char_p + + +# ===== +def _load_libc() -> ctypes.CDLL: + path = ctypes.util.find_library("c") + if not path: + raise RuntimeError("Where is libc?") + assert path + lib = ctypes.CDLL(path) + for (name, restype, argtypes) in [ + ("inotify_init", c_int, []), + ("inotify_add_watch", c_int, [c_int, c_char_p, c_uint32]), + ("inotify_rm_watch", c_int, [c_int, c_uint32]), + ]: + func = getattr(lib, name) + if not func: + raise RuntimeError(f"Where is libc.{name}?") + setattr(func, "restype", restype) + setattr(func, "argtypes", argtypes) + return lib + + +_libc = _load_libc() + + +# ===== +inotify_init = _libc.inotify_init +inotify_add_watch = _libc.inotify_add_watch +inotify_rm_watch = _libc.inotify_rm_watch |