Commit c103ceb1 authored by Roman Gilg's avatar Roman Gilg

Add support for logging categories

Summary:
Adds category logging to the KScreenLocker daemon/library and the greeter.

Replaces all current uncategorized messages with categorized ones in these
parts.

Test Plan: Tested messages with autotests and QT_LOGGING_RULES="kscreenlocker*=true".

Reviewers: #plasma, apol

Reviewed By: apol

Subscribers: apol, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28389
parent decf7c9d
......@@ -146,6 +146,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(KSLD_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/KScreenLocker")
include(ECMQtDeclareLoggingCategory)
add_subdirectory(kcheckpass)
add_subdirectory(greeter)
add_subdirectory(kcm)
......@@ -169,6 +171,18 @@ set(ksld_SRCS
powermanagement_inhibition.cpp
kscreensaversettings.cpp
)
ecm_qt_declare_logging_category(ksld_SRCS
HEADER
kscreenlocker_logging.h
IDENTIFIER
KSCREENLOCKER
CATEGORY_NAME
kscreenlocker
DEFAULT_SEVERITY
Critical
)
qt5_add_dbus_adaptor(ksld_SRCS ${screensaver_dbusXML} interface.h ScreenLocker::Interface)
qt5_add_dbus_adaptor(ksld_SRCS ${kscreensaver_dbusXML} interface.h ScreenLocker::Interface kscreensaveradaptor KScreenSaverAdaptor)
kconfig_add_kcfg_files(ksld_SRCS kcfg/kscreensaversettingsbase.kcfgc)
......
......@@ -8,7 +8,9 @@ set(logindTest_SRCS
logindtest.cpp
fakelogind.cpp
../logind.cpp
../kscreenlocker_logging.cpp
)
add_executable(logindTest ${logindTest_SRCS})
target_link_libraries(logindTest Qt5::DBus Qt5::Test KF5::I18n)
add_test(NAME ksmserver-logindTest COMMAND logindTest)
......@@ -39,7 +41,14 @@ ecm_mark_as_test(pointerGrabber)
#######################################
# LockWindowTest
#######################################
set(x11LockerTest_SRCS x11lockertest.cpp ../x11locker.cpp ../globalaccel.cpp ../abstractlocker.cpp)
set(x11LockerTest_SRCS
x11lockertest.cpp
../x11locker.cpp
../globalaccel.cpp
../abstractlocker.cpp
../kscreenlocker_logging.cpp
)
add_executable(x11LockerTest ${x11LockerTest_SRCS})
target_link_libraries(x11LockerTest
KF5::GlobalAccel
......
......@@ -21,6 +21,17 @@ if(HAVE_SECCOMP)
set(kscreenlocker_greet_SRCS ${kscreenlocker_greet_SRCS} seccomp_filter.cpp)
endif()
ecm_qt_declare_logging_category(kscreenlocker_greet_SRCS
HEADER
kscreenlocker_greet_logging.h
IDENTIFIER
KSCREENLOCKER_GREET
CATEGORY_NAME
kscreenlocker_greet
DEFAULT_SEVERITY
Critical
)
qt5_add_resources(kscreenlocker_greet_SRCS fallbacktheme.qrc)
kconfig_add_kcfg_files(kscreenlocker_greet_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../kcfg/kscreensaversettingsbase.kcfgc)
......
......@@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "wallpaper_integration.h"
#include "lnf_integration.h"
#include <kscreenlocker_greet_logging.h>
#include <config-kscreenlocker.h>
// KDE
......@@ -257,7 +258,7 @@ void UnlockApp::loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view)
{
auto package = m_wallpaperIntegration->package();
if (!package.isValid()) {
qWarning() << "Error loading the wallpaper, no valid package loaded";
qCWarning(KSCREENLOCKER_GREET) << "Error loading the wallpaper, no valid package loaded";
return;
}
......@@ -270,7 +271,7 @@ void UnlockApp::loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view)
[this, qmlObject, view] {
auto item = qobject_cast<QQuickItem*>(qmlObject->rootObject());
if (!item) {
qWarning() << "Wallpaper needs to be a QtQuick Item";
qCWarning(KSCREENLOCKER_GREET) << "Wallpaper needs to be a QtQuick Item";
return;
}
item->setParentItem(view->rootObject());
......@@ -346,7 +347,9 @@ void UnlockApp::desktopResized()
if (view->status() != QQmlComponent::Ready) {
static const QUrl fallbackUrl(QUrl(QStringLiteral("qrc:/fallbacktheme/LockScreen.qml")));
qWarning() << "Failed to load lockscreen QML, falling back to built-in locker";
qCWarning(KSCREENLOCKER_GREET)
<< "Failed to load lockscreen QML, falling back to built-in locker";
m_mainQmlPath = fallbackUrl;
view->setSource(fallbackUrl);
}
......
......@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KQuickAddons/QtQuickSettings>
#include <QDateTime>
#include <QDebug>
#include <QCommandLineParser>
#include <QSessionManager>
......@@ -31,6 +30,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "greeterapp.h"
#include <config-kscreenlocker.h>
#include <kscreenlocker_greet_logging.h>
#if HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
......@@ -56,11 +57,11 @@ static void signalHandler(int signum)
// return exit code 1 to indicate that a valid password was not entered,
// to prevent circumventing the password input by sending a SIGTERM
qDebug() << "Greeter received SIGTERM. Will exit with error.";
qCDebug(KSCREENLOCKER_GREET) << "Greeter received SIGTERM. Will exit with error.";
instance->exit(1);
break;
case SIGUSR1:
qDebug() << "Greeter received SIGUSR1. Will lock immediately.";
qCDebug(KSCREENLOCKER_GREET) << "Greeter received SIGUSR1. Will lock immediately.";
instance->lockImmediately();
break;
}
......@@ -77,7 +78,7 @@ int main(int argc, char* argv[])
procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);
#endif
qDebug() << "Greeter is starting up.";
qCDebug(KSCREENLOCKER_GREET) << "Greeter is starting up.";
KLocalizedString::setApplicationDomain("kscreenlocker_greet");
......
......@@ -28,7 +28,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "logind.h"
#include "kscreensaversettings.h"
#include "powermanagement_inhibition.h"
#include "kscreenlocker_logging.h"
#include <config-kscreenlocker.h>
#include <config-X11.h>
#include "waylandserver.h"
// KDE
......@@ -163,7 +166,7 @@ void KSldApp::initialize()
// Global keys
if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) {
qDebug() << "Configuring Lock Action";
qCDebug(KSCREENLOCKER) << "Configuring Lock Action";
QAction *a = new QAction(this);
a->setObjectName(QStringLiteral("Lock Session"));
a->setProperty("componentName", QStringLiteral("ksmserver"));
......@@ -208,7 +211,7 @@ void KSldApp::initialize()
auto finishedSignal = static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished);
connect(m_lockProcess, finishedSignal, this,
[this](int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "Greeter process exitted with status:"
qCDebug(KSCREENLOCKER) << "Greeter process exitted with status:"
<< exitStatus << "exit code:" << exitCode;
const bool regularExit = !exitCode && exitStatus == QProcess::NormalExit;
......@@ -216,12 +219,12 @@ void KSldApp::initialize()
// unlock process finished successfully - we can remove the lock grab
if (regularExit) {
qDebug() << "Unlocking now on regular exit.";
qCDebug(KSCREENLOCKER) << "Unlocking now on regular exit.";
} else if (s_graceTimeKill) {
qDebug() << "Unlocking anyway due to grace time.";
qCDebug(KSCREENLOCKER) << "Unlocking anyway due to grace time.";
} else {
Q_ASSERT(s_logindExit);
qDebug() << "Unlocking anyway since forced through logind.";
qCDebug(KSCREENLOCKER) << "Unlocking anyway since forced through logind.";
}
s_graceTimeKill = false;
......@@ -230,32 +233,34 @@ void KSldApp::initialize()
return;
}
qWarning() << "Greeter process exit unregular. Restarting lock.";
qCWarning(KSCREENLOCKER) << "Greeter process exit unregular. Restarting lock.";
m_greeterCrashedCounter++;
if (m_greeterCrashedCounter < 4) {
// Perhaps it crashed due to a graphics driver issue, force software rendering now
qDebug("Trying to lock again with software rendering (%d/4).",
qCDebug(KSCREENLOCKER, "Trying to lock again with software rendering (%d/4).",
m_greeterCrashedCounter);
setForceSoftwareRendering(true);
startLockProcess(EstablishLock::Immediate);
} else if (m_lockWindow) {
qWarning("Everything else failed. Need to put Greeter in emergency mode.");
qCWarning(KSCREENLOCKER)
<< "Everything else failed. Need to put Greeter in emergency mode.";
m_lockWindow->emergencyShow();
} else {
qCritical("Greeter process exitted and we could in no way recover from that!");
qCCritical(KSCREENLOCKER)
<< "Greeter process exitted and we could in no way recover from that!";
}
}
);
connect(m_lockProcess, &QProcess::errorOccurred, this,
[this](QProcess::ProcessError error) {
if (error == QProcess::FailedToStart) {
qDebug() << "Greeter Process failed to start. Trying to directly unlock again.";
qCDebug(KSCREENLOCKER) << "Greeter Process failed to start. Trying to directly unlock again.";
doUnlock();
m_waylandServer->stop();
qCritical() << "Greeter Process not available";
qCCritical(KSCREENLOCKER) << "Greeter Process not available";
} else {
qWarning() << "Greeter Process encountered an unhandled error:" << error;
qCWarning(KSCREENLOCKER) << "Greeter Process encountered an unhandled error:" << error;
}
}
);
......@@ -389,15 +394,15 @@ void KSldApp::lock(EstablishLock establishLock, int attemptCount)
emit aboutToLock();
}
qDebug() << "lock called";
qCDebug(KSCREENLOCKER) << "lock called";
if (!establishGrab()) {
if (attemptCount < 3) {
qWarning() << "Could not establish screen lock. Trying again in 10ms";
qCWarning(KSCREENLOCKER) << "Could not establish screen lock. Trying again in 10ms";
QTimer::singleShot(10, this, [=]() {
lock(establishLock, attemptCount+1);
});
} else {
qCritical() << "Could not establish screen lock";
qCCritical(KSCREENLOCKER) << "Could not establish screen lock";
}
return;
}
......@@ -532,7 +537,7 @@ static bool grabMouse()
void KSldApp::doUnlock()
{
qDebug() << "Grab Released";
qCDebug(KSCREENLOCKER) << "Grab Released";
if (m_isX11) {
xcb_connection_t *c = QX11Info::connection();
xcb_ungrab_keyboard(c, XCB_CURRENT_TIME);
......@@ -616,7 +621,7 @@ void KSldApp::startLockProcess(EstablishLock establishLock)
// start the Wayland server
int fd = m_waylandServer->start();
if (fd == -1) {
qWarning() << "Could not start the Wayland server.";
qCWarning(KSCREENLOCKER) << "Could not start the Wayland server.";
emit m_lockProcess->errorOccurred(QProcess::FailedToStart);
return;
}
......
......@@ -22,11 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KLocalizedString>
#include <QCoreApplication>
#include <QDebug>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusServiceWatcher>
#include <kscreenlocker_logging.h>
const static QString s_login1Service = QStringLiteral("org.freedesktop.login1");
const static QString s_login1Path = QStringLiteral("/org/freedesktop/login1");
const static QString s_login1ManagerInterface = QStringLiteral("org.freedesktop.login1.Manager");
......@@ -144,11 +145,12 @@ void LogindIntegration::commonServiceRegistered(QDBusPendingCallWatcher *watcher
return;
}
if (!reply.isValid()) {
qDebug() << "The session is not registered: " << reply.error().message();
qCDebug(KSCREENLOCKER) << "The session is not registered: "
<< reply.error().message();
return;
}
const QString sessionPath = reply.value().path();
qDebug() << "Session path:" << sessionPath;
qCDebug(KSCREENLOCKER) << "Session path:" << sessionPath;
// connections need to be done this way as the object exposes both method and signal
// with name "Lock"/"Unlock". Qt is not able to automatically handle this.
......
......@@ -27,7 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KDE
// Qt
#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QX11Info>
// X11
......@@ -35,6 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <fixx11h.h>
#include <xcb/xcb.h>
#include <kscreenlocker_logging.h>
static Window gVRoot = 0;
static Window gVRootData = 0;
static Atom gXA_VROOT;
......@@ -104,7 +105,7 @@ void X11Locker::showLockWindow()
gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace,
(unsigned char *) version, strlen(version));
qDebug() << "Lock window Id: " << m_background->winId();
qCDebug(KSCREENLOCKER) << "Lock window Id: " << m_background->winId();
m_background->setPosition(0, 0);
XSync(QX11Info::display(), False);
......@@ -337,14 +338,14 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if( index >= 0 ) {
int index2 = xc->above_sibling ? findWindowInfo( xc->above_sibling ) : 0;
if( index2 < 0 )
qDebug() << "Unknown above for ConfigureNotify";
qCDebug(KSCREENLOCKER) << "Unknown above for ConfigureNotify";
else { // move just above the other window
if( index2 < index )
++index2;
m_windowInfo.move( index, index2 );
}
} else
qDebug() << "Unknown toplevel for ConfigureNotify";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for ConfigureNotify";
//kDebug() << "ConfigureNotify:";
//the stacking order changed, so let's change the stacking order again to what we want
stayOnTop();
......@@ -355,15 +356,15 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
case XCB_MAP_NOTIFY: { // from SubstructureNotifyMask on the root window
xcb_map_notify_event_t *xm = reinterpret_cast<xcb_map_notify_event_t*>(event);
if (xm->event == QX11Info::appRootWindow()) {
qDebug() << "MapNotify:" << xm->window;
qCDebug(KSCREENLOCKER) << "MapNotify:" << xm->window;
int index = findWindowInfo( xm->window );
if( index >= 0 )
m_windowInfo[ index ].viewable = true;
else
qDebug() << "Unknown toplevel for MapNotify";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify";
if (m_allowedWindows.contains(xm->window)) {
if (m_lockWindows.contains(xm->window)) {
qDebug() << "uhoh! duplicate!";
qCDebug(KSCREENLOCKER) << "uhoh! duplicate!";
} else {
if (!m_background->isVisible()) {
// not yet shown and we have a lock window, so we show our own window
......@@ -386,12 +387,12 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
case XCB_UNMAP_NOTIFY: {
xcb_unmap_notify_event_t *xu = reinterpret_cast<xcb_unmap_notify_event_t*>(event);
if (xu->event == QX11Info::appRootWindow()) {
qDebug() << "UnmapNotify:" << xu->window;
qCDebug(KSCREENLOCKER) << "UnmapNotify:" << xu->window;
int index = findWindowInfo( xu->window );
if( index >= 0 )
m_windowInfo[ index ].viewable = false;
else
qDebug() << "Unknown toplevel for MapNotify";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for MapNotify";
m_lockWindows.removeAll(xu->window);
if (m_focusedLockWindow == xu->event && !m_lockWindows.empty()) {
// The currently focused window vanished, just focus the first one in the list
......@@ -404,10 +405,10 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
case XCB_CREATE_NOTIFY: {
xcb_create_notify_event_t *xc = reinterpret_cast<xcb_create_notify_event_t*>(event);
if (xc->parent == QX11Info::appRootWindow()) {
qDebug() << "CreateNotify:" << xc->window;
qCDebug(KSCREENLOCKER) << "CreateNotify:" << xc->window;
int index = findWindowInfo( xc->window );
if( index >= 0 )
qDebug() << "Already existing toplevel for CreateNotify";
qCDebug(KSCREENLOCKER) << "Already existing toplevel for CreateNotify";
else {
WindowInfo info;
info.window = xc->window;
......@@ -425,7 +426,7 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if( index >= 0 )
m_windowInfo.removeAt( index );
else
qDebug() << "Unknown toplevel for DestroyNotify";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for DestroyNotify";
ret = true;
}
break;
......@@ -437,11 +438,11 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if( index >= 0 )
m_windowInfo.removeAt( index );
else
qDebug() << "Unknown toplevel for ReparentNotify away";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for ReparentNotify away";
} else if (xr->parent == QX11Info::appRootWindow()) {
int index = findWindowInfo( xr->window );
if( index >= 0 )
qDebug() << "Already existing toplevel for ReparentNotify";
qCDebug(KSCREENLOCKER) << "Already existing toplevel for ReparentNotify";
else {
WindowInfo info;
info.window = xr->window;
......@@ -458,7 +459,7 @@ bool X11Locker::nativeEventFilter(const QByteArray &eventType, void *message, lo
if( index >= 0 ) {
m_windowInfo.move( index, xc->place == PlaceOnTop ? m_windowInfo.size() - 1 : 0 );
} else
qDebug() << "Unknown toplevel for CirculateNotify";
qCDebug(KSCREENLOCKER) << "Unknown toplevel for CirculateNotify";
}
break;
}
......@@ -513,7 +514,7 @@ void X11Locker::addAllowedWindow(quint32 window)
return;
}
if (m_lockWindows.contains(window)) {
qDebug() << "uhoh! duplicate!";
qCDebug(KSCREENLOCKER) << "uhoh! duplicate!";
} else {
if (!m_background->isVisible()) {
// not yet shown and we have a lock window, so we show our own window
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment