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
1=== modified file 'share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py'
2--- share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py 2014-12-03 10:21:22 +0000
3+++ share/qtcreator/ubuntu/scripts/qtc_device_applaunch.py 2015-06-01 14:33:22 +0000
4@@ -47,6 +47,20 @@
5 #make glib the default dbus event loop
6 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
7
8+#--------------------------- globals ------------------------------
9+
10+#buffer for the syslog output, always contains the last or parts of the last line
11+syslogBuffer=""
12+hook_name = None
13+package_name = None
14+package_version = None
15+package_arch = None
16+manifest = None
17+app_id = None
18+tmp_dir = "/tmp/"
19+apparmor_path = None
20+skip_apparmor_denials = 3
21+
22 # Runner to handle scopes
23 class ScopeRunner(dbus.service.Object):
24 def __init__(self,appid,loop):
25@@ -167,6 +181,18 @@
26 print("Sdk-Launcher> Received exit signal, stopping application",flush=True)
27 runner.stop()
28
29+def prepareFileHandle(handle, callback):
30+ # make handle non-blocking:
31+ fl = fcntl.fcntl(handle, fcntl.F_GETFL)
32+ fcntl.fcntl(handle, fcntl.F_SETFL, fl | os.O_NONBLOCK)
33+
34+ if GObject.pygobject_version < (3,7,2):
35+ GObject.io_add_watch(handle,GObject.IO_IN | GObject.IO_HUP,callback)
36+ else:
37+ GLib.io_add_watch(handle,GLib.PRIORITY_DEFAULT,GObject.IO_IN | GObject.IO_HUP,callback)
38+
39+ return handle
40+
41 def create_procpipe(path,callback):
42 if(os.path.exists(path)):
43 os.unlink(path)
44@@ -174,16 +200,7 @@
45 os.mkfifo(path)
46 pipe = os.open(path,os.O_RDONLY | os.O_NONBLOCK)
47
48- # make pipe non-blocking:
49- fl = fcntl.fcntl(pipe, fcntl.F_GETFL)
50- fcntl.fcntl(pipe, fcntl.F_SETFL, fl | os.O_NONBLOCK)
51-
52- if GObject.pygobject_version < (3,7,2):
53- GObject.io_add_watch(pipe,GObject.IO_IN | GObject.IO_HUP,callback)
54- else:
55- GLib.io_add_watch(pipe,GLib.PRIORITY_DEFAULT,GObject.IO_IN | GObject.IO_HUP,callback)
56-
57- return pipe
58+ return prepareFileHandle(pipe, callback)
59
60 def readPipe(pipe):
61 output=""
62@@ -211,6 +228,53 @@
63 print (output ,file=sys.stderr,end="",flush=True)
64 return True
65
66+def create_filelistener(path, callback):
67+ if(not os.path.exists(path)):
68+ return None
69+
70+ handle = os.open(path,os.O_RDONLY | os.O_NONBLOCK)
71+ os.lseek(handle,0,os.SEEK_END)
72+
73+ return prepareFileHandle(handle, callback)
74+
75+def filter_syslog_line(line):
76+ global skip_apparmor_denials
77+
78+ if app_id in line:
79+ if skip_apparmor_denials > 0:
80+ skip_apparmor_denials-=1
81+ return
82+ sys.stderr.write("Sdk-Launcher> There has been a AppArmor denial for your application.\n")
83+ sys.stderr.write("Sdk-Launcher> Most likely it is missing a policy in the AppArmor file.\n")
84+
85+ # do not change this line, it is interpreted by QtCreator
86+ sys.stderr.write("Syslog> "+line)
87+
88+def on_syslog_update(fd, condition):
89+ global syslogBuffer
90+
91+ while True:
92+ chunk = os.read(fd,256).decode();
93+ if (len(chunk) == 0):
94+ break
95+
96+ syslogBuffer += chunk
97+
98+ if len(syslogBuffer) <= 0 :
99+ return True
100+
101+ #read the buffer and filter every complete line
102+ try:
103+ while(True):
104+ idx = syslogBuffer.index("\n")
105+ line = syslogBuffer[0:idx+1]
106+ syslogBuffer = syslogBuffer[idx+1:]
107+ filter_syslog_line(line)
108+ except ValueError:
109+ pass
110+
111+ return True
112+
113 def is_confined (manifest_obj, hook_name):
114 if "apparmor" not in manifest_obj['hooks'][hook_name]:
115 raise Exception("Error: Invalid Manifest file")
116@@ -286,15 +350,6 @@
117 conf_obj['qmlDebug'] = options.qmlDebug
118 print("Sdk-Launcher> QML Debug Settings:"+options.qmlDebug,flush=True)
119
120-hook_name = None
121-package_name = None
122-package_version = None
123-package_arch = None
124-manifest = None
125-app_id = None
126-tmp_dir = "/tmp/"
127-apparmor_path = None
128-
129 #get the manifest information from the click package
130 try:
131 manifest_json = subprocess.check_output(["click","info",options.clickPck])
132@@ -439,6 +494,9 @@
133 stderrPipeName = tmp_dir+app_id+".stderr"
134 procStdErr = create_procpipe(stderrPipeName,on_proc_stderr)
135
136+ syslogFileName = "/var/log/syslog"
137+ syslogHandle = create_filelistener("/var/log/syslog",on_syslog_update)
138+
139 if "unix_signal_add" in dir(GLib):
140 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, on_sigterm, runner)
141 GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, on_sigterm, runner)
142@@ -482,6 +540,9 @@
143 os.close(procStdErr)
144 os.unlink(stderrPipeName)
145
146+if (syslogHandle):
147+ os.close(syslogHandle)
148+
149 if (options.noUninstall):
150 print("Sdk-Launcher> Skipping uninstall step (--no-uninstall)")
151 else:
152
153=== modified file 'src/ubuntu/ubunturemoterunner.cpp'
154--- src/ubuntu/ubunturemoterunner.cpp 2014-09-25 09:21:23 +0000
155+++ src/ubuntu/ubunturemoterunner.cpp 2015-06-01 14:33:22 +0000
156@@ -5,6 +5,8 @@
157 #include <utils/qtcassert.h>
158 #include <utils/qtcprocess.h>
159 #include <ssh/sshconnection.h>
160+#include <projectexplorer/taskhub.h>
161+#include <projectexplorer/projectexplorerconstants.h>
162
163 #include <QProcess>
164 #include <QPointer>
165@@ -268,12 +270,21 @@
166 QTC_ASSERT(!d->m_proc.isNull(),return);
167
168 QByteArray output = d->m_proc->readAllStandardError();
169- if (d->m_launcherPid <= 0 || d->m_appPid <= 0) {
170- d->m_launcherOutput.append( QString::fromUtf8(output) );
171+ d->m_launcherOutput.append( QString::fromUtf8(output) );
172+
173+ while(true) {
174+ int idx = d->m_launcherOutput.indexOf(QStringLiteral("\n"));
175+ if (idx < 0)
176+ break;
177+
178+ QString line = d->m_launcherOutput.mid(0,idx).trimmed();
179+ d->m_launcherOutput = d->m_launcherOutput.mid(idx+1);
180+
181+ if (debug) { qDebug()<<"Processing Line: "<<line; }
182
183 if (d->m_launcherPid <= 0) {
184 QRegularExpression exp (QStringLiteral("Launcher PID: ([0-9]+)"));
185- QRegularExpressionMatch match = exp.match(d->m_launcherOutput);
186+ QRegularExpressionMatch match = exp.match(line);
187 if(match.hasMatch()) {
188 bool ok = false;
189 d->m_launcherPid = match.captured(1).toInt(&ok);
190@@ -292,7 +303,7 @@
191
192 if (d->m_appPid <= 0) {
193 QRegularExpression exp (QStringLiteral("Application started: ([0-9]+)"));
194- QRegularExpressionMatch match = exp.match(d->m_launcherOutput);
195+ QRegularExpressionMatch match = exp.match(line);
196 if(match.hasMatch()) {
197 bool ok = false;
198 d->m_appPid = match.captured(1).toInt(&ok);
199@@ -305,7 +316,19 @@
200 }
201 }
202 }
203+
204+ if (line.startsWith(QStringLiteral("Syslog>")) && line.contains(QStringLiteral("apparmor=\"DENIED\""))) {
205+ if (debug) { qDebug()<<"Found a AppArmor denial"; }
206+ //remove the prompt
207+ line = line.mid(7);
208+
209+ if (debug) { qDebug()<<"Reporting a AppArmor denial "; }
210+ ProjectExplorer::TaskHub::addTask(ProjectExplorer::Task::Error,
211+ 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),
212+ ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
213+ }
214 }
215+
216 emit launcherStderr(output);
217 }
218

Subscribers

People subscribed via source and target branches