From 0e1ce757d530c5e84d4c3ad070fd8ebf47c2e3d2 Mon Sep 17 00:00:00 2001 From: Dominik Holland Date: Tue, 27 Sep 2022 09:51:24 +0200 Subject: [PATCH] Add a configure option to exit on poll errors If an error is returned from qt_safe_poll inside the event dispatcher the error is currently printed and ignored. For most cases this behavior seems to be fine, but when used in critical systems e.g. automotive or medical, a error might indicate a more severe problem and the application should be stopped instead. The system can then decide itself what to do e.g. restarting the application using a watchdog. Change-Id: Iaf5abb20bb3941eaeff19d14e41c395c88fa088d Reviewed-by: Thiago Macieira --- src/corelib/configure.cmake | 8 ++++++++ src/corelib/kernel/qeventdispatcher_unix.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/corelib/configure.cmake b/src/corelib/configure.cmake index 02c339a4bf9..5563729a5be 100644 --- a/src/corelib/configure.cmake +++ b/src/corelib/configure.cmake @@ -961,6 +961,13 @@ qt_feature("cborstreamwriter" PUBLIC LABEL "CBOR stream writing" PURPOSE "Provides support for writing the CBOR binary format." ) +qt_feature("poll-exit-on-error" PUBLIC + LABEL "Poll exit on error" + AUTODETECT OFF + CONDITION UNIX + PURPOSE "Exit on error instead of just printing the error code and continue." +) +qt_feature_definition("poll-exit-on-error" "QT_POLL_EXIT_ON_ERROR") qt_configure_add_summary_section(NAME "Qt Core") qt_configure_add_summary_entry(ARGS "backtrace") qt_configure_add_summary_entry(ARGS "doubleconversion") @@ -970,6 +977,7 @@ qt_configure_add_summary_entry(ARGS "icu") qt_configure_add_summary_entry(ARGS "system-libb2") qt_configure_add_summary_entry(ARGS "mimetype-database") qt_configure_add_summary_entry(ARGS "cpp-winrt") +qt_configure_add_summary_entry(ARGS "poll-exit-on-error") qt_configure_add_summary_entry( TYPE "firstAvailableFeature" ARGS "etw lttng" diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp index 94ed8c74add..af0b0d03d25 100644 --- a/src/corelib/kernel/qeventdispatcher_unix.cpp +++ b/src/corelib/kernel/qeventdispatcher_unix.cpp @@ -466,7 +466,11 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags) switch (qt_safe_poll(d->pollfds.data(), d->pollfds.size(), tm)) { case -1: +#ifdef QT_POLL_EXIT_ON_ERROR + qFatal("qt_safe_poll errno: %i error: %ls", errno, qUtf16Printable(qt_error_string())); +#else perror("qt_safe_poll"); +#endif break; case 0: break;