From d501459e08a7b20164ad4711bd999377f79ca8a7 Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Mon, 5 Feb 2018 17:07:23 +0100 Subject: CMake: protect replacement of COMMIT_LIST Signed-off-by: Guerra Mattia --- cmake/MacroVersionFromGit.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/MacroVersionFromGit.cmake b/cmake/MacroVersionFromGit.cmake index 05a9030..94931c6 100644 --- a/cmake/MacroVersionFromGit.cmake +++ b/cmake/MacroVersionFromGit.cmake @@ -23,12 +23,14 @@ IF (TAG_LIST AND NOT VERSION) OUTPUT_VARIABLE COMMIT_LIST OUTPUT_STRIP_TRAILING_WHITESPACE) - STRING (REPLACE "\n" ";" COMMIT_LIST ${COMMIT_LIST}) + IF (COMMIT_LIST) + STRING (REPLACE "\n" ";" COMMIT_LIST ${COMMIT_LIST}) - LIST (LENGTH COMMIT_LIST MINOR_VERSION) + LIST (LENGTH COMMIT_LIST MINOR_VERSION) - SET (DAEMONVERSION "${VERSION_MISSING_MINOR}.${MINOR_VERSION}") -ENDIF (TAG_LIST AND NOT VERSION) + SET (DAEMONVERSION "${VERSION_MISSING_MINOR}.${MINOR_VERSION}") + ENDIF (COMMIT_LIST) +ENDIF (TAGLIST AND NOT VERSION) if (NOT DAEMONVERSION) #Can be changed via passing -DVERSION="XXX" to cmake -- cgit v1.2.1 From c60d46d3f97dcf185f1716388eaa3907c2e545e5 Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Mon, 5 Feb 2018 17:15:41 +0100 Subject: AMUtil: Fixes infinite loop in dlt wrapper for out of range values of enumerations. Signed-off-by: Kapildev Patel --- AudioManagerUtilities/include/CAmDltWrapper.h | 367 +++++++++++++------------- 1 file changed, 183 insertions(+), 184 deletions(-) diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h index 8c5678e..25a62c7 100644 --- a/AudioManagerUtilities/include/CAmDltWrapper.h +++ b/AudioManagerUtilities/include/CAmDltWrapper.h @@ -29,68 +29,68 @@ #include "audiomanagertypes.h" #ifdef WITH_DLT - #include + #include #else - #include - #include - - #define DLT_USER_BUF_MAX_SIZE 2048 - - /** - * This structure is used for every context used in an application. - */ - typedef struct - { - char contextID[4]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ - int32_t log_level_user; /** any message above this log level is not logged */ - } DltContext; - - /** - * Definition of DLT trace status - */ - typedef enum - { - DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */ - DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */ - DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */ - } DltTraceStatusType; - - /** - * This structure is used for context data used in an application. - */ - typedef struct - { - DltContext *handle; /**< pointer to DltContext */ - std::stringstream buffer; /**< buffer for building log message*/ - int32_t log_level; /**< log level */ - int32_t trace_status; /**< trace status */ - int32_t args_num; /**< number of arguments for extended header*/ - uint8_t mcnt; /**< message counter */ - char* context_description; /**< description of context */ - } DltContextData; - - /** - * Definitions of DLT log level - */ - typedef enum - { - DLT_LOG_DEFAULT = -1, /**< Default log level */ - DLT_LOG_OFF = 0x00, /**< Log level off */ - DLT_LOG_FATAL = 0x01, /**< fatal system error */ - DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ - DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ - DLT_LOG_INFO = 0x04, /**< informational */ - DLT_LOG_DEBUG = 0x05, /**< debug */ - DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ - } DltLogLevelType; - - #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO - #define DLT_DECLARE_CONTEXT(CONTEXT) \ - DltContext CONTEXT; - - #define DLT_IMPORT_CONTEXT(CONTEXT) \ - extern DltContext CONTEXT; + #include + #include + + #define DLT_USER_BUF_MAX_SIZE 2048 + + /** + * This structure is used for every context used in an application. + */ + typedef struct + { + char contextID[4]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ + int32_t log_level_user; /** any message above this log level is not logged */ + } DltContext; + + /** + * Definition of DLT trace status + */ + typedef enum + { + DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */ + DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */ + DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */ + } DltTraceStatusType; + + /** + * This structure is used for context data used in an application. + */ + typedef struct + { + DltContext *handle; /**< pointer to DltContext */ + std::stringstream buffer; /**< buffer for building log message*/ + int32_t log_level; /**< log level */ + int32_t trace_status; /**< trace status */ + int32_t args_num; /**< number of arguments for extended header*/ + uint8_t mcnt; /**< message counter */ + char* context_description; /**< description of context */ + } DltContextData; + + /** + * Definitions of DLT log level + */ + typedef enum + { + DLT_LOG_DEFAULT = -1, /**< Default log level */ + DLT_LOG_OFF = 0x00, /**< Log level off */ + DLT_LOG_FATAL = 0x01, /**< fatal system error */ + DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ + DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ + DLT_LOG_INFO = 0x04, /**< informational */ + DLT_LOG_DEBUG = 0x05, /**< debug */ + DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ + } DltLogLevelType; + + #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO + #define DLT_DECLARE_CONTEXT(CONTEXT) \ + DltContext CONTEXT; + + #define DLT_IMPORT_CONTEXT(CONTEXT) \ + extern DltContext CONTEXT; #endif // WITH_DLT @@ -107,56 +107,55 @@ class CAmDltWrapper { public: - /** - * This structure is used for context data used in an application. - */ - typedef struct - { - DltContext *handle; /**< pointer to DltContext */ - std::stringstream buffer; /**< buffer for building log message*/ - int32_t log_level; /**< log level */ - int32_t trace_status; /**< trace status */ - int32_t args_num; /**< number of arguments for extended header*/ - uint8_t mcnt; /**< message counter */ - char* context_description; /**< description of context */ - } NoDltContextData; - - /* - * The eunum gives the logtype - */ - enum logDestination - { - DAEMON=0, //!< logging with the DLT daemon - COMMAND_LINE=1, //!< logging with commandline - FILE_OUT =2 //!< logging into a file - }; - - /** - * Instanciate the Dlt Wrapper - * @param appid The AppID - * @param description A description of the Application - * @param debugEnabled if set to true, debug outputs will be generated, default = true - * @param logDest the destination, the log should be written - * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT - * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false - */ - static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); + /** + * This structure is used for context data used in an application. + */ + typedef struct + { + DltContext *handle; /**< pointer to DltContext */ + std::stringstream buffer; /**< buffer for building log message*/ + int32_t log_level; /**< log level */ + int32_t trace_status; /**< trace status */ + int32_t args_num; /**< number of arguments for extended header*/ + uint8_t mcnt; /**< message counter */ + char* context_description; /**< description of context */ + } NoDltContextData; + + /* + * The eunum gives the logtype + */ + enum logDestination + { + DAEMON=0, //!< logging with the DLT daemon + COMMAND_LINE=1, //!< logging with commandline + FILE_OUT =2 //!< logging into a file + }; + + /** + * Instanciate the Dlt Wrapper + * @param appid The AppID + * @param description A description of the Application + * @param debugEnabled if set to true, debug outputs will be generated, default = true + * @param logDest the destination, the log should be written + * @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT + * @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false + */ + static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); /** * get the Wrapper Instance */ static CAmDltWrapper* instance(); - - /** - * register a context - */ + + /** + * register a context + */ void registerContext(DltContext& handle, const char *contextid, const char * description); void registerContext(DltContext& handle, const char *contextid, const char * description, const DltLogLevelType level, const DltTraceStatusType status); void unregisterContext(DltContext& handle); bool getEnabled(); ~CAmDltWrapper(); - - + bool init(DltLogLevelType loglevel, DltContext* context = NULL); bool checkLogLevel(DltLogLevelType logLevel) { @@ -186,147 +185,147 @@ public: void append(const std::vector & data); template void appendNoDLT(T value) - { - mNoDltContextData.buffer << value <<" "; - } + { + mNoDltContextData.buffer << value <<" "; + } // specialization for const char* template void append(const char* value) { - #ifdef WITH_DLT - if (mlogDestination == logDestination::DAEMON) - { - dlt_user_log_write_string(&mDltContextData, value); - } - else - { - mNoDltContextData.buffer << std::string(value); - } - #else - mNoDltContextData.buffer << std::string(value); - #endif //WITH_DLT - - } - + #ifdef WITH_DLT + if (mlogDestination == logDestination::DAEMON) + { + dlt_user_log_write_string(&mDltContextData, value); + } + else + { + mNoDltContextData.buffer << std::string(value); + } + #else + mNoDltContextData.buffer << std::string(value); + #endif //WITH_DLT + + } + private: - static const std::vector mStr_error; - static const std::vector mStr_sourceState; - static const std::vector mStr_MuteState; - static const std::vector mStr_DomainState; - static const std::vector mStr_ConnectionState; - static const std::vector mStr_Availability; - static const std::vector mStr_Interrupt; - static const std::vector mStr_Handle; - static const std::vector mStr_NotificationStatus; + static const std::vector mStr_error; + static const std::vector mStr_sourceState; + static const std::vector mStr_MuteState; + static const std::vector mStr_DomainState; + static const std::vector mStr_ConnectionState; + static const std::vector mStr_Availability; + static const std::vector mStr_Interrupt; + static const std::vector mStr_Handle; + static const std::vector mStr_NotificationStatus; public: // specialization for const am_Error_e template void append(const am_Error_e value) { - if ((int)value >=mStr_error.size()) + if (static_cast(value) >= mStr_error.size()) { - append("value for am_Error_e out of bounds!"); - append(value); - return; + append("value for am_Error_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_error[value]); + append(mStr_error[value]); } // specialization for const am_Error_e template void append(const am_SourceState_e value) { - if ((int)value >=(mStr_sourceState.size())) + if (static_cast(value) >= mStr_sourceState.size()) { - append("value for am_SourceState_e out of bounds!"); - append(value); - return; + append("value for am_SourceState_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_sourceState[value]); + append(mStr_sourceState[value]); } template void append(const am_MuteState_e value) { - if ((int)value >=mStr_MuteState.size()) + if (static_cast(value) >= mStr_MuteState.size()) { - append("value for am_MuteState_e out of bounds!"); - append(value); - return; + append("value for am_MuteState_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_MuteState[value]); + append(mStr_MuteState[value]); } template void append(const am_DomainState_e value) { - if ((int)value >= mStr_DomainState.size()) + if (static_cast(value) >= mStr_DomainState.size()) { - append("value for am_DomainState_e out of bounds!"); - append(value); - return; + append("value for am_DomainState_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_DomainState[value]); + append(mStr_DomainState[value]); } template void append(const am_ConnectionState_e value) { - if ((int)value >=mStr_ConnectionState.size()) + if (static_cast(value) >= mStr_ConnectionState.size()) { - append("value for am_ConnectionState_e out of bounds!"); - append(value); - return; + append("value for am_ConnectionState_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_ConnectionState[value]); + append(mStr_ConnectionState[value]); } template void append(const am_Availability_e value) { - if ((int)value >= mStr_Availability.size()) + if (static_cast(value) >= mStr_Availability.size()) { - append("value for am_Availability_e out of bounds!"); - append(value); - return; + append("value for am_Availability_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_Availability[value]); + append(mStr_Availability[value]); } template void append(const am_InterruptState_e value) { - if ((int)value >=mStr_Interrupt.size()) + if (static_cast(value) >= mStr_Interrupt.size()) { - append("value for am_InterruptState_e out of bounds!"); - append(value); - return; + append("value for am_InterruptState_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_Interrupt[value]); + append(mStr_Interrupt[value]); } template void append(const am_Handle_e value) { - if ((int)value >=mStr_Handle.size()) + if (static_cast(value) >= mStr_Handle.size()) { - append("value for am_Handle_e out of bounds!"); - append(value); - return; + append("value for am_Handle_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_Handle[value]); + append(mStr_Handle[value]); } template void append(const am_Handle_s value) { - append (value.handleType); - append (value.handle); + append (value.handleType); + append (value.handle); } template void append(const am_NotificationStatus_e value) { - if ((int)value >=mStr_NotificationStatus.size()) + if (static_cast(value) >= mStr_NotificationStatus.size()) { - append("value for am_NotificationStatus_e out of bounds!"); - append(value); - return; + append("value for am_NotificationStatus_e out of bounds!"); + append(static_cast(value)); + return; } - append(mStr_NotificationStatus[value]); + append(mStr_NotificationStatus[value]); } // Template to print unknown pointer types with their address @@ -354,9 +353,9 @@ public: } private: - /** - * private contructor - */ + /** + * private contructor + */ CAmDltWrapper(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); //is private because of singleton pattern bool initNoDlt(DltLogLevelType loglevel, DltContext* context); std::string now(); @@ -364,7 +363,7 @@ private: DltContextData mDltContextData; //!< contextdata NoDltContextData mNoDltContextData; //! mMapContext; //!< a Map for all registered context - bool mDebugEnabled; //!< debug Enabled or not + bool mDebugEnabled; //!< debug Enabled or not logDestination mlogDestination; //!< The log destination std::ofstream mFilename; //!< Filename for logging bool mOnlyError; //!< Only if Log Level is above Error @@ -385,14 +384,14 @@ template void log(DltContext* const context, DltLogLevelType loglevel, T value, TArgs... args) { CAmDltWrapper* inst(CAmDltWrapper::instance()); - if (!inst->getEnabled()) + if (!inst->getEnabled()) { - return; - } + return; + } if (!inst->init(loglevel, context)) { - return; - } + return; + } inst->append(value); inst->append(args...); inst->send(); -- cgit v1.2.1 From a551ce940f073a7a2afa7df104b9eabc99e9f4a2 Mon Sep 17 00:00:00 2001 From: Jens Lorenz Date: Mon, 5 Feb 2018 17:29:44 +0100 Subject: AmUtil: Check for valid timer handles to fix callback exception In case plugins remove dbus timer callbacks at runtime a race might happen between the deletion of timer and the callback invocation. Now the timer callback function checks if the timer is valid before proceeding with the restart. Signed-off-by: Kapildev Patel --- AudioManagerUtilities/src/CAmDbusWrapper.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/AudioManagerUtilities/src/CAmDbusWrapper.cpp b/AudioManagerUtilities/src/CAmDbusWrapper.cpp index 1f1d5a6..e25439c 100644 --- a/AudioManagerUtilities/src/CAmDbusWrapper.cpp +++ b/AudioManagerUtilities/src/CAmDbusWrapper.cpp @@ -176,7 +176,6 @@ void CAmDbusWrapper::registerCallback(const DBusObjectPathVTable* vtable, const std::string completePath = prefix + "/" + path; dbus_error_init(&mDBusError); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); dbus_connection_register_object_path(mpDbusConnection, completePath.c_str(), vtable, userdata); if (dbus_error_is_set(&mDBusError)) { @@ -196,7 +195,6 @@ void CAmDbusWrapper::registerSignalWatch(DBusHandleMessageFunction handler, cons { logInfo("DBusWrapper::registerSignalWatch register callback:", rule); dbus_error_init(&mDBusError); - mpDbusConnection = dbus_bus_get(mDbusType, &mDBusError); dbus_bus_add_match(mpDbusConnection, rule.c_str(), &mDBusError); dbus_connection_flush(mpDbusConnection); dbus_connection_add_filter(mpDbusConnection, handler, userdata, 0); @@ -389,8 +387,6 @@ dbus_bool_t CAmDbusWrapper::addTimeoutDelegate(DBusTimeout *timeout, void* userD //save the handle with dbus context dbus_timeout_set_data(timeout, handle, NULL); - //save timeout in Socket context - userData = timeout; return (true); } @@ -516,11 +512,19 @@ void CAmDbusWrapper::toggleTimeoutDelegate(DBusTimeout *timeout, void* userData) void CAmDbusWrapper::dbusTimerCallback(sh_timerHandle_t handle, void *userData) { assert(userData!=NULL); - if (dbus_timeout_get_enabled((DBusTimeout*) userData)) + for (auto && timerHandle : mpListTimerhandles) { - mpSocketHandler->restartTimer(handle); + if (*timerHandle == handle) + { + if (dbus_timeout_get_enabled((DBusTimeout*) userData)) + { + mpSocketHandler->restartTimer(handle); + } + dbus_timeout_handle((DBusTimeout*) userData); + return; + } } - dbus_timeout_handle((DBusTimeout*) userData); + logWarning("CAmDbusWrapper::dbusTimerCallback Unknown timer handle"); } } -- cgit v1.2.1