summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/softwarecontainer-plugin/softwarecontainer.cpp
blob: d8494da38aa38a4273ca338d3149cdc21a265042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2019 Luxoft Sweden AB
** Copyright (C) 2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtApplicationManager module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <tuple>

#include <QtDBus/QtDBus>
#include <QtAppManCommon/global.h>
#include <QJsonDocument>
#include <QSocketNotifier>
#include <QMetaObject>
#include <qplatformdefs.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include "softwarecontainer.h"


QT_BEGIN_NAMESPACE

QDBusArgument &operator<<(QDBusArgument &argument, const QMap<QString,QString> &map)
{
    argument.beginMap(QMetaType::QString, QMetaType::QString);
    for (auto it = map.cbegin(); it != map.cend(); ++it) {
        argument.beginMapEntry();
        argument << it.key() << it.value();
        argument.endMapEntry();
    }
    argument.endMap();

    return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, QMap<QString,QString> &map)
{
    argument.beginMap();
    while (!argument.atEnd()) {
        argument.beginMapEntry();
        QString key, value;
        argument >> key >> value;
        map.insert(key, value);
        argument.endMapEntry();
    }
    argument.endMap();

    return argument;
}

QT_END_NAMESPACE


QT_USE_NAMESPACE_AM

// unfortunately, this is a copy of the code from debugwrapper.cpp
static QStringList substituteCommand(const QStringList &debugWrapperCommand, const QString &program,
                                     const QStringList &arguments)
{
    QString stringifiedArguments = arguments.join(QLatin1Char(' '));
    QStringList result;

    for (const QString &s : debugWrapperCommand) {
        if (s == QStringLiteral("%arguments%")) {
            result << arguments;
        } else {
            QString str(s);
            str.replace(QStringLiteral("%program%"), program);
            str.replace(QStringLiteral("%arguments%"), stringifiedArguments);
            result << str;
        }
    }
    return result;
}

SoftwareContainerManager::SoftwareContainerManager()
{
    static bool once = false;
    if (!once) {
        once = true;
        qDBusRegisterMetaType<QMap<QString, QString>>();
    }
}

QString SoftwareContainerManager::identifier() const
{
    return QStringLiteral("softwarecontainer");
}

bool SoftwareContainerManager::supportsQuickLaunch() const
{
    return false;
}

void SoftwareContainerManager::setConfiguration(const QVariantMap &configuration)
{
    m_configuration = configuration;
}

