fixes to get pid on FreeBSD

This commit is contained in:
Isaac Connor
2015-02-24 09:22:08 -05:00
parent 0bea381510
commit 3cc4c2e24d
3 changed files with 49 additions and 4 deletions

View File

@@ -31,6 +31,9 @@
#include <signal.h>
#include <stdarg.h>
#include <errno.h>
#ifdef __FreeBSD__
#include <sys/thr.h>
#endif
bool Logger::smInitialised = false;
Logger *Logger::smInstance = 0;
@@ -527,9 +530,17 @@ void Logger::logPrint( bool hex, const char * const file, const int line, const
#endif
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
if (tid < 0 ) // Thread/Process id
#else
#ifdef HAVE_SYSCALL
if ( (tid = syscall(SYS_gettid)) < 0 ) // Thread/Process id
#endif // HAVE_SYSCALL
#endif
tid = getpid(); // Process id
char *logPtr = logString;

View File

@@ -28,12 +28,26 @@
#endif // HAVE_SYS_SYSCALL_H
#include "zm_exception.h"
#include "zm_utils.h"
#ifdef __FreeBSD__
#include <sys/thr.h>
#endif
class ThreadException : public Exception
{
private:
pid_t pid() {
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
#else
tid=syscall(SYS_gettid);
#endif
return tid;
}
public:
ThreadException( const std::string &message ) : Exception( stringtf( "(%d) "+message, (long int)syscall(SYS_gettid) ) )
{
ThreadException( const std::string &message ) : Exception( stringtf( "(%d) "+message, (long int)pid() ) ) {
}
};
@@ -205,7 +219,15 @@ protected:
pid_t id() const
{
return( (pid_t)syscall(SYS_gettid) );
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
#else
tid=syscall(SYS_gettid);
#endif
return tid;
}
void exit( int status = 0 )
{

View File

@@ -32,8 +32,20 @@ class Timer
private:
class TimerException : public Exception
{
private:
pid_t pid() {
pid_t tid;
#ifdef __FreeBSD__
long lwpid;
thr_self(&lwpid);
tid = lwpid;
#else
tid=syscall(SYS_gettid);
#endif
return tid;
}
public:
TimerException( const std::string &message ) : Exception( stringtf( "(%d) "+message, (long int)syscall(SYS_gettid) ) )
TimerException( const std::string &message ) : Exception( stringtf( "(%d) "+message, (long int)pid() ) )
{
}
};