Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/DtkCore/DLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
#include <ConsoleAppender.h>
#include <AbstractStringAppender.h>
#include <AbstractAppender.h>
#ifdef BUILD_WITH_SYSTEMD
#include <JournalAppender.h>
#endif
#include <dloghelper.h>
21 changes: 14 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ set(CMAKE_AUTORCC ON)

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
find_package(Dtk${DTK_NAME_SUFFIX}Log REQUIRED)
find_package(DBus1 REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus)
if(LINUX)
find_package(PkgConfig REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus)

find_package(DBus1 REQUIRED)
if(${QT_VERSION_MAJOR} EQUAL 5)
pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) #Dtk6 removed.
elseif(${QT_VERSION_MAJOR} EQUAL 6)
Expand Down Expand Up @@ -89,6 +88,9 @@ if(LINUX)
endif()

else()
if("${QT_VERSION_MAJOR}" STREQUAL "6")
find_package(Qt6 REQUIRED COMPONENTS CorePrivate)
endif()
add_library(${LIB_NAME} SHARED
${base_SRCS}
${dci_SRCS}
Expand All @@ -101,10 +103,13 @@ else()
target_link_libraries(
${LIB_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Xml
Dtk${DTK_NAME_SUFFIX}::Log
)
target_link_libraries(${LIB_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::CorePrivate
iconv
)
if("${QT_VERSION_MAJOR}" STREQUAL "5")
target_link_libraries(${LIB_NAME} PRIVATE
Expand All @@ -127,9 +132,11 @@ target_compile_definitions(${LIB_NAME} PRIVATE
LIBDTKCORE_LIBRARY
)

target_link_libraries(${LIB_NAME} PRIVATE
dbus-1
)
if(LINUX)
target_link_libraries(${LIB_NAME} PRIVATE
dbus-1
)
endif()
target_include_directories(${LIB_NAME} PRIVATE
${uchardet_INCLUDE_DIRS}
)
Expand Down
7 changes: 7 additions & 0 deletions src/dconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
#include "dobject_p.h"
#include <DSGApplication>

#include <QLoggingCategory>

Check warning on line 18 in src/dconfig.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCoreApplication>

Check warning on line 19 in src/dconfig.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QThread>

Check warning on line 20 in src/dconfig.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QThread> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#ifdef Q_OS_LINUX
#include <unistd.h>

Check warning on line 22 in src/dconfig.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

// https://gitlabwh.uniontech.com/wuhan/se/deepin-specifications/-/issues/3

DCORE_BEGIN_NAMESPACE

#ifdef D_DISABLE_DCONFIG
Q_LOGGING_CATEGORY(cfLog, "dtk.dsg.config")
#else
Q_DECLARE_LOGGING_CATEGORY(cfLog)
#endif
static QString NoAppId;

/*!
Expand Down
38 changes: 27 additions & 11 deletions src/dsgapplication.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// SPDX-FileCopyrightText: 2022-2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dsgapplication.h"

Check warning on line 5 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsgapplication.h" not found.

#ifdef Q_OS_LINUX
#include <sys/syscall.h>

Check warning on line 8 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/syscall.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unistd.h>

Check warning on line 9 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dbus/dbus.h>
#else
#include <QStandardPaths>

Check warning on line 12 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStandardPaths> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif

#include <QDir>

Check warning on line 15 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 16 in src/dsgapplication.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QByteArray>
#include <QCoreApplication>
#include <QDebug>
#include <QRegularExpression>
#include <QLoggingCategory>

#include <dbus/dbus.h>
#include <QFileInfo>

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(dsgApp, "dtk.core.dsg")
Expand All @@ -25,6 +29,8 @@

DCORE_BEGIN_NAMESPACE

#ifdef Q_OS_LINUX

// D-Bus resource deleters for RAII management
static void dbusErrorDeleter(DBusError *error) {
if (error) { dbus_error_free(error); delete error; }
Expand Down Expand Up @@ -217,19 +223,13 @@
return appId;
}

static inline QByteArray getSelfAppId() {
// The env is set by the application starter(eg, org.desktopspec.ApplicationManager service)
QByteArray selfId = qgetenv("DSG_APP_ID");
if (!selfId.isEmpty())
return selfId;
return DSGApplication::getId(QCoreApplication::applicationPid());
}

static bool isServiceActivatable(const QByteArray &service)
{
return checkDBusServiceActivatable(service);
}

#endif // Q_OS_LINUX

// Format appId to valid.
static QByteArray formatAppId(const QByteArray &appId)
{
Expand All @@ -243,6 +243,14 @@
return format.toLocal8Bit();
}

static inline QByteArray getSelfAppId() {
// The env is set by the application starter(eg, org.desktopspec.ApplicationManager service)
QByteArray selfId = qgetenv("DSG_APP_ID");
if (!selfId.isEmpty())
return selfId;
return DSGApplication::getId(QCoreApplication::applicationPid());
}

QByteArray DSGApplication::id()
{
static QByteArray selfId = getSelfAppId();
Expand All @@ -251,6 +259,7 @@
QByteArray result = selfId;
if (!qEnvironmentVariableIsSet("DTK_DISABLED_FALLBACK_APPID")) {
result = QCoreApplication::applicationName().toLocal8Bit();
#ifdef Q_OS_LINUX
if (result.isEmpty()) {
QFile file("/proc/self/cmdline");
if (file.open(QIODevice::ReadOnly))
Expand All @@ -261,6 +270,7 @@
if (file.exists())
result = file.absoluteFilePath().toLocal8Bit();
}
#endif
if (!result.isEmpty()) {
result = formatAppId(result);
qCDebug(dsgApp) << "The applicatiion ID is fallback to " << result;
Expand All @@ -286,6 +296,7 @@
*/
QByteArray DSGApplication::getId(qint64 pid)
{
#ifdef Q_OS_LINUX
if (!isServiceActivatable("org.desktopspec.ApplicationManager1")) {
qCInfo(dsgApp) << "Can't getId from AM for the " << pid << ", because AM is unavailable.";
return QByteArray();
Expand All @@ -305,6 +316,11 @@
close(pidfd);

return appId;
#else
Q_UNUSED(pid)
// On non-Linux platforms, D-Bus ApplicationManager is not available
return QByteArray();
#endif
}

DCORE_END_NAMESPACE
5 changes: 4 additions & 1 deletion src/dsysinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -13,6 +13,9 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#ifdef Q_OS_WIN
#include <windows.h>
#endif
#include <QSettings>
#include <QStandardPaths>
#include <QDateTime>
Expand Down
18 changes: 17 additions & 1 deletion src/filesystem/dstandardpaths.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dstandardpaths.h"

#include <QProcessEnvironment>
#include <QDir>
#ifdef Q_OS_LINUX
#include <unistd.h>
#include <pwd.h>
#endif

DCORE_BEGIN_NAMESPACE

Expand Down Expand Up @@ -118,7 +121,11 @@ QString DStandardPaths::homePath()
if (!home.isEmpty())
return QString::fromLocal8Bit(home);

#ifdef Q_OS_LINUX
return homePath(getuid());
#else
return QDir::homePath();
#endif
}

QString DStandardPaths::path(DStandardPaths::XDG type)
Expand Down Expand Up @@ -146,7 +153,11 @@ QString DStandardPaths::path(DStandardPaths::XDG type)
const QByteArray &path = qgetenv("XDG_RUNTIME_DIR");
if (!path.isEmpty())
return QString::fromLocal8Bit(path);
#ifdef Q_OS_LINUX
return QStringLiteral("/run/user/") + QString::number(getuid());
#else
return QDir::tempPath();
#endif
}
case XDG::StateHome: {
const QByteArray &path = qgetenv("XDG_STATE_HOME");
Expand Down Expand Up @@ -213,13 +224,18 @@ QString DStandardPaths::filePath(DStandardPaths::DSG type, const QString fileNam

QString DStandardPaths::homePath(const uint uid)
{
#ifdef Q_OS_LINUX
struct passwd *pw = getpwuid(uid);

if (!pw)
return QString();

const char *homedir = pw->pw_dir;
return QString::fromLocal8Bit(homedir);
#else
Q_UNUSED(uid)
return QDir::homePath();
#endif
}

DCORE_END_NAMESPACE
11 changes: 10 additions & 1 deletion src/log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <Logger.h>
#include <ConsoleAppender.h>
#include <RollingFileAppender.h>
#if defined(BUILD_WITH_SYSTEMD) && defined(Q_OS_LINUX)
#include <JournalAppender.h>
#endif

#ifdef Q_OS_LINUX
#include <sys/stat.h>
Expand Down Expand Up @@ -56,7 +58,9 @@ class DLogManagerPrivate {
QString m_logPath;
ConsoleAppender* m_consoleAppender = nullptr;
RollingFileAppender* m_rollingFileAppender = nullptr;
#if defined(BUILD_WITH_SYSTEMD) && defined(Q_OS_LINUX)
JournalAppender* m_journalAppender = nullptr;
#endif
QScopedPointer<dconfig_org_deepin_dtk_preference> m_dsgConfig;
QScopedPointer<dconfig_org_deepin_dtk_preference> m_fallbackConfig;

Expand Down Expand Up @@ -134,7 +138,7 @@ bool DLogManagerPrivate::shouldSkipConsoleAppender() const
if (qEnvironmentVariableIsSet("DTK_FORCE_CONSOLE_LOGGING"))
return false;


#ifdef Q_OS_LINUX
// Skip ConsoleAppender if running under systemd and stdout is connected to journal to avoid duplicate logging
QByteArray journalStream = qgetenv("JOURNAL_STREAM");
if (journalStream.isEmpty())
Expand All @@ -153,6 +157,9 @@ bool DLogManagerPrivate::shouldSkipConsoleAppender() const
auto ino = parts[1].toULongLong(&ok2);

return ok1 && ok2 && st.st_dev == dev && st.st_ino == ino;
#else
return false;
#endif
}

/*!
Expand All @@ -172,11 +179,13 @@ DLogManager::DLogManager()
void DLogManager::initConsoleAppender(){
Q_D(DLogManager);

#if defined(BUILD_WITH_SYSTEMD) && defined(Q_OS_LINUX)
// Skip ConsoleAppender if JournalAppender is active under systemd to avoid duplicate logging
if (d->shouldSkipConsoleAppender() && d->m_journalAppender) {
qDebug() << "Running under systemd with JournalAppender enabled, skipping ConsoleAppender to avoid duplicate logging";
return;
}
#endif

d->m_consoleAppender = new ConsoleAppender;
d->m_consoleAppender->setFormat(d->m_format);
Expand Down
10 changes: 6 additions & 4 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
add_subdirectory(dci)
add_subdirectory(deepin-os-release)
if(LINUX)
add_subdirectory(dci)
add_subdirectory(deepin-os-release)
add_subdirectory(settings)
add_subdirectory(ch2py)
endif()
add_subdirectory(qdbusxml2cpp)
add_subdirectory(settings)
add_subdirectory(ch2py)
add_subdirectory(dconfig2cpp)
Loading