clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: I9ff64598516b419af832abda0fce295f722f6969
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index d43e884..28e3328 100644
--- a/.clang-format
+++ b/.clang-format
@@ -87,7 +87,7 @@
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: false
-LambdaBodyIndentation: OuterScope
+LambdaBodyIndentation: Signature
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
@@ -98,13 +98,14 @@
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 25
-PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakBeforeFirstCallParameter: 50
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
-PenaltyIndentedWhitespace: 0
+PenaltyIndentedWhitespace: 1
PointerAlignment: Left
QualifierAlignment: Left
ReferenceAlignment: Left
diff --git a/src/main.cpp b/src/main.cpp
index 84c15e4..ff72874 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -89,8 +89,8 @@
auto instancePos = fullUnitName.rfind("@");
if (instancePos != std::string::npos)
{
- instanceName = fullUnitName.substr(instancePos + 1,
- typePos - instancePos - 1);
+ instanceName =
+ fullUnitName.substr(instancePos + 1, typePos - instancePos - 1);
unitName = fullUnitName.substr(0, instancePos);
}
else
@@ -101,11 +101,11 @@
return std::make_tuple(unitName, type, instanceName);
}
-static inline void
- handleListUnitsResponse(sdbusplus::asio::object_server& server,
- std::shared_ptr<sdbusplus::asio::connection>& conn,
- boost::system::error_code /*ec*/,
- const std::vector<ListUnitsType>& listUnits)
+static inline void handleListUnitsResponse(
+ sdbusplus::asio::object_server& server,
+ std::shared_ptr<sdbusplus::asio::connection>& conn,
+ boost::system::error_code /*ec*/,
+ const std::vector<ListUnitsType>& listUnits)
{
// Loop through all units, and mark all units, which has to be
// managed, irrespective of instance name.
@@ -261,14 +261,14 @@
conn->async_method_call(
[&server, &conn](boost::system::error_code ec,
const std::vector<ListUnitsType>& listUnits) {
- if (ec)
- {
- lg2::error("async_method_call error: ListUnits failed: {EC}", "EC",
- ec.value());
- return;
- }
- handleListUnitsResponse(server, conn, ec, listUnits);
- },
+ if (ec)
+ {
+ lg2::error("async_method_call error: ListUnits failed: {EC}",
+ "EC", ec.value());
+ return;
+ }
+ handleListUnitsResponse(server, conn, ec, listUnits);
+ },
sysdService, sysdObjPath, sysdMgrIntf, "ListUnits");
}
@@ -279,46 +279,46 @@
conn->async_method_call(
[&server, &conn](boost::system::error_code ec,
const std::variant<uint64_t>& value) {
- if (ec)
- {
- lg2::error("async_method_call error: ListUnits failed: {EC}", "EC",
- ec.value());
- return;
- }
- if (std::get<uint64_t>(value))
- {
- if (!unitQueryStarted)
+ if (ec)
{
- unitQueryStarted = true;
- init(server, conn);
+ lg2::error("async_method_call error: ListUnits failed: {EC}",
+ "EC", ec.value());
+ return;
}
- }
- else
- {
- // FIX-ME: Latest up-stream sync caused issue in receiving
- // StartupFinished signal. Unable to get StartupFinished signal
- // from systemd1 hence using poll method too, to trigger it
- // properly.
- constexpr size_t pollTimeout = 10; // seconds
- initTimer->expires_after(std::chrono::seconds(pollTimeout));
- initTimer->async_wait(
- [&server, &conn](const boost::system::error_code& ec) {
- if (ec == boost::asio::error::operation_aborted)
+ if (std::get<uint64_t>(value))
+ {
+ if (!unitQueryStarted)
{
- // Timer reset.
- return;
+ unitQueryStarted = true;
+ init(server, conn);
}
- if (ec)
- {
- lg2::error(
- "service config mgr - init - async wait error: {EC}",
- "EC", ec.value());
- return;
- }
- checkAndInit(server, conn);
- });
- }
- },
+ }
+ else
+ {
+ // FIX-ME: Latest up-stream sync caused issue in receiving
+ // StartupFinished signal. Unable to get StartupFinished signal
+ // from systemd1 hence using poll method too, to trigger it
+ // properly.
+ constexpr size_t pollTimeout = 10; // seconds
+ initTimer->expires_after(std::chrono::seconds(pollTimeout));
+ initTimer->async_wait([&server, &conn](
+ const boost::system::error_code& ec) {
+ if (ec == boost::asio::error::operation_aborted)
+ {
+ // Timer reset.
+ return;
+ }
+ if (ec)
+ {
+ lg2::error(
+ "service config mgr - init - async wait error: {EC}",
+ "EC", ec.value());
+ return;
+ }
+ checkAndInit(server, conn);
+ });
+ }
+ },
sysdService, sysdObjPath, dBusPropIntf, dBusGetMethod, sysdMgrIntf,
"FinishTimestamp");
}
@@ -339,12 +339,12 @@
"member='StartupFinished',path='/org/freedesktop/systemd1',"
"interface='org.freedesktop.systemd1.Manager'",
[&server, &conn](sdbusplus::message_t& /*msg*/) {
- if (!unitQueryStarted)
- {
- unitQueryStarted = true;
- init(server, conn);
- }
- });
+ if (!unitQueryStarted)
+ {
+ unitQueryStarted = true;
+ init(server, conn);
+ }
+ });
// this will make sure to initialize the objects, when daemon is
// restarted.
checkAndInit(server, conn);
diff --git a/src/srvcfg_manager.cpp b/src/srvcfg_manager.cpp
index 3a771d9..69f639d 100644
--- a/src/srvcfg_manager.cpp
+++ b/src/srvcfg_manager.cpp
@@ -224,8 +224,8 @@
void ServiceConfig::queryAndUpdateProperties()
{
- std::string objectPath = isSocketActivatedService ? socketObjectPath
- : serviceObjectPath;
+ std::string objectPath =
+ isSocketActivatedService ? socketObjectPath : serviceObjectPath;
if (objectPath.empty())
{
return;
@@ -235,60 +235,60 @@
[this](boost::system::error_code ec,
const boost::container::flat_map<std::string, VariantType>&
propertyMap) {
- if (ec)
- {
- lg2::error(
- "async_method_call error: Failed to service unit properties: {EC}",
- "EC", ec.value());
- return;
- }
- try
- {
- updateServiceProperties(propertyMap);
- if (!socketObjectPath.empty())
+ if (ec)
{
- conn->async_method_call(
- [this](boost::system::error_code ec,
- const boost::container::flat_map<
- std::string, VariantType>& propertyMap) {
- if (ec)
- {
- lg2::error(
- "async_method_call error: Failed to get all property: {EC}",
- "EC", ec.value());
- return;
- }
- try
- {
- updateSocketProperties(propertyMap);
- if (!srvCfgIface)
- {
- registerProperties();
- }
- }
- catch (const std::exception& e)
- {
- lg2::error(
- "Exception in getting socket properties: {ERROR}",
- "ERROR", e);
- return;
- }
- },
- sysdService, socketObjectPath, dBusPropIntf,
- dBusGetAllMethod, sysdSocketIntf);
+ lg2::error(
+ "async_method_call error: Failed to service unit properties: {EC}",
+ "EC", ec.value());
+ return;
}
- else if (!srvCfgIface)
+ try
{
- registerProperties();
+ updateServiceProperties(propertyMap);
+ if (!socketObjectPath.empty())
+ {
+ conn->async_method_call(
+ [this](boost::system::error_code ec,
+ const boost::container::flat_map<
+ std::string, VariantType>& propertyMap) {
+ if (ec)
+ {
+ lg2::error(
+ "async_method_call error: Failed to get all property: {EC}",
+ "EC", ec.value());
+ return;
+ }
+ try
+ {
+ updateSocketProperties(propertyMap);
+ if (!srvCfgIface)
+ {
+ registerProperties();
+ }
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error(
+ "Exception in getting socket properties: {ERROR}",
+ "ERROR", e);
+ return;
+ }
+ },
+ sysdService, socketObjectPath, dBusPropIntf,
+ dBusGetAllMethod, sysdSocketIntf);
+ }
+ else if (!srvCfgIface)
+ {
+ registerProperties();
+ }
}
- }
- catch (const std::exception& e)
- {
- lg2::error("Exception in getting socket properties: {ERROR}",
- "ERROR", e);
- return;
- }
- },
+ catch (const std::exception& e)
+ {
+ lg2::error("Exception in getting socket properties: {ERROR}",
+ "ERROR", e);
+ return;
+ }
+ },
sysdService, objectPath, dBusPropIntf, dBusGetAllMethod, sysdUnitIntf);
return;
}
@@ -322,8 +322,7 @@
const std::string& objPath_, const std::string& baseUnitName_,
const std::string& instanceName_, const std::string& serviceObjPath_,
const std::string& socketObjPath_) :
- conn(conn_),
- server(srv_), objPath(objPath_), baseUnitName(baseUnitName_),
+ conn(conn_), server(srv_), objPath(objPath_), baseUnitName(baseUnitName_),
instanceName(instanceName_), serviceObjectPath(serviceObjPath_),
socketObjectPath(socketObjPath_)
{
@@ -504,28 +503,28 @@
updateInProgress = true;
boost::asio::spawn(conn->get_io_context(),
[this](boost::asio::yield_context yield) {
- // Stop and apply configuration for all objects
- for (auto& srvMgrObj : srvMgrObjects)
- {
- auto& srvObj = srvMgrObj.second;
- if (srvObj->updatedFlag)
- {
- srvObj->stopAndApplyUnitConfig(yield);
- }
- }
- // Do system reload
- systemdDaemonReload(conn, yield);
- // restart unit config.
- for (auto& srvMgrObj : srvMgrObjects)
- {
- auto& srvObj = srvMgrObj.second;
- if (srvObj->updatedFlag)
- {
- srvObj->restartUnitConfig(yield);
- }
- }
- updateInProgress = false;
- });
+ // Stop and apply configuration for all objects
+ for (auto& srvMgrObj : srvMgrObjects)
+ {
+ auto& srvObj = srvMgrObj.second;
+ if (srvObj->updatedFlag)
+ {
+ srvObj->stopAndApplyUnitConfig(yield);
+ }
+ }
+ // Do system reload
+ systemdDaemonReload(conn, yield);
+ // restart unit config.
+ for (auto& srvMgrObj : srvMgrObjects)
+ {
+ auto& srvObj = srvMgrObj.second;
+ if (srvObj->updatedFlag)
+ {
+ srvObj->restartUnitConfig(yield);
+ }
+ }
+ updateInProgress = false;
+ });
});
}
@@ -539,8 +538,50 @@
sockAttrIface->register_property(
sockAttrPropPort, portNum,
[this](const uint16_t& req, uint16_t& res) {
+ if (!internalSet)
+ {
+ if (req == res)
+ {
+ return 1;
+ }
+ if (updateInProgress)
+ {
+ return 0;
+ }
+ portNum = req;
+ updatedFlag |=
+ (1 << static_cast<uint8_t>(UpdatedProp::port));
+ startServiceRestartTimer();
+ }
+ res = req;
+ return 1;
+ });
+ }
+
+ srvCfgIface->register_property(
+ srvCfgPropMasked, unitMaskedState, [this](const bool& req, bool& res) {
if (!internalSet)
{
+#ifdef USB_CODE_UPDATE
+ if (baseUnitName == usbCodeUpdateUnitName)
+ {
+ unitMaskedState = req;
+ unitEnabledState = !unitMaskedState;
+ unitRunningState = !unitMaskedState;
+ internalSet = true;
+ srvCfgIface->set_property(srvCfgPropEnabled,
+ unitEnabledState);
+ srvCfgIface->set_property(srvCfgPropRunning,
+ unitRunningState);
+ srvCfgIface->set_property(srvCfgPropMasked,
+ unitMaskedState);
+ internalSet = false;
+ setUSBCodeUpdateState(unitEnabledState);
+ saveUSBCodeUpdateStateToFile(unitMaskedState,
+ unitEnabledState);
+ return 1;
+ }
+#endif
if (req == res)
{
return 1;
@@ -549,151 +590,122 @@
{
return 0;
}
- portNum = req;
- updatedFlag |= (1 << static_cast<uint8_t>(UpdatedProp::port));
+ unitMaskedState = req;
+ unitEnabledState = !unitMaskedState;
+ unitRunningState = !unitMaskedState;
+ updatedFlag |=
+ (1 << static_cast<uint8_t>(UpdatedProp::maskedState)) |
+ (1 << static_cast<uint8_t>(UpdatedProp::enabledState)) |
+ (1 << static_cast<uint8_t>(UpdatedProp::runningState));
+ internalSet = true;
+ srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
+ srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
+ internalSet = false;
startServiceRestartTimer();
}
res = req;
return 1;
});
- }
- srvCfgIface->register_property(srvCfgPropMasked, unitMaskedState,
- [this](const bool& req, bool& res) {
- if (!internalSet)
- {
-#ifdef USB_CODE_UPDATE
- if (baseUnitName == usbCodeUpdateUnitName)
+ srvCfgIface->register_property(
+ srvCfgPropEnabled, unitEnabledState,
+ [this](const bool& req, bool& res) {
+ if (!internalSet)
{
- unitMaskedState = req;
- unitEnabledState = !unitMaskedState;
- unitRunningState = !unitMaskedState;
- internalSet = true;
- srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
- srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
- srvCfgIface->set_property(srvCfgPropMasked, unitMaskedState);
- internalSet = false;
- setUSBCodeUpdateState(unitEnabledState);
- saveUSBCodeUpdateStateToFile(unitMaskedState, unitEnabledState);
- return 1;
- }
+#ifdef USB_CODE_UPDATE
+ if (baseUnitName == usbCodeUpdateUnitName)
+ {
+ if (unitMaskedState)
+ { // block updating if masked
+ lg2::error("Invalid value specified");
+ return -EINVAL;
+ }
+ unitEnabledState = req;
+ unitRunningState = req;
+ internalSet = true;
+ srvCfgIface->set_property(srvCfgPropEnabled,
+ unitEnabledState);
+ srvCfgIface->set_property(srvCfgPropRunning,
+ unitRunningState);
+ internalSet = false;
+ setUSBCodeUpdateState(unitEnabledState);
+ saveUSBCodeUpdateStateToFile(unitMaskedState,
+ unitEnabledState);
+ res = req;
+ return 1;
+ }
#endif
- if (req == res)
- {
- return 1;
- }
- if (updateInProgress)
- {
- return 0;
- }
- unitMaskedState = req;
- unitEnabledState = !unitMaskedState;
- unitRunningState = !unitMaskedState;
- updatedFlag |=
- (1 << static_cast<uint8_t>(UpdatedProp::maskedState)) |
- (1 << static_cast<uint8_t>(UpdatedProp::enabledState)) |
- (1 << static_cast<uint8_t>(UpdatedProp::runningState));
- internalSet = true;
- srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
- srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
- internalSet = false;
- startServiceRestartTimer();
- }
- res = req;
- return 1;
- });
-
- srvCfgIface->register_property(srvCfgPropEnabled, unitEnabledState,
- [this](const bool& req, bool& res) {
- if (!internalSet)
- {
-#ifdef USB_CODE_UPDATE
- if (baseUnitName == usbCodeUpdateUnitName)
- {
+ if (req == res)
+ {
+ return 1;
+ }
+ if (updateInProgress)
+ {
+ return 0;
+ }
if (unitMaskedState)
{ // block updating if masked
lg2::error("Invalid value specified");
return -EINVAL;
}
unitEnabledState = req;
- unitRunningState = req;
- internalSet = true;
- srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
- srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
- internalSet = false;
- setUSBCodeUpdateState(unitEnabledState);
- saveUSBCodeUpdateStateToFile(unitMaskedState, unitEnabledState);
- res = req;
- return 1;
+ updatedFlag |=
+ (1 << static_cast<uint8_t>(UpdatedProp::enabledState));
+ startServiceRestartTimer();
}
-#endif
- if (req == res)
- {
- return 1;
- }
- if (updateInProgress)
- {
- return 0;
- }
- if (unitMaskedState)
- { // block updating if masked
- lg2::error("Invalid value specified");
- return -EINVAL;
- }
- unitEnabledState = req;
- updatedFlag |= (1
- << static_cast<uint8_t>(UpdatedProp::enabledState));
- startServiceRestartTimer();
- }
- res = req;
- return 1;
- });
+ res = req;
+ return 1;
+ });
- srvCfgIface->register_property(srvCfgPropRunning, unitRunningState,
- [this](const bool& req, bool& res) {
- if (!internalSet)
- {
-#ifdef USB_CODE_UPDATE
- if (baseUnitName == usbCodeUpdateUnitName)
+ srvCfgIface->register_property(
+ srvCfgPropRunning, unitRunningState,
+ [this](const bool& req, bool& res) {
+ if (!internalSet)
{
+#ifdef USB_CODE_UPDATE
+ if (baseUnitName == usbCodeUpdateUnitName)
+ {
+ if (unitMaskedState)
+ { // block updating if masked
+ lg2::error("Invalid value specified");
+ return -EINVAL;
+ }
+ unitEnabledState = req;
+ unitRunningState = req;
+ internalSet = true;
+ srvCfgIface->set_property(srvCfgPropEnabled,
+ unitEnabledState);
+ srvCfgIface->set_property(srvCfgPropRunning,
+ unitRunningState);
+ internalSet = false;
+ setUSBCodeUpdateState(unitEnabledState);
+ saveUSBCodeUpdateStateToFile(unitMaskedState,
+ unitEnabledState);
+ res = req;
+ return 1;
+ }
+#endif
+ if (req == res)
+ {
+ return 1;
+ }
+ if (updateInProgress)
+ {
+ return 0;
+ }
if (unitMaskedState)
{ // block updating if masked
lg2::error("Invalid value specified");
return -EINVAL;
}
- unitEnabledState = req;
unitRunningState = req;
- internalSet = true;
- srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
- srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
- internalSet = false;
- setUSBCodeUpdateState(unitEnabledState);
- saveUSBCodeUpdateStateToFile(unitMaskedState, unitEnabledState);
- res = req;
- return 1;
+ updatedFlag |=
+ (1 << static_cast<uint8_t>(UpdatedProp::runningState));
+ startServiceRestartTimer();
}
-#endif
- if (req == res)
- {
- return 1;
- }
- if (updateInProgress)
- {
- return 0;
- }
- if (unitMaskedState)
- { // block updating if masked
- lg2::error("Invalid value specified");
- return -EINVAL;
- }
- unitRunningState = req;
- updatedFlag |= (1
- << static_cast<uint8_t>(UpdatedProp::runningState));
- startServiceRestartTimer();
- }
- res = req;
- return 1;
- });
+ res = req;
+ return 1;
+ });
srvCfgIface->initialize();
if (!socketObjectPath.empty())