summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormae <matthias.ettrich@nokia.com>2012-05-14 18:56:32 +0200
committerAndrew Christian <andrew.christian@nokia.com>2012-05-14 19:11:11 +0200
commit5d6fb033d4e92bb44c3478afae02da17dde41b81 (patch)
tree0db390c5aac52fc6af0555fd9e8a9fe7d2b0de83
parent45251292590ef9e3ce0740e5521936a4ad2e3033 (diff)
Minor fixes to fork-launching
1. pass correct command line arguments 2. abort waitForChildren when waitpit returns 0 (normal case under Linux) 3. avoid writing empty json objects to the pipes 4. encode binary data as base64 Change-Id: I6b2076215d6d62e121a9e75a25acbb139be37598 Reviewed-by: Andrew Christian <andrew.christian@nokia.com>
-rw-r--r--src/core/forklauncher.cpp16
-rw-r--r--src/core/remoteprocessbackend.cpp7
2 files changed, 10 insertions, 13 deletions
diff --git a/src/core/forklauncher.cpp b/src/core/forklauncher.cpp
index 90ab4e4..78c4c26 100644
--- a/src/core/forklauncher.cpp
+++ b/src/core/forklauncher.cpp
@@ -273,8 +273,8 @@ static void fixProcessState(const ProcessInfo& info, int *argc_ptr, char ***argv
argv[0] = strdup(info.program().toLocal8Bit().constData());
else
argv[0] = (*argv_ptr)[0];
- for (int i = 0 ; i < argc ; i++ )
- argv[i+1] = strdup(info.arguments().at(0).toLocal8Bit().constData());
+ for (int i = 1 ; i < argc ; i++ )
+ argv[i] = strdup(info.arguments().at(i-1).toLocal8Bit().constData());
argv[argc] = 0;
*argc_ptr = argc;
*argv_ptr = argv;
@@ -368,11 +368,13 @@ void ChildProcess::processFdSet(QByteArray& outgoing, fd_set& rfds, fd_set& wfds
}
if (FD_ISSET(m_stdout, &rfds)) { // Data to read
readToBuffer(m_stdout, m_outbuf);
- copyToOutgoing(outgoing, RemoteProtocol::stdout(), m_outbuf, m_id);
+ if (m_outbuf.size())
+ copyToOutgoing(outgoing, RemoteProtocol::stdout(), m_outbuf, m_id);
}
if (FD_ISSET(m_stderr, &rfds)) { // Data to read
readToBuffer(m_stderr, m_errbuf);
- copyToOutgoing(outgoing, RemoteProtocol::stderr(), m_errbuf, m_id);
+ if (m_errbuf.size())
+ copyToOutgoing(outgoing, RemoteProtocol::stderr(), m_errbuf, m_id);
}
if (m_state == SentSigTerm && m_timer.hasExpired(m_timeout)) {
m_state = SentSigKill;
@@ -577,7 +579,7 @@ void ParentProcess::waitForChildren()
int status;
while (1) {
pid_t pid = ::waitpid(-1, &status, WNOHANG);
- if (pid == -1 && errno == ECHILD)
+ if (pid == 0)
return;
if (pid < 0)
qFatal("Error in wait %s", strerror(errno));
@@ -624,7 +626,7 @@ bool ParentProcess::processFdSet(fd_set& rfds, fd_set& wfds)
return true;
}
}
- if (FD_ISSET(1, &wfds)) // Write to stdout
+ if (m_sendbuf.size() && FD_ISSET(1, &wfds)) // Write to stdout
writeFromBuffer(1, m_sendbuf);
return false;
}
@@ -674,7 +676,7 @@ bool ParentProcess::handleMessage(QJsonObject& message)
} else if (command == RemoteProtocol::write()) {
ChildProcess *child = m_children.value(id);
if (child)
- child->write(message.value(RemoteProtocol::data()).toString().toLocal8Bit());
+ child->write(QByteArray::fromBase64(message.value(RemoteProtocol::data()).toString().toLatin1()));
}
}
return false;
diff --git a/src/core/remoteprocessbackend.cpp b/src/core/remoteprocessbackend.cpp
index a6fafec..6cd260b 100644
--- a/src/core/remoteprocessbackend.cpp
+++ b/src/core/remoteprocessbackend.cpp
@@ -211,10 +211,6 @@ void RemoteProcessBackend::stop(int timeout)
/*!
Writes at most \a maxSize bytes of data from \a data to the device.
Returns the number of bytes that were actually written, or -1 if an error occurred.
-
- This function isn't quite correct, because we have a JSON encoding problem.
- For the moment we'll pretend that any data sent is actually something in
- standard ASCII.
*/
qint64 RemoteProcessBackend::write(const char *data, qint64 maxSize)
{
@@ -222,7 +218,7 @@ qint64 RemoteProcessBackend::write(const char *data, qint64 maxSize)
QJsonObject object;
object.insert(RemoteProtocol::command(), RemoteProtocol::write());
object.insert(RemoteProtocol::id(), m_id);
- object.insert(RemoteProtocol::data(), QString::fromLocal8Bit(data, maxSize));
+ object.insert(RemoteProtocol::data(), QString::fromLatin1(QByteArray(data, maxSize).toBase64()));
if (m_factory->send(object))
return maxSize;
}
@@ -246,7 +242,6 @@ QString RemoteProcessBackend::errorString() const
void RemoteProcessBackend::receive(const QJsonObject& message)
{
QString event = message.value(RemoteProtocol::event()).toString();
- // qDebug() << Q_FUNC_INFO << message;
if (event == RemoteProtocol::started()) {
m_pid = message.value(RemoteProtocol::pid()).toDouble();
emit started();