Skip to content

Commit

Permalink
Fix /proc inotify interfaces.
Browse files Browse the repository at this point in the history
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 seb-m#73
  • Loading branch information
seb-m committed Jul 6, 2014
1 parent 3372528 commit 499a975
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
32 changes: 20 additions & 12 deletions python2/pyinotify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

# pyinotify.py - python interface to inotify
# Copyright (c) 2005-2011 Sebastien Martini <[email protected]>
# Copyright (c) 2005-2014 Sebastien Martini <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -310,22 +310,26 @@ def create(attrname):

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
Expand All @@ -334,11 +338,15 @@ def set_val(self, nval):
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)

Expand Down
32 changes: 20 additions & 12 deletions python3/pyinotify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

# pyinotify.py - python interface to inotify
# Copyright (c) 2005-2011 Sebastien Martini <[email protected]>
# Copyright (c) 2005-2014 Sebastien Martini <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -300,22 +300,26 @@ def create(attrname):

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
Expand All @@ -324,11 +328,15 @@ def set_val(self, nval):
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)

Expand Down

0 comments on commit 499a975

Please sign in to comment.