Merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/show-apparmor-denials into lp:qtcreator-plugin-ubuntu

Proposed by Benjamin Zeller
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 392
Merged at revision: 398
Proposed branch: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/show-apparmor-denials
Merge into: lp:qtcreator-plugin-ubuntu
Prerequisite: lp:~zeller-benjamin/qtcreator-plugin-ubuntu/fixdevicedetection
Diff against target: 217 lines (+107/-23)
2 files modified
share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py (+80/-19)
src/ubuntu/ubunturemoterunner.cpp (+27/-4)
To merge this branch: bzr merge lp:~zeller-benjamin/qtcreator-plugin-ubuntu/show-apparmor-denials
Reviewer Review Type Date Requested Status
Zoltan Balogh Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+260726@code.launchpad.net

Commit message

Fix Bug lp:1362028 "SDK not able to provide further hint about missing apparmor policy"

Description of the change

Fix Bug lp:1362028 "SDK not able to provide further hint about missing apparmor policy"

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 :

OK

Revision history for this message
Zoltan Balogh (bzoltan) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py'
--- share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py 2014-12-03 10:21:22 +0000
+++ share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py 2015-06-01 14:33:22 +0000
@@ -47,6 +47,20 @@
47#make glib the default dbus event loop47#make glib the default dbus event loop
48dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)48dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
4949
50#--------------------------- globals ------------------------------
51
52#buffer for the syslog output, always contains the last or parts of the last line
53syslogBuffer=""
54hook_name = None
55package_name = None
56package_version = None
57package_arch = None
58manifest = None
59app_id = None
60tmp_dir = "/tmp/"
61apparmor_path = None
62skip_apparmor_denials = 3
63
50# Runner to handle scopes64# Runner to handle scopes
51class ScopeRunner(dbus.service.Object):65class ScopeRunner(dbus.service.Object):
52 def __init__(self,appid,loop):66 def __init__(self,appid,loop):
@@ -167,6 +181,18 @@
167 print("Sdk-Launcher> Received exit signal, stopping application",flush=True)181 print("Sdk-Launcher> Received exit signal, stopping application",flush=True)
168 runner.stop()182 runner.stop()
169183
184def prepareFileHandle(handle, callback):
185 # make handle non-blocking:
186 fl = fcntl.fcntl(handle, fcntl.F_GETFL)
187 fcntl.fcntl(handle, fcntl.F_SETFL, fl | os.O_NONBLOCK)
188
189 if GObject.pygobject_version < (3,7,2):
190 GObject.io_add_watch(handle,GObject.IO_IN | GObject.IO_HUP,callback)
191 else:
192 GLib.io_add_watch(handle,GLib.PRIORITY_DEFAULT,GObject.IO_IN | GObject.IO_HUP,callback)
193
194 return handle
195
170def create_procpipe(path,callback):196def create_procpipe(path,callback):
171 if(os.path.exists(path)):197 if(os.path.exists(path)):
172 os.unlink(path)198 os.unlink(path)
@@ -174,16 +200,7 @@
174 os.mkfifo(path)200 os.mkfifo(path)
175 pipe = os.open(path,os.O_RDONLY | os.O_NONBLOCK)201 pipe = os.open(path,os.O_RDONLY | os.O_NONBLOCK)
176202
177 # make pipe non-blocking:203 return prepareFileHandle(pipe, callback)
178 fl = fcntl.fcntl(pipe, fcntl.F_GETFL)
179 fcntl.fcntl(pipe, fcntl.F_SETFL, fl | os.O_NONBLOCK)
180
181 if GObject.pygobject_version < (3,7,2):
182 GObject.io_add_watch(pipe,GObject.IO_IN | GObject.IO_HUP,callback)
183 else:
184 GLib.io_add_watch(pipe,GLib.PRIORITY_DEFAULT,GObject.IO_IN | GObject.IO_HUP,callback)
185
186 return pipe
187204
188def readPipe(pipe):205def readPipe(pipe):
189 output=""206 output=""
@@ -211,6 +228,53 @@
211 print (output ,file=sys.stderr,end="",flush=True)228 print (output ,file=sys.stderr,end="",flush=True)
212 return True229 return True
213230
231def create_filelistener(path, callback):
232 if(not os.path.exists(path)):
233 return None
234
235 handle = os.open(path,os.O_RDONLY | os.O_NONBLOCK)
236 os.lseek(handle,0,os.SEEK_END)
237
238 return prepareFileHandle(handle, callback)
239
240def filter_syslog_line(line):
241 global skip_apparmor_denials
242
243 if app_id in line:
244 if skip_apparmor_denials > 0:
245 skip_apparmor_denials-=1
246 return
247 sys.stderr.write("Sdk-Launcher> There has been a AppArmor denial for your application.\n")
248 sys.stderr.write("Sdk-Launcher> Most likely it is missing a policy in the AppArmor file.\n")
249
250 # do not change this line, it is interpreted by QtCreator
251 sys.stderr.write("Syslog> "+line)
252
253def on_syslog_update(fd, condition):
254 global syslogBuffer
255
256 while True:
257 chunk = os.read(fd,256).decode();
258 if (len(chunk) == 0):
259 break
260
261 syslogBuffer += chunk
262
263 if len(syslogBuffer) <= 0 :
264 return True
265
266 #read the buffer and filter every complete line
267 try:
268 while(True):
269 idx = syslogBuffer.index("\n")
270 line = syslogBuffer[0:idx+1]
271 syslogBuffer = syslogBuffer[idx+1:]
272 filter_syslog_line(line)
273 except ValueError:
274 pass
275
276 return True
277
214def is_confined (manifest_obj, hook_name):278def is_confined (manifest_obj, hook_name):
215 if "apparmor" not in manifest_obj['hooks'][hook_name]:279 if "apparmor" not in manifest_obj['hooks'][hook_name]:
216 raise Exception("Error: Invalid Manifest file")280 raise Exception("Error: Invalid Manifest file")
@@ -286,15 +350,6 @@
286 conf_obj['qmlDebug'] = options.qmlDebug350 conf_obj['qmlDebug'] = options.qmlDebug
287 print("Sdk-Launcher> QML Debug Settings:"+options.qmlDebug,flush=True)351 print("Sdk-Launcher> QML Debug Settings:"+options.qmlDebug,flush=True)
288352
289hook_name = None
290package_name = None
291package_version = None
292package_arch = None
293manifest = None
294app_id = None
295tmp_dir = "/tmp/"
296apparmor_path = None
297
298#get the manifest information from the click package353#get the manifest information from the click package
299try:354try:
300 manifest_json = subprocess.check_output(["click","info",options.clickPck])355 manifest_json = subprocess.check_output(["click","info",options.clickPck])
@@ -439,6 +494,9 @@
439 stderrPipeName = tmp_dir+app_id+".stderr"494 stderrPipeName = tmp_dir+app_id+".stderr"
440 procStdErr = create_procpipe(stderrPipeName,on_proc_stderr)495 procStdErr = create_procpipe(stderrPipeName,on_proc_stderr)
441496
497 syslogFileName = "/var/log/syslog"
498 syslogHandle = create_filelistener("/var/log/syslog",on_syslog_update)
499
442 if "unix_signal_add" in dir(GLib):500 if "unix_signal_add" in dir(GLib):
443 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, on_sigterm, runner)501 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, on_sigterm, runner)
444 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, on_sigterm, runner)502 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, on_sigterm, runner)
@@ -482,6 +540,9 @@
482 os.close(procStdErr)540 os.close(procStdErr)
483 os.unlink(stderrPipeName)541 os.unlink(stderrPipeName)
484542
543if (syslogHandle):
544 os.close(syslogHandle)
545
485if (options.noUninstall):546if (options.noUninstall):
486 print("Sdk-Launcher> Skipping uninstall step (--no-uninstall)")547 print("Sdk-Launcher> Skipping uninstall step (--no-uninstall)")
487else:548else:
488549
=== modified file 'src/ubuntu/ubunturemoterunner.cpp'
--- src/ubuntu/ubunturemoterunner.cpp 2014-09-25 09:21:23 +0000
+++ src/ubuntu/ubunturemoterunner.cpp 2015-06-01 14:33:22 +0000
@@ -5,6 +5,8 @@
5#include <utils/qtcassert.h>5#include <utils/qtcassert.h>
6#include <utils/qtcprocess.h>6#include <utils/qtcprocess.h>
7#include <ssh/sshconnection.h>7#include <ssh/sshconnection.h>
8#include <projectexplorer/taskhub.h>
9#include <projectexplorer/projectexplorerconstants.h>
810
9#include <QProcess>11#include <QProcess>
10#include <QPointer>12#include <QPointer>
@@ -268,12 +270,21 @@
268 QTC_ASSERT(!d->m_proc.isNull(),return);270 QTC_ASSERT(!d->m_proc.isNull(),return);
269271
270 QByteArray output = d->m_proc->readAllStandardError();272 QByteArray output = d->m_proc->readAllStandardError();
271 if (d->m_launcherPid <= 0 || d->m_appPid <= 0) {273 d->m_launcherOutput.append( QString::fromUtf8(output) );
272 d->m_launcherOutput.append( QString::fromUtf8(output) );274
275 while(true) {
276 int idx = d->m_launcherOutput.indexOf(QStringLiteral("\n"));
277 if (idx < 0)
278 break;
279
280 QString line = d->m_launcherOutput.mid(0,idx).trimmed();
281 d->m_launcherOutput = d->m_launcherOutput.mid(idx+1);
282
283 if (debug) { qDebug()<<"Processing Line: "<<line; }
273284
274 if (d->m_launcherPid <= 0) {285 if (d->m_launcherPid <= 0) {
275 QRegularExpression exp (QStringLiteral("Launcher PID: ([0-9]+)"));286 QRegularExpression exp (QStringLiteral("Launcher PID: ([0-9]+)"));
276 QRegularExpressionMatch match = exp.match(d->m_launcherOutput);287 QRegularExpressionMatch match = exp.match(line);
277 if(match.hasMatch()) {288 if(match.hasMatch()) {
278 bool ok = false;289 bool ok = false;
279 d->m_launcherPid = match.captured(1).toInt(&ok);290 d->m_launcherPid = match.captured(1).toInt(&ok);
@@ -292,7 +303,7 @@
292303
293 if (d->m_appPid <= 0) {304 if (d->m_appPid <= 0) {
294 QRegularExpression exp (QStringLiteral("Application started: ([0-9]+)"));305 QRegularExpression exp (QStringLiteral("Application started: ([0-9]+)"));
295 QRegularExpressionMatch match = exp.match(d->m_launcherOutput);306 QRegularExpressionMatch match = exp.match(line);
296 if(match.hasMatch()) {307 if(match.hasMatch()) {
297 bool ok = false;308 bool ok = false;
298 d->m_appPid = match.captured(1).toInt(&ok);309 d->m_appPid = match.captured(1).toInt(&ok);
@@ -305,7 +316,19 @@
305 }316 }
306 }317 }
307 }318 }
319
320 if (line.startsWith(QStringLiteral("Syslog>")) && line.contains(QStringLiteral("apparmor=\"DENIED\""))) {
321 if (debug) { qDebug()<<"Found a AppArmor denial"; }
322 //remove the prompt
323 line = line.mid(7);
324
325 if (debug) { qDebug()<<"Reporting a AppArmor denial "; }
326 ProjectExplorer::TaskHub::addTask(ProjectExplorer::Task::Error,
327 tr("There has been a AppArmor denial for the application. It usually means it is missing a policy in the AppArmor file:\n%1").arg(line),
328 ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
329 }
308 }330 }
331
309 emit launcherStderr(output);332 emit launcherStderr(output);
310}333}
311334

Subscribers

People subscribed via source and target branches