From ad85c15f07f4e92831e7c41ba5576cc1d02dfe79 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sun, 10 Jul 2016 22:33:23 -0700 Subject: [PATCH] Initial tweaks for RTEMS support, though linking is still a work in progress. --- config.h.in | 3 +++ configure | 13 +++++++++++++ configure.ac | 1 + src/core/platform.h | 22 ++++++++++++++-------- src/core/sha.cpp | 5 ++++- src/core/unixfsservices.cpp | 15 ++++++++++++--- src/db/hierdatabase.h | 5 +++++ src/fco/fcodatasourceiter.cpp | 4 ++++ src/fco/genreswitcher.cpp | 4 ++++ src/siggen/siggencmdline.cpp | 6 ++++-- src/tripwire/smtpmailmessage.cpp | 12 ++++++++++-- src/tw/twinit.cpp | 6 ++++++ src/tw/twutil.cpp | 18 +++++++++++++++--- 13 files changed, 95 insertions(+), 19 deletions(-) diff --git a/config.h.in b/config.h.in index 444d5e6..387a1cd 100644 --- a/config.h.in +++ b/config.h.in @@ -114,6 +114,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_USTAT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/configure b/configure index 0466062..b42dc6b 100755 --- a/configure +++ b/configure @@ -5733,6 +5733,19 @@ fi done +for ac_header in sys/utsname.h memory.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + for ac_header in sys/fs/vx_ioctl.h do : ac_fn_c_check_header_mongrel "$LINENO" "sys/fs/vx_ioctl.h" "ac_cv_header_sys_fs_vx_ioctl_h" "$ac_includes_default" diff --git a/configure.ac b/configure.ac index 3ef15af..bc70fc1 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,7 @@ AC_CHECK_HEADERS(sys/ustat.h sys/sysmacros.h sys/syslog.h sys/socket.h) AC_CHECK_HEADERS(unistd.h syslog.h langinfo.h sys/statfs.h sys/select.h) AC_CHECK_HEADERS(signum.h bits/signum.h, break ) AC_CHECK_HEADERS(stdarg.h varargs.h, break ) +AC_CHECK_HEADERS(sys/utsname.h memory.h) AC_CHECK_HEADERS(sys/fs/vx_ioctl.h) dnl # Special case for malloc.h, because it's depreciated on most systems. diff --git a/src/core/platform.h b/src/core/platform.h index 4fbe137..4d36dd4 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -78,8 +78,8 @@ #define OS_SKYOS 0x0505 #define OS_SORTIX 0x0506 #define OS_MINT 0x0507 -#define OS_AROS 0x0506 - +#define OS_AROS 0x0508 +#define OS_RTEMS 0x0509 #define COMP_UNKNOWN 0 #define COMP_GCC 0x0001 @@ -196,20 +196,24 @@ #elif defined(SKYOS) #define OS OS_SKYOS - #define IS_SKYOS 1 + #define IS_SKYOS 1 #elif defined(_SORTIX_SOURCE) - #define OS OS_SORTIX - #define IS_SORTIX 1 + #define OS OS_SORTIX + #define IS_SORTIX 1 #elif defined(__MINT__) #define OS OS_MINT - #define IS_MINT 1 + #define IS_MINT 1 #elif defined(__AROS__) #define OS OS_AROS #define IS_AROS 1 +#elif defined(__rtems__) + #define OS OS_RTEMS + #define IS_RTEMS 1 + #else // OK for OS not to resolve, it's being phased out. // #error Unknown OS @@ -301,8 +305,10 @@ #define USES_MBLEN (!IS_ANDROID && !IS_AROS) #define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP) #define ICONV_CONST_SOURCE (IS_MINIX) -#define SUPPORTS_DIRECT_IO (IS_LINUX) // Others may work, but only tested & verified on Linux so far. - +#define SUPPORTS_DIRECT_IO (IS_LINUX) +// Linux is the only platform where direct i/o hashing has been tested & works properly so far. +#define SUPPORTS_TERMIOS (!IS_RTEMS) +// RTEMS errors are probably just a buildsys issue & this will change or go away. //============================================================================= diff --git a/src/core/sha.cpp b/src/core/sha.cpp index bf3f104..b58a4a0 100644 --- a/src/core/sha.cpp +++ b/src/core/sha.cpp @@ -64,7 +64,10 @@ #include "stdcore.h" #include #include -#include + +#if HAVE_MEMORY_H +# include +#endif #include "sha.h" diff --git a/src/core/unixfsservices.cpp b/src/core/unixfsservices.cpp index 76b9d13..aafde75 100644 --- a/src/core/unixfsservices.cpp +++ b/src/core/unixfsservices.cpp @@ -70,7 +70,11 @@ #ifdef HAVE_SYS_SYSMACROS_H # include #endif -#include + +#if HAVE_SYS_UTSNAME_H +# include +#endif + #include #if HAVE_SYS_SOCKET_H @@ -397,15 +401,20 @@ void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const th void cUnixFSServices::GetMachineName( TSTRING& strName ) const throw( eFSServices ) { +#if HAVE_SYS_UTSNAME_H struct utsname namebuf; if( uname( &namebuf ) == -1 ) throw eFSServicesGeneric( strName ); else strName = namebuf.nodename; +#else + strName = "localhost"; +#endif } void cUnixFSServices::GetMachineNameFullyQualified( TSTRING& strName ) const { +#if HAVE_SYS_UTSNAME_H char buf[256]; if (gethostname(buf, 256) != 0) { @@ -423,7 +432,7 @@ void cUnixFSServices::GetMachineNameFullyQualified( TSTRING& strName ) const } #endif } - +#endif try { cUnixFSServices::GetMachineName(strName); @@ -464,7 +473,7 @@ bool cUnixFSServices::GetIPAddress( uint32& uiIPAddress ) bool fGotAddress = false; cDebug d( _T("cUnixFSServices::GetIPAddress") ); -#if SUPPORTS_NETWORKING +#if SUPPORTS_NETWORKING && HAVE_SYS_UTSNAME_H struct utsname utsnameBuf; if( EFAULT != uname( &utsnameBuf) ) { diff --git a/src/db/hierdatabase.h b/src/db/hierdatabase.h index a2f8413..54d335f 100644 --- a/src/db/hierdatabase.h +++ b/src/db/hierdatabase.h @@ -49,6 +49,11 @@ #include "hierdbpath.h" #endif +#if HAVE_STRINGS_H // RTEMS needs this for strcasecmp +# include +#endif + + class cHierDatabaseIter; class cErrorBucket; diff --git a/src/fco/fcodatasourceiter.cpp b/src/fco/fcodatasourceiter.cpp index cdf64b2..ce9d68f 100644 --- a/src/fco/fcodatasourceiter.cpp +++ b/src/fco/fcodatasourceiter.cpp @@ -40,6 +40,10 @@ #include "stdfco.h" #include "fcodatasourceiter.h" +#if HAVE_STRINGS_H // for strcasecmp on RTEMS +# include +#endif + //========================================================================= // METHOD CODE //========================================================================= diff --git a/src/fco/genreswitcher.cpp b/src/fco/genreswitcher.cpp index 594c26a..d1e5796 100644 --- a/src/fco/genreswitcher.cpp +++ b/src/fco/genreswitcher.cpp @@ -43,6 +43,10 @@ #include "genreinfo.h" #include "core/errorutil.h" +#if HAVE_STRINGS_H // for strcasecmp on RTEMS +# include +#endif + //========================================================================= // STATIC MEMBERS //========================================================================= diff --git a/src/siggen/siggencmdline.cpp b/src/siggen/siggencmdline.cpp index 27767b1..347f87c 100644 --- a/src/siggen/siggencmdline.cpp +++ b/src/siggen/siggencmdline.cpp @@ -50,8 +50,10 @@ #if IS_UNIX #include #include -#include -#include +#if SUPPORTS_TERMIOS +# include +# include +#endif //#include int _getch(void); #endif diff --git a/src/tripwire/smtpmailmessage.cpp b/src/tripwire/smtpmailmessage.cpp index 046735c..4a9ee5e 100644 --- a/src/tripwire/smtpmailmessage.cpp +++ b/src/tripwire/smtpmailmessage.cpp @@ -54,7 +54,10 @@ #endif #include #include -#include + +#if HAVE_SYS_UTSNAME_H +# include +#endif #if HAVE_SYS_SELECT_H # include @@ -82,7 +85,8 @@ static int gethostname( char* name, int namelen ) { name[0] = '\0'; - + +#if HAVE_SYS_UTSNAME_H struct utsname myname; uname( & myname ); @@ -97,6 +101,10 @@ static int gethostname( char* name, int namelen ) return -1; // equivalent of SOCKET_ERROR } +#else + strncpy(name, "localhost", namelen); +#endif + } #endif // Unix does not require us to go though any silly DLL hoops, so we'll diff --git a/src/tw/twinit.cpp b/src/tw/twinit.cpp index f3a057e..99e2947 100644 --- a/src/tw/twinit.cpp +++ b/src/tw/twinit.cpp @@ -308,8 +308,14 @@ void cTWInit::Init( const TSTRING& strArgv0 ) tw_HandleSignal( SIGSYS ); // Bad system call. #endif tw_HandleSignal( SIGFPE ); // Floating point exception. + +#ifdef SIGXCPU tw_HandleSignal( SIGXCPU ); // CPU time exceeded. Might very well be an issue for us. +#endif + +#ifdef SIGXFSZ tw_HandleSignal( SIGXFSZ ); // File size limit exceeded. +#endif #endif diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index c6979ba..4172aaa 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -74,8 +74,11 @@ #if IS_UNIX #include #include -#include -#include +#if SUPPORTS_TERMIOS +# include +# include +#endif + #include "core/tw_signal.h" int _getch(void); #endif @@ -1118,10 +1121,15 @@ void cTWUtil::CreatePrivateKey(cPrivateKeyProxy& proxy, cKeyFile& keyFile, const #if IS_UNIX static void (*old_SIGINT)(int); static void (*old_SIGQUIT)(int); + +#if SUPPORTS_TERMIOS static struct termios Otty; +#endif + static void RestoreEcho(int sig) { +#if SUPPORTS_TERMIOS #ifdef _DEBUG std::cout << "Caught signal, resetting echo."<< std::endl; sleep(2); @@ -1130,7 +1138,7 @@ static void RestoreEcho(int sig) tcsetattr( 0, TCSAFLUSH, &Otty); tw_signal(SIGINT, old_SIGINT); tw_signal(SIGQUIT, old_SIGQUIT); - +#endif tw_raise(sig); } @@ -1173,6 +1181,7 @@ void cTWUtil::GetString(wc16_string& ret) cTWUtil::NoEcho::NoEcho() { +#if SUPPORTS_TERMIOS // set the terminal to no echo mode static struct termios Ntty; @@ -1190,13 +1199,16 @@ cTWUtil::NoEcho::NoEcho() { ThrowAndAssert(eTWUtilEchoModeSet()); } +#endif } cTWUtil::NoEcho::~NoEcho() { +#if SUPPORTS_TERMIOS tcsetattr( 0, TCSAFLUSH, &Otty); tw_signal(SIGINT, old_SIGINT); tw_signal(SIGQUIT, old_SIGQUIT); +#endif } void cTWUtil::GetStringNoEcho(wc16_string& ret)