Using the thread wrapper in charon, libstrongswan and their plugins.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <daemon.h>
|
||||
#include <utils/host.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <threading/condvar.h>
|
||||
#include <threading/mutex.h>
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <linux/udp.h>
|
||||
#include <net/if.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@@ -30,6 +29,7 @@
|
||||
#include "kernel_klips_ipsec.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <threading/thread.h>
|
||||
#include <threading/mutex.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
#include <processing/jobs/acquire_job.h>
|
||||
@@ -1375,11 +1375,12 @@ static job_requeue_t receive_events(private_kernel_klips_ipsec_t *this)
|
||||
{
|
||||
unsigned char buf[PFKEY_BUFFER_SIZE];
|
||||
struct sadb_msg *msg = (struct sadb_msg*)buf;
|
||||
int len, oldstate;
|
||||
int len;
|
||||
bool oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = recv(this->socket_events, buf, sizeof(buf), 0);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/xfrm.h>
|
||||
#include <linux/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "kernel_netlink_shared.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <threading/thread.h>
|
||||
#include <threading/mutex.h>
|
||||
#include <utils/hashtable.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
@@ -748,12 +749,13 @@ static job_requeue_t receive_events(private_kernel_netlink_ipsec_t *this)
|
||||
struct nlmsghdr *hdr = (struct nlmsghdr*)response;
|
||||
struct sockaddr_nl addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
int len, oldstate;
|
||||
int len;
|
||||
bool oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = recvfrom(this->socket_xfrm_events, response, sizeof(response), 0,
|
||||
(struct sockaddr*)&addr, &addr_len);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <sys/socket.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <net/if.h>
|
||||
@@ -26,6 +25,8 @@
|
||||
#include "kernel_netlink_shared.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <threading/thread.h>
|
||||
#include <threading/condvar.h>
|
||||
#include <threading/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
@@ -481,12 +482,13 @@ static job_requeue_t receive_events(private_kernel_netlink_net_t *this)
|
||||
struct nlmsghdr *hdr = (struct nlmsghdr*)response;
|
||||
struct sockaddr_nl addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
int len, oldstate;
|
||||
int len;
|
||||
bool oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = recvfrom(this->socket_events, response, sizeof(response), 0,
|
||||
(struct sockaddr*)&addr, &addr_len);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
|
||||
@@ -49,13 +49,14 @@
|
||||
#endif /*HAVE_NATT*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "kernel_pfkey_ipsec.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <utils/host.h>
|
||||
#include <threading/thread.h>
|
||||
#include <threading/mutex.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
#include <processing/jobs/acquire_job.h>
|
||||
@@ -1083,11 +1084,12 @@ static job_requeue_t receive_events(private_kernel_pfkey_ipsec_t *this)
|
||||
{
|
||||
unsigned char buf[PFKEY_BUFFER_SIZE];
|
||||
struct sadb_msg *msg = (struct sadb_msg*)buf;
|
||||
int len, oldstate;
|
||||
int len;
|
||||
bool oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = recvfrom(this->socket_events, buf, sizeof(buf), 0, NULL, 0);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
#include <ifaddrs.h>
|
||||
#include <net/route.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "kernel_pfroute_net.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <utils/host.h>
|
||||
#include <threading/thread.h>
|
||||
#include <threading/mutex.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
@@ -326,11 +326,12 @@ static job_requeue_t receive_events(private_kernel_pfroute_net_t *this)
|
||||
{
|
||||
unsigned char buf[PFROUTE_BUFFER_SIZE];
|
||||
struct rt_msghdr *msg = (struct rt_msghdr*)buf;
|
||||
int len, oldstate;
|
||||
int len;
|
||||
bool oldstate;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = recvfrom(this->socket_events, buf, sizeof(buf), 0, NULL, 0);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
|
||||
@@ -68,7 +68,7 @@ static bool ike_state_change(private_load_tester_listener_t *this,
|
||||
if (this->shutdown_on == ++this->established)
|
||||
{
|
||||
DBG1(DBG_CFG, "load-test complete, raising SIGTERM");
|
||||
pthread_kill(charon->main_thread_id, SIGTERM);
|
||||
kill(0, SIGTERM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <daemon.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
#include <threading/condvar.h>
|
||||
#include <threading/mutex.h>
|
||||
|
||||
typedef struct private_load_tester_plugin_t private_load_tester_plugin_t;
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <libxml/xmlreader.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
|
||||
#include <library.h>
|
||||
#include <daemon.h>
|
||||
#include <threading/thread.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
|
||||
|
||||
@@ -361,7 +361,7 @@ static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
|
||||
xmlTextWriterStartElement(writer, "item");
|
||||
xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level);
|
||||
xmlTextWriterWriteFormatAttribute(writer, "source", "%N", debug_names, group);
|
||||
xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", pthread_self());
|
||||
xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", thread_current_id());
|
||||
xmlTextWriterWriteVFormatString(writer, format, args);
|
||||
xmlTextWriterEndElement(writer);
|
||||
/* </item> */
|
||||
@@ -622,17 +622,18 @@ static void closefdp(int *fd)
|
||||
*/
|
||||
static job_requeue_t process(int *fdp)
|
||||
{
|
||||
int oldstate, fd = *fdp;
|
||||
int fd = *fdp;
|
||||
bool oldstate;
|
||||
char buffer[4096];
|
||||
size_t len;
|
||||
xmlTextReaderPtr reader;
|
||||
char *id = NULL, *type = NULL;
|
||||
|
||||
pthread_cleanup_push((void*)closefdp, (void*)&fd);
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
thread_cleanup_push((thread_cleanup_t)closefdp, (void*)&fd);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
len = read(fd, buffer, sizeof(buffer));
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
pthread_cleanup_pop(0);
|
||||
thread_cancelability(oldstate);
|
||||
thread_cleanup_pop(FALSE);
|
||||
if (len <= 0)
|
||||
{
|
||||
close(fd);
|
||||
@@ -682,13 +683,14 @@ static job_requeue_t process(int *fdp)
|
||||
static job_requeue_t dispatch(private_smp_t *this)
|
||||
{
|
||||
struct sockaddr_un strokeaddr;
|
||||
int oldstate, fd, *fdp, strokeaddrlen = sizeof(strokeaddr);
|
||||
int fd, *fdp, strokeaddrlen = sizeof(strokeaddr);
|
||||
callback_job_t *job;
|
||||
bool oldstate;
|
||||
|
||||
/* wait for connections, but allow thread to terminate */
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
fd = accept(this->socket, (struct sockaddr *)&strokeaddr, &strokeaddrlen);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
|
||||
@@ -23,11 +23,10 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <processing/jobs/callback_job.h>
|
||||
#include <daemon.h>
|
||||
#include <threading/mutex.h> /* for Mac OS X compatible accept */
|
||||
#include <threading/thread.h>
|
||||
|
||||
#include "stroke_config.h"
|
||||
#include "stroke_control.h"
|
||||
@@ -547,13 +546,13 @@ static job_requeue_t receive(private_stroke_socket_t *this)
|
||||
struct sockaddr_un strokeaddr;
|
||||
int strokeaddrlen = sizeof(strokeaddr);
|
||||
int strokefd;
|
||||
int oldstate;
|
||||
bool oldstate;
|
||||
callback_job_t *job;
|
||||
stroke_job_context_t *ctx;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
strokefd = accept(this->socket, (struct sockaddr *)&strokeaddr, &strokeaddrlen);
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
|
||||
if (strokefd < 0)
|
||||
{
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "uci_control.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <threading/thread.h>
|
||||
#include <processing/jobs/callback_job.h>
|
||||
|
||||
#define FIFO_FILE "/var/run/charon.fifo"
|
||||
@@ -237,13 +237,14 @@ static void process(private_uci_control_t *this, char *message)
|
||||
static job_requeue_t receive(private_uci_control_t *this)
|
||||
{
|
||||
char message[128];
|
||||
int oldstate, len;
|
||||
int len;
|
||||
bool oldstate;
|
||||
FILE *in;
|
||||
|
||||
memset(message, 0, sizeof(message));
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
|
||||
oldstate = thread_cancelability(TRUE);
|
||||
in = fopen(FIFO_FILE, "r");
|
||||
pthread_setcancelstate(oldstate, NULL);
|
||||
thread_cancelability(oldstate);
|
||||
if (in)
|
||||
{
|
||||
len = fread(message, 1, sizeof(message) - 1, in);
|
||||
|
||||
Reference in New Issue
Block a user