io/qprocess_unix.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42//#define QPROCESS_DEBUG -
43#include "qdebug.h" -
44 -
45#ifndef QT_NO_PROCESS -
46 -
47#if defined QPROCESS_DEBUG -
48#include "qstring.h" -
49#include <ctype.h> -
50 -
51 -
52/* -
53 Returns a human readable representation of the first \a len -
54 characters in \a data. -
55*/ -
56QT_BEGIN_NAMESPACE -
57static QByteArray qt_prettyDebug(const char *data, int len, int maxSize) -
58{ -
59 if (!data) return "(null)"; -
60 QByteArray out; -
61 for (int i = 0; i < len; ++i) { -
62 char c = data[i]; -
63 if (isprint(c)) { -
64 out += c; -
65 } else switch (c) { -
66 case '\n': out += "\\n"; break; -
67 case '\r': out += "\\r"; break; -
68 case '\t': out += "\\t"; break; -
69 default: -
70 QString tmp; -
71 tmp.sprintf("\\%o", c); -
72 out += tmp.toLatin1(); -
73 } -
74 } -
75 -
76 if (len < maxSize) -
77 out += "..."; -
78 -
79 return out; -
80} -
81QT_END_NAMESPACE -
82#endif -
83 -
84#include "qplatformdefs.h" -
85 -
86#include "qprocess.h" -
87#include "qprocess_p.h" -
88#include "private/qcore_unix_p.h" -
89 -
90#ifdef Q_OS_MAC -
91#include <private/qcore_mac_p.h> -
92#endif -
93 -
94#include <private/qcoreapplication_p.h> -
95#include <private/qthread_p.h> -
96#include <qfile.h> -
97#include <qfileinfo.h> -
98#include <qlist.h> -
99#include <qhash.h> -
100#include <qmutex.h> -
101#include <qsemaphore.h> -
102#include <qsocketnotifier.h> -
103#include <qthread.h> -
104#include <qelapsedtimer.h> -
105 -
106#include <errno.h> -
107#include <stdlib.h> -
108#include <string.h> -
109#ifdef Q_OS_QNX -
110#include "qvarlengtharray.h" -
111 -
112#include <spawn.h> -
113#include <sys/neutrino.h> -
114#endif -
115 -
116QT_BEGIN_NAMESPACE -
117 -
118// POSIX requires PIPE_BUF to be 512 or larger -
119// so we will use 512 -
120static const int errorBufferMax = 512; -
121 -
122static int qt_qprocess_deadChild_pipe[2]; -
123static struct sigaction qt_sa_old_sigchld_handler; -
124static void qt_sa_sigchld_handler(int signum) -
125{ -
126 qt_safe_write(qt_qprocess_deadChild_pipe[1], "", 1);
executed (the execution status of this line is deduced): qt_safe_write(qt_qprocess_deadChild_pipe[1], "", 1);
-
127#if defined (QPROCESS_DEBUG) -
128 fprintf(stderr, "*** SIGCHLD\n"); -
129#endif -
130 -
131 // load it as volatile -
132 void (*oldAction)(int) = ((volatile struct sigaction *)&qt_sa_old_sigchld_handler)->sa_handler;
executed (the execution status of this line is deduced): void (*oldAction)(int) = ((volatile struct sigaction *)&qt_sa_old_sigchld_handler)->__sigaction_handler.sa_handler;
-
133 if (oldAction && oldAction != SIG_IGN)
partially evaluated: oldAction
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2778
never evaluated: oldAction != ((__sighandler_t) 1)
0-2778
134 oldAction(signum);
never executed: oldAction(signum);
0
135}
executed: }
Execution Count:2778
2778
136 -
137static inline void add_fd(int &nfds, int fd, fd_set *fdset) -
138{ -
139 FD_SET(fd, fdset);
executed (the execution status of this line is deduced): (((fdset)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((fd) % (8 * (int) sizeof (__fd_mask)))));
-
140 if ((fd) > nfds)
evaluated: (fd) > nfds
TRUEFALSE
yes
Evaluation Count:144488
yes
Evaluation Count:3813
3813-144488
141 nfds = fd;
executed: nfds = fd;
Execution Count:144488
144488
142}
executed: }
Execution Count:148301
148301
143 -
144struct QProcessInfo { -
145 QProcess *process; -
146 int deathPipe; -
147 int exitResult; -
148 pid_t pid; -
149 int serialNumber; -
150}; -
151 -
152class QProcessManager : public QThread -
153{ -
154 Q_OBJECT -
155public: -
156 QProcessManager(); -
157 ~QProcessManager(); -
158 -
159 void run(); -
160 void catchDeadChildren(); -
161 void add(pid_t pid, QProcess *process); -
162 void remove(QProcess *process); -
163 void lock(); -
164 void unlock(); -
165 -
166private: -
167 QMutex mutex; -
168 QHash<int, QProcessInfo *> children; -
169}; -
170 -
171 -
172static QProcessManager *processManagerInstance = 0; -
173 -
174static QProcessManager *processManager() -
175{ -
176 // The constructor of QProcessManager should be called only once -
177 // so we cannot use Q_GLOBAL_STATIC directly for QProcessManager -
178 static QBasicMutex processManagerGlobalMutex; -
179 QMutexLocker locker(&processManagerGlobalMutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&processManagerGlobalMutex);
-
180 -
181 if (!processManagerInstance)
evaluated: !processManagerInstance
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:16159
7-16159
182 new QProcessManager;
executed: new QProcessManager;
Execution Count:7
7
183 -
184 Q_ASSERT(processManagerInstance);
executed (the execution status of this line is deduced): qt_noop();
-
185 return processManagerInstance;
executed: return processManagerInstance;
Execution Count:16166
16166
186} -
187 -
188QProcessManager::QProcessManager() -
189{ -
190#if defined (QPROCESS_DEBUG) -
191 qDebug() << "QProcessManager::QProcessManager()"; -
192#endif -
193 // initialize the dead child pipe and make it non-blocking. in the -
194 // extremely unlikely event that the pipe fills up, we do not under any -
195 // circumstances want to block. -
196 qt_safe_pipe(qt_qprocess_deadChild_pipe, O_NONBLOCK);
executed (the execution status of this line is deduced): qt_safe_pipe(qt_qprocess_deadChild_pipe, 04000);
-
197 -
198 // set up the SIGCHLD handler, which writes a single byte to the dead -
199 // child pipe every time a child dies. -
200 struct sigaction action;
executed (the execution status of this line is deduced): struct sigaction action;
-
201 memset(&action, 0, sizeof(action));
executed (the execution status of this line is deduced): memset(&action, 0, sizeof(action));
-
202 action.sa_handler = qt_sa_sigchld_handler;
executed (the execution status of this line is deduced): action.__sigaction_handler.sa_handler = qt_sa_sigchld_handler;
-
203 action.sa_flags = SA_NOCLDSTOP;
executed (the execution status of this line is deduced): action.sa_flags = 1;
-
204 ::sigaction(SIGCHLD, &action, &qt_sa_old_sigchld_handler);
executed (the execution status of this line is deduced): ::sigaction(17, &action, &qt_sa_old_sigchld_handler);
-
205 -
206 processManagerInstance = this;
executed (the execution status of this line is deduced): processManagerInstance = this;
-
207}
executed: }
Execution Count:7
7
208 -
209QProcessManager::~QProcessManager() -
210{ -
211 // notify the thread that we're shutting down. -
212 qt_safe_write(qt_qprocess_deadChild_pipe[1], "@", 1);
never executed (the execution status of this line is deduced): qt_safe_write(qt_qprocess_deadChild_pipe[1], "@", 1);
-
213 qt_safe_close(qt_qprocess_deadChild_pipe[1]);
never executed (the execution status of this line is deduced): qt_safe_close(qt_qprocess_deadChild_pipe[1]);
-
214 wait();
never executed (the execution status of this line is deduced): wait();
-
215 -
216 // on certain unixes, closing the reading end of the pipe will cause -
217 // select in run() to block forever, rather than return with EBADF. -
218 qt_safe_close(qt_qprocess_deadChild_pipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(qt_qprocess_deadChild_pipe[0]);
-
219 -
220 qt_qprocess_deadChild_pipe[0] = -1;
never executed (the execution status of this line is deduced): qt_qprocess_deadChild_pipe[0] = -1;
-
221 qt_qprocess_deadChild_pipe[1] = -1;
never executed (the execution status of this line is deduced): qt_qprocess_deadChild_pipe[1] = -1;
-
222 -
223 qDeleteAll(children.values());
never executed (the execution status of this line is deduced): qDeleteAll(children.values());
-
224 children.clear();
never executed (the execution status of this line is deduced): children.clear();
-
225 -
226 struct sigaction currentAction;
never executed (the execution status of this line is deduced): struct sigaction currentAction;
-
227 ::sigaction(SIGCHLD, 0, &currentAction);
never executed (the execution status of this line is deduced): ::sigaction(17, 0, &currentAction);
-
228 if (currentAction.sa_handler == qt_sa_sigchld_handler) {
never evaluated: currentAction.__sigaction_handler.sa_handler == qt_sa_sigchld_handler
0
229 ::sigaction(SIGCHLD, &qt_sa_old_sigchld_handler, 0);
never executed (the execution status of this line is deduced): ::sigaction(17, &qt_sa_old_sigchld_handler, 0);
-
230 }
never executed: }
0
231 -
232 processManagerInstance = 0;
never executed (the execution status of this line is deduced): processManagerInstance = 0;
-
233}
never executed: }
0
234 -
235void QProcessManager::run() -
236{ -
237 forever {
executed (the execution status of this line is deduced): for(;;) {
-
238 fd_set readset;
executed (the execution status of this line is deduced): fd_set readset;
-
239 FD_ZERO(&readset);
executed: }
Execution Count:2549
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2549
0-2549
240 FD_SET(qt_qprocess_deadChild_pipe[0], &readset);
executed (the execution status of this line is deduced): (((&readset)->fds_bits)[((qt_qprocess_deadChild_pipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((qt_qprocess_deadChild_pipe[0]) % (8 * (int) sizeof (__fd_mask)))));
-
241 -
242#if defined (QPROCESS_DEBUG) -
243 qDebug() << "QProcessManager::run() waiting for children to die"; -
244#endif -
245 -
246 // block forever, or until activity is detected on the dead child -
247 // pipe. the only other peers are the SIGCHLD signal handler, and the -
248 // QProcessManager destructor. -
249 int nselect = select(qt_qprocess_deadChild_pipe[0] + 1, &readset, 0, 0, 0);
executed (the execution status of this line is deduced): int nselect = select(qt_qprocess_deadChild_pipe[0] + 1, &readset, 0, 0, 0);
-
250 if (nselect < 0) {
evaluated: nselect < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2517
1-2517
251 if (errno == EINTR)
partially evaluated: (*__errno_location ()) == 4
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
252 continue;
executed: continue;
Execution Count:1
1
253 break;
never executed: break;
0
254 } -
255 -
256 // empty only one byte from the pipe, even though several SIGCHLD -
257 // signals may have been delivered in the meantime, to avoid race -
258 // conditions. -
259 char c;
executed (the execution status of this line is deduced): char c;
-
260 if (qt_safe_read(qt_qprocess_deadChild_pipe[0], &c, 1) < 0 || c == '@')
partially evaluated: qt_safe_read(qt_qprocess_deadChild_pipe[0], &c, 1) < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2517
partially evaluated: c == '@'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2517
0-2517
261 break;
never executed: break;
0
262 -
263 // catch any and all children that we can. -
264 catchDeadChildren();
executed (the execution status of this line is deduced): catchDeadChildren();
-
265 }
executed: }
Execution Count:2517
2517
266}
never executed: }
0
267 -
268void QProcessManager::catchDeadChildren() -
269{ -
270 QMutexLocker locker(&mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&mutex);
-
271 -
272 // try to catch all children whose pid we have registered, and whose -
273 // deathPipe is still valid (i.e, we have not already notified it). -
274 QHash<int, QProcessInfo *>::Iterator it = children.begin();
executed (the execution status of this line is deduced): QHash<int, QProcessInfo *>::Iterator it = children.begin();
-
275 while (it != children.end()) {
evaluated: it != children.end()
TRUEFALSE
yes
Evaluation Count:3193
yes
Evaluation Count:2517
2517-3193
276 // notify all children that they may have died. they need to run -
277 // waitpid() in their own thread. -
278 QProcessInfo *info = it.value();
executed (the execution status of this line is deduced): QProcessInfo *info = it.value();
-
279 qt_safe_write(info->deathPipe, "", 1);
executed (the execution status of this line is deduced): qt_safe_write(info->deathPipe, "", 1);
-
280 -
281#if defined (QPROCESS_DEBUG) -
282 qDebug() << "QProcessManager::run() sending death notice to" << info->process; -
283#endif -
284 ++it;
executed (the execution status of this line is deduced): ++it;
-
285 }
executed: }
Execution Count:3193
3193
286}
executed: }
Execution Count:2517
2517
287 -
288static QBasicAtomicInt idCounter = Q_BASIC_ATOMIC_INITIALIZER(1); -
289 -
290void QProcessManager::add(pid_t pid, QProcess *process) -
291{ -
292#if defined (QPROCESS_DEBUG) -
293 qDebug() << "QProcessManager::add() adding pid" << pid << "process" << process; -
294#endif -
295 -
296 // insert a new info structure for this process -
297 QProcessInfo *info = new QProcessInfo;
executed (the execution status of this line is deduced): QProcessInfo *info = new QProcessInfo;
-
298 info->process = process;
executed (the execution status of this line is deduced): info->process = process;
-
299 info->deathPipe = process->d_func()->deathPipe[1];
executed (the execution status of this line is deduced): info->deathPipe = process->d_func()->deathPipe[1];
-
300 info->exitResult = 0;
executed (the execution status of this line is deduced): info->exitResult = 0;
-
301 info->pid = pid;
executed (the execution status of this line is deduced): info->pid = pid;
-
302 -
303 int serial = idCounter.fetchAndAddRelaxed(1);
executed (the execution status of this line is deduced): int serial = idCounter.fetchAndAddRelaxed(1);
-
304 process->d_func()->serial = serial;
executed (the execution status of this line is deduced): process->d_func()->serial = serial;
-
305 children.insert(serial, info);
executed (the execution status of this line is deduced): children.insert(serial, info);
-
306}
executed: }
Execution Count:2520
2520
307 -
308void QProcessManager::remove(QProcess *process) -
309{ -
310 QMutexLocker locker(&mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&mutex);
-
311 -
312 int serial = process->d_func()->serial;
executed (the execution status of this line is deduced): int serial = process->d_func()->serial;
-
313 QProcessInfo *info = children.take(serial);
executed (the execution status of this line is deduced): QProcessInfo *info = children.take(serial);
-
314#if defined (QPROCESS_DEBUG) -
315 if (info) -
316 qDebug() << "QProcessManager::remove() removing pid" << info->pid << "process" << info->process; -
317#endif -
318 delete info;
executed (the execution status of this line is deduced): delete info;
-
319}
executed: }
Execution Count:5937
5937
320 -
321void QProcessManager::lock() -
322{ -
323 mutex.lock();
executed (the execution status of this line is deduced): mutex.lock();
-
324}
executed: }
Execution Count:2520
2520
325 -
326void QProcessManager::unlock() -
327{ -
328 mutex.unlock();
executed (the execution status of this line is deduced): mutex.unlock();
-
329}
executed: }
Execution Count:2520
2520
330 -
331static void qt_create_pipe(int *pipe) -
332{ -
333 if (pipe[0] != -1)
partially evaluated: pipe[0] != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12580
0-12580
334 qt_safe_close(pipe[0]);
never executed: qt_safe_close(pipe[0]);
0
335 if (pipe[1] != -1)
partially evaluated: pipe[1] != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12580
0-12580
336 qt_safe_close(pipe[1]);
never executed: qt_safe_close(pipe[1]);
0
337 if (qt_safe_pipe(pipe) != 0) {
partially evaluated: qt_safe_pipe(pipe) != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12580
0-12580
338 qWarning("QProcessPrivate::createPipe: Cannot create pipe %p: %s",
never executed (the execution status of this line is deduced): QMessageLogger("io/qprocess_unix.cpp", 338, __PRETTY_FUNCTION__).warning("QProcessPrivate::createPipe: Cannot create pipe %p: %s",
-
339 pipe, qPrintable(qt_error_string(errno)));
never executed (the execution status of this line is deduced): pipe, QString(qt_error_string((*__errno_location ()))).toLocal8Bit().constData());
-
340 }
never executed: }
0
341}
executed: }
Execution Count:12580
12580
342 -
343void QProcessPrivate::destroyPipe(int *pipe) -
344{ -
345 if (pipe[1] != -1) {
evaluated: pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:5037
yes
Evaluation Count:23105
5037-23105
346 qt_safe_close(pipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(pipe[1]);
-
347 pipe[1] = -1;
executed (the execution status of this line is deduced): pipe[1] = -1;
-
348 }
executed: }
Execution Count:5037
5037
349 if (pipe[0] != -1) {
evaluated: pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:7541
yes
Evaluation Count:20601
7541-20601
350 qt_safe_close(pipe[0]);
executed (the execution status of this line is deduced): qt_safe_close(pipe[0]);
-
351 pipe[0] = -1;
executed (the execution status of this line is deduced): pipe[0] = -1;
-
352 }
executed: }
Execution Count:7541
7541
353}
executed: }
Execution Count:28142
28142
354 -
355void QProcessPrivate::destroyChannel(Channel *channel) -
356{ -
357 destroyPipe(channel->pipe);
executed (the execution status of this line is deduced): destroyPipe(channel->pipe);
-
358}
executed: }
Execution Count:19654
19654
359 -
360/* -
361 Create the pipes to a QProcessPrivate::Channel. -
362 -
363 This function must be called in order: stdin, stdout, stderr -
364*/ -
365bool QProcessPrivate::createChannel(Channel &channel) -
366{ -
367 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
368 -
369 if (&channel == &stderrChannel && processChannelMode == QProcess::MergedChannels) {
evaluated: &channel == &stderrChannel
TRUEFALSE
yes
Evaluation Count:2520
yes
Evaluation Count:5040
evaluated: processChannelMode == QProcess::MergedChannels
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:2509
11-5040
370 channel.pipe[0] = -1;
executed (the execution status of this line is deduced): channel.pipe[0] = -1;
-
371 channel.pipe[1] = -1;
executed (the execution status of this line is deduced): channel.pipe[1] = -1;
-
372 return true;
executed: return true;
Execution Count:11
11
373 } -
374 -
375 if (channel.type == Channel::Normal) {
evaluated: channel.type == Channel::Normal
TRUEFALSE
yes
Evaluation Count:7538
yes
Evaluation Count:11
11-7538
376 // we're piping this channel to our own process -
377 qt_create_pipe(channel.pipe);
executed (the execution status of this line is deduced): qt_create_pipe(channel.pipe);
-
378 -
379 // create the socket notifiers -
380 if (threadData->eventDispatcher) {
evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:7295
yes
Evaluation Count:243
243-7295
381 if (&channel == &stdinChannel) {
evaluated: &channel == &stdinChannel
TRUEFALSE
yes
Evaluation Count:2436
yes
Evaluation Count:4859
2436-4859
382 channel.notifier = new QSocketNotifier(channel.pipe[1],
executed (the execution status of this line is deduced): channel.notifier = new QSocketNotifier(channel.pipe[1],
-
383 QSocketNotifier::Write, q);
executed (the execution status of this line is deduced): QSocketNotifier::Write, q);
-
384 channel.notifier->setEnabled(false);
executed (the execution status of this line is deduced): channel.notifier->setEnabled(false);
-
385 QObject::connect(channel.notifier, SIGNAL(activated(int)),
executed (the execution status of this line is deduced): QObject::connect(channel.notifier, "2""activated(int)",
-
386 q, SLOT(_q_canWrite()));
executed (the execution status of this line is deduced): q, "1""_q_canWrite()");
-
387 } else {
executed: }
Execution Count:2436
2436
388 channel.notifier = new QSocketNotifier(channel.pipe[0],
executed (the execution status of this line is deduced): channel.notifier = new QSocketNotifier(channel.pipe[0],
-
389 QSocketNotifier::Read, q);
executed (the execution status of this line is deduced): QSocketNotifier::Read, q);
-
390 const char *receiver;
executed (the execution status of this line is deduced): const char *receiver;
-
391 if (&channel == &stdoutChannel)
evaluated: &channel == &stdoutChannel
TRUEFALSE
yes
Evaluation Count:2433
yes
Evaluation Count:2426
2426-2433
392 receiver = SLOT(_q_canReadStandardOutput());
executed: receiver = "1""_q_canReadStandardOutput()";
Execution Count:2433
2433
393 else -
394 receiver = SLOT(_q_canReadStandardError());
executed: receiver = "1""_q_canReadStandardError()";
Execution Count:2426
2426
395 QObject::connect(channel.notifier, SIGNAL(activated(int)),
executed (the execution status of this line is deduced): QObject::connect(channel.notifier, "2""activated(int)",
-
396 q, receiver);
executed (the execution status of this line is deduced): q, receiver);
-
397 }
executed: }
Execution Count:4859
4859
398 } -
399 -
400 return true;
executed: return true;
Execution Count:7538
7538
401 } else if (channel.type == Channel::Redirect) {
evaluated: channel.type == Channel::Redirect
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:4
4-7
402 // we're redirecting the channel to/from a file -
403 QByteArray fname = QFile::encodeName(channel.file);
executed (the execution status of this line is deduced): QByteArray fname = QFile::encodeName(channel.file);
-
404 -
405 if (&channel == &stdinChannel) {
evaluated: &channel == &stdinChannel
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
1-6
406 // try to open in read-only mode -
407 channel.pipe[1] = -1;
executed (the execution status of this line is deduced): channel.pipe[1] = -1;
-
408 if ( (channel.pipe[0] = qt_safe_open(fname, O_RDONLY)) != -1)
partially evaluated: (channel.pipe[0] = qt_safe_open(fname, 00)) != -1
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
409 return true; // success
executed: return true;
Execution Count:1
1
410 -
411 q->setErrorString(QProcess::tr("Could not open input redirection for reading"));
never executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Could not open input redirection for reading"));
-
412 } else {
never executed: }
0
413 int mode = O_WRONLY | O_CREAT;
executed (the execution status of this line is deduced): int mode = 01 | 0100;
-
414 if (channel.append)
evaluated: channel.append
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
415 mode |= O_APPEND;
executed: mode |= 02000;
Execution Count:3
3
416 else -
417 mode |= O_TRUNC;
executed: mode |= 01000;
Execution Count:3
3
418 -
419 channel.pipe[0] = -1;
executed (the execution status of this line is deduced): channel.pipe[0] = -1;
-
420 if ( (channel.pipe[1] = qt_safe_open(fname, mode, 0666)) != -1)
partially evaluated: (channel.pipe[1] = qt_safe_open(fname, mode, 0666)) != -1
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
421 return true; // success
executed: return true;
Execution Count:6
6
422 -
423 q->setErrorString(QProcess::tr("Could not open output redirection for writing"));
never executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Could not open output redirection for writing"));
-
424 }
never executed: }
0
425 -
426 // could not open file -
427 processError = QProcess::FailedToStart;
never executed (the execution status of this line is deduced): processError = QProcess::FailedToStart;
-
428 emit q->error(processError);
never executed (the execution status of this line is deduced): q->error(processError);
-
429 cleanup();
never executed (the execution status of this line is deduced): cleanup();
-
430 return false;
never executed: return false;
0
431 } else { -
432 Q_ASSERT_X(channel.process, "QProcess::start", "Internal error");
executed (the execution status of this line is deduced): qt_noop();
-
433 -
434 Channel *source;
executed (the execution status of this line is deduced): Channel *source;
-
435 Channel *sink;
executed (the execution status of this line is deduced): Channel *sink;
-
436 -
437 if (channel.type == Channel::PipeSource) {
evaluated: channel.type == Channel::PipeSource
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
2
438 // we are the source -
439 source = &channel;
executed (the execution status of this line is deduced): source = &channel;
-
440 sink = &channel.process->stdinChannel;
executed (the execution status of this line is deduced): sink = &channel.process->stdinChannel;
-
441 -
442 Q_ASSERT(source == &stdoutChannel);
executed (the execution status of this line is deduced): qt_noop();
-
443 Q_ASSERT(sink->process == this && sink->type == Channel::PipeSink);
executed (the execution status of this line is deduced): qt_noop();
-
444 } else {
executed: }
Execution Count:2
2
445 // we are the sink; -
446 source = &channel.process->stdoutChannel;
executed (the execution status of this line is deduced): source = &channel.process->stdoutChannel;
-
447 sink = &channel;
executed (the execution status of this line is deduced): sink = &channel;
-
448 -
449 Q_ASSERT(sink == &stdinChannel);
executed (the execution status of this line is deduced): qt_noop();
-
450 Q_ASSERT(source->process == this && source->type == Channel::PipeSource);
executed (the execution status of this line is deduced): qt_noop();
-
451 }
executed: }
Execution Count:2
2
452 -
453 if (source->pipe[1] != INVALID_Q_PIPE || sink->pipe[0] != INVALID_Q_PIPE) {
partially evaluated: source->pipe[1] != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
evaluated: sink->pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
0-4
454 // already created, do nothing -
455 return true;
executed: return true;
Execution Count:2
2
456 } else { -
457 Q_ASSERT(source->pipe[0] == INVALID_Q_PIPE && source->pipe[1] == INVALID_Q_PIPE);
executed (the execution status of this line is deduced): qt_noop();
-
458 Q_ASSERT(sink->pipe[0] == INVALID_Q_PIPE && sink->pipe[1] == INVALID_Q_PIPE);
executed (the execution status of this line is deduced): qt_noop();
-
459 -
460 Q_PIPE pipe[2] = { -1, -1 };
executed (the execution status of this line is deduced): Q_PIPE pipe[2] = { -1, -1 };
-
461 qt_create_pipe(pipe);
executed (the execution status of this line is deduced): qt_create_pipe(pipe);
-
462 sink->pipe[0] = pipe[0];
executed (the execution status of this line is deduced): sink->pipe[0] = pipe[0];
-
463 source->pipe[1] = pipe[1];
executed (the execution status of this line is deduced): source->pipe[1] = pipe[1];
-
464 -
465 return true;
executed: return true;
Execution Count:2
2
466 } -
467 } -
468} -
469 -
470QT_BEGIN_INCLUDE_NAMESPACE -
471#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) -
472# include <crt_externs.h> -
473# define environ (*_NSGetEnviron()) -
474#else -
475 extern char **environ; -
476#endif -
477QT_END_INCLUDE_NAMESPACE -
478 -
479QProcessEnvironment QProcessEnvironment::systemEnvironment() -
480{ -
481 QProcessEnvironment env;
executed (the execution status of this line is deduced): QProcessEnvironment env;
-
482#if !defined(Q_OS_IOS) -
483 const char *entry;
executed (the execution status of this line is deduced): const char *entry;
-
484 for (int count = 0; (entry = environ[count]); ++count) {
evaluated: (entry = environ[count])
TRUEFALSE
yes
Evaluation Count:313
yes
Evaluation Count:14
14-313
485 const char *equal = strchr(entry, '=');
executed (the execution status of this line is deduced): const char *equal = strchr(entry, '=');
-
486 if (!equal)
partially evaluated: !equal
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:313
0-313
487 continue;
never executed: continue;
0
488 -
489 QByteArray name(entry, equal - entry);
executed (the execution status of this line is deduced): QByteArray name(entry, equal - entry);
-
490 QByteArray value(equal + 1);
executed (the execution status of this line is deduced): QByteArray value(equal + 1);
-
491 env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
executed (the execution status of this line is deduced): env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
-
492 QProcessEnvironmentPrivate::Value(value));
executed (the execution status of this line is deduced): QProcessEnvironmentPrivate::Value(value));
-
493 }
executed: }
Execution Count:313
313
494#endif -
495 return env;
executed: return env;
Execution Count:14
14
496} -
497 -
498static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environment, int *envc) -
499{ -
500 *envc = 0;
executed (the execution status of this line is deduced): *envc = 0;
-
501 if (environment.isEmpty())
partially evaluated: environment.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:871
0-871
502 return 0;
never executed: return 0;
0
503 -
504 // if LD_LIBRARY_PATH exists in the current environment, but -
505 // not in the environment list passed by the programmer, then -
506 // copy it over. -
507#if defined(Q_OS_MAC) -
508 static const char libraryPath[] = "DYLD_LIBRARY_PATH"; -
509#else -
510 static const char libraryPath[] = "LD_LIBRARY_PATH"; -
511#endif -
512 const QByteArray envLibraryPath = qgetenv(libraryPath);
executed (the execution status of this line is deduced): const QByteArray envLibraryPath = qgetenv(libraryPath);
-
513 bool needToAddLibraryPath = !envLibraryPath.isEmpty() &&
evaluated: !envLibraryPath.isEmpty()
TRUEFALSE
yes
Evaluation Count:173
yes
Evaluation Count:698
173-698
514 !environment.contains(QProcessEnvironmentPrivate::Key(QByteArray(libraryPath)));
partially evaluated: !environment.contains(QProcessEnvironmentPrivate::Key(QByteArray(libraryPath)))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:173
0-173
515 -
516 char **envp = new char *[environment.count() + 2];
executed (the execution status of this line is deduced): char **envp = new char *[environment.count() + 2];
-
517 envp[environment.count()] = 0;
executed (the execution status of this line is deduced): envp[environment.count()] = 0;
-
518 envp[environment.count() + 1] = 0;
executed (the execution status of this line is deduced): envp[environment.count() + 1] = 0;
-
519 -
520 QProcessEnvironmentPrivate::Hash::ConstIterator it = environment.constBegin();
executed (the execution status of this line is deduced): QProcessEnvironmentPrivate::Hash::ConstIterator it = environment.constBegin();
-
521 const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd();
executed (the execution status of this line is deduced): const QProcessEnvironmentPrivate::Hash::ConstIterator end = environment.constEnd();
-
522 for ( ; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:7129
yes
Evaluation Count:871
871-7129
523 QByteArray key = it.key().key;
executed (the execution status of this line is deduced): QByteArray key = it.key().key;
-
524 QByteArray value = it.value().bytes();
executed (the execution status of this line is deduced): QByteArray value = it.value().bytes();
-
525 key.reserve(key.length() + 1 + value.length());
executed (the execution status of this line is deduced): key.reserve(key.length() + 1 + value.length());
-
526 key.append('=');
executed (the execution status of this line is deduced): key.append('=');
-
527 key.append(value);
executed (the execution status of this line is deduced): key.append(value);
-
528 -
529 envp[(*envc)++] = ::strdup(key.constData());
executed (the execution status of this line is deduced): envp[(*envc)++] = ::strdup(key.constData());
-
530 }
executed: }
Execution Count:7129
7129
531 -
532 if (needToAddLibraryPath)
partially evaluated: needToAddLibraryPath
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:871
0-871
533 envp[(*envc)++] = ::strdup(QByteArray(QByteArray(libraryPath) + '=' +
never executed: envp[(*envc)++] = ::strdup(QByteArray(QByteArray(libraryPath) + '=' + envLibraryPath).constData());
0
534 envLibraryPath).constData());
never executed: envp[(*envc)++] = ::strdup(QByteArray(QByteArray(libraryPath) + '=' + envLibraryPath).constData());
0
535 return envp;
executed: return envp;
Execution Count:871
871
536} -
537 -
538void QProcessPrivate::startProcess() -
539{ -
540 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
541 -
542#if defined (QPROCESS_DEBUG) -
543 qDebug("QProcessPrivate::startProcess()"); -
544#endif -
545 -
546 processManager()->start();
executed (the execution status of this line is deduced): processManager()->start();
-
547 -
548 // Initialize pipes -
549 if (!createChannel(stdinChannel) ||
partially evaluated: !createChannel(stdinChannel)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2520
0-2520
550 !createChannel(stdoutChannel) ||
partially evaluated: !createChannel(stdoutChannel)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2520
0-2520
551 !createChannel(stderrChannel))
partially evaluated: !createChannel(stderrChannel)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2520
0-2520
552 return;
never executed: return;
0
553 qt_create_pipe(childStartedPipe);
executed (the execution status of this line is deduced): qt_create_pipe(childStartedPipe);
-
554 qt_create_pipe(deathPipe);
executed (the execution status of this line is deduced): qt_create_pipe(deathPipe);
-
555 -
556 if (threadData->eventDispatcher) {
evaluated: threadData->eventDispatcher
TRUEFALSE
yes
Evaluation Count:2439
yes
Evaluation Count:81
81-2439
557 startupSocketNotifier = new QSocketNotifier(childStartedPipe[0],
executed (the execution status of this line is deduced): startupSocketNotifier = new QSocketNotifier(childStartedPipe[0],
-
558 QSocketNotifier::Read, q);
executed (the execution status of this line is deduced): QSocketNotifier::Read, q);
-
559 QObject::connect(startupSocketNotifier, SIGNAL(activated(int)),
executed (the execution status of this line is deduced): QObject::connect(startupSocketNotifier, "2""activated(int)",
-
560 q, SLOT(_q_startupNotification()));
executed (the execution status of this line is deduced): q, "1""_q_startupNotification()");
-
561 -
562 deathNotifier = new QSocketNotifier(deathPipe[0],
executed (the execution status of this line is deduced): deathNotifier = new QSocketNotifier(deathPipe[0],
-
563 QSocketNotifier::Read, q);
executed (the execution status of this line is deduced): QSocketNotifier::Read, q);
-
564 QObject::connect(deathNotifier, SIGNAL(activated(int)),
executed (the execution status of this line is deduced): QObject::connect(deathNotifier, "2""activated(int)",
-
565 q, SLOT(_q_processDied()));
executed (the execution status of this line is deduced): q, "1""_q_processDied()");
-
566 }
executed: }
Execution Count:2439
2439
567 -
568 // Start the process (platform dependent) -
569 q->setProcessState(QProcess::Starting);
executed (the execution status of this line is deduced): q->setProcessState(QProcess::Starting);
-
570 -
571 // Create argument list with right number of elements, and set the final -
572 // one to 0. -
573 char **argv = new char *[arguments.count() + 2];
executed (the execution status of this line is deduced): char **argv = new char *[arguments.count() + 2];
-
574 argv[arguments.count() + 1] = 0;
executed (the execution status of this line is deduced): argv[arguments.count() + 1] = 0;
-
575 -
576 // Encode the program name. -
577 QByteArray encodedProgramName = QFile::encodeName(program);
executed (the execution status of this line is deduced): QByteArray encodedProgramName = QFile::encodeName(program);
-
578#ifdef Q_OS_MAC -
579 // allow invoking of .app bundles on the Mac. -
580 QFileInfo fileInfo(program); -
581 if (encodedProgramName.endsWith(".app") && fileInfo.isDir()) { -
582 QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, -
583 QCFString(fileInfo.absoluteFilePath()), -
584 kCFURLPOSIXPathStyle, true); -
585 { -
586 // CFBundle is not reentrant, since CFBundleCreate might return a reference -
587 // to a cached bundle object. Protect the bundle calls with a mutex lock. -
588 static QBasicMutex cfbundleMutex; -
589 QMutexLocker lock(&cfbundleMutex); -
590 QCFType<CFBundleRef> bundle = CFBundleCreate(0, url); -
591 url = CFBundleCopyExecutableURL(bundle); -
592 } -
593 if (url) { -
594 QCFString str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); -
595 encodedProgramName += "/Contents/MacOS/" + QCFString::toQString(str).toUtf8(); -
596 } -
597 } -
598#endif -
599 -
600 // Add the program name to the argument list. -
601 char *dupProgramName = ::strdup(encodedProgramName.constData());
executed (the execution status of this line is deduced): char *dupProgramName = ::strdup(encodedProgramName.constData());
-
602 argv[0] = dupProgramName;
executed (the execution status of this line is deduced): argv[0] = dupProgramName;
-
603 -
604 // Add every argument to the list -
605 for (int i = 0; i < arguments.count(); ++i)
evaluated: i < arguments.count()
TRUEFALSE
yes
Evaluation Count:3808
yes
Evaluation Count:2520
2520-3808
606 argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
executed: argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
Execution Count:3808
3808
607 -
608 // Duplicate the environment. -
609 int envc = 0;
executed (the execution status of this line is deduced): int envc = 0;
-
610 char **envp = 0;
executed (the execution status of this line is deduced): char **envp = 0;
-
611 if (environment.d.constData())
evaluated: environment.d.constData()
TRUEFALSE
yes
Evaluation Count:871
yes
Evaluation Count:1649
871-1649
612 envp = _q_dupEnvironment(environment.d.constData()->hash, &envc);
executed: envp = _q_dupEnvironment(environment.d.constData()->hash, &envc);
Execution Count:871
871
613 -
614 // Encode the working directory if it's non-empty, otherwise just pass 0. -
615 const char *workingDirPtr = 0;
executed (the execution status of this line is deduced): const char *workingDirPtr = 0;
-
616 QByteArray encodedWorkingDirectory;
executed (the execution status of this line is deduced): QByteArray encodedWorkingDirectory;
-
617 if (!workingDirectory.isEmpty()) {
evaluated: !workingDirectory.isEmpty()
TRUEFALSE
yes
Evaluation Count:204
yes
Evaluation Count:2316
204-2316
618 encodedWorkingDirectory = QFile::encodeName(workingDirectory);
executed (the execution status of this line is deduced): encodedWorkingDirectory = QFile::encodeName(workingDirectory);
-
619 workingDirPtr = encodedWorkingDirectory.constData();
executed (the execution status of this line is deduced): workingDirPtr = encodedWorkingDirectory.constData();
-
620 }
executed: }
Execution Count:204
204
621 -
622 // If the program does not specify a path, generate a list of possible -
623 // locations for the binary using the PATH environment variable. -
624 char **path = 0;
executed (the execution status of this line is deduced): char **path = 0;
-
625 int pathc = 0;
executed (the execution status of this line is deduced): int pathc = 0;
-
626 if (!program.contains(QLatin1Char('/'))) {
evaluated: !program.contains(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:379
yes
Evaluation Count:2141
379-2141
627 const QString pathEnv = QString::fromLocal8Bit(::getenv("PATH"));
executed (the execution status of this line is deduced): const QString pathEnv = QString::fromLocal8Bit(::getenv("PATH"));
-
628 if (!pathEnv.isEmpty()) {
partially evaluated: !pathEnv.isEmpty()
TRUEFALSE
yes
Evaluation Count:379
no
Evaluation Count:0
0-379
629 QStringList pathEntries = pathEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
executed (the execution status of this line is deduced): QStringList pathEntries = pathEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
-
630 if (!pathEntries.isEmpty()) {
partially evaluated: !pathEntries.isEmpty()
TRUEFALSE
yes
Evaluation Count:379
no
Evaluation Count:0
0-379
631 pathc = pathEntries.size();
executed (the execution status of this line is deduced): pathc = pathEntries.size();
-
632 path = new char *[pathc + 1];
executed (the execution status of this line is deduced): path = new char *[pathc + 1];
-
633 path[pathc] = 0;
executed (the execution status of this line is deduced): path[pathc] = 0;
-
634 -
635 for (int k = 0; k < pathEntries.size(); ++k) {
evaluated: k < pathEntries.size()
TRUEFALSE
yes
Evaluation Count:4927
yes
Evaluation Count:379
379-4927
636 QByteArray tmp = QFile::encodeName(pathEntries.at(k));
executed (the execution status of this line is deduced): QByteArray tmp = QFile::encodeName(pathEntries.at(k));
-
637 if (!tmp.endsWith('/')) tmp += '/';
executed: tmp += '/';
Execution Count:4927
partially evaluated: !tmp.endsWith('/')
TRUEFALSE
yes
Evaluation Count:4927
no
Evaluation Count:0
0-4927
638 tmp += encodedProgramName;
executed (the execution status of this line is deduced): tmp += encodedProgramName;
-
639 path[k] = ::strdup(tmp.constData());
executed (the execution status of this line is deduced): path[k] = ::strdup(tmp.constData());
-
640 }
executed: }
Execution Count:4927
4927
641 }
executed: }
Execution Count:379
379
642 }
executed: }
Execution Count:379
379
643 }
executed: }
Execution Count:379
379
644 -
645 // Start the process manager, and fork off the child process. -
646 processManager()->lock();
executed (the execution status of this line is deduced): processManager()->lock();
-
647#if defined(Q_OS_QNX) -
648 pid_t childPid = spawnChild(workingDirPtr, argv, envp); -
649#else -
650 pid_t childPid = fork();
executed (the execution status of this line is deduced): pid_t childPid = fork();
-
651 int lastForkErrno = errno;
executed (the execution status of this line is deduced): int lastForkErrno = (*__errno_location ());
-
652#endif -
653 if (childPid != 0) {
partially evaluated: childPid != 0
TRUEFALSE
yes
Evaluation Count:2520
no
Evaluation Count:0
0-2520
654 // Clean up duplicated memory. -
655 free(dupProgramName);
executed (the execution status of this line is deduced): free(dupProgramName);
-
656 for (int i = 1; i <= arguments.count(); ++i)
evaluated: i <= arguments.count()
TRUEFALSE
yes
Evaluation Count:3808
yes
Evaluation Count:2520
2520-3808
657 free(argv[i]);
executed: free(argv[i]);
Execution Count:3808
3808
658 for (int i = 0; i < envc; ++i)
evaluated: i < envc
TRUEFALSE
yes
Evaluation Count:7129
yes
Evaluation Count:2520
2520-7129
659 free(envp[i]);
executed: free(envp[i]);
Execution Count:7129
7129
660 for (int i = 0; i < pathc; ++i)
evaluated: i < pathc
TRUEFALSE
yes
Evaluation Count:4927
yes
Evaluation Count:2520
2520-4927
661 free(path[i]);
executed: free(path[i]);
Execution Count:4927
4927
662 delete [] argv;
executed (the execution status of this line is deduced): delete [] argv;
-
663 delete [] envp;
executed (the execution status of this line is deduced): delete [] envp;
-
664 delete [] path;
executed (the execution status of this line is deduced): delete [] path;
-
665 }
executed: }
Execution Count:2520
2520
666 -
667 // This is not a valid check under QNX, because the semantics are -
668 // different. While under other platforms where fork() may succeed and exec() can still fail, -
669 // causing the childPid to hold a valid value (and thus evaluating the -
670 // following if to false), and then signaling the error via -
671 // childStartedPipe, under QNX on the other hand, spawn() return value will be assigned -
672 // to childPid (which will be -1 in case of failure). This will force -
673 // QProcess to cleanup, instead of signaling the error via -
674 // childStartedPipe. Since it will invalidade the pipes, functions like -
675 // QProcess::waitForStarted() will fail, for childStartedPipe will be -
676 // '-1' and mess with the select() calls. -
677#if !defined(Q_OS_QNX) -
678 if (childPid < 0) {
partially evaluated: childPid < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2520
0-2520
679 // Cleanup, report error and return -
680#if defined (QPROCESS_DEBUG) -
681 qDebug("fork failed: %s", qPrintable(qt_error_string(lastForkErrno))); -
682#endif -
683 processManager()->unlock();
never executed (the execution status of this line is deduced): processManager()->unlock();
-
684 q->setProcessState(QProcess::NotRunning);
never executed (the execution status of this line is deduced): q->setProcessState(QProcess::NotRunning);
-
685 processError = QProcess::FailedToStart;
never executed (the execution status of this line is deduced): processError = QProcess::FailedToStart;
-
686 q->setErrorString(QProcess::tr("Resource error (fork failure): %1").arg(qt_error_string(lastForkErrno)));
never executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Resource error (fork failure): %1").arg(qt_error_string(lastForkErrno)));
-
687 emit q->error(processError);
never executed (the execution status of this line is deduced): q->error(processError);
-
688 cleanup();
never executed (the execution status of this line is deduced): cleanup();
-
689 return;
never executed: return;
0
690 } -
691 -
692 // Start the child. -
693 if (childPid == 0) {
partially evaluated: childPid == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2520
0-2520
694 execChild(workingDirPtr, path, argv, envp);
never executed (the execution status of this line is deduced): execChild(workingDirPtr, path, argv, envp);
-
695 ::_exit(-1);
never executed (the execution status of this line is deduced): ::_exit(-1);
-
696 }
never executed: }
0
697#endif -
698 -
699 // Register the child. In the mean time, we can get a SIGCHLD, so we need -
700 // to keep the lock held to avoid a race to catch the child. -
701 processManager()->add(childPid, q);
executed (the execution status of this line is deduced): processManager()->add(childPid, q);
-
702 pid = Q_PID(childPid);
executed (the execution status of this line is deduced): pid = Q_PID(childPid);
-
703 processManager()->unlock();
executed (the execution status of this line is deduced): processManager()->unlock();
-
704 -
705 // parent -
706 // close the ends we don't use and make all pipes non-blocking -
707 ::fcntl(deathPipe[0], F_SETFL, ::fcntl(deathPipe[0], F_GETFL) | O_NONBLOCK);
executed (the execution status of this line is deduced): ::fcntl(deathPipe[0], 4, ::fcntl(deathPipe[0], 3) | 04000);
-
708 qt_safe_close(childStartedPipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(childStartedPipe[1]);
-
709 childStartedPipe[1] = -1;
executed (the execution status of this line is deduced): childStartedPipe[1] = -1;
-
710 -
711 if (stdinChannel.pipe[0] != -1) {
partially evaluated: stdinChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:2520
no
Evaluation Count:0
0-2520
712 qt_safe_close(stdinChannel.pipe[0]);
executed (the execution status of this line is deduced): qt_safe_close(stdinChannel.pipe[0]);
-
713 stdinChannel.pipe[0] = -1;
executed (the execution status of this line is deduced): stdinChannel.pipe[0] = -1;
-
714 }
executed: }
Execution Count:2520
2520
715 -
716 if (stdinChannel.pipe[1] != -1)
evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:2517
yes
Evaluation Count:3
3-2517
717 ::fcntl(stdinChannel.pipe[1], F_SETFL, ::fcntl(stdinChannel.pipe[1], F_GETFL) | O_NONBLOCK);
executed: ::fcntl(stdinChannel.pipe[1], 4, ::fcntl(stdinChannel.pipe[1], 3) | 04000);
Execution Count:2517
2517
718 -
719 if (stdoutChannel.pipe[1] != -1) {
partially evaluated: stdoutChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:2520
no
Evaluation Count:0
0-2520
720 qt_safe_close(stdoutChannel.pipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(stdoutChannel.pipe[1]);
-
721 stdoutChannel.pipe[1] = -1;
executed (the execution status of this line is deduced): stdoutChannel.pipe[1] = -1;
-
722 }
executed: }
Execution Count:2520
2520
723 -
724 if (stdoutChannel.pipe[0] != -1)
evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:2514
yes
Evaluation Count:6
6-2514
725 ::fcntl(stdoutChannel.pipe[0], F_SETFL, ::fcntl(stdoutChannel.pipe[0], F_GETFL) | O_NONBLOCK);
executed: ::fcntl(stdoutChannel.pipe[0], 4, ::fcntl(stdoutChannel.pipe[0], 3) | 04000);
Execution Count:2514
2514
726 -
727 if (stderrChannel.pipe[1] != -1) {
evaluated: stderrChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:2509
yes
Evaluation Count:11
11-2509
728 qt_safe_close(stderrChannel.pipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(stderrChannel.pipe[1]);
-
729 stderrChannel.pipe[1] = -1;
executed (the execution status of this line is deduced): stderrChannel.pipe[1] = -1;
-
730 }
executed: }
Execution Count:2509
2509
731 if (stderrChannel.pipe[0] != -1)
evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:2507
yes
Evaluation Count:13
13-2507
732 ::fcntl(stderrChannel.pipe[0], F_SETFL, ::fcntl(stderrChannel.pipe[0], F_GETFL) | O_NONBLOCK);
executed: ::fcntl(stderrChannel.pipe[0], 4, ::fcntl(stderrChannel.pipe[0], 3) | 04000);
Execution Count:2507
2507
733}
executed: }
Execution Count:2520
2520
734 -
735#if defined(Q_OS_QNX) -
736static pid_t doSpawn(int fd_count, int fd_map[], char **argv, char **envp, -
737 const char *workingDir, bool spawn_detached) -
738{ -
739 // A multi threaded QNX Process can't fork so we call spawn() instead. -
740 -
741 struct inheritance inherit; -
742 memset(&inherit, 0, sizeof(inherit)); -
743 inherit.flags |= SPAWN_SETSID; -
744 inherit.flags |= SPAWN_CHECK_SCRIPT; -
745 if (spawn_detached) -
746 inherit.flags |= SPAWN_NOZOMBIE; -
747 inherit.flags |= SPAWN_SETSIGDEF; -
748 sigaddset(&inherit.sigdefault, SIGPIPE); // reset the signal that we ignored -
749 -
750 // enter the working directory -
751 const char *oldWorkingDir = 0; -
752 char buff[PATH_MAX + 1]; -
753 -
754 if (workingDir) { -
755 //we need to freeze everyone in order to avoid race conditions with //chdir(). -
756 if (ThreadCtl(_NTO_TCTL_THREADS_HOLD, 0) == -1) -
757 qWarning("ThreadCtl(): cannot hold threads: %s", qPrintable(qt_error_string(errno))); -
758 -
759 oldWorkingDir = QT_GETCWD(buff, PATH_MAX + 1); -
760 if (QT_CHDIR(workingDir) == -1) -
761 qWarning("ThreadCtl(): failed to chdir to %s", workingDir); -
762 } -
763 -
764 pid_t childPid; -
765 EINTR_LOOP(childPid, ::spawn(argv[0], fd_count, fd_map, &inherit, argv, envp)); -
766 if (childPid == -1) { -
767 inherit.flags |= SPAWN_SEARCH_PATH; -
768 EINTR_LOOP(childPid, ::spawn(argv[0], fd_count, fd_map, &inherit, argv, envp)); -
769 } -
770 -
771 if (oldWorkingDir) { -
772 if (QT_CHDIR(oldWorkingDir) == -1) -
773 qWarning("ThreadCtl(): failed to chdir to %s", oldWorkingDir); -
774 -
775 if (ThreadCtl(_NTO_TCTL_THREADS_CONT, 0) == -1) -
776 qFatal("ThreadCtl(): cannot resume threads: %s", qPrintable(qt_error_string(errno))); -
777 } -
778 -
779 return childPid; -
780} -
781 -
782pid_t QProcessPrivate::spawnChild(const char *workingDir, char **argv, char **envp) -
783{ -
784 // we need to manually fill in fd_map -
785 // to inherit the file descriptors from -
786 // the parent -
787 const int fd_count = sysconf(_SC_OPEN_MAX); -
788 QVarLengthArray<int, 1024> fd_map(fd_count); -
789 -
790 for (int i = 3; i < fd_count; ++i) { -
791 // here we rely that fcntl returns -1 and -
792 // sets errno to EBADF -
793 const int flags = ::fcntl(i, F_GETFD); -
794 -
795 fd_map[i] = ((flags >= 0) && !(flags & FD_CLOEXEC)) -
796 ? i : SPAWN_FDCLOSED; -
797 } -
798 -
799 switch (processChannelMode) { -
800 case QProcess::ForwardedChannels: -
801 fd_map[0] = stdinChannel.pipe[0]; -
802 fd_map[1] = QT_FILENO(stdout); -
803 fd_map[2] = QT_FILENO(stderr); -
804 break; -
805 case QProcess::MergedChannels: -
806 fd_map[0] = stdinChannel.pipe[0]; -
807 fd_map[1] = stdoutChannel.pipe[1]; -
808 fd_map[2] = stdoutChannel.pipe[1]; -
809 break; -
810 case QProcess::SeparateChannels: -
811 fd_map[0] = stdinChannel.pipe[0]; -
812 fd_map[1] = stdoutChannel.pipe[1]; -
813 fd_map[2] = stderrChannel.pipe[1]; -
814 break; -
815 } -
816 -
817 pid_t childPid = doSpawn(fd_count, fd_map.data(), argv, envp, workingDir, false); -
818 -
819 if (childPid == -1) { -
820 QString error = qt_error_string(errno); -
821 qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar)); -
822 qt_safe_close(childStartedPipe[1]); -
823 childStartedPipe[1] = -1; -
824 } -
825 -
826 return childPid; -
827} -
828 -
829#else -
830 -
831void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv, char **envp) -
832{ -
833 ::signal(SIGPIPE, SIG_DFL); // reset the signal that we ignored
never executed (the execution status of this line is deduced): ::signal(13, ((__sighandler_t) 0));
-
834 -
835 Q_Q(QProcess);
never executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
836 -
837 // copy the stdin socket (without closing on exec) -
838 qt_safe_dup2(stdinChannel.pipe[0], fileno(stdin), 0);
never executed (the execution status of this line is deduced): qt_safe_dup2(stdinChannel.pipe[0], fileno(stdin), 0);
-
839 -
840 // copy the stdout and stderr if asked to -
841 if (processChannelMode != QProcess::ForwardedChannels) {
never evaluated: processChannelMode != QProcess::ForwardedChannels
0
842 qt_safe_dup2(stdoutChannel.pipe[1], fileno(stdout), 0);
never executed (the execution status of this line is deduced): qt_safe_dup2(stdoutChannel.pipe[1], fileno(stdout), 0);
-
843 -
844 // merge stdout and stderr if asked to -
845 if (processChannelMode == QProcess::MergedChannels) {
never evaluated: processChannelMode == QProcess::MergedChannels
0
846 qt_safe_dup2(fileno(stdout), fileno(stderr), 0);
never executed (the execution status of this line is deduced): qt_safe_dup2(fileno(stdout), fileno(stderr), 0);
-
847 } else {
never executed: }
0
848 qt_safe_dup2(stderrChannel.pipe[1], fileno(stderr), 0);
never executed (the execution status of this line is deduced): qt_safe_dup2(stderrChannel.pipe[1], fileno(stderr), 0);
-
849 }
never executed: }
0
850 } -
851 -
852 // make sure this fd is closed if execvp() succeeds -
853 qt_safe_close(childStartedPipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(childStartedPipe[0]);
-
854 -
855 // enter the working directory -
856 if (workingDir) {
never evaluated: workingDir
0
857 if (QT_CHDIR(workingDir) == -1)
never evaluated: ::chdir(workingDir) == -1
0
858 qWarning("QProcessPrivate::execChild() failed to chdir to %s", workingDir);
never executed: QMessageLogger("io/qprocess_unix.cpp", 858, __PRETTY_FUNCTION__).warning("QProcessPrivate::execChild() failed to chdir to %s", workingDir);
0
859 }
never executed: }
0
860 -
861 // this is a virtual call, and it base behavior is to do nothing. -
862 q->setupChildProcess();
never executed (the execution status of this line is deduced): q->setupChildProcess();
-
863 -
864 // execute the process -
865 if (!envp) {
never evaluated: !envp
0
866 qt_safe_execvp(argv[0], argv);
never executed (the execution status of this line is deduced): qt_safe_execvp(argv[0], argv);
-
867 } else {
never executed: }
0
868 if (path) {
never evaluated: path
0
869 char **arg = path;
never executed (the execution status of this line is deduced): char **arg = path;
-
870 while (*arg) {
never evaluated: *arg
0
871 argv[0] = *arg;
never executed (the execution status of this line is deduced): argv[0] = *arg;
-
872#if defined (QPROCESS_DEBUG) -
873 fprintf(stderr, "QProcessPrivate::execChild() searching / starting %s\n", argv[0]); -
874#endif -
875 qt_safe_execve(argv[0], argv, envp);
never executed (the execution status of this line is deduced): qt_safe_execve(argv[0], argv, envp);
-
876 ++arg;
never executed (the execution status of this line is deduced): ++arg;
-
877 }
never executed: }
0
878 } else {
never executed: }
0
879#if defined (QPROCESS_DEBUG) -
880 fprintf(stderr, "QProcessPrivate::execChild() starting %s\n", argv[0]); -
881#endif -
882 qt_safe_execve(argv[0], argv, envp);
never executed (the execution status of this line is deduced): qt_safe_execve(argv[0], argv, envp);
-
883 }
never executed: }
0
884 } -
885 -
886 // notify failure -
887 QString error = qt_error_string(errno);
never executed (the execution status of this line is deduced): QString error = qt_error_string((*__errno_location ()));
-
888#if defined (QPROCESS_DEBUG) -
889 fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", qPrintable(error)); -
890#endif -
891 qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar));
never executed (the execution status of this line is deduced): qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar));
-
892 qt_safe_close(childStartedPipe[1]);
never executed (the execution status of this line is deduced): qt_safe_close(childStartedPipe[1]);
-
893 childStartedPipe[1] = -1;
never executed (the execution status of this line is deduced): childStartedPipe[1] = -1;
-
894}
never executed: }
0
895#endif -
896 -
897bool QProcessPrivate::processStarted() -
898{ -
899 ushort buf[errorBufferMax];
executed (the execution status of this line is deduced): ushort buf[errorBufferMax];
-
900 int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf);
executed (the execution status of this line is deduced): int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf);
-
901 if (startupSocketNotifier) {
evaluated: startupSocketNotifier
TRUEFALSE
yes
Evaluation Count:2439
yes
Evaluation Count:81
81-2439
902 startupSocketNotifier->setEnabled(false);
executed (the execution status of this line is deduced): startupSocketNotifier->setEnabled(false);
-
903 startupSocketNotifier->deleteLater();
executed (the execution status of this line is deduced): startupSocketNotifier->deleteLater();
-
904 startupSocketNotifier = 0;
executed (the execution status of this line is deduced): startupSocketNotifier = 0;
-
905 }
executed: }
Execution Count:2439
2439
906 qt_safe_close(childStartedPipe[0]);
executed (the execution status of this line is deduced): qt_safe_close(childStartedPipe[0]);
-
907 childStartedPipe[0] = -1;
executed (the execution status of this line is deduced): childStartedPipe[0] = -1;
-
908 -
909#if defined (QPROCESS_DEBUG) -
910 qDebug("QProcessPrivate::processStarted() == %s", i <= 0 ? "true" : "false"); -
911#endif -
912 -
913 // did we read an error message? -
914 if (i > 0)
evaluated: i > 0
TRUEFALSE
yes
Evaluation Count:827
yes
Evaluation Count:1693
827-1693
915 q_func()->setErrorString(QString((const QChar *)buf, i / sizeof(QChar)));
executed: q_func()->setErrorString(QString((const QChar *)buf, i / sizeof(QChar)));
Execution Count:827
827
916 -
917 return i <= 0;
executed: return i <= 0;
Execution Count:2520
2520
918} -
919 -
920qint64 QProcessPrivate::bytesAvailableFromStdout() const -
921{ -
922 int nbytes = 0;
executed (the execution status of this line is deduced): int nbytes = 0;
-
923 qint64 available = 0;
executed (the execution status of this line is deduced): qint64 available = 0;
-
924 if (::ioctl(stdoutChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0)
evaluated: ::ioctl(stdoutChannel.pipe[0], 0x541B, (char *) &nbytes) >= 0
TRUEFALSE
yes
Evaluation Count:47993
yes
Evaluation Count:1662
1662-47993
925 available = (qint64) nbytes;
executed: available = (qint64) nbytes;
Execution Count:47993
47993
926#if defined (QPROCESS_DEBUG) -
927 qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", available); -
928#endif -
929 return available;
executed: return available;
Execution Count:49655
49655
930} -
931 -
932qint64 QProcessPrivate::bytesAvailableFromStderr() const -
933{ -
934 int nbytes = 0;
executed (the execution status of this line is deduced): int nbytes = 0;
-
935 qint64 available = 0;
executed (the execution status of this line is deduced): qint64 available = 0;
-
936 if (::ioctl(stderrChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0)
evaluated: ::ioctl(stderrChannel.pipe[0], 0x541B, (char *) &nbytes) >= 0
TRUEFALSE
yes
Evaluation Count:2039
yes
Evaluation Count:1691
1691-2039
937 available = (qint64) nbytes;
executed: available = (qint64) nbytes;
Execution Count:2039
2039
938#if defined (QPROCESS_DEBUG) -
939 qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", available); -
940#endif -
941 return available;
executed: return available;
Execution Count:3730
3730
942} -
943 -
944qint64 QProcessPrivate::readFromStdout(char *data, qint64 maxlen) -
945{ -
946 qint64 bytesRead = qt_safe_read(stdoutChannel.pipe[0], data, maxlen);
executed (the execution status of this line is deduced): qint64 bytesRead = qt_safe_read(stdoutChannel.pipe[0], data, maxlen);
-
947#if defined QPROCESS_DEBUG -
948 qDebug("QProcessPrivate::readFromStdout(%p \"%s\", %lld) == %lld", -
949 data, qt_prettyDebug(data, bytesRead, 16).constData(), maxlen, bytesRead); -
950#endif -
951 return bytesRead;
executed: return bytesRead;
Execution Count:46306
46306
952} -
953 -
954qint64 QProcessPrivate::readFromStderr(char *data, qint64 maxlen) -
955{ -
956 qint64 bytesRead = qt_safe_read(stderrChannel.pipe[0], data, maxlen);
executed (the execution status of this line is deduced): qint64 bytesRead = qt_safe_read(stderrChannel.pipe[0], data, maxlen);
-
957#if defined QPROCESS_DEBUG -
958 qDebug("QProcessPrivate::readFromStderr(%p \"%s\", %lld) == %lld", -
959 data, qt_prettyDebug(data, bytesRead, 16).constData(), maxlen, bytesRead); -
960#endif -
961 return bytesRead;
executed: return bytesRead;
Execution Count:359
359
962} -
963 -
964qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) -
965{ -
966 qint64 written = qt_safe_write_nosignal(stdinChannel.pipe[1], data, maxlen);
executed (the execution status of this line is deduced): qint64 written = qt_safe_write_nosignal(stdinChannel.pipe[1], data, maxlen);
-
967#if defined QPROCESS_DEBUG -
968 qDebug("QProcessPrivate::writeToStdin(%p \"%s\", %lld) == %lld", -
969 data, qt_prettyDebug(data, maxlen, 16).constData(), maxlen, written); -
970 if (written == -1) -
971 qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qPrintable(qt_error_string(errno))); -
972#endif -
973 // If the O_NONBLOCK flag is set and If some data can be written without blocking -
974 // the process, write() will transfer what it can and return the number of bytes written. -
975 // Otherwise, it will return -1 and set errno to EAGAIN -
976 if (written == -1 && errno == EAGAIN)
partially evaluated: written == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1175
never evaluated: (*__errno_location ()) == 11
0-1175
977 written = 0;
never executed: written = 0;
0
978 return written;
executed: return written;
Execution Count:1175
1175
979} -
980 -
981void QProcessPrivate::terminateProcess() -
982{ -
983#if defined (QPROCESS_DEBUG) -
984 qDebug("QProcessPrivate::killProcess()"); -
985#endif -
986 if (pid)
evaluated: pid
TRUEFALSE
yes
Evaluation Count:115
yes
Evaluation Count:38
38-115
987 ::kill(pid_t(pid), SIGTERM);
executed: ::kill(pid_t(pid), 15);
Execution Count:115
115
988}
executed: }
Execution Count:153
153
989 -
990void QProcessPrivate::killProcess() -
991{ -
992#if defined (QPROCESS_DEBUG) -
993 qDebug("QProcessPrivate::killProcess()"); -
994#endif -
995 if (pid)
evaluated: pid
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:3
3-16
996 ::kill(pid_t(pid), SIGKILL);
executed: ::kill(pid_t(pid), 9);
Execution Count:16
16
997}
executed: }
Execution Count:19
19
998 -
999static int select_msecs(int nfds, fd_set *fdread, fd_set *fdwrite, int timeout) -
1000{ -
1001 if (timeout < 0)
evaluated: timeout < 0
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:53058
17-53058
1002 return qt_safe_select(nfds, fdread, fdwrite, 0, 0);
executed: return qt_safe_select(nfds, fdread, fdwrite, 0, 0);
Execution Count:17
17
1003 -
1004 struct timeval tv;
executed (the execution status of this line is deduced): struct timeval tv;
-
1005 tv.tv_sec = timeout / 1000;
executed (the execution status of this line is deduced): tv.tv_sec = timeout / 1000;
-
1006 tv.tv_usec = (timeout % 1000) * 1000;
executed (the execution status of this line is deduced): tv.tv_usec = (timeout % 1000) * 1000;
-
1007 return qt_safe_select(nfds, fdread, fdwrite, 0, &tv);
executed: return qt_safe_select(nfds, fdread, fdwrite, 0, &tv);
Execution Count:53058
53058
1008} -
1009 -
1010/* -
1011 Returns the difference between msecs and elapsed. If msecs is -1, -
1012 however, -1 is returned. -
1013*/ -
1014static int qt_timeout_value(int msecs, int elapsed) -
1015{ -
1016 if (msecs == -1)
evaluated: msecs == -1
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:50751
8-50751
1017 return -1;
executed: return -1;
Execution Count:8
8
1018 -
1019 int timeout = msecs - elapsed;
executed (the execution status of this line is deduced): int timeout = msecs - elapsed;
-
1020 return timeout < 0 ? 0 : timeout;
executed: return timeout < 0 ? 0 : timeout;
Execution Count:50751
50751
1021} -
1022 -
1023bool QProcessPrivate::waitForStarted(int msecs) -
1024{ -
1025 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1026 -
1027#if defined (QPROCESS_DEBUG) -
1028 qDebug("QProcessPrivate::waitForStarted(%d) waiting for child to start (fd = %d)", msecs, -
1029 childStartedPipe[0]); -
1030#endif -
1031 -
1032 fd_set fds;
executed (the execution status of this line is deduced): fd_set fds;
-
1033 FD_ZERO(&fds);
executed: }
Execution Count:2316
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2316
0-2316
1034 FD_SET(childStartedPipe[0], &fds);
executed (the execution status of this line is deduced): (((&fds)->fds_bits)[((childStartedPipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((childStartedPipe[0]) % (8 * (int) sizeof (__fd_mask)))));
-
1035 if (select_msecs(childStartedPipe[0] + 1, &fds, 0, msecs) == 0) {
partially evaluated: select_msecs(childStartedPipe[0] + 1, &fds, 0, msecs) == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2316
0-2316
1036 processError = QProcess::Timedout;
never executed (the execution status of this line is deduced): processError = QProcess::Timedout;
-
1037 q->setErrorString(QProcess::tr("Process operation timed out"));
never executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Process operation timed out"));
-
1038#if defined (QPROCESS_DEBUG) -
1039 qDebug("QProcessPrivate::waitForStarted(%d) == false (timed out)", msecs); -
1040#endif -
1041 return false;
never executed: return false;
0
1042 } -
1043 -
1044 bool startedEmitted = _q_startupNotification();
executed (the execution status of this line is deduced): bool startedEmitted = _q_startupNotification();
-
1045#if defined (QPROCESS_DEBUG) -
1046 qDebug("QProcessPrivate::waitForStarted() == %s", startedEmitted ? "true" : "false"); -
1047#endif -
1048 return startedEmitted;
executed: return startedEmitted;
Execution Count:2316
2316
1049} -
1050 -
1051bool QProcessPrivate::waitForReadyRead(int msecs) -
1052{ -
1053 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1054#if defined (QPROCESS_DEBUG) -
1055 qDebug("QProcessPrivate::waitForReadyRead(%d)", msecs); -
1056#endif -
1057 -
1058 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
1059 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
1060 -
1061 forever {
executed (the execution status of this line is deduced): for(;;) {
-
1062 fd_set fdread;
executed (the execution status of this line is deduced): fd_set fdread;
-
1063 fd_set fdwrite;
executed (the execution status of this line is deduced): fd_set fdwrite;
-
1064 -
1065 FD_ZERO(&fdread);
executed: }
Execution Count:709
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:709
0-709
1066 FD_ZERO(&fdwrite);
executed: }
Execution Count:709
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:709
0-709
1067 -
1068 int nfds = deathPipe[0];
executed (the execution status of this line is deduced): int nfds = deathPipe[0];
-
1069 FD_SET(deathPipe[0], &fdread);
executed (the execution status of this line is deduced): (((&fdread)->fds_bits)[((deathPipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((deathPipe[0]) % (8 * (int) sizeof (__fd_mask)))));
-
1070 -
1071 if (processState == QProcess::Starting)
evaluated: processState == QProcess::Starting
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:526
183-526
1072 add_fd(nfds, childStartedPipe[0], &fdread);
executed: add_fd(nfds, childStartedPipe[0], &fdread);
Execution Count:183
183
1073 -
1074 if (stdoutChannel.pipe[0] != -1)
evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:706
yes
Evaluation Count:3
3-706
1075 add_fd(nfds, stdoutChannel.pipe[0], &fdread);
executed: add_fd(nfds, stdoutChannel.pipe[0], &fdread);
Execution Count:706
706
1076 if (stderrChannel.pipe[0] != -1)
evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:484
yes
Evaluation Count:225
225-484
1077 add_fd(nfds, stderrChannel.pipe[0], &fdread);
executed: add_fd(nfds, stderrChannel.pipe[0], &fdread);
Execution Count:484
484
1078 -
1079 if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
evaluated: !writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:218
yes
Evaluation Count:491
partially evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:218
no
Evaluation Count:0
0-491
1080 add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
executed: add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
Execution Count:218
218
1081 -
1082 int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
executed (the execution status of this line is deduced): int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
-
1083 int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
executed (the execution status of this line is deduced): int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
-
1084 if (ret < 0) {
partially evaluated: ret < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:709
0-709
1085 break;
never executed: break;
0
1086 } -
1087 if (ret == 0) {
evaluated: ret == 0
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:703
6-703
1088 processError = QProcess::Timedout;
executed (the execution status of this line is deduced): processError = QProcess::Timedout;
-
1089 q->setErrorString(QProcess::tr("Process operation timed out"));
executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Process operation timed out"));
-
1090 return false;
executed: return false;
Execution Count:6
6
1091 } -
1092 -
1093 if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
evaluated: childStartedPipe[0] != -1
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:520
evaluated: ((((&fdread)->fds_bits)[((childStartedPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((childStartedPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:106
yes
Evaluation Count:77
77-520
1094 if (!_q_startupNotification())
evaluated: !_q_startupNotification()
TRUEFALSE
yes
Evaluation Count:101
yes
Evaluation Count:5
5-101
1095 return false;
executed: return false;
Execution Count:101
101
1096 }
executed: }
Execution Count:5
5
1097 -
1098 bool readyReadEmitted = false;
executed (the execution status of this line is deduced): bool readyReadEmitted = false;
-
1099 if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread)) {
evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:600
yes
Evaluation Count:2
evaluated: ((((&fdread)->fds_bits)[((stdoutChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdoutChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:293
yes
Evaluation Count:307
2-600
1100 bool canRead = _q_canReadStandardOutput();
executed (the execution status of this line is deduced): bool canRead = _q_canReadStandardOutput();
-
1101 if (processChannel == QProcess::StandardOutput && canRead)
evaluated: processChannel == QProcess::StandardOutput
TRUEFALSE
yes
Evaluation Count:288
yes
Evaluation Count:5
evaluated: canRead
TRUEFALSE
yes
Evaluation Count:285
yes
Evaluation Count:3
3-288
1102 readyReadEmitted = true;
executed: readyReadEmitted = true;
Execution Count:285
285
1103 }
executed: }
Execution Count:293
293
1104 if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread)) {
evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:378
yes
Evaluation Count:224
evaluated: ((((&fdread)->fds_bits)[((stderrChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stderrChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:354
24-378
1105 bool canRead = _q_canReadStandardError();
executed (the execution status of this line is deduced): bool canRead = _q_canReadStandardError();
-
1106 if (processChannel == QProcess::StandardError && canRead)
evaluated: processChannel == QProcess::StandardError
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:13
partially evaluated: canRead
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-13
1107 readyReadEmitted = true;
executed: readyReadEmitted = true;
Execution Count:11
11
1108 }
executed: }
Execution Count:24
24
1109 if (readyReadEmitted)
evaluated: readyReadEmitted
TRUEFALSE
yes
Evaluation Count:296
yes
Evaluation Count:306
296-306
1110 return true;
executed: return true;
Execution Count:296
296
1111 -
1112 if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
partially evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:306
no
Evaluation Count:0
evaluated: ((((&fdwrite)->fds_bits)[((stdinChannel.pipe[1]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdinChannel.pipe[1]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:218
yes
Evaluation Count:88
0-306
1113 _q_canWrite();
executed: _q_canWrite();
Execution Count:218
218
1114 -
1115 if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
partially evaluated: deathPipe[0] == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:306
evaluated: ((((&fdread)->fds_bits)[((deathPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((deathPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:77
yes
Evaluation Count:229
0-306
1116 if (_q_processDied())
evaluated: _q_processDied()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:75
2-75
1117 return false;
executed: return false;
Execution Count:2
2
1118 }
executed: }
Execution Count:75
75
1119 }
executed: }
Execution Count:304
304
1120 return false;
never executed: return false;
0
1121} -
1122 -
1123bool QProcessPrivate::waitForBytesWritten(int msecs) -
1124{ -
1125 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1126#if defined (QPROCESS_DEBUG) -
1127 qDebug("QProcessPrivate::waitForBytesWritten(%d)", msecs); -
1128#endif -
1129 -
1130 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
1131 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
1132 -
1133 while (!writeBuffer.isEmpty()) {
evaluated: !writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:727
yes
Evaluation Count:3
3-727
1134 fd_set fdread;
executed (the execution status of this line is deduced): fd_set fdread;
-
1135 fd_set fdwrite;
executed (the execution status of this line is deduced): fd_set fdwrite;
-
1136 -
1137 FD_ZERO(&fdread);
executed: }
Execution Count:727
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
0-727
1138 FD_ZERO(&fdwrite);
executed: }
Execution Count:727
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
0-727
1139 -
1140 int nfds = deathPipe[0];
executed (the execution status of this line is deduced): int nfds = deathPipe[0];
-
1141 FD_SET(deathPipe[0], &fdread);
executed (the execution status of this line is deduced): (((&fdread)->fds_bits)[((deathPipe[0]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((deathPipe[0]) % (8 * (int) sizeof (__fd_mask)))));
-
1142 -
1143 if (processState == QProcess::Starting)
partially evaluated: processState == QProcess::Starting
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
0-727
1144 add_fd(nfds, childStartedPipe[0], &fdread);
never executed: add_fd(nfds, childStartedPipe[0], &fdread);
0
1145 -
1146 if (stdoutChannel.pipe[0] != -1)
partially evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
0-727
1147 add_fd(nfds, stdoutChannel.pipe[0], &fdread);
executed: add_fd(nfds, stdoutChannel.pipe[0], &fdread);
Execution Count:727
727
1148 if (stderrChannel.pipe[0] != -1)
partially evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
0-727
1149 add_fd(nfds, stderrChannel.pipe[0], &fdread);
executed: add_fd(nfds, stderrChannel.pipe[0], &fdread);
Execution Count:727
727
1150 -
1151 -
1152 if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
partially evaluated: !writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
partially evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
0-727
1153 add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
executed: add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
Execution Count:727
727
1154 -
1155 int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
executed (the execution status of this line is deduced): int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
-
1156 int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
executed (the execution status of this line is deduced): int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
-
1157 if (ret < 0) {
partially evaluated: ret < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
0-727
1158 break;
never executed: break;
0
1159 } -
1160 -
1161 if (ret == 0) {
partially evaluated: ret == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
0-727
1162 processError = QProcess::Timedout;
never executed (the execution status of this line is deduced): processError = QProcess::Timedout;
-
1163 q->setErrorString(QProcess::tr("Process operation timed out"));
never executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Process operation timed out"));
-
1164 return false;
never executed: return false;
0
1165 } -
1166 -
1167 if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
partially evaluated: childStartedPipe[0] != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:727
never evaluated: ((((&fdread)->fds_bits)[((childStartedPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((childStartedPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
0-727
1168 if (!_q_startupNotification())
never evaluated: !_q_startupNotification()
0
1169 return false;
never executed: return false;
0
1170 }
never executed: }
0
1171 -
1172 if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
partially evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
partially evaluated: ((((&fdwrite)->fds_bits)[((stdinChannel.pipe[1]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdinChannel.pipe[1]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:727
no
Evaluation Count:0
0-727
1173 return _q_canWrite();
executed: return _q_canWrite();
Execution Count:727
727
1174 -
1175 if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread))
never evaluated: stdoutChannel.pipe[0] != -1
never evaluated: ((((&fdread)->fds_bits)[((stdoutChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdoutChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
0
1176 _q_canReadStandardOutput();
never executed: _q_canReadStandardOutput();
0
1177 -
1178 if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
never evaluated: stderrChannel.pipe[0] != -1
never evaluated: ((((&fdread)->fds_bits)[((stderrChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stderrChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
0
1179 _q_canReadStandardError();
never executed: _q_canReadStandardError();
0
1180 -
1181 if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
never evaluated: deathPipe[0] == -1
never evaluated: ((((&fdread)->fds_bits)[((deathPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((deathPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
0
1182 if (_q_processDied())
never evaluated: _q_processDied()
0
1183 return false;
never executed: return false;
0
1184 }
never executed: }
0
1185 }
never executed: }
0
1186 -
1187 return false;
executed: return false;
Execution Count:3
3
1188} -
1189 -
1190bool QProcessPrivate::waitForFinished(int msecs) -
1191{ -
1192 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1193#if defined (QPROCESS_DEBUG) -
1194 qDebug("QProcessPrivate::waitForFinished(%d)", msecs); -
1195#endif -
1196 -
1197 QElapsedTimer stopWatch;
executed (the execution status of this line is deduced): QElapsedTimer stopWatch;
-
1198 stopWatch.start();
executed (the execution status of this line is deduced): stopWatch.start();
-
1199 -
1200 forever {
executed (the execution status of this line is deduced): for(;;) {
-
1201 fd_set fdread;
executed (the execution status of this line is deduced): fd_set fdread;
-
1202 fd_set fdwrite;
executed (the execution status of this line is deduced): fd_set fdwrite;
-
1203 int nfds = -1;
executed (the execution status of this line is deduced): int nfds = -1;
-
1204 -
1205 FD_ZERO(&fdread);
executed: }
Execution Count:49323
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49323
0-49323
1206 FD_ZERO(&fdwrite);
executed: }
Execution Count:49323
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49323
0-49323
1207 -
1208 if (processState == QProcess::Starting)
partially evaluated: processState == QProcess::Starting
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49323
0-49323
1209 add_fd(nfds, childStartedPipe[0], &fdread);
never executed: add_fd(nfds, childStartedPipe[0], &fdread);
0
1210 -
1211 if (stdoutChannel.pipe[0] != -1)
evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:47557
yes
Evaluation Count:1766
1766-47557
1212 add_fd(nfds, stdoutChannel.pipe[0], &fdread);
executed: add_fd(nfds, stdoutChannel.pipe[0], &fdread);
Execution Count:47557
47557
1213 if (stderrChannel.pipe[0] != -1)
evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:47608
yes
Evaluation Count:1715
1715-47608
1214 add_fd(nfds, stderrChannel.pipe[0], &fdread);
executed: add_fd(nfds, stderrChannel.pipe[0], &fdread);
Execution Count:47608
47608
1215 -
1216 if (processState == QProcess::Running)
partially evaluated: processState == QProcess::Running
TRUEFALSE
yes
Evaluation Count:49323
no
Evaluation Count:0
0-49323
1217 add_fd(nfds, deathPipe[0], &fdread);
executed: add_fd(nfds, deathPipe[0], &fdread);
Execution Count:49323
49323
1218 -
1219 if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1)
evaluated: !writeBuffer.isEmpty()
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:49282
partially evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:41
no
Evaluation Count:0
0-49282
1220 add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
executed: add_fd(nfds, stdinChannel.pipe[1], &fdwrite);
Execution Count:41
41
1221 -
1222 int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
executed (the execution status of this line is deduced): int timeout = qt_timeout_value(msecs, stopWatch.elapsed());
-
1223 int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
executed (the execution status of this line is deduced): int ret = select_msecs(nfds + 1, &fdread, &fdwrite, timeout);
-
1224 if (ret < 0) {
partially evaluated: ret < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49323
0-49323
1225 break;
never executed: break;
0
1226 } -
1227 if (ret == 0) {
evaluated: ret == 0
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:49320
3-49320
1228 processError = QProcess::Timedout;
executed (the execution status of this line is deduced): processError = QProcess::Timedout;
-
1229 q->setErrorString(QProcess::tr("Process operation timed out"));
executed (the execution status of this line is deduced): q->setErrorString(QProcess::tr("Process operation timed out"));
-
1230 return false;
executed: return false;
Execution Count:3
3
1231 } -
1232 -
1233 if (childStartedPipe[0] != -1 && FD_ISSET(childStartedPipe[0], &fdread)) {
partially evaluated: childStartedPipe[0] != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49320
never evaluated: ((((&fdread)->fds_bits)[((childStartedPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((childStartedPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
0-49320
1234 if (!_q_startupNotification())
never evaluated: !_q_startupNotification()
0
1235 return false;
never executed: return false;
0
1236 }
never executed: }
0
1237 if (stdinChannel.pipe[1] != -1 && FD_ISSET(stdinChannel.pipe[1], &fdwrite))
evaluated: stdinChannel.pipe[1] != -1
TRUEFALSE
yes
Evaluation Count:48519
yes
Evaluation Count:801
evaluated: ((((&fdwrite)->fds_bits)[((stdinChannel.pipe[1]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdinChannel.pipe[1]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:48478
41-48519
1238 _q_canWrite();
executed: _q_canWrite();
Execution Count:41
41
1239 -
1240 if (stdoutChannel.pipe[0] != -1 && FD_ISSET(stdoutChannel.pipe[0], &fdread))
evaluated: stdoutChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:47556
yes
Evaluation Count:1764
evaluated: ((((&fdread)->fds_bits)[((stdoutChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stdoutChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:47093
yes
Evaluation Count:463
463-47556
1241 _q_canReadStandardOutput();
executed: _q_canReadStandardOutput();
Execution Count:47093
47093
1242 -
1243 if (stderrChannel.pipe[0] != -1 && FD_ISSET(stderrChannel.pipe[0], &fdread))
evaluated: stderrChannel.pipe[0] != -1
TRUEFALSE
yes
Evaluation Count:47607
yes
Evaluation Count:1713
evaluated: ((((&fdread)->fds_bits)[((stderrChannel.pipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((stderrChannel.pipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:1956
yes
Evaluation Count:45651
1713-47607
1244 _q_canReadStandardError();
executed: _q_canReadStandardError();
Execution Count:1956
1956
1245 -
1246 if (deathPipe[0] == -1 || FD_ISSET(deathPipe[0], &fdread)) {
partially evaluated: deathPipe[0] == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:49320
evaluated: ((((&fdread)->fds_bits)[((deathPipe[0]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) 1 << ((deathPipe[0]) % (8 * (int) sizeof (__fd_mask))))) != 0)
TRUEFALSE
yes
Evaluation Count:1903
yes
Evaluation Count:47417
0-49320
1247 if (_q_processDied())
evaluated: _q_processDied()
TRUEFALSE
yes
Evaluation Count:1642
yes
Evaluation Count:261
261-1642
1248 return true;
executed: return true;
Execution Count:1642
1642
1249 }
executed: }
Execution Count:261
261
1250 }
executed: }
Execution Count:47678
47678
1251 return false;
never executed: return false;
0
1252} -
1253 -
1254bool QProcessPrivate::waitForWrite(int msecs) -
1255{ -
1256 fd_set fdwrite;
never executed (the execution status of this line is deduced): fd_set fdwrite;
-
1257 FD_ZERO(&fdwrite);
never executed: }
never evaluated: 0
0
1258 FD_SET(stdinChannel.pipe[1], &fdwrite);
never executed (the execution status of this line is deduced): (((&fdwrite)->fds_bits)[((stdinChannel.pipe[1]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) 1 << ((stdinChannel.pipe[1]) % (8 * (int) sizeof (__fd_mask)))));
-
1259 return select_msecs(stdinChannel.pipe[1] + 1, 0, &fdwrite, msecs < 0 ? 0 : msecs) == 1;
never executed: return select_msecs(stdinChannel.pipe[1] + 1, 0, &fdwrite, msecs < 0 ? 0 : msecs) == 1;
0
1260} -
1261 -
1262void QProcessPrivate::findExitCode() -
1263{ -
1264 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1265 processManager()->remove(q);
executed (the execution status of this line is deduced): processManager()->remove(q);
-
1266}
executed: }
Execution Count:4244
4244
1267 -
1268bool QProcessPrivate::waitForDeadChild() -
1269{ -
1270 Q_Q(QProcess);
executed (the execution status of this line is deduced): QProcess * const q = q_func();
-
1271 -
1272 // read a byte from the death pipe -
1273 char c;
executed (the execution status of this line is deduced): char c;
-
1274 qt_safe_read(deathPipe[0], &c, 1);
executed (the execution status of this line is deduced): qt_safe_read(deathPipe[0], &c, 1);
-
1275 -
1276 // check if our process is dead -
1277 int exitStatus;
executed (the execution status of this line is deduced): int exitStatus;
-
1278 if (qt_safe_waitpid(pid_t(pid), &exitStatus, WNOHANG) > 0) {
evaluated: qt_safe_waitpid(pid_t(pid), &exitStatus, 1) > 0
TRUEFALSE
yes
Evaluation Count:1693
yes
Evaluation Count:1231
1231-1693
1279 processManager()->remove(q);
executed (the execution status of this line is deduced): processManager()->remove(q);
-
1280 crashed = !WIFEXITED(exitStatus);
executed (the execution status of this line is deduced): crashed = !((((*(int *) &(exitStatus))) & 0x7f) == 0);
-
1281 exitCode = WEXITSTATUS(exitStatus);
executed (the execution status of this line is deduced): exitCode = ((((*(int *) &(exitStatus))) & 0xff00) >> 8);
-
1282#if defined QPROCESS_DEBUG -
1283 qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode" -
1284 << exitCode << ", crashed?" << crashed; -
1285#endif -
1286 return true;
executed: return true;
Execution Count:1693
1693
1287 } -
1288#if defined QPROCESS_DEBUG -
1289 qDebug() << "QProcessPrivate::waitForDeadChild() not dead!"; -
1290#endif -
1291 return false;
executed: return false;
Execution Count:1231
1231
1292} -
1293 -
1294void QProcessPrivate::_q_notified() -
1295{ -
1296} -
1297 -
1298#if defined(Q_OS_QNX) -
1299bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) -
1300{ -
1301 const int fd_count = 3; -
1302 int fd_map[fd_count] = { QT_FILENO(stdin), QT_FILENO(stdout), QT_FILENO(stderr) }; -
1303 -
1304 QList<QByteArray> enc_args; -
1305 enc_args.append(QFile::encodeName(program)); -
1306 for (int i = 0; i < arguments.size(); ++i) -
1307 enc_args.append(arguments.at(i).toLocal8Bit()); -
1308 -
1309 const int argc = enc_args.size(); -
1310 QScopedArrayPointer<char*> raw_argv(new char*[argc + 1]); -
1311 for (int i = 0; i < argc; ++i) -
1312 raw_argv[i] = const_cast<char *>(enc_args.at(i).data()); -
1313 raw_argv[argc] = 0; -
1314 -
1315 char **envp = 0; // inherit environment -
1316 -
1317 // Encode the working directory if it's non-empty, otherwise just pass 0. -
1318 const char *workingDirPtr = 0; -
1319 QByteArray encodedWorkingDirectory; -
1320 if (!workingDirectory.isEmpty()) { -
1321 encodedWorkingDirectory = QFile::encodeName(workingDirectory); -
1322 workingDirPtr = encodedWorkingDirectory.constData(); -
1323 } -
1324 -
1325 pid_t childPid = doSpawn(fd_count, fd_map, raw_argv.data(), envp, workingDirPtr, true); -
1326 if (pid && childPid != -1) -
1327 *pid = childPid; -
1328 -
1329 return childPid != -1; -
1330} -
1331 -
1332#else -
1333 -
1334bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid) -
1335{ -
1336 processManager()->start();
executed (the execution status of this line is deduced): processManager()->start();
-
1337 -
1338 QByteArray encodedWorkingDirectory = QFile::encodeName(workingDirectory);
executed (the execution status of this line is deduced): QByteArray encodedWorkingDirectory = QFile::encodeName(workingDirectory);
-
1339 -
1340 // To catch the startup of the child -
1341 int startedPipe[2];
executed (the execution status of this line is deduced): int startedPipe[2];
-
1342 qt_safe_pipe(startedPipe);
executed (the execution status of this line is deduced): qt_safe_pipe(startedPipe);
-
1343 // To communicate the pid of the child -
1344 int pidPipe[2];
executed (the execution status of this line is deduced): int pidPipe[2];
-
1345 qt_safe_pipe(pidPipe);
executed (the execution status of this line is deduced): qt_safe_pipe(pidPipe);
-
1346 -
1347 pid_t childPid = fork();
executed (the execution status of this line is deduced): pid_t childPid = fork();
-
1348 if (childPid == 0) {
partially evaluated: childPid == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1349 struct sigaction noaction;
never executed (the execution status of this line is deduced): struct sigaction noaction;
-
1350 memset(&noaction, 0, sizeof(noaction));
never executed (the execution status of this line is deduced): memset(&noaction, 0, sizeof(noaction));
-
1351 noaction.sa_handler = SIG_IGN;
never executed (the execution status of this line is deduced): noaction.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
-
1352 ::sigaction(SIGPIPE, &noaction, 0);
never executed (the execution status of this line is deduced): ::sigaction(13, &noaction, 0);
-
1353 -
1354 ::setsid();
never executed (the execution status of this line is deduced): ::setsid();
-
1355 -
1356 qt_safe_close(startedPipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(startedPipe[0]);
-
1357 qt_safe_close(pidPipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(pidPipe[0]);
-
1358 -
1359 pid_t doubleForkPid = fork();
never executed (the execution status of this line is deduced): pid_t doubleForkPid = fork();
-
1360 if (doubleForkPid == 0) {
never evaluated: doubleForkPid == 0
0
1361 qt_safe_close(pidPipe[1]);
never executed (the execution status of this line is deduced): qt_safe_close(pidPipe[1]);
-
1362 -
1363 if (!encodedWorkingDirectory.isEmpty()) {
never evaluated: !encodedWorkingDirectory.isEmpty()
0
1364 if (QT_CHDIR(encodedWorkingDirectory.constData()) == -1)
never evaluated: ::chdir(encodedWorkingDirectory.constData()) == -1
0
1365 qWarning("QProcessPrivate::startDetached: failed to chdir to %s", encodedWorkingDirectory.constData());
never executed: QMessageLogger("io/qprocess_unix.cpp", 1365, __PRETTY_FUNCTION__).warning("QProcessPrivate::startDetached: failed to chdir to %s", encodedWorkingDirectory.constData());
0
1366 }
never executed: }
0
1367 -
1368 char **argv = new char *[arguments.size() + 2];
never executed (the execution status of this line is deduced): char **argv = new char *[arguments.size() + 2];
-
1369 for (int i = 0; i < arguments.size(); ++i)
never evaluated: i < arguments.size()
0
1370 argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
never executed: argv[i + 1] = ::strdup(QFile::encodeName(arguments.at(i)).constData());
0
1371 argv[arguments.size() + 1] = 0;
never executed (the execution status of this line is deduced): argv[arguments.size() + 1] = 0;
-
1372 -
1373 if (!program.contains(QLatin1Char('/'))) {
never evaluated: !program.contains(QLatin1Char('/'))
0
1374 const QString path = QString::fromLocal8Bit(::getenv("PATH"));
never executed (the execution status of this line is deduced): const QString path = QString::fromLocal8Bit(::getenv("PATH"));
-
1375 if (!path.isEmpty()) {
never evaluated: !path.isEmpty()
0
1376 QStringList pathEntries = path.split(QLatin1Char(':'));
never executed (the execution status of this line is deduced): QStringList pathEntries = path.split(QLatin1Char(':'));
-
1377 for (int k = 0; k < pathEntries.size(); ++k) {
never evaluated: k < pathEntries.size()
0
1378 QByteArray tmp = QFile::encodeName(pathEntries.at(k));
never executed (the execution status of this line is deduced): QByteArray tmp = QFile::encodeName(pathEntries.at(k));
-
1379 if (!tmp.endsWith('/')) tmp += '/';
never executed: tmp += '/';
never evaluated: !tmp.endsWith('/')
0
1380 tmp += QFile::encodeName(program);
never executed (the execution status of this line is deduced): tmp += QFile::encodeName(program);
-
1381 argv[0] = tmp.data();
never executed (the execution status of this line is deduced): argv[0] = tmp.data();
-
1382 qt_safe_execv(argv[0], argv);
never executed (the execution status of this line is deduced): qt_safe_execv(argv[0], argv);
-
1383 }
never executed: }
0
1384 }
never executed: }
0
1385 } else {
never executed: }
0
1386 QByteArray tmp = QFile::encodeName(program);
never executed (the execution status of this line is deduced): QByteArray tmp = QFile::encodeName(program);
-
1387 argv[0] = tmp.data();
never executed (the execution status of this line is deduced): argv[0] = tmp.data();
-
1388 qt_safe_execv(argv[0], argv);
never executed (the execution status of this line is deduced): qt_safe_execv(argv[0], argv);
-
1389 }
never executed: }
0
1390 -
1391 struct sigaction noaction;
never executed (the execution status of this line is deduced): struct sigaction noaction;
-
1392 memset(&noaction, 0, sizeof(noaction));
never executed (the execution status of this line is deduced): memset(&noaction, 0, sizeof(noaction));
-
1393 noaction.sa_handler = SIG_IGN;
never executed (the execution status of this line is deduced): noaction.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
-
1394 ::sigaction(SIGPIPE, &noaction, 0);
never executed (the execution status of this line is deduced): ::sigaction(13, &noaction, 0);
-
1395 -
1396 // '\1' means execv failed -
1397 char c = '\1';
never executed (the execution status of this line is deduced): char c = '\1';
-
1398 qt_safe_write(startedPipe[1], &c, 1);
never executed (the execution status of this line is deduced): qt_safe_write(startedPipe[1], &c, 1);
-
1399 qt_safe_close(startedPipe[1]);
never executed (the execution status of this line is deduced): qt_safe_close(startedPipe[1]);
-
1400 ::_exit(1);
never executed (the execution status of this line is deduced): ::_exit(1);
-
1401 } else if (doubleForkPid == -1) {
never executed: }
never evaluated: doubleForkPid == -1
0
1402 struct sigaction noaction;
never executed (the execution status of this line is deduced): struct sigaction noaction;
-
1403 memset(&noaction, 0, sizeof(noaction));
never executed (the execution status of this line is deduced): memset(&noaction, 0, sizeof(noaction));
-
1404 noaction.sa_handler = SIG_IGN;
never executed (the execution status of this line is deduced): noaction.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
-
1405 ::sigaction(SIGPIPE, &noaction, 0);
never executed (the execution status of this line is deduced): ::sigaction(13, &noaction, 0);
-
1406 -
1407 // '\2' means internal error -
1408 char c = '\2';
never executed (the execution status of this line is deduced): char c = '\2';
-
1409 qt_safe_write(startedPipe[1], &c, 1);
never executed (the execution status of this line is deduced): qt_safe_write(startedPipe[1], &c, 1);
-
1410 }
never executed: }
0
1411 -
1412 qt_safe_close(startedPipe[1]);
never executed (the execution status of this line is deduced): qt_safe_close(startedPipe[1]);
-
1413 qt_safe_write(pidPipe[1], (const char *)&doubleForkPid, sizeof(pid_t));
never executed (the execution status of this line is deduced): qt_safe_write(pidPipe[1], (const char *)&doubleForkPid, sizeof(pid_t));
-
1414 if (QT_CHDIR("/") == -1)
never evaluated: ::chdir("/") == -1
0
1415 qWarning("QProcessPrivate::startDetached: failed to chdir to /");
never executed: QMessageLogger("io/qprocess_unix.cpp", 1415, __PRETTY_FUNCTION__).warning("QProcessPrivate::startDetached: failed to chdir to /");
0
1416 ::_exit(1);
never executed (the execution status of this line is deduced): ::_exit(1);
-
1417 }
never executed: }
0
1418 -
1419 qt_safe_close(startedPipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(startedPipe[1]);
-
1420 qt_safe_close(pidPipe[1]);
executed (the execution status of this line is deduced): qt_safe_close(pidPipe[1]);
-
1421 -
1422 if (childPid == -1) {
partially evaluated: childPid == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1423 qt_safe_close(startedPipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(startedPipe[0]);
-
1424 qt_safe_close(pidPipe[0]);
never executed (the execution status of this line is deduced): qt_safe_close(pidPipe[0]);
-
1425 return false;
never executed: return false;
0
1426 } -
1427 -
1428 char reply = '\0';
executed (the execution status of this line is deduced): char reply = '\0';
-
1429 int startResult = qt_safe_read(startedPipe[0], &reply, 1);
executed (the execution status of this line is deduced): int startResult = qt_safe_read(startedPipe[0], &reply, 1);
-
1430 int result;
executed (the execution status of this line is deduced): int result;
-
1431 qt_safe_close(startedPipe[0]);
executed (the execution status of this line is deduced): qt_safe_close(startedPipe[0]);
-
1432 qt_safe_waitpid(childPid, &result, 0);
executed (the execution status of this line is deduced): qt_safe_waitpid(childPid, &result, 0);
-
1433 bool success = (startResult != -1 && reply == '\0');
partially evaluated: startResult != -1
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
evaluated: reply == '\0'
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
0-4
1434 if (success && pid) {
evaluated: success
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
evaluated: pid
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1-2
1435 pid_t actualPid = 0;
executed (the execution status of this line is deduced): pid_t actualPid = 0;
-
1436 if (qt_safe_read(pidPipe[0], (char *)&actualPid, sizeof(pid_t)) == sizeof(pid_t)) {
partially evaluated: qt_safe_read(pidPipe[0], (char *)&actualPid, sizeof(pid_t)) == sizeof(pid_t)
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
1437 *pid = actualPid;
executed (the execution status of this line is deduced): *pid = actualPid;
-
1438 } else {
executed: }
Execution Count:1
1
1439 *pid = 0;
never executed (the execution status of this line is deduced): *pid = 0;
-
1440 }
never executed: }
0
1441 } -
1442 qt_safe_close(pidPipe[0]);
executed (the execution status of this line is deduced): qt_safe_close(pidPipe[0]);
-
1443 return success;
executed: return success;
Execution Count:4
4
1444} -
1445#endif -
1446 -
1447void QProcessPrivate::initializeProcessManager() -
1448{ -
1449 (void) processManager();
executed (the execution status of this line is deduced): (void) processManager();
-
1450}
executed: }
Execution Count:145
145
1451 -
1452QT_END_NAMESPACE -
1453 -
1454#include "qprocess_unix.moc" -
1455 -
1456#endif // QT_NO_PROCESS -
1457 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial