Commit Graph

341 Commits

Author SHA1 Message Date
Jarek Kobus
9402841d99 QtcProcess: Fix runBlocking() on remote
There is no need for special handling when running on remote.

Change-Id: If30245d2ece475cb72df2be4390210d6b8c0c1aa
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-05-03 19:31:50 +00:00
Jarek Kobus
ece39c7c2f QtcProcess: Use generic waitFor...()
Task-number: QTCREATORBUG-27430
Change-Id: I34ecc8a5937204875c235eee285c32d9cb0a0a86
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-05-03 14:32:41 +00:00
Jarek Kobus
221414c5e8 QtcProcess: Implement waitFor...() in general way
Task-number: QTCREATORBUG-27430
Change-Id: I34aff44258d2c7cabae0b63fe4e9ec55aa7b3b7d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-05-03 14:32:29 +00:00
Marcus Tillmanns
c8024046f9 Docker: implement process interface
Change-Id: I57dd9e060ee35280b663611ebb5ddef20b7d0eb7
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-05-03 08:26:13 +00:00
Jarek Kobus
703dbd9c79 QtcProcess: Add a warning when starting a process in non-QThread
When a QProcess is being started in a thread that doesn't have
event dispatcher installed, e.g. in a thread started with
std::async(), the process signals are emitted only from inside
QProcess::waitFor...() functions, but not emitted spontaneously.
This may cause issues when adding the running process into the
ProcessReaper, as the implementation of the latter relies on
signal emission and doesn't use blocking API of QProcess.

Currently there is one case like this: ProcessCreator::createProcess()
of clangsupport library.

Change-Id: I823a139b356f62fee9e0e5d6fc8326301c36b449
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-28 20:15:30 +00:00
hjk
b971c27312 Utils: Use a somewhat better fallback when no environment was set
Change-Id: Ic92b7b2bf50ecfed4790393a763b17bb988e892c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-04-28 16:21:59 +00:00
hjk
aa3bdcb427 Utils: Add a QString-based write to QtcProcess
Centralize some boiler plate and warn about best-guessed cases.

Keep the QByteArray based access as writeRaw()

Fixes: QTCREATORBUG-27445
Change-Id: I948d80fba78b36cf85cc73664175ab05eb7707d4
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-04-28 08:20:11 +00:00
Jarek Kobus
c81a7b5c70 QtcProcess: Add processChannelMode() getter
Use ProcessInterface's setup data when handling
readyRead signals. In this way the user may still
change this setting, also when QtcProcess is running,
as a preparation for the next run. In this way this
works like all other QtcProcess mutators.

Change-Id: Ie80475e322162ce109fb95468ce858f9c98eefa9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-04-26 16:29:41 +00:00
David Schulz
11ce6e365f Utils: fix QProcess backend on Windows
Do not return false from QtcProces::waitForStarted if the process is
already running. This causes mayor issues on windows since QProcess
directly emits started and therefore switches to the running state after
calling QProcess::start.

Change-Id: I4604b08a59918d3df11c8a174b57e1e483e78a0d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-04-25 10:04:48 +00:00
Aaron Barany
df0593b5e1 Utils: Preserve output order with merged channels
Restored the process channel mode members to ProcessSetupData and
StartProcessPacket and forward to the QProcess created in
LaunchSocketHandler. LaunchSocketHandler now avoids reading from stderr
for merged channels since it's guaranteed to not be available.

This avoids asserts in Qt 6.3.0 and warnings in Qt 6.3.1 while
preserving the original output order when an application has a mix of
stdout and stderr output.

Change-Id: I9f4541932cf9d8638b38658a5efea9cb5f1798f3
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-04-19 19:39:24 +00:00
Jarek Kobus
44c7020651 ProcessInterface: Get rid of state() method
This is fully controlled by QtcProcess itself, so provide
general implementation of state() inside QtcProcess.

