Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 526d785

Browse filesBrowse files
committed
......
1 parent f88e2ba commit 526d785
Copy full SHA for 526d785

File tree

4 files changed

+21
-75
lines changed
Filter options

4 files changed

+21
-75
lines changed

‎src/plugins/servicebackends/windows/windowsservicebackend.cpp

Copy file name to clipboardExpand all lines: src/plugins/servicebackends/windows/windowsservicebackend.cpp
+11-14Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ int WindowsServiceBackend::runService(int &argc, char **argv, int flags)
7373
Q_UNUSED(argc)
7474
Q_UNUSED(argv)
7575
xPath = QFileInfo{QString::fromUtf8(argv[0])}.dir().absolutePath();
76-
qInfo() << Q_FUNC_INFO << "installing message handler";
7776
qInstallMessageHandler(WindowsServiceBackend::winsvcMessageHandler);
78-
qInfo() << Q_FUNC_INFO << "installed message handler";
7977

8078
// if not set: get the app name from it's basename
8179
Q_ASSERT_X(!QCoreApplication::applicationName().isEmpty(), Q_FUNC_INFO, "QCoreApplication::applicationName must be set before starting a windows service!");
8280

8381
// start handler and wait for service init
8482
SvcControlThread controlThread{this};
85-
qInfo() << Q_FUNC_INFO << "waiting for control thread...";
83+
qCDebug(logBackend) << "waiting for control thread...";
8684
controlThread.start();
8785
QMutexLocker lock(&_svcLock);
8886
if(!_startCondition.wait(&_svcLock, 20000))
@@ -98,7 +96,7 @@ int WindowsServiceBackend::runService(int &argc, char **argv, int flags)
9896
lock.unlock();
9997

10098
// create and prepare the coreapp
101-
qInfo() << Q_FUNC_INFO << "setting status to start pending";
99+
qCDebug(logBackend) << "setting status to start pending";
102100
setStatus(SERVICE_START_PENDING);
103101
QCoreApplication app(sArgc, sArgv.data(), flags);
104102
app.installNativeEventFilter(new SvcEventFilter{});
@@ -126,21 +124,20 @@ int WindowsServiceBackend::runService(int &argc, char **argv, int flags)
126124
setStatus(SERVICE_START_PENDING);
127125

128126
lock.relock();
129-
qInfo() << Q_FUNC_INFO << "continuing control thread";
127+
qCDebug(logBackend) << "continuing control thread";
130128
_startCondition.wakeAll();
131129
lock.unlock();
132130

133131
//execute the app
134-
qInfo() << Q_FUNC_INFO << "running application";
132+
qCDebug(logBackend) << "running application";
135133
_status.dwServiceSpecificExitCode = app.exec();
136-
qInfo() << Q_FUNC_INFO << "setting exit code";
137134
if(_status.dwServiceSpecificExitCode != EXIT_SUCCESS)
138135
_status.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
139136
setStatus(SERVICE_STOPPED);
140137

