refact: suppress warnings and standardize project

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2024-02-18 13:11:57 +08:00 committed by Comix
parent aca0531e85
commit 9d2cee79fe
14 changed files with 71 additions and 46 deletions

View File

@ -7,12 +7,17 @@ project(dde-application-manager
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
add_definitions(-Wall -Wextra -Wpedantic -Wformat)
set(BUILD_EXAMPLES OFF CACHE BOOL "Whether to build examples or not.")
set(DDE_AM_USE_DEBUG_DBUS_NAME OFF CACHE BOOL "build a dbus service using a different bus name for debug.")
set(PROFILING_MODE OFF CACHE BOOL "run a valgrind performance profiling.")

View File

@ -73,9 +73,7 @@ int processExecStart(msg_ptr &msg, const std::deque<std::string_view> &execArgs)
if (ret = sd_bus_message_open_container(msg, SD_BUS_TYPE_VARIANT, "a(sasb)"); ret < 0) {
sd_journal_perror("open variant of execStart failed.");
if (auto tmp = sd_bus_message_close_container(msg)) {
return ret;
}
return ret;
}
if (ret = sd_bus_message_open_container(msg, SD_BUS_TYPE_ARRAY, "(sasb)"); ret < 0) {
@ -229,7 +227,7 @@ std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
}
auto kvStr = str.substr(2);
if (!kvStr.empty()) [[likely]] {
if (!kvStr.empty()) {
const auto *it = kvStr.cbegin();
if (it = std::find(it, kvStr.cend(), '='); it == kvStr.cend()) {
sd_journal_print(LOG_WARNING, "invalid k-v pair: %s", kvStr.data());

View File

@ -82,7 +82,7 @@ QString CGroupsIdentifier::parseCGroupsPath(QFile &cgroupFile) noexcept
return {};
}
if (auto processUID = processUIDStr.toInt(); processUID != getCurrentUID()) {
if (auto processUID = processUIDStr.toInt(); static_cast<uid_t>(processUID) != getCurrentUID()) {
qWarning() << "process is not in CGroups of current user, ignore....";
return {};
}

View File

@ -32,7 +32,10 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
qFatal("%s", connection.lastError().message().toLocal8Bit().data());
}
new (std::nothrow) ProcessGuesser1Service{connection, this};
if (auto *tmp = new (std::nothrow) ProcessGuesser1Service{connection, this}; tmp == nullptr) {
qCritical() << "new ProcessGuesser1Service failed.";
std::terminate();
}
if (auto *tmp = new (std::nothrow) ApplicationManager1Adaptor{this}; tmp == nullptr) {
qCritical() << "new Application Manager Adaptor failed.";
@ -154,7 +157,9 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
watcher->deleteLater();
};
*sigCon = connect(watcher, &QDBusServiceWatcher::serviceRegistered, singleSlot);
if (watcher != nullptr) {
*sigCon = connect(watcher, &QDBusServiceWatcher::serviceRegistered, singleSlot);
}
auto msg =
QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameHasOwner");
@ -192,7 +197,7 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
m_applicationList.cend(),
[&appId](const QSharedPointer<ApplicationService> &app) { return app->id() == appId; });
if (appIt == m_applicationList.cend()) [[unlikely]] {
if (appIt == m_applicationList.cend()) {
qWarning() << "couldn't find app" << appId << "in application manager.";
return;
}
@ -201,7 +206,7 @@ void ApplicationManager1Service::addInstanceToApplication(const QString &unitNam
const auto &applicationPath = (*appIt)->applicationPath().path();
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher)) [[likely]] {
if (!(*appIt)->addOneInstance(instanceId, applicationPath, systemdUnitPath.path(), launcher)) {
qCritical() << "add Instance failed:" << applicationPath << unitName << systemdUnitPath.path();
}
}
@ -225,7 +230,7 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
m_applicationList.cend(),
[&appId](const QSharedPointer<ApplicationService> &app) { return app->id() == appId; });
if (appIt == m_applicationList.cend()) [[unlikely]] {
if (appIt == m_applicationList.cend()) {
qWarning() << "couldn't find app" << appId << "in application manager.";
return;
}
@ -237,12 +242,12 @@ void ApplicationManager1Service::removeInstanceFromApplication(const QString &un
return value->property("SystemdUnitPath") == systemdUnitPath;
});
if (instanceIt != appIns.cend()) [[likely]] {
if (instanceIt != appIns.cend()) {
(*appIt)->removeOneInstance(instanceIt.key());
return;
}
orphanedInstances->removeIf([&systemdUnitPath](const QSharedPointer<InstanceService> &ptr) {
orphanedInstances.removeIf([&systemdUnitPath](const QSharedPointer<InstanceService> &ptr) {
return (ptr->property("SystemdUnitPath").value<QDBusObjectPath>() == systemdUnitPath);
});
}
@ -426,7 +431,7 @@ QHash<QSharedPointer<ApplicationService>, QString> ApplicationManager1Service::s
}
qInfo() << "launch new autostart application " << newApp->id();
newApp->setAutostartSource({desktopFile.sourcePath()});
newApp->setAutostartSource({desktopFile.sourcePath(), {}});
ret.insert(newApp, {});
}

View File

@ -779,23 +779,29 @@ QList<QDBusObjectPath> ApplicationService::instances() const noexcept
bool ApplicationService::addOneInstance(const QString &instanceId,
const QString &application,
const QString &systemdUnitPath,
const QString &launcher)
const QString &launcher) noexcept
{
auto *service = new InstanceService{instanceId, application, systemdUnitPath, launcher};
auto *adaptor = new InstanceAdaptor(service);
QString objectPath{m_applicationPath.path() + "/" + instanceId};
if (registerObjectToDBus(service, objectPath, InstanceInterface)) {
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
service->moveToThread(this->thread());
adaptor->moveToThread(this->thread());
emit InterfacesAdded(QDBusObjectPath{objectPath}, getChildInterfacesAndPropertiesFromObject(service));
return true;
auto *service = new (std::nothrow) InstanceService{instanceId, application, systemdUnitPath, launcher};
if (service == nullptr) {
qCritical() << "couldn't new InstanceService.";
return false;
}
adaptor->deleteLater();
service->deleteLater();
return false;
auto *adaptor = new (std::nothrow) InstanceAdaptor{service};
QString objectPath{m_applicationPath.path() + "/" + instanceId};
if (adaptor == nullptr or !registerObjectToDBus(service, objectPath, InstanceInterface)) {
adaptor->deleteLater();
service->deleteLater();
return false;
}
m_Instances.insert(QDBusObjectPath{objectPath}, QSharedPointer<InstanceService>{service});
service->moveToThread(this->thread());
adaptor->moveToThread(this->thread());
emit InterfacesAdded(QDBusObjectPath{objectPath}, getChildInterfacesAndPropertiesFromObject(service));
return true;
}
void ApplicationService::removeOneInstance(const QDBusObjectPath &instance) noexcept
@ -817,7 +823,7 @@ void ApplicationService::removeAllInstance() noexcept
void ApplicationService::detachAllInstance() noexcept
{
for (auto &instance : m_Instances.values()) {
orphanedInstances->append(instance);
orphanedInstances.append(instance);
instance->setProperty("Orphaned", true);
}
@ -869,7 +875,12 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
wordfree(word);
delete word;
};
std::unique_ptr<wordexp_t, decltype(deleter)> words{new (std::nothrow) wordexp_t{0, nullptr, 0}, deleter};
if (words == nullptr) {
qCritical() << "couldn't new wordexp_t";
return std::nullopt;
}
if (auto ret = wordexp(unescapedStr.toLocal8Bit(), words.get(), WRDE_SHOWERR); ret != 0) {
if (ret != 0) {
@ -899,7 +910,7 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
}
QStringList execList;
for (int i = 0; i < words->we_wordc; ++i) {
for (std::size_t i = 0; i < words->we_wordc; ++i) {
execList.emplace_back(words->we_wordv[i]);
}

View File

@ -111,7 +111,7 @@ public:
bool addOneInstance(const QString &instanceId,
const QString &application,
const QString &systemdUnitPath,
const QString &launcher);
const QString &launcher) noexcept;
void recoverInstances(const QList<QDBusObjectPath> &instanceList) noexcept;
void removeOneInstance(const QDBusObjectPath &instance) noexcept;
void removeAllInstance() noexcept;

View File

@ -14,7 +14,10 @@ InstanceService::InstanceService(QString instanceId, QString application, QStrin
, m_Application(std::move(application))
, m_SystemdUnitPath(std::move(systemdUnitPath))
{
new PropertiesForwarder{application + "/" + instanceId, this};
if (auto *tmp = new (std::nothrow) PropertiesForwarder{application + "/" + instanceId, this}; tmp == nullptr) {
qCritical() << "couldn't new PropertiesForwarder for instanceService.";
return;
}
}
InstanceService::~InstanceService() = default;

View File

@ -42,6 +42,6 @@ private:
QDBusObjectPath m_SystemdUnitPath;
};
Q_GLOBAL_STATIC(QList<QSharedPointer<InstanceService>>, orphanedInstances)
static inline QList<QSharedPointer<InstanceService>> orphanedInstances{};
#endif

View File

@ -8,10 +8,11 @@
JobManager1Service::JobManager1Service(ApplicationManager1Service *parent)
: m_parent(parent)
{
new JobManager1Adaptor{this};
if (!registerObjectToDBus(this, DDEApplicationManager1JobManager1ObjectPath, JobManager1Interface)) {
auto *adaptor = new (std::nothrow) JobManager1Adaptor{this};
if (adaptor == nullptr or !registerObjectToDBus(this, DDEApplicationManager1JobManager1ObjectPath, JobManager1Interface)) {
std::terminate();
}
qRegisterMetaType<LaunchTask>();
}

View File

@ -58,11 +58,16 @@ public:
qOverload<QVariantList::parameter_type>(&QVariantList::append),
QVariantList{},
QtConcurrent::ReduceOption::OrderedReduce);
QSharedPointer<JobService> job{new JobService{future}};
QSharedPointer<JobService> job{new (std::nothrow) JobService{future}};
if (job == nullptr) {
qCritical() << "couldn't new JobService.";
future.cancel();
return {};
}
auto *ptr = job.data();
new JobAdaptor(ptr);
if (!registerObjectToDBus(ptr, objectPath, JobInterface)) {
auto *adaptor = new (std::nothrow) JobAdaptor(ptr);
if (adaptor == nullptr or !registerObjectToDBus(ptr, objectPath, JobInterface)) {
qCritical() << "can't register job to dbus.";
future.cancel();
return {};

View File

@ -10,8 +10,8 @@
MimeManager1Service::MimeManager1Service(ApplicationManager1Service *parent)
: QObject(parent)
{
new MimeManager1Adaptor{this};
if (!registerObjectToDBus(this, DDEApplicationManager1MimeManager1ObjectPath, MimeManager1Interface)) {
auto *adaptor = new (std::nothrow) MimeManager1Adaptor{this};
if (adaptor == nullptr or !registerObjectToDBus(this, DDEApplicationManager1MimeManager1ObjectPath, MimeManager1Interface)) {
std::terminate();
}
}

View File

@ -13,11 +13,9 @@ ProcessGuesser1Service::ProcessGuesser1Service(QDBusConnection &connection, Appl
qFatal("%s", connection.lastError().message().toLocal8Bit().data());
}
if (auto *tmp = new (std::nothrow) ProcessGuesser1Adaptor{this}; tmp == nullptr) {
qFatal("new Process Guesser Adaptor failed.");
}
if (!registerObjectToDBus(this, "/org/desktopspec/ProcessGuesser1", "org.desktopspec.ProcessGuesser1")) {
auto *adaptor = new (std::nothrow) ProcessGuesser1Adaptor{this};
if (adaptor == nullptr or
!registerObjectToDBus(this, "/org/desktopspec/ProcessGuesser1", "org.desktopspec.ProcessGuesser1")) {
std::terminate();
}
}

View File

@ -165,7 +165,7 @@ ParserError DesktopFileParser::addEntry(typename Groups::iterator &group) noexce
}
auto localeMap = keyIt->value<QStringMap>();
if (auto valueIt = localeMap.find(localeStr) != localeMap.end()) {
if (localeMap.find(localeStr) != localeMap.end()) {
qWarning() << "duplicate locale key:" << key << "skip.";
return ParserError::NoError;
}

View File

@ -86,7 +86,6 @@ QStringList setUserLaunchOption::generateCommandLine() const noexcept
QString userName = destUser->pw_name;
ret.append(userName);
struct passwd *curUser = getpwuid(curUID);
ret.append("env");
ret.append("DISPLAY=:0");