Replace usages of sigwait(3) with sigwaitinfo(2)
This is basically the same call, but it has the advantage of being supported by FreeBSD's valgrind, which sigwait() is not. References #1106.
This commit is contained in:
@@ -17,14 +17,13 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#define _POSIX_PTHREAD_SEMANTICS /* for two param sigwait on OpenSolaris */
|
||||
#include <signal.h>
|
||||
#undef _POSIX_PTHREAD_SEMANTICS
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <library.h>
|
||||
#include <hydra.h>
|
||||
@@ -112,12 +111,11 @@ static int run()
|
||||
while (TRUE)
|
||||
{
|
||||
int sig;
|
||||
int error;
|
||||
|
||||
error = sigwait(&set, &sig);
|
||||
if (error)
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "error %d while waiting for a signal", error);
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
switch (sig)
|
||||
@@ -382,7 +380,7 @@ int main(int argc, char *argv[])
|
||||
lib->plugins->status(lib->plugins, LEVEL_CTRL);
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT, TERM and HUP are handled by sigwait() in run() */
|
||||
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <hydra.h>
|
||||
#include <daemon.h>
|
||||
@@ -80,12 +81,11 @@ static void run()
|
||||
while (TRUE)
|
||||
{
|
||||
int sig;
|
||||
int error;
|
||||
|
||||
error = sigwait(&set, &sig);
|
||||
if (error)
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "error %d while waiting for a signal", error);
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
switch (sig)
|
||||
@@ -237,7 +237,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT and TERM are handled by sigwait() in run() */
|
||||
* INT and TERM are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
@@ -249,10 +249,10 @@ static int run()
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
int sig, error;
|
||||
int sig;
|
||||
|
||||
error = sigwait(&set, &sig);
|
||||
if (error)
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(error));
|
||||
return SS_RC_INITIALIZATION_FAILED;
|
||||
@@ -393,7 +393,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT, TERM and HUP are handled by sigwait() in run() */
|
||||
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <hydra.h>
|
||||
#include <daemon.h>
|
||||
@@ -98,12 +99,11 @@ static void run()
|
||||
while (TRUE)
|
||||
{
|
||||
int sig;
|
||||
int error;
|
||||
|
||||
error = sigwait(&set, &sig);
|
||||
if (error)
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "error %d while waiting for a signal", error);
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(error));
|
||||
return;
|
||||
}
|
||||
switch (sig)
|
||||
@@ -358,7 +358,7 @@ int main(int argc, char *argv[])
|
||||
lib->encoding->add_encoder(lib->encoding, tkm_encoder_encode);
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT and TERM are handled by sigwait() in run() */
|
||||
* INT and TERM are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
+4
-7
@@ -17,9 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#define _POSIX_PTHREAD_SEMANTICS /* for two param sigwait on OpenSolaris */
|
||||
#include <signal.h>
|
||||
#undef _POSIX_PTHREAD_SEMANTICS
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -110,12 +108,11 @@ static void run()
|
||||
while (TRUE)
|
||||
{
|
||||
int sig;
|
||||
int error;
|
||||
|
||||
error = sigwait(&set, &sig);
|
||||
if (error)
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "error %d while waiting for a signal", error);
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
switch (sig)
|
||||
@@ -434,7 +431,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT, TERM and HUP are handled by sigwait() in run() */
|
||||
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
@@ -563,7 +563,7 @@ int main(int argc, char *argv[])
|
||||
sigaddset(&set, SIGTERM);
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
|
||||
while (sigwait(&set, &sig) == 0)
|
||||
while ((sig = sigwaitinfo(&set, NULL)) != -1)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <library.h>
|
||||
#include <hydra.h>
|
||||
@@ -84,9 +85,10 @@ static int run()
|
||||
{
|
||||
int sig;
|
||||
|
||||
if (sigwait(&set, &sig))
|
||||
sig = sigwaitinfo(&set, NULL);
|
||||
if (sig == -1)
|
||||
{
|
||||
DBG1(DBG_DMN, "error while waiting for a signal");
|
||||
DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
switch (sig)
|
||||
@@ -206,7 +208,7 @@ int main(int argc, char *argv[])
|
||||
VERSION, utsname.sysname, utsname.release, utsname.machine);
|
||||
|
||||
/* add handler for SEGV and ILL,
|
||||
* INT, TERM and HUP are handled by sigwait() in run() */
|
||||
* INT, TERM and HUP are handled by sigwaitinfo() in run() */
|
||||
action.sa_handler = segv_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
|
||||
@@ -383,14 +383,13 @@ METHOD(fast_dispatcher_t, waitsignal, void,
|
||||
private_fast_dispatcher_t *this)
|
||||
{
|
||||
sigset_t set;
|
||||
int sig;
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGINT);
|
||||
sigaddset(&set, SIGTERM);
|
||||
sigaddset(&set, SIGHUP);
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
sigwait(&set, &sig);
|
||||
sigwaitinfo(&set, NULL);
|
||||
}
|
||||
|
||||
METHOD(fast_dispatcher_t, destroy, void,
|
||||
|
||||
@@ -117,14 +117,13 @@ void wait_sigint()
|
||||
void wait_sigint()
|
||||
{
|
||||
sigset_t set;
|
||||
int sig;
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGINT);
|
||||
sigaddset(&set, SIGTERM);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
sigwait(&set, &sig);
|
||||
sigwaitinfo(&set, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user