ContainerInterface *SoftwareContainerManager::create(bool isQuickLaunch, const QVector<int> &stdioRedirections,
                                                     const QMap<QString, QString> &debugWrapperEnvironment,
                                                     const QStringList &debugWrapperCommand)
{
    if (!m_interface) {
        QString dbus = configuration().value(QStringLiteral("dbus")).toString();
        QDBusConnection conn(QStringLiteral("sc-bus"));

        if (dbus.isEmpty())
            dbus = QStringLiteral("system");

        if (dbus == QLatin1String("system"))
             conn = QDBusConnection::systemBus();
        else if (dbus == QLatin1String("session"))
            conn = QDBusConnection::sessionBus();
        else
            conn = QDBusConnection::connectToBus(dbus, QStringLiteral("sc-bus"));

        if (!conn.isConnected()) {
            qWarning() << "The" << dbus << "D-Bus is not available to connect to the SoftwareContainer agent.";
            return nullptr;
        }
        m_interface = new QDBusInterface(QStringLiteral("com.pelagicore.SoftwareContainerAgent"),
                                         QStringLiteral("/com/pelagicore/SoftwareContainerAgent"),
                                         QStringLiteral("com.pelagicore.SoftwareContainerAgent"),
                                         conn, this);
        if (m_interface->lastError().isValid()) {
            qWarning() << "Could not connect to com.pelagicore.SoftwareContainerAgent, "
                          "/com/pelagicore/SoftwareContainerAgent on the" << dbus << "D-Bus";
            delete m_interface;
            m_interface = nullptr;
            return nullptr;
        }

        if (!connect(m_interface, SIGNAL(ProcessStateChanged(int,uint,bool,uint)), this, SLOT(processStateChanged(int,uint,bool,uint)))) {
            qWarning() << "Could not connect to the com.pelagicore.SoftwareContainerAgent.ProcessStateChanged "
                          "signal on the" << dbus << "D-Bus";
            delete m_interface;
            m_interface = nullptr;
            return nullptr;
        }
    }

    QString config = QStringLiteral("[]");
    QVariant v = configuration().value(QStringLiteral("createConfig"));
    if (v.isValid())
        config = QString::fromUtf8(QJsonDocument::fromVariant(v).toJson(QJsonDocument::Compact));

    QDBusMessage reply = m_interface->call(QDBus::Block, QStringLiteral("Create"), config);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qWarning() << "SoftwareContainer failed to create a new container:" << reply.errorMessage()
                   << "(config was:" << config << ")";
        return nullptr;
    }

    int containerId = reply.arguments().at(0).toInt();

    if (containerId < 0) {
        qCritical() << "SoftwareContainer failed to create a new container. (config was:" << config << ")";
        return nullptr;
    }

    // calculate where to dump stdout/stderr
    int outputFd = stdioRedirections.value(STDERR_FILENO, -1);
    if (outputFd < 0)
        outputFd = stdioRedirections.value(STDOUT_FILENO, -1);
    if ((::fcntl(outputFd, F_GETFD) < 0) && (errno == EBADF))
        outputFd = STDOUT_FILENO;

    SoftwareContainer *container = new SoftwareContainer(this, isQuickLaunch, containerId,
                                                         outputFd, debugWrapperEnvironment,
                                                         debugWrapperCommand);
    m_containers.insert(containerId, container);
    connect(container, &QObject::destroyed, this, [this, containerId]() { m_containers.remove(containerId); });
    return container;
}

QDBusInterface *SoftwareContainerManager::interface() const
{
    return m_interface;
}

QVariantMap SoftwareContainerManager::configuration() const
{
    return m_configuration;
}

void SoftwareContainerManager::processStateChanged(int containerId, uint processId, bool isRunning, uint exitCode)
{
    Q_UNUSED(processId)

    SoftwareContainer *container = m_containers.value(containerId);
    if (!container) {
        qWarning() << "Received a processStateChanged signal for unknown container" << containerId;
        return;
    }

    if (!isRunning)
        container->containerExited(exitCode);
}



SoftwareContainer::SoftwareContainer(SoftwareContainerManager *manager, bool isQuickLaunch, int containerId,
                                     int outputFd, const QMap<QString, QString> &debugWrapperEnvironment,
                                     const QStringList &debugWrapperCommand)
    : m_manager(manager)
    , m_isQuickLaunch(isQuickLaunch)
    , m_id(containerId)
    , m_outputFd(outputFd)
    , m_debugWrapperEnvironment(debugWrapperEnvironment)
    , m_debugWrapperCommand(debugWrapperCommand)
{ }

SoftwareContainer::~SoftwareContainer()
{
    if (m_fifoFd >= 0)
        QT_CLOSE(m_fifoFd);
    if (!m_fifoPath.isEmpty())
        ::unlink(m_fifoPath);
    if (m_outputFd > STDERR_FILENO)
        QT_CLOSE(m_outputFd);
}

SoftwareContainerManager *SoftwareContainer::manager() const
{
    return m_manager;
}

bool SoftwareContainer::attachApplication(const QVariantMap &application)
{

    // In normal launch attachApplication is called first, then the start()
    // method is called. During quicklaunch start() is called first and then
    // attachApplication. In this case we need to configure the container
    // with any extra capabilities etc.

    m_state = StartingUp;
    m_application = application;

    m_hostPath = application.value(QStringLiteral("codeDir")).toString();
    if (m_hostPath.isEmpty())
        m_hostPath = QDir::currentPath();

    m_appRelativeCodePath = application.value(QStringLiteral("codeFilePath")).toString();
    m_containerPath = QStringLiteral("/app");

    // If this is a quick launch instance, we need to renew the capabilities
    // and send the bindmounts.
    if (m_isQuickLaunch) {
        if (!sendCapabilities())
            return false;

        if (!sendBindMounts())
            return false;
    }

    m_ready = true;
    emit ready();
    return true;
}

QString SoftwareContainer::controlGroup() const
{
    return QString();
}

bool SoftwareContainer::setControlGroup(const QString &groupName)
{
    Q_UNUSED(groupName)
    return false;
}

bool SoftwareContainer::setProgram(const QString &program)
{
    m_program = program;
    return true;
}

void SoftwareContainer::setBaseDirectory(const QString &baseDirectory)
{
    m_baseDir = baseDirectory;
}

bool SoftwareContainer::isReady() const
{
    return m_ready;
}

QString SoftwareContainer::mapContainerPathToHost(const QString &containerPath) const
{
    return containerPath;
}

QString SoftwareContainer::mapHostPathToContainer(const QString &hostPath) const
{
    QString containerPath = m_containerPath;

    QFileInfo fileInfo(hostPath);
    if (fileInfo.isFile())
        containerPath = m_containerPath + QStringLiteral("/") + fileInfo.fileName();

    return containerPath;
}

bool SoftwareContainer::sendCapabilities()
{
    auto iface = manager()->interface();
    if (!iface)
        return false;

    // this is the one and only capability in io.qt.ApplicationManager.Application.json
    static const QStringList capabilities { QStringLiteral("io.qt.ApplicationManager.Application") };

    QDBusMessage reply = iface->call(QDBus::Block, QStringLiteral("SetCapabilities"), m_id, QVariant::fromValue(capabilities));
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qWarning() << "SoftwareContainer failed to set capabilities to" << capabilities << ":" << reply.errorMessage();
        return false;
    }
    return true;
}

bool SoftwareContainer::sendBindMounts()
{
    auto iface = manager()->interface();
    if (!iface)
        return false;

    QFileInfo fontCacheInfo(QStringLiteral("/var/cache/fontconfig"));

    QVector<std::tuple<QString, QString, bool>> bindMounts; // bool == isReadOnly
    // the private P2P D-Bus
    bindMounts.append(std::make_tuple(m_dbusP2PInfo.absoluteFilePath(), m_dbusP2PInfo.absoluteFilePath(), false));

    // we need to share the fontconfig cache - otherwise the container startup might take a long time
    bindMounts.append(std::make_tuple(fontCacheInfo.absoluteFilePath(), fontCacheInfo.absoluteFilePath(), false));

    // Qt's plugin path
    bindMounts.append(std::make_tuple(m_qtPluginPathInfo.absoluteFilePath(), m_qtPluginPathInfo.absoluteFilePath(), false));

    // the actual path to the application
    bindMounts.append(std::make_tuple(m_hostPath, m_containerPath, true));

    // for development only - mount the user's $HOME dir into the container as read-only. Otherwise
    // you would have to `make install` the AM into /usr on every rebuild
    if (manager()->configuration().value(QStringLiteral("bindMountHome")).toBool())
        bindMounts.append(std::make_tuple(QDir::homePath(), QDir::homePath(), true));

    // do all the bind-mounts in parallel to waste as little time as possible
    QList<QDBusPendingReply<>> bindMountResults;

    for (auto it = bindMounts.cbegin(); it != bindMounts.cend(); ++it)
        bindMountResults << iface->asyncCall(QStringLiteral("BindMount"), m_id, std::get<0>(*it),
                                             std::get<1>(*it), std::get<2>(*it));

    for (const auto &pending : qAsConst(bindMountResults))
        QDBusPendingCallWatcher(pending).waitForFinished();

    for (int i = 0; i < bindMounts.size(); ++i) {
        if (bindMountResults.at(i).isError()) {
            qWarning() << "SoftwareContainer failed to bind-mount the directory" << std::get<0>(bindMounts.at(i))
                       << "into the container at" << std::get<1>(bindMounts.at(i)) << ":" << bindMountResults.at(i).error().message();
            return false;
        }
    }

    return true;

}