Task-number: QTCREATORBUG-27358
Change-Id: Id6f0b771ed933f870b80d6856c6d94896f946516
Reviewed-by: hjk <hjk@qt.io>
2022-04-14 13:49:25 +00:00
Jarek Kobus
bc30523293 ProcessInterface: Get rid of ProcessInterface::Ptr
Keep the setup data on stack instead on heap.

Task-number: QTCREATORBUG-27358
Change-Id: I0fffd525e2bd4f46533804e3b88fe5b330d02a91
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-14 12:41:01 +00:00
Jarek Kobus
bfc0d5ec32 ProcessInterface: Get rid of ProcessProxyInterface
It doesn't seem to be useful anymore.
Add some comments to the ProcessInterface API.
Move virtual interface into the private section
in order to not to use it directly from implementation.

Task-number: QTCREATORBUG-27358
Change-Id: Idd9fd39cf153832e6e44e125fbbd5c8236a2d930
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-14 12:13:08 +00:00
Jarek Kobus
a4a651aa32 QtcProcess: Fix StartFailed result
Amends 4ca336762e

Change-Id: I3781bec37b17ea3f86eedc51657db0931a456c39
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-14 07:55:22 +00:00
Jarek Kobus
7c8b5648fe ProcessInterface: Add sendControlSignal() method
It substitutes terminate, kill, interrupt and kickoffProcess
methods.

Task-number: QTCREATORBUG-27358
Change-Id: I9e952c2f4c1a7e76339366566f2c804a3df30347
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-13 14:39:33 +00:00
Jarek Kobus
25be242c6f ProcessInterface: Get rid of close() method
Implement it in general way inside QtcProcess instead.

Task-number: QTCREATORBUG-27358
Change-Id: Ibc4c9753c57cd73afcccb2991282ee459dc69780
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-13 14:39:25 +00:00
Jarek Kobus
267aa92a8a ProcessInterface: Pass processId with started() signal
Pass also applicationMainThreadId optionally (Windows only).
Remove two virtual accessors.

Task-number: QTCREATORBUG-27358
Change-Id: I3b12b642cc3c109653276c0fbf65e7f614ce6b56
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-13 14:39:18 +00:00
Jarek Kobus
aa3f467ee2 ProcessInterface: Add readyRead() signal
And get rid of readyReadStandard[Output/Error]() signals.
Get rid of readAllStandard[Output/Error]() accessors, as
this data is passed with readyRead() signal.

Task-number: QTCREATORBUG-27358
Change-Id: I01341feba650e650761f97e90f83b6042c899251
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-12 14:00:14 +00:00
Jarek Kobus
4ca336762e ProcessInterface: Add done() signal
And get rid of errorOccurred() and finished() signals.
Get rid of resultData() accessor, as this data is passed
with done() signal.

Task-number: QTCREATORBUG-27358
Change-Id: I677bbd174cceea6d8f5a989f961222c417992b60
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-12 14:00:03 +00:00
Jarek Kobus
00acccfd3d QtcProcess: Fix terminate() for process launcher
ProcessLauncherImpl::terminate() was behaving the same as
ProcessLauncherImpl::kill() in case of process launcher
implementation - in both cases the launcher
immediately returned confirmation about receiving the
close request and was putting the corresponding
process into its reaper. However, the issue with this approach
is that we can't receive anymore any potential ready
read signal from the process being terminated after
a call to terminate().

The fix is to diverge the behavior of terminate()
and kill() of ProcessLauncherImpl. The behavior of kill()
remains the same, while terminate() just instructs the
process launcher to start termination without putting
the process into the reaper, yet.

Add a test that checks for any possible zombies.

We run the RecursiveBlockingProcess recursively. The most
nested process blocks. After a short wait we terminate
the outermost process. With this test we are trying to see
if terminating the middle process terminates also its
children and doesn't leave zombies.

Before we execute the test (and also by the end of this test)
we call Singleton::deleteAll() in order to ensure that reaping
of previously running processes has finished. We ensure the
number of running processtestapps is zero. Later, we ensure that
the leaf process was already started and the number of running
processtestapps equals the depth of recursion.

