diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c index b90a2db81..b1653a85c 100644 --- a/lib/misc/lvm-signal.c +++ b/lib/misc/lvm-signal.c @@ -153,3 +153,16 @@ void unblock_signals(void) _signals_blocked = 0; } + +/* usleep with enabled signal handler. + * Returns 1 when there was interruption */ +int interruptible_usleep(useconds_t usec) +{ + int r; + + sigint_allow(); + r = usleep(usec); + sigint_restore(); + + return (sigint_caught() || r) ? 1 : 0; +} diff --git a/lib/misc/lvm-signal.h b/lib/misc/lvm-signal.h index 2f7309f5d..a39f77eb2 100644 --- a/lib/misc/lvm-signal.h +++ b/lib/misc/lvm-signal.h @@ -16,6 +16,8 @@ #ifndef _LVM_SIGNAL_H #define _LVM_SIGNAL_H +#include + void remove_ctrl_c_handler(void); void install_ctrl_c_handler(void); int init_signals(int suppress_messages); @@ -28,4 +30,5 @@ void sigint_clear(void); void block_signals(uint32_t flags); void unblock_signals(void); +int interruptible_usleep(useconds_t usec); #endif