diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,8 @@ set(KSLD_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/KScreenLocker") +include(ECMQtDeclareLoggingCategory) + add_subdirectory(kcheckpass) add_subdirectory(greeter) add_subdirectory(kcm) @@ -169,6 +171,18 @@ 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) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -8,7 +8,9 @@ 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 @@ ####################################### # 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 diff --git a/greeter/CMakeLists.txt b/greeter/CMakeLists.txt --- a/greeter/CMakeLists.txt +++ b/greeter/CMakeLists.txt @@ -21,6 +21,17 @@ 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) diff --git a/greeter/greeterapp.cpp b/greeter/greeterapp.cpp --- a/greeter/greeterapp.cpp +++ b/greeter/greeterapp.cpp @@ -25,6 +25,7 @@ #include "wallpaper_integration.h" #include "lnf_integration.h" +#include #include // KDE @@ -257,7 +258,7 @@ { 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 @@ [this, qmlObject, view] { auto item = qobject_cast(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 @@ 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); } diff --git a/greeter/main.cpp b/greeter/main.cpp --- a/greeter/main.cpp +++ b/greeter/main.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -31,6 +30,8 @@ #include "greeterapp.h" #include +#include + #if HAVE_SYS_PRCTL_H #include #endif @@ -56,11 +57,11 @@ // 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 @@ 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"); diff --git a/ksldapp.cpp b/ksldapp.cpp --- a/ksldapp.cpp +++ b/ksldapp.cpp @@ -28,7 +28,10 @@ #include "logind.h" #include "kscreensaversettings.h" #include "powermanagement_inhibition.h" + +#include "kscreenlocker_logging.h" #include + #include #include "waylandserver.h" // KDE @@ -163,7 +166,7 @@ // 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,54 +211,56 @@ auto finishedSignal = static_cast(&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; if (regularExit || s_graceTimeKill || s_logindExit) { // 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; s_logindExit = false; doUnlock(); 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 @@ 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 @@ 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 @@ // 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; } diff --git a/logind.cpp b/logind.cpp --- a/logind.cpp +++ b/logind.cpp @@ -22,11 +22,12 @@ #include #include -#include #include #include #include +#include + 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 @@ 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. diff --git a/x11locker.cpp b/x11locker.cpp --- a/x11locker.cpp +++ b/x11locker.cpp @@ -27,14 +27,15 @@ // KDE // Qt #include -#include #include #include // X11 #include #include #include +#include + static Window gVRoot = 0; static Window gVRootData = 0; static Atom gXA_VROOT; @@ -104,7 +105,7 @@ 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 @@ 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 @@ case XCB_MAP_NOTIFY: { // from SubstructureNotifyMask on the root window xcb_map_notify_event_t *xm = reinterpret_cast(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 @@ case XCB_UNMAP_NOTIFY: { xcb_unmap_notify_event_t *xu = reinterpret_cast(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 @@ case XCB_CREATE_NOTIFY: { xcb_create_notify_event_t *xc = reinterpret_cast(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 @@ 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 @@ 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 @@ 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 @@ 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