Fix apparent bug in getLocalProcessesUsingProc().

Change-Id: I7e2bc46ad5ca22f26620da86fbaf0fa00a7db3c3
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-04-12 13:59:41 +00:00
Jarek Kobus
2794b5e543 tst_QtcProcess: Get rid of lineCallbackIntern() test
This test introduced some additional private API to QtcProcess.
This makes refactorings of QtcProcess harder, as we need to
handle this artificial code working.

We have a real lineCallback() test instead which doesn't
employ this private API.

Change-Id: Idbc314210cecc2044e1ccc298e5d3e0a9747e811
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-11 15:26:10 +00:00
Jarek Kobus
936c44f367 Introduce ProcessResultData
It should be useful when reimplementing ProcessInterface.
It replaces 4 virtual methods with just 1.

Task-number: QTCREATORBUG-27358
Change-Id: I2dafbfbc25f8f016ff2aa19c1a176335a4a7498c
Reviewed-by: hjk <hjk@qt.io>
2022-04-11 06:51:51 +00:00
Jarek Kobus
5b923954c0 QtcProcess: Make exitMessage() a const method
Change-Id: Ibb0aaf0bf3bf216673646ea7b869fd7e55e6b81c
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-05 13:36:48 +00:00
Jarek Kobus
a717ff71f4 QtcProcess: Ensure we don't delete the process from handlers
Guard that we don't delete the QtcProcess directly from
inside its handlers.

This helps in detecting wrong usage of QtcProcess.

Change-Id: Ia5b154b3e1f827d579910ebe81ae230fc797c377
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-04-05 12:41:13 +00:00
Jarek Kobus
ab11c4373b QtcProcess: Introduce done() signal
Introduce QtcProcess::done() signal. It's similar to
QtcProcess::finished() signal, but also emitted when
process failed to start (so after QProcess::FailedToStart
error occurred).

SshRemoteProcess::finished() signal was already behaving
like this. So, we remove special handling of
FailedToStart error in this class and connect all clients
of SshRemoteProcess to done() signal, instead of finished().

Task-number: QTCREATORBUG-27232
Change-Id: If4240e2172f3f706e812bca669a1d5b24bdc3285
Reviewed-by: hjk <hjk@qt.io>
2022-04-04 13:28:12 +00:00
Jarek Kobus
365a05640b QtcProcess: Get rid of setErrorString() method
It's internal method, not meant to be used outside.
It's only used in case of FailedToStart error.
Remove it also from ProcessInterface.
Leave it inside DefaultImpl and its subclasses only.

Remove m_errorString field from ProcessSetupData.

Change-Id: Ie605b95c2ff605ab1259045f1a5b16049207c1d3
Reviewed-by: hjk <hjk@qt.io>
2022-04-04 10:20:34 +00:00
hjk
6297851f29 Utils: Merge TerminalProcess into TerminalImpl
Change-Id: I60a03f315e84e17877d4ecd809a994f08934bedf
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-01 11:25:46 +00:00
Jarek Kobus
b76b8b1542 ProcessReaper: Implement custom terminate for CtrlCStub case
Move CtrlCStub-specific interrupt into ProcessHelper.

Amends 7d7e4af3afb5ba9d0ed5210018dd6be67abda469

Change-Id: I5cd9a750c4a89587a874515f752b0144df4b8309
Reviewed-by: hjk <hjk@qt.io>
2022-03-31 12:48:42 +00:00
hjk
27c8f00d73 Utils: Un-seat QtcProcess from ProcessInterface
I find it too confusing to have that inheritance only to enforce
similar interfaces.

Change-Id: I9da68ea59c04f709228e0874460e987115b30f56
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-03-31 10:14:36 +00:00
Jarek Kobus
d7ff76be69 QtcProcess: Drop return value from stopProcess()
It wasn't used at all.

