Move SCSetThreadName to proper functions.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 9f35a24a1f
commit eeb98c6900

@ -111,6 +111,9 @@
/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
/* Define to 1 if you have the <sys/prctl.h> header file. */
#undef HAVE_SYS_PRCTL_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H

@ -174,7 +174,6 @@ TmEcode AlertDebugLogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq
TmEcode AlertDebugLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
if (PKT_IS_IPV4(p)) {
return AlertDebugLogIPv4(tv, p, data, pq);
} else if (PKT_IS_IPV6(p)) {

@ -182,7 +182,6 @@ TmEcode AlertFastLogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
TmEcode AlertFastLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
if (PKT_IS_IPV4(p)) {
return AlertFastLogIPv4(tv, p, data, pq);
} else if (PKT_IS_IPV6(p)) {

@ -607,7 +607,6 @@ static int EventToReference(PacketAlert *pa, Packet *p, idmef_classification_t *
*/
TmEcode AlertPrelude (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
AlertPreludeThread *apn = (AlertPreludeThread *)data;
uint8_t ethh_offset = 0;
int ret;

@ -174,7 +174,6 @@ int AlertUnifiedAlertRotateFile(ThreadVars *t, AlertUnifiedAlertThread *aun) {
TmEcode AlertUnifiedAlert (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
AlertUnifiedAlertThread *aun = (AlertUnifiedAlertThread *)data;
AlertUnifiedAlertPacketHeader hdr;

@ -172,7 +172,6 @@ int AlertUnifiedLogRotateFile(ThreadVars *t, AlertUnifiedLogThread *aun) {
TmEcode AlertUnifiedLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
AlertUnifiedLogThread *aun = (AlertUnifiedLogThread *)data;
AlertUnifiedLogPacketHeader hdr;
int ret;

@ -183,7 +183,6 @@ int Unified2AlertRotateFile(ThreadVars *t, Unified2AlertThread *aun) {
TmEcode Unified2Alert (ThreadVars *t, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(t->name);
int ret = 0;
if(PKT_IS_IPV4(p)) {

@ -141,10 +141,12 @@ static void SCPerfReleaseOPCtx()
static void *SCPerfMgmtThread(void *arg)
{
ThreadVars *tv_local = (ThreadVars *)arg;
SCSetThreadName(tv_local->name);
uint8_t run = 1;
struct timespec cond_time;
/* Set the thread name */
SCSetThreadName(tv_local->name);
if (sc_perf_op_ctx == NULL) {
SCLogError(SC_ERR_PERF_STATS_NOT_INIT, "Perf Counter API not init"
"SCPerfInitCounterApi() has to be called first");
@ -184,12 +186,14 @@ static void *SCPerfMgmtThread(void *arg)
static void *SCPerfWakeupThread(void *arg)
{
ThreadVars *tv_local = (ThreadVars *)arg;
SCSetThreadName(tv_local->name);
uint8_t run = 1;
ThreadVars *tv = NULL;
PacketQueue *q = NULL;
struct timespec cond_time;
/* Set the thread name */
SCSetThreadName(tv_local->name);
if (sc_perf_op_ctx == NULL) {
SCLogError(SC_ERR_PERF_STATS_NOT_INIT, "Perf Counter API not init"
"SCPerfInitCounterApi() has to be called first");

@ -807,9 +807,7 @@ end:
*/
TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
/*No need to perform any detection on this packet, if the the given flag is set.*/
/* No need to perform any detection on this packet, if the the given flag is set.*/
if (p->flags & PKT_NOPACKET_INSPECTION)
return 0;

@ -639,7 +639,6 @@ void FlowShutdown(void) {
void *FlowManagerThread(void *td)
{
ThreadVars *th_v = (ThreadVars *)td;
SCSetThreadName(th_v->name);
struct timeval ts;
struct timeval tsdiff;
uint32_t established_cnt = 0, new_cnt = 0, closing_cnt = 0, nowcnt;
@ -648,6 +647,8 @@ void *FlowManagerThread(void *td)
memset(&ts, 0, sizeof(ts));
/* set the thread name */
SCSetThreadName(th_v->name);
SCLogDebug("%s started...", th_v->name);
TmThreadsSetFlag(th_v, THV_INIT_DONE);

@ -306,7 +306,6 @@ end:
TmEcode LogHttpLog (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCEnter();
SCSetThreadName(tv->name);
/* no flow, no htp state */
if (p->flow == NULL) {

@ -40,8 +40,6 @@ void TmModuleRespondRejectRegister (void) {
}
TmEcode RespondRejectFunc(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
int ret = 0;
/* ACTION_REJECT defaults to rejecting the SRC */

@ -163,7 +163,6 @@ void TmModuleDecodeIPFWRegister (void) {
* \retval TM_ECODE_FAILED on failure and TM_ECODE_OK on success
*/
TmEcode ReceiveIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
IPFWThreadVars *ptv = (IPFWThreadVars *)data;
char pkt[IP_MAXPACKET];
int pktlen=0;
@ -386,7 +385,6 @@ TmEcode ReceiveIPFWThreadDeinit(ThreadVars *tv, void *data) {
*/
TmEcode DecodeIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
IPV4Hdr *ip4h = (IPV4Hdr *)p->pkt;
IPV6Hdr *ip6h = (IPV6Hdr *)p->pkt;
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
@ -523,7 +521,6 @@ TmEcode IPFWSetVerdict(ThreadVars *tv, IPFWThreadVars *ptv, Packet *p) {
* \param pq pointer for the Packet Queue access (Not used)
*/
TmEcode VerdictIPFW(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
IPFWThreadVars *ptv = (IPFWThreadVars *)data;
TmEcode retval = TM_ECODE_OK;

@ -385,7 +385,6 @@ void NFQRecvPkt(NFQThreadVars *t) {
}
TmEcode ReceiveNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
NFQThreadVars *ntv = (NFQThreadVars *)data;
//printf("%p receiving on queue %" PRIu32 "\n", ntv, ntv->queue_num);
@ -448,7 +447,6 @@ void NFQSetVerdict(NFQThreadVars *t, Packet *p) {
}
TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
NFQThreadVars *ntv = (NFQThreadVars *)data;
/* if this is a tunnel packet we check if we are ready to verdict
@ -488,7 +486,6 @@ TmEcode VerdictNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
*/
TmEcode DecodeNFQ(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
IPV4Hdr *ip4h = (IPV4Hdr *)p->pkt;
IPV6Hdr *ip6h = (IPV6Hdr *)p->pkt;
DecodeThreadVars *dtv = (DecodeThreadVars *)data;

@ -111,7 +111,6 @@ void PcapFileCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
*/
TmEcode ReceivePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCEnter();
SCSetThreadName(tv->name);
PcapFileThreadVars *ptv = (PcapFileThreadVars *)data;
ptv->in_p = p;
@ -223,7 +222,6 @@ TmEcode ReceivePcapFileThreadDeinit(ThreadVars *tv, void *data) {
TmEcode DecodePcapFile(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCEnter();
SCSetThreadName(tv->name);
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
/* update counters */

@ -128,7 +128,6 @@ void PcapCallback(char *user, struct pcap_pkthdr *h, u_char *pkt) {
*/
TmEcode ReceivePcap(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCEnter();
SCSetThreadName(tv->name);
PcapThreadVars *ptv = (PcapThreadVars *)data;
/* Just read one packet at a time for now. */
@ -364,7 +363,6 @@ TmEcode ReceivePcapThreadDeinit(ThreadVars *tv, void *data) {
TmEcode DecodePcap(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCEnter();
SCSetThreadName(tv->name);
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
/* update counters */

@ -164,7 +164,6 @@ void PfringProcessPacket(void *user, struct pfring_pkthdr *h, u_char *pkt, Packe
* \retval TM_ECODE_FAILED on failure
*/
TmEcode ReceivePfring(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq) {
SCSetThreadName(tv->name);
PfringThreadVars *ptv = (PfringThreadVars *)data;
struct pfring_pkthdr hdr;
@ -324,7 +323,6 @@ TmEcode ReceivePfringThreadDeinit(ThreadVars *tv, void *data) {
*/
TmEcode DecodePfring(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
DecodeThreadVars *dtv = (DecodeThreadVars *)data;
/* update counters */

@ -2535,7 +2535,6 @@ static int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt)
TmEcode StreamTcp (ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
{
SCSetThreadName(tv->name);
StreamTcpThread *stt = (StreamTcpThread *)data;
TmEcode ret = TM_ECODE_OK;

@ -37,6 +37,7 @@
#include <sys/prctl.h>
#define THREAD_NAME_LEN 16
#endif
#define PRIO_LOW 2
#define PRIO_MEDIUM 0
#define PRIO_HIGH -2
@ -323,19 +324,29 @@
#define SCSpinDestroy(spin) pthread_spin_destroy(spin)
#endif /* DBG_THREADS */
#ifdef OS_FREEBSD
/* TODO Add implementation for FreeBSD */
#elif OS_WIN32
/* TODO Add implementation for Windows */
#elif OS_DARWIN
/* TODO Add implementation for MacOS */
#else
/*
* OS specific macro's for setting the thread name. "top" can display
* this name.
*/
#ifdef OS_FREEBSD /* FreeBSD */
/** \todo Add implementation for FreeBSD */
#define SCSetThreadName(n)
#elif OS_WIN32 /* Windows */
/** \todo Add implementation for Windows */
#define SCSetThreadName(n)
#elif OS_DARWIN /* Mac OS X */
/** \todo Add implementation for MacOS */
#define SCSetThreadName(n)
#else /* Linux */
/**
* \brief Set the threads name
*/
#define SCSetThreadName(n) ({ \
char tname[THREAD_NAME_LEN + 1] = {'\0'}; \
char tname[THREAD_NAME_LEN + 1] = ""; \
if (strlen(n) > THREAD_NAME_LEN) \
SCLogDebug("Thread name is too long, truncating it..."); \
strncpy(tname, n, THREAD_NAME_LEN); \
int ret; \
strlcpy(tname, n, THREAD_NAME_LEN); \
int ret = 0; \
if ((ret = prctl(PR_SET_NAME, tname, 0, 0, 0)) < 0) \
SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \
ret; \
@ -343,5 +354,6 @@
#endif
void ThreadMacrosRegisterTests(void);
#endif /* __THREADS_H__ */

@ -118,6 +118,9 @@ void *TmThreadsSlot1NoIn(void *td) {
char run = 1;
TmEcode r = TM_ECODE_OK;
/* Set the thread name */
SCSetThreadName(tv->name);
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
@ -182,6 +185,9 @@ void *TmThreadsSlot1NoOut(void *td) {
char run = 1;
TmEcode r = TM_ECODE_OK;
/* Set the thread name */
SCSetThreadName(tv->name);
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
@ -239,6 +245,9 @@ void *TmThreadsSlot1NoInOut(void *td) {
char run = 1;
TmEcode r = TM_ECODE_OK;
/* Set the thread name */
SCSetThreadName(tv->name);
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
@ -300,6 +309,9 @@ void *TmThreadsSlot1(void *td) {
char run = 1;
TmEcode r = TM_ECODE_OK;
/* Set the thread name */
SCSetThreadName(tv->name);
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
@ -417,6 +429,9 @@ void *TmThreadsSlotVar(void *td) {
TmEcode r = TM_ECODE_OK;
TmSlot *slot = NULL;
/* Set the thread name */
SCSetThreadName(tv->name);
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);

Loading…
Cancel
Save