2
* Copyright (C) 2014 Canonical Ltd.
4
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
6
* This file is part of online-accounts-ui
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <QCoreApplication>
25
#include <QStringList>
27
QStringList parseParameters(const QByteArray &cmdLine)
32
bool insideDoubleQuotes = false;
34
for (int i = 0; i < cmdLine.count(); i++) {
35
char c = cmdLine.at(i);
36
if (c == '\'' && !insideDoubleQuotes) {
37
int endQuote = cmdLine.indexOf('\'', i + 1);
38
if (Q_UNLIKELY(endQuote < 0)) {
39
qWarning() << "Cannot parse parameters" << cmdLine;
42
nextParam += cmdLine.mid(i + 1, endQuote - i - 1);
44
} else if (c == '"') {
45
if (insideDoubleQuotes) {
46
insideDoubleQuotes = false;
48
insideDoubleQuotes = true;
50
} else if (c == '\\') {
52
if (Q_UNLIKELY(i == cmdLine.count())) {
53
qWarning() << "Incomplete command line" << cmdLine;
56
nextParam += cmdLine.at(i);
57
} else if (c == ' ' && !insideDoubleQuotes) {
58
params.append(QString::fromUtf8(nextParam));
61
nextParam += cmdLine.at(i);
65
if (!nextParam.isEmpty()) {
66
params.append(QString::fromUtf8(nextParam));
72
int main(int argc, char **argv)
74
QCoreApplication app(argc, argv);
76
QStringList appUris = parseParameters(qgetenv("APP_URIS"));
77
if (Q_UNLIKELY(appUris.count() < 2)) {
78
qCritical() << "Missing URIs";
82
QStringList arguments;
83
arguments.append("set-env");
84
arguments.append("APP_EXEC=" ONLINE_ACCOUNTS_UI_PATH);
88
QString("IPC_SOCKET=%1").arg(appUris[0]);
89
arguments.append(socketUrl);
91
// Mir socket URL; might be invalid
92
QString mirSocket = appUris[1];
93
if (!mirSocket.startsWith("invalid")) {
95
QString("MIR_SOCKET=%1").arg(mirSocket);
96
arguments.append(mirUrl);
99
arguments.append("OAU_LOGGING_LEVEL=2");
101
QStringList newAppUrisList = appUris.mid(2);
102
QString newAppUris = QString("APP_URIS=%1").arg(newAppUrisList.join(' '));
104
arguments.append(newAppUris);
106
int ret = QProcess::execute("initctl", arguments);
108
return (ret >= 0) ? EXIT_SUCCESS : EXIT_FAILURE;