clang-format: copy latest and re-format
clang-format-16 has some backwards incompatible changes that require
additional settings for best compatibility and re-running the formatter.
Copy the latest .clang-format from the docs repository and reformat the
repository.
Change-Id: I85b6e82cdf14da2fb4fa197abed9a6820c0f1e71
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/.clang-format b/.clang-format
index 945adae..d92a3f1 100644
--- a/.clang-format
+++ b/.clang-format
@@ -6,12 +6,14 @@
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
-AlignOperands: true
-AlignTrailingComments: true
+AlignOperands: Align
+AlignTrailingComments:
+ Kind: Always
+ OverEmptyLines: 1
AllowAllParametersOfDeclarationOnNextLine: true
-AllowShortBlocksOnASingleLine: false
+AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
-AllowShortFunctionsOnASingleLine: None
+AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
@@ -36,6 +38,7 @@
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
+BreakAfterAttributes: Never
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
@@ -75,9 +78,13 @@
- Regex: '.*'
Priority: 6
IndentCaseLabels: true
+IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: true
-KeepEmptyLinesAtTheStartOfBlocks: true
+InsertNewlineAtEOF: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: OuterScope
+LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
@@ -85,13 +92,19 @@
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 25
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+QualifierAlignment: Left
+ReferenceAlignment: Left
ReflowComments: true
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: Keyword
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
@@ -111,7 +124,6 @@
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
-UseCRLF: false
UseTab: Never
...
diff --git a/src/main.cpp b/src/main.cpp
index d04ea99..42a4246 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
@@ -120,8 +120,8 @@
const auto& fullUnitName =
std::get<static_cast<int>(ListUnitElements::name)>(unit);
- auto [unitName, type, instanceName] =
- getUnitNameTypeAndInstance(fullUnitName);
+ auto [unitName, type,
+ instanceName] = getUnitNameTypeAndInstance(fullUnitName);
if (managedServices.count(unitName))
{
// For socket-activated units, ignore all its instances
@@ -261,13 +261,13 @@
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,45 +279,45 @@
conn->async_method_call(
[&server, &conn](boost::system::error_code ec,
const std::variant<uint64_t>& value) {
- if (ec)
+ if (ec)
+ {
+ lg2::error("async_method_call error: ListUnits failed: {EC}", "EC",
+ ec.value());
+ return;
+ }
+ if (std::get<uint64_t>(value))
+ {
+ if (!unitQueryStarted)
{
- lg2::error("async_method_call error: ListUnits failed: {EC}",
- "EC", ec.value());
- return;
+ unitQueryStarted = true;
+ init(server, conn);
}
- if (std::get<uint64_t>(value))
- {
- if (!unitQueryStarted)
+ }
+ 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)
{
- unitQueryStarted = true;
- init(server, conn);
+ // Timer reset.
+ 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)
- {
- // Timer reset.
- return;
- }
- if (ec)
- {
- lg2::error(
- "service config mgr - init - async wait error: {EC}",
- "EC", ec.value());
- return;
- }
- checkAndInit(server, conn);
- });
- }
+ 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,11 +339,11 @@
"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.
diff --git a/src/srvcfg_manager.cpp b/src/srvcfg_manager.cpp
index cbe1afc..47c70a7 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,59 +235,59 @@
[this](boost::system::error_code ec,
const boost::container::flat_map<std::string, VariantType>&
propertyMap) {
- if (ec)
+ if (ec)
+ {
+ lg2::error(
+ "async_method_call error: Failed to service unit properties: {EC}",
+ "EC", ec.value());
+ return;
+ }
+ try
+ {
+ updateServiceProperties(propertyMap);
+ if (!socketObjectPath.empty())
{
- lg2::error(
- "async_method_call error: Failed to service unit properties: {EC}",
- "EC", ec.value());
- return;
+ 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);
}
- try
+ else if (!srvCfgIface)
{
- 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();
- }
+ 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;
@@ -504,28 +504,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,50 +539,8 @@
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;
@@ -591,122 +549,151 @@
{
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;
+ portNum = req;
+ updatedFlag |= (1 << static_cast<uint8_t>(UpdatedProp::port));
startServiceRestartTimer();
}
res = req;
return 1;
- });
+ });
+ }
- srvCfgIface->register_property(
- srvCfgPropEnabled, unitEnabledState,
- [this](const bool& req, bool& res) {
- if (!internalSet)
- {
+ srvCfgIface->register_property(srvCfgPropMasked, unitMaskedState,
+ [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;
- }
+ 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;
- }
- if (updateInProgress)
- {
- return 0;
- }
+ 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 (unitMaskedState)
{ // block updating if masked
lg2::error("Invalid value specified");
return -EINVAL;
}
unitEnabledState = req;
- updatedFlag |=
- (1 << static_cast<uint8_t>(UpdatedProp::enabledState));
- startServiceRestartTimer();
+ 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;
}
- res = req;
- return 1;
- });
-
- 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 (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;
+ });
+
+ 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;
- updatedFlag |=
- (1 << static_cast<uint8_t>(UpdatedProp::runningState));
- startServiceRestartTimer();
+ internalSet = true;
+ srvCfgIface->set_property(srvCfgPropEnabled, unitEnabledState);
+ srvCfgIface->set_property(srvCfgPropRunning, unitRunningState);
+ internalSet = false;
+ setUSBCodeUpdateState(unitEnabledState);
+ saveUSBCodeUpdateStateToFile(unitMaskedState, unitEnabledState);
+ res = req;
+ return 1;
}
- 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;
+ }
+ unitRunningState = req;
+ updatedFlag |= (1
+ << static_cast<uint8_t>(UpdatedProp::runningState));
+ startServiceRestartTimer();
+ }
+ res = req;
+ return 1;
+ });
srvCfgIface->initialize();
if (!socketObjectPath.empty())