bool SoftwareContainer::start(const QStringList &arguments, const QMap<QString, QString> &runtimeEnvironment,
                              const QVariantMap &amConfig)
{
    auto iface = manager()->interface();
    if (!iface)
        return false;

    if (!QFile::exists(m_program))
        return false;

    // Send initial capabilities even if this is a quick-launch instance
    if (!sendCapabilities())
        return false;

    // parse out the actual socket file name from the DBus specification
    QString dbusP2PSocket = amConfig.value(QStringLiteral("dbus")).toMap().value(QStringLiteral("p2p")).toString();
    dbusP2PSocket = dbusP2PSocket.mid(dbusP2PSocket.indexOf(QLatin1Char('=')) + 1);
    dbusP2PSocket = dbusP2PSocket.left(dbusP2PSocket.indexOf(QLatin1Char(',')));
    QFileInfo dbusP2PInfo(dbusP2PSocket);
    m_dbusP2PInfo = dbusP2PInfo;

    // for bind-mounting the plugin-path later on
    QString qtPluginPath = runtimeEnvironment.value(QStringLiteral("QT_PLUGIN_PATH"));
    m_qtPluginPathInfo = QFileInfo(qtPluginPath);

    // Only send the bindmounts if this is not a quick-launch instance.
    if (!m_isQuickLaunch && !sendBindMounts())
        return false;

    // create an unique fifo name in /tmp
    m_fifoPath = QDir::tempPath().toLocal8Bit() + "/sc-" + QUuid::createUuid().toByteArray().mid(1,36) + ".fifo";
    if (mkfifo(m_fifoPath, 0600) != 0) {
        qWarning() << "Failed to create FIFO at" << m_fifoPath << "to redirect stdout/stderr out of the container:" << strerror(errno);
        m_fifoPath.clear();
        return false;
    }

    // open fifo for reading
    // due to QTBUG-15261 (bytesAvailable() on a fifo always returns 0) we use a raw fd
    m_fifoFd = QT_OPEN(m_fifoPath, O_RDONLY | O_NONBLOCK);
    if (m_fifoFd < 0) {
        qWarning() << "Failed to open FIFO at" << m_fifoPath << "for reading:" << strerror(errno);
        return false;
    }

    // read from fifo and dump to message handler
    QSocketNotifier *sn = new QSocketNotifier(m_fifoFd, QSocketNotifier::Read, this);
    int outputFd = m_outputFd;
    connect(sn, &QSocketNotifier::activated, this, [sn, outputFd](int fifoFd) {
        int bytesAvailable = 0;
        if (ioctl(fifoFd, FIONREAD, &bytesAvailable) == 0) {
            static const int bufferSize = 4096;
            static QByteArray buffer(bufferSize, 0);

            while (bytesAvailable > 0) {
                auto bytesRead = QT_READ(fifoFd, buffer.data(), std::min(bytesAvailable, bufferSize));
                if (bytesRead < 0) {
                    if (errno == EINTR || errno == EAGAIN)
                        continue;
                    sn->setEnabled(false);
                    return;
                } else if (bytesRead > 0) {
                    (void) QT_WRITE(outputFd, buffer.constData(), bytesRead);
                    bytesAvailable -= bytesRead;
                }
            }
        }
    });

    // Calculate the exact command to run
    QStringList command;
    if (!m_debugWrapperCommand.isEmpty()) {
        command = substituteCommand(m_debugWrapperCommand, m_program, arguments);
    } else {
        command = arguments;
        command.prepend(m_program);
    }

    // SC expects a plain string instead of individual args
    QString cmdLine;
    for (const auto &part : qAsConst(command)) {
        if (!cmdLine.isEmpty())
            cmdLine.append(QLatin1Char(' '));
        cmdLine.append(QLatin1Char('\"'));
        cmdLine.append(part);
        cmdLine.append(QLatin1Char('\"'));
    }
    //cmdLine.prepend(QStringLiteral("/usr/bin/strace ")); // useful if things go wrong...

    // we start with a copy of the AM's environment, but some variables would overwrite important
    // redirections set by SC gateways.
    static const QStringList forbiddenVars = {
        QStringLiteral("XDG_RUNTIME_DIR"),
        QStringLiteral("DBUS_SESSION_BUS_ADDRESS"),
        QStringLiteral("DBUS_SYSTEM_BUS_ADDRESS"),
        QStringLiteral("PULSE_SERVER")
    };

    // since we have to translate between a QProcessEnvironment and a QMap<>, we cache the result
    static QMap<QString, QString> baseEnvVars;
    if (baseEnvVars.isEmpty()) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        const auto keys = env.keys();
        for (const auto &key : keys) {
            if (!key.isEmpty() && !forbiddenVars.contains(key))
                baseEnvVars.insert(key, env.value(key));
        }
    }

    QMap<QString, QString> envVars = baseEnvVars;

    // set the env. variables coming from the runtime
    for (auto it = runtimeEnvironment.cbegin(); it != runtimeEnvironment.cend(); ++it) {
        if (it.value().isEmpty())
            envVars.remove(it.key());
        else
            envVars.insert(it.key(), it.value());
    }
    // set the env. variables coming from a debug wrapper
    for (auto it = m_debugWrapperEnvironment.cbegin(); it != m_debugWrapperEnvironment.cend(); ++it) {
        if (it.value().isEmpty())
            envVars.remove(it.key());
        else
            envVars.insert(it.key(), it.value());
    }

    QVariant venvVars = QVariant::fromValue(envVars);

    qDebug () << "SoftwareContainer is trying to launch application" << m_id
              << "\n * command ..." << cmdLine
              << "\n * directory ." << m_containerPath
              << "\n * output ...." << m_fifoPath
              << "\n * environment" << envVars;

