1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

Tighten signal handlers.

This commit is contained in:
Alasdair Kergon 2005-03-21 14:16:16 +00:00
parent 02c6d3f251
commit 779b7713cf
3 changed files with 14 additions and 9 deletions

View File

@ -1,5 +1,6 @@
Version 2.01.08 - Version 2.01.08 -
================================ ================================
Tighten signal handlers.
Avoid some compiler warnings. Avoid some compiler warnings.
Additional rename failure error message. Additional rename failure error message.
read/write may be macros. read/write may be macros.

View File

@ -88,7 +88,7 @@ static pthread_t lvm_thread;
static pthread_mutex_t lvm_thread_mutex; static pthread_mutex_t lvm_thread_mutex;
static pthread_cond_t lvm_thread_cond; static pthread_cond_t lvm_thread_cond;
static struct list lvm_cmd_head; static struct list lvm_cmd_head;
static int quit = 0; static volatile sig_atomic_t quit = 0;
static int child_pipe[2]; static int child_pipe[2];
/* Reasons the daemon failed initialisation */ /* Reasons the daemon failed initialisation */

View File

@ -41,7 +41,7 @@ static char _lock_dir[NAME_LEN];
static sig_t _oldhandler; static sig_t _oldhandler;
static sigset_t _fullsigset, _intsigset; static sigset_t _fullsigset, _intsigset;
static int _handler_installed; static volatile sig_atomic_t _handler_installed;
static int _release_lock(const char *file, int unlock) static int _release_lock(const char *file, int unlock)
{ {
@ -95,38 +95,40 @@ static void _reset_file_locking(void)
static void _remove_ctrl_c_handler() static void _remove_ctrl_c_handler()
{ {
siginterrupt(SIGINT, 0); siginterrupt(SIGINT, 0);
if (!_handler_installed || _oldhandler == SIG_ERR) if (!_handler_installed)
return; return;
_handler_installed = 0;
sigprocmask(SIG_SETMASK, &_fullsigset, NULL); sigprocmask(SIG_SETMASK, &_fullsigset, NULL);
if (signal(SIGINT, _oldhandler) == SIG_ERR) if (signal(SIGINT, _oldhandler) == SIG_ERR)
log_sys_error("signal", "_remove_ctrl_c_handler"); log_sys_error("signal", "_remove_ctrl_c_handler");
_handler_installed = 0;
} }
static void _trap_ctrl_c(int sig) static void _trap_ctrl_c(int sig)
{ {
_remove_ctrl_c_handler(); _remove_ctrl_c_handler();
log_error("CTRL-c detected: giving up waiting for lock"); log_error("CTRL-c detected: giving up waiting for lock");
return;
} }
static void _install_ctrl_c_handler() static void _install_ctrl_c_handler()
{ {
if ((_oldhandler = signal(SIGINT, _trap_ctrl_c)) == SIG_ERR) _handler_installed = 1;
if ((_oldhandler = signal(SIGINT, _trap_ctrl_c)) == SIG_ERR) {
_handler_installed = 0;
return; return;
}
sigprocmask(SIG_SETMASK, &_intsigset, NULL); sigprocmask(SIG_SETMASK, &_intsigset, NULL);
siginterrupt(SIGINT, 1); siginterrupt(SIGINT, 1);
_handler_installed = 1;
} }
static int _lock_file(const char *file, int flags) static int _lock_file(const char *file, int flags)
{ {
int operation; int operation;
int r = 1; int r = 1;
int old_errno;
struct lock_list *ll; struct lock_list *ll;
struct stat buf1, buf2; struct stat buf1, buf2;
@ -176,10 +178,12 @@ static int _lock_file(const char *file, int flags)
_install_ctrl_c_handler(); _install_ctrl_c_handler();
r = flock(ll->lf, operation); r = flock(ll->lf, operation);
old_errno = errno;
if (!(flags & LCK_NONBLOCK)) if (!(flags & LCK_NONBLOCK))
_remove_ctrl_c_handler(); _remove_ctrl_c_handler();
if (r) { if (r) {
errno = old_errno;
log_sys_error("flock", ll->res); log_sys_error("flock", ll->res);
goto err; goto err;
} }