Commit Graph

274 Commits

Author SHA1 Message Date
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
Jarek Kobus
fdc8193f13 ProcessInterface: Drop ProcessMode from c'tor
Drop it also from registerHandle() methods, as it wasn't
used there.

Change-Id: I34b72c38368b82f22d73314fe3cd429ed43cadbc
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-02-18 08:29:24 +00:00
Alessandro Portale
74643556f9 Utils: Print out QtcProcess number in result debug log
That makes it easier to understand which result belongs to which
process. And make the result output a 1-liner in the case of logging,
which makes filtering easier.

Change-Id: I6da84d28fe2269d2d6dfe6f5a1d300faf5697ca1
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-02-17 17:07:10 +00:00
Jarek Kobus
ae36fd943a ProcessInterface: Drop arguments from finished() signal
Make the API more similar to QtcProcess API.

Change-Id: If62051908b7974008bebda21dd288b02e7a772f3
Reviewed-by: hjk <hjk@qt.io>
2022-02-17 16:58:19 +00:00
Jarek Kobus
531e24892b Fix starting remote process in terminal
SshDeviceProcess::start() is overridden and it starts
connecting phase. It marks the current state as
Starting. Later, when connection is being established,
it calls back the base QtcProcess::start() and it
fails on assert. This doesn't happen when starting
not in terminal, as in this case SshDeviceProcess
delegates the start to the aggregated SshRemoteProcess
instead of calling QtcProcess::start().

Disabling the assert for a while, until we de-virtualize
the public interface back again, as from the public
API side it's still a valid assert.

Change-Id: I0d62ec0db778f68fcc5afa4a6f08d54f98d74e4f
Reviewed-by: hjk <hjk@qt.io>
2022-02-17 11:43:04 +00:00
Jarek Kobus
0b08b24682 A gift for Alessandro
Add an info to the start process log about whether it was
started by a call to QtcProcess::runBlocking() or not.
In case it was, specify the event loop mode.

Change-Id: Ie1adf0526b341eedcd0d84505075a942b057ff99
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-02-17 08:46:56 +00:00
Jarek Kobus
e0d6568751 QtcProcess: Fix a lacking call to setBelowNormalPriority()
Amends 825c89987c

Change-Id: Ib6a812efb924f8ea840b510656fee3a5b3b41fbc
Reviewed-by: hjk <hjk@qt.io>
2022-02-17 08:11:36 +00:00
Leena Miettinen
2a1ce51ce3 Utils: Fix UI text punctuation and capitalization
Also simplify the wording of a message.

Task-number: QTCREATORBUG-27055
Change-Id: I29df31f8484d451d8d8d1869ca3a1b182072d2c1
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-02-16 16:57:17 +00:00
Jarek Kobus
86017efdd4 QtcProcess: Recreate process interface on every start
Since the input data may have changed in meantime.
Ensure we are not running when restarting the process.

Change-Id: I79a515b3c0526a6315027433fd821698fb2c6e94
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:55:56 +00:00
Jarek Kobus
82c2450fbe Reuse ProcessSetupData in CallerHandle
Change-Id: I4a2d3fef15331343e7763149550280b722fc3781
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:30:01 +00:00
Jarek Kobus
aa3166df78 ProcessInterface: Simplify start() API
Get rid of program and arguments parameters from
start() method. Get rid of customStart() and isCustomStart()
methods. Provide a default implementation for start() method.
Introduce virtual doDefaultStart() method, to be called when
default implementation for start() is used() - it's being
triggered by a call to defaultStart(). When some implemetation
provides the custom implemetation of start() method
(e.g. TerminalImpl), the doDefaultStart() may stay unimplemented
(won't be called).

Rename WrongFileNameFailure to WrongCommandFailure, as that's
being used also in case when command arguments parsing failed.

Cleanup some unimplemented or unused fields of ProcessLauncherImpl.

Change-Id: I87661e9838dc30888034b2fa62d47c861bf8f9dd
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:20:08 +00:00
Jarek Kobus
d06449d1a5 ProcessInterface: Remove setEnvironment()
Use environment from ProcessSetupData instead.

Change-Id: I8f0436b8ce024ca5ce39ae2cd842b4d195f2c54d
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:14:30 +00:00
Jarek Kobus
d520d457c1 ProcessInterface: Simplify customStart() method
Change-Id: I8940ca016076e42a73774a18a24b6b5ce2cb81ad
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:09:31 +00:00
Jarek Kobus
5c3a08bc4b ProcessInterface: Simplify start() method
Don't pass writeData, as that's available through
ProcessSetupData.

Change-Id: Ic55b21c6a3338168ee251bcc1c57594f50c52d2f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 09:09:24 +00:00
Jarek Kobus
c49ce24a92 ProcessInterface: Make a copy of ProcessSetupData
Don't share the same instance of data with the QtcProcess
itself, as some of the fields needs to be modified just
for the starting purposes. In this way we avoid cyclic
modifications of the original data on subsequent runs.

Change-Id: I937978ee92f848d247025939ac5b0c6c60c29ff7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
2022-02-16 08:22:23 +00:00
Jarek Kobus
ccb42b3c74 ProcessInterface: Remove setWorkingDirectory()
It's a part of passed ProcessSetupData.

Change-Id: I125d31cb1b316c1802d1d9d7fb5e1c5b3a3b8c18
Reviewed-by: hjk <hjk@qt.io>
2022-02-15 14:55:46 +00:00
Jarek Kobus
5c1dc2fd5e Move more internal data into ProcessSetupData
It's going to be reused in other parts of implementation.

Change-Id: I4721bba28537d3f00c20c0f3c8e5ca633dc8727e
Reviewed-by: hjk <hjk@qt.io>
2022-02-15 14:54:42 +00:00
Jarek Kobus
ce40605934 ProcessInterface: Remove program() method
It looks it's really unneeded.

Change-Id: Ie9447abfbe57968e5f5302be6b23cb950c4d0ea7
Reviewed-by: hjk <hjk@qt.io>
2022-02-14 16:24:56 +00:00