#if 0
    qWarning() << "Attach to container now!";
    qWarning().nospace() << "  sudo lxc-attach -n SC-" << m_id;
    sleep(10000000);
#endif

    auto reply = iface->call(QDBus::Block, QStringLiteral("Execute"), m_id, cmdLine,
                             m_containerPath, QString::fromLocal8Bit(m_fifoPath), venvVars);
    if (reply.type() == QDBusMessage::ErrorMessage) {
        qWarning() << "SoftwareContainer failed to execute application" << m_id << "in directory"
                   << m_containerPath << "in the container:" << reply.errorMessage();
        return false;
    }

    m_pid = reply.arguments().at(0).value<int>();

    m_state = Running;
    QMetaObject::invokeMethod(this, [this]() {
        emit stateChanged(m_state);
        emit started();
    }, Qt::QueuedConnection);
    return true;
}

qint64 SoftwareContainer::processId() const
{
    return m_pid;
}

SoftwareContainer::RunState SoftwareContainer::state() const
{
    return m_state;
}

void SoftwareContainer::kill()
{
    auto iface = manager()->interface();

    if (iface) {
        QDBusMessage reply = iface->call(QDBus::Block, QStringLiteral("Destroy"), m_id);
        if (reply.type() == QDBusMessage::ErrorMessage) {
            qWarning() << "SoftwareContainer failed to destroy container" << reply.errorMessage();
        }

        if (!reply.arguments().at(0).toBool()) {
            qWarning() << "SoftwareContainer failed to destroy container.";
        }
    }
}

void SoftwareContainer::terminate()
{
    //TODO: handle graceful shutdown
    kill();
}

void SoftwareContainer::containerExited(uint exitCode)
{
    m_state = NotRunning;
    emit stateChanged(m_state);
    emit finished(WEXITSTATUS(exitCode), WIFEXITED(exitCode) ? NormalExit : CrashExit);
    deleteLater();
}

#include "moc_softwarecontainer.cpp"