1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

signals: add interruptible usleep

Add small wrapper that temporarily enables signal handling during
usleep() and return  '0' when interrupted.
This commit is contained in:
Zdenek Kabelac 2021-03-12 11:18:53 +01:00
parent bbac843268
commit 941f67ed09
2 changed files with 16 additions and 0 deletions

View File

@ -153,3 +153,16 @@ void unblock_signals(void)
_signals_blocked = 0; _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;
}

View File

@ -16,6 +16,8 @@
#ifndef _LVM_SIGNAL_H #ifndef _LVM_SIGNAL_H
#define _LVM_SIGNAL_H #define _LVM_SIGNAL_H
#include <unistd.h>
void remove_ctrl_c_handler(void); void remove_ctrl_c_handler(void);
void install_ctrl_c_handler(void); void install_ctrl_c_handler(void);
int init_signals(int suppress_messages); int init_signals(int suppress_messages);
@ -28,4 +30,5 @@ void sigint_clear(void);
void block_signals(uint32_t flags); void block_signals(uint32_t flags);
void unblock_signals(void); void unblock_signals(void);
int interruptible_usleep(useconds_t usec);
#endif #endif