Commit c9c9fe47 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: fix sigpending to check blocked signal masks

Here are a few bugs which hide each other.
* memcmp(&newset, &oldset, sizeof(newset) returns 0 is masks are equal.
* sigprocmask return sigset_t and it contains extra bits for the future,
so we need to initialize all this bits otherwise they will contain
random data.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a21cdb84
...@@ -91,6 +91,9 @@ static void *thread_fn(void *args) ...@@ -91,6 +91,9 @@ static void *thread_fn(void *args)
sigset_t blockmask, oldset, newset; sigset_t blockmask, oldset, newset;
struct sigaction act; struct sigaction act;
memset(&oldset, 0, sizeof(oldset));
memset(&newset, 0, sizeof(oldset));
sigfillset(&blockmask); sigfillset(&blockmask);
sigdelset(&blockmask, SIGTERM); sigdelset(&blockmask, SIGTERM);
...@@ -99,7 +102,7 @@ static void *thread_fn(void *args) ...@@ -99,7 +102,7 @@ static void *thread_fn(void *args)
return NULL; return NULL;
} }
if (sigprocmask(SIG_BLOCK, NULL, &oldset) == -1) { if (sigprocmask(SIG_SETMASK, NULL, &oldset) == -1) {
err("sigprocmask"); err("sigprocmask");
return NULL; return NULL;
} }
...@@ -125,7 +128,9 @@ static void *thread_fn(void *args) ...@@ -125,7 +128,9 @@ static void *thread_fn(void *args)
return NULL; return NULL;
} }
if (!memcmp(&newset, &oldset, sizeof(newset))) { sigdelset(&oldset, SIGTRAP);
sigdelset(&newset, SIGTRAP);
if (memcmp(&newset, &oldset, sizeof(newset))) {
fail("The signal blocking mask was changed"); fail("The signal blocking mask was changed");
numsig = INT_MAX; numsig = INT_MAX;
} }
...@@ -161,6 +166,9 @@ int main(int argc, char ** argv) ...@@ -161,6 +166,9 @@ int main(int argc, char ** argv)
pthread_t pthrd; pthread_t pthrd;
int i; int i;
memset(&oldset, 0, sizeof(oldset));
memset(&newset, 0, sizeof(oldset));
test_init(argc, argv); test_init(argc, argv);
pthread_mutex_init(&exit_lock, NULL); pthread_mutex_init(&exit_lock, NULL);
pthread_mutex_lock(&exit_lock); pthread_mutex_lock(&exit_lock);
...@@ -182,7 +190,7 @@ int main(int argc, char ** argv) ...@@ -182,7 +190,7 @@ int main(int argc, char ** argv)
return -1; return -1;
} }
if (sigprocmask(SIG_BLOCK, &oldset, NULL) == -1) { if (sigprocmask(SIG_BLOCK, NULL, &oldset) == -1) {
err("sigprocmask"); err("sigprocmask");
return -1; return -1;
} }
...@@ -242,7 +250,9 @@ int main(int argc, char ** argv) ...@@ -242,7 +250,9 @@ int main(int argc, char ** argv)
pthread_mutex_unlock(&exit_lock); pthread_mutex_unlock(&exit_lock);
pthread_join(pthrd, NULL); pthread_join(pthrd, NULL);
if (!memcmp(&newset, &oldset, sizeof(newset))) { sigdelset(&oldset, SIGTRAP);
sigdelset(&newset, SIGTRAP);
if (memcmp(&newset, &oldset, sizeof(newset))) {
fail("The signal blocking mask was changed"); fail("The signal blocking mask was changed");
return 1; return 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment