Merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/chroot-agent-cli into lp:qtcreator-plugin-ubuntu

Proposed by Benjamin Zeller
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 340
Merged at revision: 323
Proposed branch: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/chroot-agent-cli
Merge into: lp:qtcreator-plugin-ubuntu
Prerequisite: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/chroot-agent
Diff against target: 233 lines (+137/-7)
4 files modified
chroot-agent/chroot-agent.pro (+2/-1)
chroot-agent/chrootagent.cpp (+17/-0)
chroot-agent/chrootagent.h (+3/-0)
chroot-agent/main.cpp (+115/-6)
To merge this branch: bzr merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/chroot-agent-cli
Reviewer Review Type Date Requested Status
Zoltan Balogh Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+245853@code.launchpad.net

Commit message

Add cli interface to the chroot agent

Description of the change

Add cli interface to the chroot agent

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zoltan Balogh (bzoltan) wrote :

Brilliant

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'chroot-agent/chroot-agent.pro'
2--- chroot-agent/chroot-agent.pro 2015-01-08 13:08:17 +0000
3+++ chroot-agent/chroot-agent.pro 2015-01-08 13:08:17 +0000
4@@ -13,7 +13,7 @@
5 CONFIG -= app_bundle
6
7 QMAKE_CXXFLAGS += -Werror
8-CONFIG += c++11 dbusadaptors
9+CONFIG += c++11 dbusadaptors dbusinterfaces
10
11 TEMPLATE = app
12
13@@ -31,6 +31,7 @@
14 QMAKE_EXTRA_TARGETS+=xml_desc
15
16 DBUS_ADAPTORS += $$xml_desc.target
17+DBUS_INTERFACES += $$xml_desc.target
18
19 target.path=/bin
20 INSTALLS+=target
21
22=== modified file 'chroot-agent/chrootagent.cpp'
23--- chroot-agent/chrootagent.cpp 2015-01-08 13:08:17 +0000
24+++ chroot-agent/chrootagent.cpp 2015-01-08 13:08:17 +0000
25@@ -130,6 +130,23 @@
26 return s;
27 }
28
29+QStringList ChrootAgent::sessionInfo() const
30+{
31+ QStringList info;
32+ for(auto i = m_knownChroots.constBegin(); i != m_knownChroots.constEnd(); i++) {
33+ const Chroot &chroot = i.value();
34+ if(chroot.session.isEmpty())
35+ continue;
36+
37+ QString desc = QString(QStringLiteral("Architecture: %1, Framework: %2, Session: %3"))
38+ .arg(chroot.architecture)
39+ .arg(chroot.framework)
40+ .arg(chroot.session);
41+ info.append(desc);
42+ }
43+ return info;
44+}
45+
46 void ChrootAgent::shutdown()
47 {
48 foreach(const QString &key, m_knownChroots.keys())
49
50=== modified file 'chroot-agent/chrootagent.h'
51--- chroot-agent/chrootagent.h 2015-01-08 13:08:17 +0000
52+++ chroot-agent/chrootagent.h 2015-01-08 13:08:17 +0000
53@@ -5,6 +5,7 @@
54
55 #include <QObject>
56 #include <QStringList>
57+#include <QVariantMap>
58
59 class QFileSystemWatcher;
60
61@@ -33,6 +34,8 @@
62 QString spawnSession (const QString &framework, const QString &architecture);
63 bool releaseSession (const QString &framework, const QString &architecture);
64
65+ QStringList sessionInfo () const;
66+
67 Q_NOREPLY void shutdown ();
68 void hangup ();
69
70
71=== modified file 'chroot-agent/main.cpp'
72--- chroot-agent/main.cpp 2015-01-08 13:08:17 +0000
73+++ chroot-agent/main.cpp 2015-01-08 13:08:17 +0000
74@@ -8,6 +8,8 @@
75 #include <signal.h>
76 #include <unistd.h>
77 #include <pwd.h>
78+#include <stdlib.h>
79+#include <getopt.h>
80
81 #include <sys/types.h>
82 #include <sys/stat.h>
83@@ -21,6 +23,14 @@
84 #include <QStandardPaths>
85
86 #include "chrootagent.h"
87+#include "clickchrootagent_interface.h"
88+
89+int cliMode (int argc, char *argv[]);
90+int serviceMode (int argc, char *argv[]);
91+void log_message (const char *message, int logType = LOG_INFO);
92+void signal_handler(int sig);
93+void daemonize();
94+void useage ();
95
96 void syslogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
97 {
98@@ -48,7 +58,7 @@
99 if(do_abort) abort();
100 }
101
102-void log_message (const char *message, int logType = LOG_INFO)
103+void log_message (const char *message, int logType)
104 {
105 openlog ("click-chroot-agent", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
106 syslog (logType, message,0);
107@@ -107,7 +117,7 @@
108 }
109
110 if (lockf(lfp,F_TLOCK,0)<0) {
111- log_message("Can not lock lockfile");
112+ log_message("Can not lock lockfile, click-chroot-agent is probably already running.");
113 exit(2); /* can not lock, server already running */
114 }
115
116@@ -122,10 +132,100 @@
117 signal(SIGTTIN,SIG_IGN);
118 }
119
120-int main(int argc, char *argv[])
121-{
122- daemonize();
123-
124+void useage ()
125+{
126+ puts("Usage: click-chroot-agent [OPTION]");
127+ puts("-s, --stop Stops the currently running instance of the click-chroot-agent");
128+ puts("-r, --reload Recreates sessions for all exising chroots");
129+ puts("-i, --info Shows currently mounted sessions");
130+ puts("-h, --help Shows this text");
131+}
132+
133+/*!
134+ * \brief cliMode
135+ * Runs the command in CLI mode to allow a more convenient use
136+ */
137+int cliMode (int argc, char *argv[])
138+{
139+ if(argc > 2) {
140+ puts("Too many arguments.");
141+
142+ useage();
143+ return 0;
144+ }
145+
146+ QCoreApplication a(argc, argv);
147+ Q_UNUSED(a);
148+
149+ static struct option long_options[] = {
150+ {"stop", no_argument, 0, 's'},
151+ {"reload", no_argument, 0, 'r'},
152+ {"info", no_argument, 0, 'i'},
153+ {"help", no_argument, 0, 'h'},
154+ {0, 0, 0, 0}
155+ };
156+
157+ ComUbuntuSdkClickChrootAgentInterface clickAgent(QStringLiteral("com.ubuntu.sdk.ClickChrootAgent"),
158+ QStringLiteral("/com/ubuntu/sdk/ClickChrootAgent"),
159+ QDBusConnection::sessionBus());
160+ if(!clickAgent.isValid()) {
161+ puts("Could not connect to click-chroot-agent service");
162+ return 1;
163+ }
164+
165+ bool cont = true;
166+ while(cont) {
167+ int option_index = 0;
168+ int c = getopt_long (argc, argv, "srih",long_options, &option_index);
169+
170+ if (c == -1)
171+ break;
172+
173+ switch(c) {
174+ case 's': {
175+ clickAgent.shutdown();
176+ cont = false;
177+ break;
178+ }
179+ case 'r': {
180+ QDBusPendingReply<void> ret = clickAgent.hangup();
181+ if(ret.isError())
182+ puts(qPrintable(ret.error().message()));
183+ else
184+ ret.waitForFinished();
185+ cont = false;
186+ break;
187+ }
188+ case 'i': {
189+ QDBusPendingReply<QStringList> ret = clickAgent.sessionInfo();
190+ if(ret.isError()) {
191+ puts(qPrintable(ret.error().message()));
192+ } else {
193+ ret.waitForFinished();
194+ foreach(const QString &desc, ret.value()) {
195+ puts(qPrintable(desc));
196+ }
197+ }
198+ cont = false;
199+ break;
200+ }
201+ case 'h':
202+ case '?': {
203+ cont = false;
204+ useage();
205+ break;
206+ }
207+ }
208+ }
209+ return 0;
210+}
211+
212+/*!
213+ * \brief serviceMode
214+ * starts the click-chroot-agents service and returns only if its shut down
215+ */
216+int serviceMode (int argc, char *argv[])
217+{
218 qInstallMessageHandler(syslogMessageHandler);
219 QCoreApplication a(argc, argv);
220
221@@ -157,3 +257,12 @@
222
223 return a.exec();
224 }
225+
226+int main(int argc, char *argv[])
227+{
228+ if(argc > 1)
229+ return cliMode(argc,argv);
230+
231+ daemonize();
232+ return serviceMode(argc,argv);
233+}

Subscribers

People subscribed via source and target branches