Merge lp:~juliank/apport/named-arguments into lp:~apport-hackers/apport/trunk

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 3224
Proposed branch: lp:~juliank/apport/named-arguments
Merge into: lp:~apport-hackers/apport/trunk
Diff against target: 164 lines (+57/-19)
4 files modified
NEWS (+2/-0)
data/apport (+48/-17)
etc/init.d/apport (+6/-1)
use-local (+1/-1)
To merge this branch: bzr merge lp:~juliank/apport/named-arguments
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+337590@code.launchpad.net

Description of the change

New command line parsing for bug 1732962

To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) wrote :

This could be somewhat nicer after some refactoring to make it support int arguments, but I wanted to keep the diff tiny rather than doing big refactoring.

Not tested yet, BTW.

Revision history for this message
Julian Andres Klode (juliank) wrote :

Please don't merge without considering the comments in 1732962

lp:~juliank/apport/named-arguments updated
3195. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3196. By Brian Murray

apport/ui.py: Include ProblemType in reports which are updated as package hooks may expect the report to have a ProblemType. (LP: #1766794)

3197. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3198. By Brian Murray

backends/packaging-apt-dpkg.py: fix a pep8 error

3199. By Brian Murray

test/test_ui.py: modify run_crash_kernel test to account for the fact that linux-image-- is now built from the linux-signed source package on amd64 and ppc64el.

3200. By Brian Murray

release 2.20.10

3201. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3202. By Brian Murray

SECURITY UPDATE: Ensure that we propely handle crashes that originate from a PID namespace. Thanks to Sander Bos for discovering this issue.

3203. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3204. By Brian Murray

merge didier's changes to utilize a remember option which stores the send or don't send information.

3205. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3206. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

Revision history for this message
Brian Murray (brian-murray) wrote :

This looks good to me.

review: Approve
lp:~juliank/apport/named-arguments updated
3207. By Brian Murray

backends/packaging-apt-dpkg.py: install only the matching -dbg from the source package so we fall back to installing the -dbgsym package

3208. By Brian Murray

backends/packaging-apt-dpkg.py: switch to using python3-launchpadlib to communicate with Launchpad.

3209. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3210. By Brian Murray

backends/packaging-apt-dpkg.py: The Contents file can contain files with spaces in the name, e.g. liblcms2-dev package in bionic, so use the part after the last space as the package.

3211. By Brian Murray

merge my branch to use a glocal mapping of files to packages

3212. By Brian Murray

assign variables default values

3213. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3214. By Brian Murray

merge my change to failover to using -dbgsym packages if the versioned -dbg packages are not available.

3215. By Brian Murray

data/iwlwifi_error_dump: resolve W605 re invalid escape sequence

3216. By Brian Murray

test/run: Ignore PEP8 W503, W504 warnings

3217. By Brian Murray

apport/ui.py: guard against report.get_timestamp() returning None

3218. By Brian Murray

backends/packaging-apt-dpkg.py: switch back to installing all -dbg from the source package as not doing so causes a failure to find the -dbg package for libkrb5-3

3219. By Brian Murray

merge Launchpad automatic translations updates

3220. By Brian Murray

merge didier's branch handling older reports w/o a remember option

3221. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3222. By Brian Murray

Merge slangasek's changes to accomodate new exit codes from gdb 8.2.50.

3223. By Launchpad Translations on behalf of apport-hackers

Launchpad automatic translations update.

3224. By Julian Andres Klode

data/apport: Refactor argument parsing into function

3225. By Julian Andres Klode

Introduce support for non-positional arguments

This makes it much easier to support new kernel features. For
compatibility with old containers, we need to have the global
PID as the 5th argument: The forwarding code parses that argument
and passes the rest of the arguments to the host via a socket.

It also checks that there are precisely 6 arguments, though, so we
cannot directly use the new arguments, but need to hack around
a bit to fit them into that space, by introducing --more.

(LP: #1732962)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2019-02-15 14:42:39 +0000
3+++ NEWS 2019-03-04 16:41:51 +0000
4@@ -17,6 +17,8 @@
5 option. If the option isn't there, consider as false. (LP: #1791324)
6 * apport/report.py: End our gdb batch script with a separator, to accomodate
7 new exit codes from gdb 8.2.50. Thanks Steve Langasek!
8+ * data/apport: Introduce support for non-positional arguments so we
9+ can easily extend core_pattern in the future (LP: #1732962)
10
11 2.20.10 (2018-05-09)
12 --------------------
13
14=== modified file 'data/apport'
15--- data/apport 2018-05-30 20:49:07 +0000
16+++ data/apport 2019-03-04 16:41:51 +0000
17@@ -15,7 +15,7 @@
18
19 import sys, os, os.path, subprocess, time, traceback, pwd, io
20 import signal, inspect, grp, fcntl, socket, atexit, array, struct
21-import errno
22+import errno, argparse
23
24 import apport, apport.fileutils
25
26@@ -325,6 +325,42 @@
27 return False
28
29
30+def parse_arguments():
31+ parser = argparse.ArgumentParser(epilog="""
32+ Alternatively, the following command line is understood for legacy hosts:
33+ <pid> <signal number> <core file ulimit> <dump mode> [global pid]
34+ """)
35+
36+ # TODO: Use type=int
37+ parser.add_argument("-p", "--pid", help="process id (%%p)")
38+ parser.add_argument("-s", "--signal-number", help="signal number (%%s)")
39+ parser.add_argument("-c", "--core-ulimit", help="core ulimit (%%c)")
40+ parser.add_argument("-d", "--dump-mode", help="dump mode (%%d)")
41+ parser.add_argument("-P", "--global-pid", nargs='?', help="pid in root namespace (%%P)")
42+
43+ options, rest = parser.parse_known_args()
44+
45+ if options.pid is not None:
46+ for arg in rest:
47+ error_log("Unknown argument: %s", arg)
48+
49+ elif len(rest) in (4,5):
50+ # Translate legacy command line
51+ options.pid = rest[0]
52+ options.signal_number = rest[1]
53+ options.core_ulimit = rest[2]
54+ options.dump_mode = rest[3]
55+ try:
56+ options.global_pid = rest[4]
57+ except IndexError:
58+ options.global_pid = None
59+ else:
60+ parser.print_usage()
61+ sys.exit(1)
62+
63+ return options
64+
65+
66 #################################################################
67 #
68 # main
69@@ -373,16 +409,8 @@
70 error_log('Received a bad number of arguments from forwarder, received %d, expected 5, aborting.' % len(sys.argv))
71 sys.exit(1)
72
73-# Normal startup
74-if len(sys.argv) not in (5, 6):
75- try:
76- print('Usage: %s <pid> <signal number> <core file ulimit> <dump mode> [global pid]' % sys.argv[0])
77- print('The core dump is read from stdin.')
78- except IOError:
79- # sys.stderr might not actually exist, expecially not when being called
80- # from the kernel
81- pass
82- sys.exit(1)
83+
84+options = parse_arguments()
85
86 init_error_log()
87
88@@ -390,8 +418,8 @@
89 # then compare it with the local PID. If they don't match, it's an
90 # indication that the crash originated from another PID namespace.
91 # Simply log an entry in the host error log and exit 0.
92-if len(sys.argv) == 6:
93- host_pid = int(sys.argv[5])
94+if options.global_pid is not None:
95+ host_pid = int(options.global_pid)
96
97 if not is_same_ns(host_pid, "pid") and not is_same_ns(host_pid, "mnt"):
98 # If the crash came from a container, don't attempt to handle
99@@ -401,7 +429,7 @@
100 # forward the process information there.
101 if not os.path.exists('/proc/%d/root/run/apport.socket' % host_pid):
102 error_log('host pid %s crashed in a container without apport support' %
103- sys.argv[5])
104+ options.global_pid)
105 sys.exit(0)
106
107 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
108@@ -409,7 +437,7 @@
109 sock.connect('/proc/%d/root/run/apport.socket' % host_pid)
110 except Exception as e:
111 error_log('host pid %s crashed in a container with a broken apport' %
112- sys.argv[5])
113+ options.global_pid)
114 sys.exit(0)
115
116 # Send all arguments except for the first (exec path) and last (global pid)
117@@ -440,14 +468,17 @@
118 # sandbox will use container namespaces as a security measure but are
119 # still otherwise host processes. When that's the case, we need to keep
120 # handling those crashes locally using the global pid.
121- sys.argv[1] = str(host_pid)
122+ options.pid = str(host_pid)
123
124 check_lock()
125
126 try:
127 setup_signals()
128
129- (pid, signum, core_ulimit, dump_mode) = sys.argv[1:5]
130+ pid = options.pid
131+ signum = options.signal_number
132+ core_ulimit = options.core_ulimit
133+ dump_mode = options.dump_mode
134
135 get_pid_info(pid)
136
137
138=== modified file 'etc/init.d/apport'
139--- etc/init.d/apport 2017-11-15 20:07:23 +0000
140+++ etc/init.d/apport 2019-03-04 16:41:51 +0000
141@@ -50,7 +50,12 @@
142 rm -f /var/lib/pm-utils/resume-hang.log
143 fi
144
145- echo "|$AGENT %p %s %c %d %P" > /proc/sys/kernel/core_pattern
146+ # Old compatibility mode, switch later to second one
147+ if true; then
148+ echo "|$AGENT %p %s %c %d %P" > /proc/sys/kernel/core_pattern
149+ else
150+ echo "|$AGENT -p%p -s%s -c%c -d%d -P%P" > /proc/sys/kernel/core_pattern
151+ fi
152 echo 2 > /proc/sys/fs/suid_dumpable
153 }
154
155
156=== modified file 'use-local'
157--- use-local 2017-11-15 20:07:23 +0000
158+++ use-local 2019-03-04 16:41:51 +0000
159@@ -4,4 +4,4 @@
160 # making changes to bin/apport and want to test them without copying them to
161 # /usr/share/apport/ every time.
162
163-echo "|$(readlink -f $(dirname $0)/data/apport) %p %s %c %d %P" > /proc/sys/kernel/core_pattern
164+echo "|$(readlink -f $(dirname $0)/data/apport) -p%p -s%s -c%c -d%d -P%P" | tee /proc/sys/kernel/core_pattern

Subscribers

People subscribed via source and target branches