141138
//cleanup
142139
if(controlThread.isRunning()) {
143-
qInfo() << Q_FUNC_INFO << "stopping control thread";
140+
qCDebug(logBackend) << "stopping control thread";
144141
controlThread.requestInterruption();
145142
if(!controlThread.wait(2000)) {
146143
controlThread.terminate();
@@ -209,10 +206,10 @@ void WindowsServiceBackend::setStatus(DWORD status)
209206

210207
void WindowsServiceBackend::serviceMain(DWORD dwArgc, wchar_t **lpszArgv)
211208
{
212-
qInfo() << Q_FUNC_INFO << "entered control thread";
209+
qCDebug(logBackend) << "entered control thread";
213210
Q_ASSERT(_backendInstance);
214211

215-
qInfo() << Q_FUNC_INFO << "registering service";
212+
qCDebug(logBackend) << "registering service";
216213
_backendInstance->_statusHandle = RegisterServiceCtrlHandlerW(SVCNAME, WindowsServiceBackend::handler);
217214
if (!_backendInstance->_statusHandle) {
218215
qCCritical(logBackend) << "Failed to acquire service handle with error:"
@@ -222,7 +219,7 @@ void WindowsServiceBackend::serviceMain(DWORD dwArgc, wchar_t **lpszArgv)
222219
_backendInstance->setStatus(SERVICE_START_PENDING);
223220

224221
// pass the arguments to the main thread and notifiy him
225-
qInfo() << Q_FUNC_INFO << "passing start arguments to main thread";
222+
qCDebug(logBackend) << "passing start arguments to main thread";
226223
QMutexLocker lock(&_backendInstance->_svcLock);
227224
_backendInstance->_svcArgs.clear();
228225
_backendInstance->_svcArgs.reserve(dwArgc);
@@ -234,20 +231,20 @@ void WindowsServiceBackend::serviceMain(DWORD dwArgc, wchar_t **lpszArgv)
234231

235232
// wait for the mainthread to finish startup, then register the service handler
236233
lock.relock();
237-
qInfo() << Q_FUNC_INFO << "wait for main thread to finish startup";
234+
qCDebug(logBackend) << "wait for main thread to finish startup";
238235
_backendInstance->_startCondition.wait(&_backendInstance->_svcLock);
239236
lock.unlock();
240237

241238
// handle the start event
242-
qInfo() << Q_FUNC_INFO << "handle service start event";
239+
qCDebug(logBackend) << "handle service start event";
243240
_backendInstance->setStatus(SERVICE_START_PENDING);
244241
QMetaObject::invokeMethod(_backendInstance, "processServiceCommand", Qt::QueuedConnection,
245242
Q_ARG(QtService::ServiceBackend::ServiceCommand, ServiceCommand::Start));
246243
}
247244

248245
void WindowsServiceBackend::handler(DWORD dwOpcode)
249246
{
250-
qInfo() << Q_FUNC_INFO << "received service event" << dwOpcode;
247+
qCDebug(logBackend) << "received service event" << dwOpcode;
251248
// could theoretically happen in a cleanup scenario?
252249
if(!_backendInstance)
253250
return;

‎src/plugins/servicebackends/windows/windowsservicebackend.h

Copy file name to clipboardExpand all lines: src/plugins/servicebackends/windows/windowsservicebackend.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ private Q_SLOTS:
6767
static void winsvcMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
6868
};
6969

70-
Q_DECLARE_LOGGING_CATEGORY(logWinSvc)
70+
Q_DECLARE_LOGGING_CATEGORY(logBackend)
7171

7272
#endif // WINDOWSSERVICEBACKEND_H

‎tests/auto/service/TestService/main.cpp

Copy file name to clipboardExpand all lines: tests/auto/service/TestService/main.cpp
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
int main(int argc, char *argv[])
55
{
6-
#ifdef Q_CC_MSVC
7-
// WORKAROUND for CI bug
6+
#ifndef Q_CC_MSVC
7+
// WORKAROUND for windows service not beeing able to pass env vars
88
if (qEnvironmentVariable("QT_PLUGIN_PATH").isEmpty()) {
99
qputenv("QT_PLUGIN_PATH", QFileInfo{QString::fromUtf8(argv[0])}.dir().absolutePath().toUtf8());
1010
qDebug() << "QT_PLUGIN_PATH" << qEnvironmentVariable("QT_PLUGIN_PATH");
1111
}
12+
if (qEnvironmentVariable("QT_LOGGING_RULES").isEmpty()) {
13+
qputenv("QT_LOGGING_RULES", "qt.service.*.debug=true");
14+
qDebug() << "QT_LOGGING_RULES" << qEnvironmentVariable("QT_LOGGING_RULES");
15+
}
1216
#endif
1317
qDebug() << "libraryPaths" << QCoreApplication::libraryPaths();
1418

‎tests/auto/service/TestWindowsService/tst_windowsservice.cpp

Copy file name to clipboardExpand all lines: tests/auto/service/TestWindowsService/tst_windowsservice.cpp
+3-58Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ void TestWindowsService::init()
7272
QStringLiteral("--pdb"),
7373
QStringLiteral("--no-quick-import"),
7474
QStringLiteral("--no-translations"),
75-
QStringLiteral("--compiler-runtime"),
76-
QStringLiteral("--verbose"), QStringLiteral("2"),
75+
QStringLiteral("--compiler-runtime")
7776
svcName
7877
});
7978
auto env = QProcessEnvironment::systemEnvironment();
@@ -113,55 +112,6 @@ void TestWindowsService::init()
113112
}
114113
QVERIFY(svcDir.cdUp());
115114

116-
// {
117-
// // try ldd to check deps
118-
// QProcess ldd;
119-
// ldd.setProgram(QStringLiteral("ldd")); // should be in path
120-
// ldd.setArguments(QStringList{
121-
// svcName
122-
// });
123-
// ldd.setWorkingDirectory(svcDir.absolutePath());
124-
// ldd.setProcessChannelMode(QProcess::MergedChannels);
125-
// ldd.start();
126-
// QVERIFY2(ldd.waitForFinished(), qUtf8Printable(ldd.errorString()));
127-
// qInfo() << "ldd output:\n" << ldd.readAll().constData();
128-
// QVERIFY2(ldd.exitStatus() == QProcess::NormalExit, qUtf8Printable(ldd.errorString()));
129-
// QCOMPARE(ldd.exitCode(), EXIT_SUCCESS);
130-
// }
131-
132-
// {
133-
// // list files recursively
134-
// QDirIterator lIter{
135-
// _svcDir.path(),
136-
// QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden | QDir::System | QDir::CaseSensitive,
137-
// QDirIterator::Subdirectories
138-
// };
139-
// while (lIter.hasNext())
140-
// qDebug() << lIter.next();
141-
// }
142-
143-
// {
144-
// // test normal service run
145-
// QProcess testP;
146-
// testP.setProgram(svcDir.absoluteFilePath(svcName));
147-
// testP.setArguments({QStringLiteral("--backend"), QStringLiteral("windows")});
148-
// testP.setWorkingDirectory(svcDir.absolutePath());
149-
// testP.setProcessChannelMode(QProcess::MergedChannels);
150-
// auto env = QProcessEnvironment::systemEnvironment();
151-
// env.remove(QStringLiteral("PATH"));
152-
// env.remove(QStringLiteral("QT_PLUGIN_PATH"));
153-
// env.remove(QStringLiteral("QML2_IMPORT_PATH"));
154-
// env.remove(QStringLiteral("QT_PLUGIN_PATH"));
155-
// testP.setProcessEnvironment(env);
156-
// testP.start();
157-
// QVERIFY2(testP.waitForStarted(), qUtf8Printable(testP.errorString()));
158-
// QThread::sleep(5);
159-
// testP.kill();
160-
// qDebug() << testP.exitCode() << testP.readAll();
161-
// QVERIFY2(testP.waitForFinished(), qUtf8Printable(testP.errorString()));
162-
// qDebug() << testP.exitCode() << testP.readAll().constData();
163-
// }
164-
165115
_manager = OpenSCManagerW(nullptr, nullptr,
166116
SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | STANDARD_RIGHTS_REQUIRED);
167117
QVERIFY2(_manager, qUtf8Printable(qt_error_string(GetLastError())));
@@ -185,13 +135,8 @@ void TestWindowsService::init()
185135

186136
void TestWindowsService::cleanup()
187137
{
188-
// print log file
189-
QFile lFile{_svcDir.filePath(QStringLiteral("log.txt"))};
190-
lFile.open(QIODevice::ReadOnly | QIODevice::Text);
191-
qDebug() << lFile.readAll().constData();
192-
193138
// Print eventlog in hopes for some error info:
194-
QProcess::execute(QStringLiteral("wevtutil qe Application"));
139+
//QProcess::execute(QStringLiteral("wevtutil qe Application"));
195140

196141
if(_manager) {
197142
auto handle = OpenServiceW(_manager,
@@ -205,7 +150,7 @@ void TestWindowsService::cleanup()
205150
_manager = nullptr;
206151
}
207152

208-
QVERIFY(_svcDir.remove());
153+
qDebug() << "cleanup result:" << _svcDir.remove();
209154
}
210155

211156
void TestWindowsService::testCustomImpl()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.