diff --git a/common/consumer_state_table_pops.lua b/common/consumer_state_table_pops.lua index b5dcbe7d4..150f1a16b 100644 --- a/common/consumer_state_table_pops.lua +++ b/common/consumer_state_table_pops.lua @@ -6,16 +6,20 @@ local keys = redis.call('SPOP', KEYS[1], ARGV[1]) local n = table.getn(keys) for i = 1, n do local key = keys[i] + local fieldvalues = {} -- Check if there was request to delete the key, clear it in table first local num = redis.call('SREM', KEYS[3], key) if num == 1 then redis.call('DEL', tablename..key) + table.insert(ret, {key, fieldvalues}) end -- Push the new set of field/value for this key in table local fieldvalues = redis.call('HGETALL', stateprefix..tablename..key) - table.insert(ret, {key, fieldvalues}) - for i = 1, #fieldvalues, 2 do - redis.call('HSET', tablename..key, fieldvalues[i], fieldvalues[i + 1]) + if table.getn(fieldvalues) > 0 then + table.insert(ret, {key, fieldvalues}) + for i = 1, #fieldvalues, 2 do + redis.call('HSET', tablename..key, fieldvalues[i], fieldvalues[i + 1]) + end end -- Clean up the key in temporary state table redis.call('DEL', stateprefix..tablename..key) diff --git a/common/logger.cpp b/common/logger.cpp index b27cbed93..f52e9da49 100644 --- a/common/logger.cpp +++ b/common/logger.cpp @@ -231,34 +231,50 @@ void Logger::settingThread() SWSS_LOG_DEBUG("%s select timeout", __PRETTY_FUNCTION__); continue; } - - KeyOpFieldsValuesTuple koValues; - dynamic_cast(selectable)->pop(koValues); - std::string key = kfvKey(koValues), op = kfvOp(koValues); - - if (op != SET_COMMAND || !m_settingChangeObservers.contains(key)) + /*CID 37420 FORWARD_NULL, PeterWang, 2023/6/14*/ + if (selectable==nullptr) { continue; } - - const auto& values = kfvFieldsValues(koValues); - - for (auto& i : values) + else { - auto& field = fvField(i); - auto& value = fvValue(i); - - if ((field == DAEMON_LOGLEVEL) && (value != m_currentPrios.get(key))) + KeyOpFieldsValuesTuple koValues; + /*CID 37420 FORWARD_NULL, PeterWang, 2023/7/7*/ + ConsumerStateTable* consumerTable = dynamic_cast(selectable); + if (consumerTable == nullptr) { - m_currentPrios.set(key, value); - m_settingChangeObservers.get(key).first(key, value); + continue; } - else if ((field == DAEMON_LOGOUTPUT) && (value != m_currentOutputs.get(key))) + else { - m_currentOutputs.set(key, value); - m_settingChangeObservers.get(key).second(key, value); - } - } + consumerTable->pop(koValues); + std::string key = kfvKey(koValues), op = kfvOp(koValues); + + if (op != SET_COMMAND || !m_settingChangeObservers.contains(key)) + { + continue; + } + + const auto& values = kfvFieldsValues(koValues); + + for (auto& i : values) + { + auto& field = fvField(i); + auto& value = fvValue(i); + + if ((field == DAEMON_LOGLEVEL) && (value != m_currentPrios.get(key))) + { + m_currentPrios.set(key, value); + m_settingChangeObservers.get(key).first(key, value); + } + else if ((field == DAEMON_LOGOUTPUT) && (value != m_currentOutputs.get(key))) + { + m_currentOutputs.set(key, value); + m_settingChangeObservers.get(key).second(key, value); + } + } + } + } } } diff --git a/common/loglevel.cpp b/common/loglevel.cpp index 1be85c099..41a9f0147 100644 --- a/common/loglevel.cpp +++ b/common/loglevel.cpp @@ -106,92 +106,109 @@ int main(int argc, char **argv) } } - DBConnector db("LOGLEVEL_DB", 0); - auto keys = db.keys("*"); - for (auto& key : keys) + /*CID 38520 UNCAUGHT_EXCEPT, PeterWang, 2023/6/14*/ + try { - size_t colonPos = key.find(':'); - if (colonPos == std::string::npos) + DBConnector db("LOGLEVEL_DB", 0); + auto keys = db.keys("*"); + for (auto& key : keys) { - continue; + size_t colonPos = key.find(':'); + if (colonPos == std::string::npos) + { + continue; + } + key = key.substr(0, colonPos); } + // Ignore autogenerated keysets + keys.erase(std::remove_if(keys.begin(), keys.end(), filterOutKeysets), keys.end()); - key = key.substr(0, colonPos); - } - // Ignore autogenerated keysets - keys.erase(std::remove_if(keys.begin(), keys.end(), filterOutKeysets), keys.end()); - - if (print) - { - int errorCount = 0; - - if (argc != 2) + if (print) { - exitWithUsage(EXIT_FAILURE, "-p option does not accept other options"); - } + int errorCount = 0; - std::sort(keys.begin(), keys.end()); - for (const auto& key : keys) - { - const auto redis_key = std::string(key).append(":").append(key); - auto level = db.hget(redis_key, DAEMON_LOGLEVEL); - if (nullptr == level) + if (argc != 2) { - std::cerr << std::left << std::setw(30) << key << "Unknown log level" << std::endl; - errorCount ++; + exitWithUsage(EXIT_FAILURE, "-p option does not accept other options"); } - else + + std::sort(keys.begin(), keys.end()); + for (const auto& key : keys) { - std::cout << std::left << std::setw(30) << key << *level << std::endl; + const auto redis_key = std::string(key).append(":").append(key); + /*CID 323404 UNCAUGHT_EXCEPT, PeterWang, 2023/6/14*/ + try + { + auto level = db.hget(redis_key, DAEMON_LOGLEVEL); + if (nullptr == level) + { + std::cerr << std::left << std::setw(30) << key << "Unknown log level" << std::endl; + errorCount ++; + } + else + { + std::cout << std::left << std::setw(30) << key << *level << std::endl; + } + + } + catch (const std::exception& e) + { + std::cout << "db.hget error " << std::endl; + } } - } - if (errorCount > 0) - return (EXIT_FAILURE); - - return (EXIT_SUCCESS); - } + if (errorCount > 0) + return (EXIT_FAILURE); - if ((prefix == "SAI_API_") && !validateSaiLoglevel(loglevel)) - { - exitWithUsage(EXIT_FAILURE, "Invalid SAI loglevel value"); - } - else if ((prefix == "") && (Logger::priorityStringMap.find(loglevel) == Logger::priorityStringMap.end())) - { - exitWithUsage(EXIT_FAILURE, "Invalid loglevel value"); - } + return (EXIT_SUCCESS); + } - if (applyToAll) - { - if (component != "") + if ((prefix == "SAI_API_") && !validateSaiLoglevel(loglevel)) { - exitWithUsage(EXIT_FAILURE, "Invalid options provided with -a"); + exitWithUsage(EXIT_FAILURE, "Invalid SAI loglevel value"); } - if (prefix == "SAI_API_") + else if ((prefix == "") && (Logger::priorityStringMap.find(loglevel) == Logger::priorityStringMap.end())) { - keys.erase(std::remove_if(keys.begin(), keys.end(), filterSaiKeys), keys.end()); + exitWithUsage(EXIT_FAILURE, "Invalid loglevel value"); } - else + + if (applyToAll) { - keys.erase(std::remove_if(keys.begin(), keys.end(), filterOutSaiKeys), keys.end()); + if (component != "") + { + exitWithUsage(EXIT_FAILURE, "Invalid options provided with -a"); + } + + if (prefix == "SAI_API_") + { + keys.erase(std::remove_if(keys.begin(), keys.end(), filterSaiKeys), keys.end()); + } + else + { + keys.erase(std::remove_if(keys.begin(), keys.end(), filterOutSaiKeys), keys.end()); + } + + for (const auto& key : keys) + { + setLoglevel(db, key, loglevel); + } + + exit(EXIT_SUCCESS); } - for (const auto& key : keys) + component = prefix + component; + if (std::find(std::begin(keys), std::end(keys), component) == keys.end()) { - setLoglevel(db, key, loglevel); + exitWithUsage(EXIT_FAILURE, "Component not present in DB"); } - exit(EXIT_SUCCESS); + setLoglevel(db, component, loglevel); + return EXIT_SUCCESS; } - component = prefix + component; - if (std::find(std::begin(keys), std::end(keys), component) == keys.end()) + catch (const std::exception& e) { - exitWithUsage(EXIT_FAILURE, "Component not present in DB"); + std::cout << "db get key error " << std::endl; } - - setLoglevel(db, component, loglevel); - - return EXIT_SUCCESS; } diff --git a/common/netdispatcher.cpp b/common/netdispatcher.cpp index e7f8878ad..008d26ce4 100644 --- a/common/netdispatcher.cpp +++ b/common/netdispatcher.cpp @@ -63,5 +63,9 @@ void NetDispatcher::onNetlinkMessage(struct nl_msg *msg) if (callback == nullptr) return; - nl_msg_parse(msg, NetDispatcher::nlCallback, (callback)); + /*CID 38551 CHECKED_RETURN, PeterWang, 2023/6/14*/ + if(nl_msg_parse(msg, NetDispatcher::nlCallback, (callback))<0) + { + throw "Unknown message type(RTM_NEWLINK)"; + } }