Change-Id: Ife0989c73c67b6106e61c40931f318ee7a5b062d
Reviewed-by: hjk <hjk@qt.io>
2022-03-24 08:12:03 +00:00
hjk
1960799be2 Utils: Add bits of process output when debugging QtcProcess
Change-Id: I03b7825e29be5dd5a78768c5831756703ce7fdf1
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-03-18 15:29:49 +00:00
Jarek Kobus
cfe8b7ad88 Fix handling of unfinished lines by QtcProcess callbacks
Don't detect a call to QtcProcess::kill() from inside the
QtcProcess callback while awaiting inside QtcProcess::waitFor...().
That's not needed, since a call to kill() sends a stop message
to the process launcher, so we wait for confirmation
from process launcher instead. This may bring e.g. new
read data from the running process.

Fix a runBlockingStdOut() test so that when we write to the stdOut
from the running process we flush the unfinished line so that
it's not buffered inside the process.

Change-Id: I7944ac214d8cb9e10a71715a7ef8bfacab6df7c9
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-03-14 07:38:08 +00:00
Jarek Kobus
82108e949a ProcessInterface: Rename interruptProcess() -> interrupt()
Both functionalities meant to do the same.

Change-Id: Idd9373cdb24b7b41f9e4befb09326c339263eeb1
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-03-10 08:41:05 +00:00
Jarek Kobus
65dd738a01 Fix a call to endFeed() when process wasn't started
Fixes the tst_qtcprocess::lineCallbackIntern() test.

Change-Id: Id608ab834deaccf854f3d8ff9f4a172de58ef9a2
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-09 09:38:20 +00:00
Jarek Kobus
ac3aa805b9 QtcProcess: Ensure we set the data just after creating handle
...instead of ensuring in many functions that m_setup isn't null.
This amends 36c49cd2ea and
solves the issue for other functions like processId(),
exitCode(), etc...

Amends 36c49cd2ea

Change-Id: I986f7b30e90e5825ae2bb57b4bc2aa14f56e401f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-03-03 10:02:36 +00:00
Jarek Kobus
a17374778a Introduce ProcessProxyInterface, enable data sharing
ProcessProxyInterface will be helpful when implementing
public subclasses of ProcessInterface, like
general ssh impl, linux specific impl, qnx specific, etc.

ProcessProxyInterface is sharing private data
between proxy and target.

Change-Id: I8350837bb5f770d6605b860b146604cba5e6b592
Reviewed-by: hjk <hjk@qt.io>
2022-03-02 15:31:13 +00:00
Jarek Kobus
8e0ae8ba96 QtcProcess: Limit the inclusion of qtcprocess.h
Move the rest of QtcProcess enums to processenums.h.
Move ExitCodeInterpreter into processenums.h.
Remove superfluous Utils:: prefix.

Change-Id: Iaa596f353d33d6930085a621b114cc15a35caa80
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-02 13:30:39 +00:00
Jarek Kobus
6ff1723c4c ProcessInterface: Move out default impl into separate class
Introduce private DefaultImpl class and base QProcessImpl
and ProcessLauncherImpl on it. Remove default impl specific
methods from ProcessInterface.

Change-Id: Iea964ab19cc0ea8401180f65351b6ef3f595703f
Reviewed-by: hjk <hjk@qt.io>
2022-03-02 13:30:14 +00:00
hjk
92de389a61 QtcProcess: Fix crash when logging process stats
Change-Id: I204366a008dea91d1b2b946689c7598fe9ab009c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-02-28 14:52:23 +00:00
Jarek Kobus
7b234e0fae QtcProcess: Introduce virtual emit* temporarily
Introduce emitStarted, emitFinished and emitErrorOccurred
virtual protected methods for QtcProcess subclasses.
It makes it easier to connect to self signals and
filter out the unneeded emissions. This is a temporary
change until QtcProcess is de-virtualized.

Amends ff68923846

Change-Id: I784676458e86314e092366e3b3b1244dfe2712f3
Reviewed-by: hjk <hjk@qt.io>
2022-02-28 14:52:15 +00:00
Alessandro Portale
cc139b768f Utils: Cleanup logging to qtc.utils.qtcprocess + elapsed time
Always write the process number on the same column of "started" and
"finished" line, for easier reading.
Do not quote the command line.
Write out only count of bytes for stderr (like for stdout).
Add extra logging categories qtc.utils.qtcprocess.stout and *.stderr for
verbose outpout.

