summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Martini <seb@dbzteam.org>2014-07-06 13:19:39 +0200
committerSebastien Martini <seb@dbzteam.org>2014-07-06 13:19:39 +0200
commit499a975f651495c35f2616f829e946213a5454f9 (patch)
tree67f208f784cba266cf0462e09c813d7c545810e4
parent33725288abd029ff53d0d8de4841808359e0d4a9 (diff)
downloadpyinotify-499a975f651495c35f2616f829e946213a5454f9.tar.gz
Fix /proc inotify interfaces.
There was a bug preventing the variables to be assigned a new value. The operations accessing (get and set) these interfaces now return an OSError exception on failure. Closes #73
-rwxr-xr-xpython2/pyinotify.py32
-rwxr-xr-xpython3/pyinotify.py32
2 files changed, 40 insertions, 24 deletions
diff --git a/python2/pyinotify.py b/python2/pyinotify.py
index 0b76e7d..a91282f 100755
--- a/python2/pyinotify.py
+++ b/python2/pyinotify.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# pyinotify.py - python interface to inotify
-# Copyright (c) 2005-2011 Sebastien Martini <seb@dbzteam.org>
+# Copyright (c) 2005-2014 Sebastien Martini <seb@dbzteam.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -310,22 +310,26 @@ class SysCtlINotify:
def get_val(self):
"""
- Gets attribute's value.
+ Gets attribute's value. Raises OSError if the operation failed.
@return: stored value.
@rtype: int
"""
oldv = ctypes.c_int(0)
size = ctypes.c_int(ctypes.sizeof(oldv))
- self._inotify_wrapper._sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(size),
- None, 0)
+ sysctl = self._inotify_wrapper._sysctl
+ res = sysctl(self._attr, 3,
+ ctypes.c_voidp(ctypes.addressof(oldv)),
+ ctypes.addressof(size),
+ None, 0)
+ if res == -1:
+ raise OSError(self._inotify_wrapper.get_errno(),
+ self._inotify_wrapper.str_errno())
return oldv.value
def set_val(self, nval):
"""
- Sets new attribute's value.
+ Sets new attribute's value. Raises OSError if the operation failed.
@param nval: replaces current value by nval.
@type nval: int
@@ -334,11 +338,15 @@ class SysCtlINotify:
sizeo = ctypes.c_int(ctypes.sizeof(oldv))
newv = ctypes.c_int(nval)
sizen = ctypes.c_int(ctypes.sizeof(newv))
- self._inotify_wrapper._sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(sizeo),
- ctypes.c_voidp(ctypes.addressof(newv)),
- ctypes.addressof(sizen))
+ sysctl = self._inotify_wrapper._sysctl
+ res = sysctl(self._attr, 3,
+ ctypes.c_voidp(ctypes.addressof(oldv)),
+ ctypes.addressof(sizeo),
+ ctypes.c_voidp(ctypes.addressof(newv)),
+ sizen)
+ if res == -1:
+ raise OSError(self._inotify_wrapper.get_errno(),
+ self._inotify_wrapper.str_errno())
value = property(get_val, set_val)
diff --git a/python3/pyinotify.py b/python3/pyinotify.py
index 96ff29c..16d2d8c 100755
--- a/python3/pyinotify.py
+++ b/python3/pyinotify.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# pyinotify.py - python interface to inotify
-# Copyright (c) 2005-2011 Sebastien Martini <seb@dbzteam.org>
+# Copyright (c) 2005-2014 Sebastien Martini <seb@dbzteam.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -300,22 +300,26 @@ class SysCtlINotify:
def get_val(self):
"""
- Gets attribute's value.
+ Gets attribute's value. Raises OSError if the operation failed.
@return: stored value.
@rtype: int
"""
oldv = ctypes.c_int(0)
size = ctypes.c_int(ctypes.sizeof(oldv))
- self._inotify_wrapper._sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(size),
- None, 0)
+ sysctl = self._inotify_wrapper._sysctl
+ res = sysctl(self._attr, 3,
+ ctypes.c_voidp(ctypes.addressof(oldv)),
+ ctypes.addressof(size),
+ None, 0)
+ if res == -1:
+ raise OSError(self._inotify_wrapper.get_errno(),
+ self._inotify_wrapper.str_errno())
return oldv.value
def set_val(self, nval):
"""
- Sets new attribute's value.
+ Sets new attribute's value. Raises OSError if the operation failed.
@param nval: replaces current value by nval.
@type nval: int
@@ -324,11 +328,15 @@ class SysCtlINotify:
sizeo = ctypes.c_int(ctypes.sizeof(oldv))
newv = ctypes.c_int(nval)
sizen = ctypes.c_int(ctypes.sizeof(newv))
- self._inotify_wrapper._sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(sizeo),
- ctypes.c_voidp(ctypes.addressof(newv)),
- ctypes.addressof(sizen))
+ sysctl = self._inotify_wrapper._sysctl
+ res = sysctl(self._attr, 3,
+ ctypes.c_voidp(ctypes.addressof(oldv)),
+ ctypes.addressof(sizeo),
+ ctypes.c_voidp(ctypes.addressof(newv)),
+ sizen)
+ if res == -1:
+ raise OSError(self._inotify_wrapper.get_errno(),
+ self._inotify_wrapper.str_errno())
value = property(get_val, set_val)