diff options
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/syncdutils.py')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/syncdutils.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py index 4bf51da74..81c4e2e4b 100644 --- a/xlators/features/marker/utils/syncdaemon/syncdutils.py +++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py @@ -5,9 +5,11 @@ import fcntl import shutil import logging from threading import Lock, Thread as baseThread -from errno import EACCES, EAGAIN +from errno import EACCES, EAGAIN, EINTR from signal import SIGTERM, SIGKILL from time import sleep +import select as oselect +from os import waitpid as owaitpid from gconf import gconf @@ -158,3 +160,24 @@ class Thread(baseThread): kw['target'] = twrap baseThread.__init__(self, *a, **kw) self.setDaemon(True) + +class GsyncdError(Exception): + pass + +def eintr_wrap(func, exc, *a): + """ + wrapper around syscalls resilient to interrupt caused + by signals + """ + while True: + try: + return func(*a) + except exc, ex: + if not ex[0] == EINTR: + raise GsyncdError(ex[1]) + +def select(*a): + return eintr_wrap(oselect.select, oselect.error, *a) + +def waitpid(*a): + return eintr_wrap(owaitpid, OSError, *a) |