Add the elapsed time in ms to the "finished" line.

Change-Id: I493279c1b4cdaf8f4c292df4777befc7f6c50753
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-02-23 08:35:45 +00:00
Jarek Kobus
fd7bf831ba Introduce processImplHook
Call new hook from inside QtcProcess::start().
This hook calls new virtual method
IDevice::createProcessInterface().
That's all what should be needed from device
to setup properly device specific process.

Make QtcProcess::createProcessInterface() private now.

Change-Id: I2136698063bafc846ebc2d3db6cc11376902eff0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-02-22 17:28:31 +00:00
Eike Ziller
8259df00d0 Merge remote-tracking branch 'origin/7.0'
Conflicts:
	src/plugins/mcusupport/mcupackage.cpp
	src/plugins/mcusupport/mcusupportoptions.cpp
	src/plugins/mcusupport/mcusupportoptions.h
	src/plugins/mcusupport/mcusupportoptionspage.cpp
	src/plugins/mcusupport/mcusupportplugin.cpp
	src/plugins/mcusupport/mcusupportsdk.cpp

Change-Id: Ib423e9f23877176f01b188104b0a179ed32c4770
2022-02-22 14:06:41 +01:00
Jarek Kobus
d502f78c4f TerminalImpl: Drop ProcessImpl and Terminal mode from c'tor
Change-Id: I0571eabb1a20389055a8e98dd942776b3d054981
Reviewed-by: hjk <hjk@qt.io>
2022-02-21 16:49:43 +00:00
Jarek Kobus
02d9a9b7b7 ProcessInterface: Fix parent-child relationship
Make ProcessInterface c'tor accept nullptr as parent.
Remove parent argument from subclasses of
ProcessInterface, as calling setProcessInterface()
sets the parent anyway. Fix parent-child relationship
in subclasses of ProcessInterface - pass *this as a parent.

Change-Id: I3c37c305a87bad0e6d11251ec3db538f3a5dd64b
Reviewed-by: hjk <hjk@qt.io>
2022-02-21 16:49:24 +00:00
Jarek Kobus
6360cffc80 Fix passing environment to remote
After removing Runnable parameter from DeviceProcess::start()
(see 95c9579c58) we are now
setting the runnable's environment to the remote process
directly. This is now used in 2 places:

1. For forming the proper fullCommandLine(), so that
the passed environment is expanded to command line
arguments

2. For running the remote process itself.

Before the mentioned change these two environments were
separated (1st was taken from run environment aspect,
2nd was left with its default value - see SshProcess c'tor).
After the mentioned change 1 and 2 are equal (i.e. both are
env aspect). This affects running app in terminal,
as the aspect env is applied to the stub process, so it
can't start properly.

This change brings the separation back.

Amends 95c9579c58

Change-Id: I5efe82e19d3fb5608f97e56c2f4b7651643e156a
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-02-21 14:21:33 +00:00
Jarek Kobus
192bbb7618 ProcessInterface: Place the class in separate header file
Change-Id: I9f3924f7cf69af58f93fc19f0af25c6fa9cfb55e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-02-21 14:18:40 +00:00
Jarek Kobus
357c39f2d7 Base QtcProcess on ProcessInterface
Change-Id: I51bc6b7aea8e2d3aa0ef9fbba3b5fc796058c8cb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-02-18 23:35:55 +00:00
Jarek Kobus
48960b5cfc QtcProcess: Extract QtcProcess specific enums into separate header
Change-Id: Ib3498f189000fd8f5501130c0d280b0f5ae83849
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-02-18 10:51:55 +00:00
Jarek Kobus
e49f57b3ec ProcessInterface: Hide m_setup in protected section
Change-Id: I8931ae0eabbc1962a8cf104fbbb849149e0cf88b
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-02-18 09:34:22 +00:00