Merge lp:~ev/whoopsie/libwhoopsie into lp:whoopsie

Proposed by Evan on 2012-05-27
Status: Merged
Merged at revision: 495
Proposed branch: lp:~ev/whoopsie/libwhoopsie
Merge into: lp:whoopsie
Diff against target: 784 lines (+267/-81) (has conflicts)
17 files modified
.bzrignore (+5/-0)
Makefile (+35/-7)
debian/compat (+1/-1)
debian/control (+24/-6)
debian/copyright (+20/-2)
debian/libwhoopsie-dev.install (+3/-0)
debian/libwhoopsie0.install (+1/-0)
debian/whoopsie.install (+3/-0)
lib/libwhoopsie.pc (+13/-0)
src/connectivity.c (+20/-3)
src/identifier.c (+44/-5)
src/identifier.h (+5/-4)
src/monitor.c (+4/-0)
src/tests/Makefile (+10/-10)
src/tests/test_identifier.c (+25/-8)
src/utils.c (+16/-1)
src/whoopsie.c (+38/-34)
Text conflict in debian/copyright
To merge this branch: bzr merge lp:~ev/whoopsie/libwhoopsie
Reviewer Review Type Date Requested Status
Metrics 2012-05-27 Pending
Canonical Foundations Team 2012-05-27 Pending
Whoopsie Daisy hackers 2012-05-27 Pending
Review via email: mp+107562@code.launchpad.net

Description of the Change

This branch factors out the identifier generation into a new library, libwhoopsie.

The motivation for this is to allow the preferences panel in gnome-control-center to have a button for showing crashes that have occurred on the system in the past. To do this it needs to construct a URL that has the system identifier used by whoopsie as a component.

The metrics database and the hardware database will also need to generate this exact same identifier (so we can query across all three data sets), and it remains to be determined whether these will use the whoopsie binary to shovel data into their respective backend services.

libwhoopsie provides the following functions:
void whoopsie_identifier_generate (char** res, GError** error);
void whoopsie_identifier_get_mac_address (char** res, GError** error);
void whoopsie_identifier_get_system_uuid (char** res, GError** error);
void whoopsie_identifier_sha512 (char* source, char* res, GError** error);
void whoopsie_hex_to_char (char* buf, const char *str, int len);

whoopsie_identifier_generate gets the system UUID, falling back to the MAC address, and SHA-512 hashes it.

Whoopsie is dynamically linked against libwhoopsie as part of this change. I also have a branch of activity-log-manager that depends on libwhoopsie and uses the whoopsie_identifier_generate function in the privileged DBus backend to construct the aforementioned URL (lp:~ev/activity-log-manager/show-previous-reports).

Questions:
- Is libwhoopsie an acceptable name, or do we want to further generalize this?
- Should we push whoopsie_identifier_get_*, whoopsie_identifier_sha512 and whoopsie_hex_to_char into a private header, to be used only for unit testing? Or is it acceptable to expose this functions as part of the public API?

I've also taken the opportunity to fix a few Lintian errors and have debhelper pass the more secure build options via dpkg-buildflags (which is does by default in dh 9). Sorry for the extra diff noise caused by this.

To post a comment you must log in.
James Hunt (jamesodhunt) wrote :

Hi Evan,

Here are my review comments:

- shouldn't lib/bson/* be in a separate package? (bug 1006500)
- might be worth adding assert() calls for all function arguments?
- src/connectivity.c:setup_network_route_monitor():
   - no g_print() if g_network_monitor_get_default() fails.
- src/utils.c:already_handled_report():
  - should check uploaded_file before using it with stat() since if
    change_file_extension() fails, *either* call to free(uploaded_file) could cause a crash.
- src/whoopsie.c:
  - process_existing_files()
    - need to check return of g_dir_open() before using 'dir' in g_dir_read_name().
    - can g_build_filename() ever return NULL?
    - use of crash_file when it is known to be NULL (mark_handled(crash_file) and g_print(..., crash_file)).
    - crash_file is freed even if change_file_extension() failed.

lp:~ev/whoopsie/libwhoopsie updated on 2012-05-31
513. By Evan on 2012-05-31

Fixes from James Hunt's review: print an error message if g_network_monitor_get_default fails.

514. By Evan on 2012-05-31

Fixes from James Hunt's review: do not deference NULL pointers

515. By Evan on 2012-05-31

Fixes from James Hunt's review: future proof against g_build_filename returning NULL.

516. By Evan on 2012-05-31

Fixes from James Hunt's review: do not try to deference and print strings we know to be NULL.

Evan (ev) wrote :

Thanks for the thorough review!

On Wed, May 30, 2012 at 9:23 PM, James Hunt <email address hidden> wrote:
> - shouldn't lib/bson/* be in a separate package? (bug 1006500)

I'll take care of this in a separate merge, but thanks a bunch for
pointing it out.

> - might be worth adding assert() calls for all function arguments?

Fixed (r517).

> - src/connectivity.c:setup_network_route_monitor():
>   - no g_print() if g_network_monitor_get_default() fails.

Fixed (r513).

> - src/utils.c:already_handled_report():
>  - should check uploaded_file before using it with stat() since if
>    change_file_extension() fails, *either* call to free(uploaded_file) could cause a crash.

Fixed (r514).

> - src/whoopsie.c:
>  - process_existing_files()
>    - need to check return of g_dir_open() before using 'dir' in g_dir_read_name().

g_dir_read_name will return NULL if it receives a NULL argument.

>    - can g_build_filename() ever return NULL?

Fixed (r515).

>    - use of crash_file when it is known to be NULL (mark_handled(crash_file) and g_print(..., crash_file)).

Fixed (r516).

>    - crash_file is freed even if change_file_extension() failed.

Fixed by r516 as well.

lp:~ev/whoopsie/libwhoopsie updated on 2012-05-31
517. By Evan on 2012-05-31

Fixes from James Hunt's review: guard against invalid arguments to functions.

Evan (ev) wrote :

Comments from Ted:
[16:00:19] <ev> I don't suppose I could have your eyes on https://code.launchpad.net/~ev/whoopsie/libwhoopsie/+merge/107562 ?
[16:01:37] <ted> Meeting right now, but I can look after.
[16:01:44] <ev> thanks!
[16:43:04] <ted> Uhm, so what are your goals :-)
[16:43:18] <ted> There's a lot of things that glib libraries do like versioned API's
[16:43:33] <ted> That are handy, but chances are libwhoopsie won't be "that big"
[16:44:07] <ted> Also, you're not using autotools, eh?
[16:44:41] <ted> Makes some things a bit tricky.
[16:46:06] <ev> I *hate* autotools
[16:46:19] <ted> Heh
[16:46:20] <ev> I don't care about esoteric hardware or operating systems
[16:46:23] <ev> I want readable code
[16:46:30] <ted> Here's my libdbustest Makefile.am
[16:46:30] <ted> http://bazaar.launchpad.net/~indicator-applet-developers/dbus-test-runner/trunk.12.10/view/head:/libdbustest/Makefile.am
[16:47:09] <ev> yeah, it looks clean, but dragons. If I change things and then it starts complaining about a missing brace.
[16:47:19] <ted> So then I end up with this at my pc file
[16:47:19] <ted> http://bazaar.launchpad.net/~indicator-applet-developers/dbus-test-runner/trunk.12.10/view/head:/libdbustest/dbustest.pc.in
[16:47:59] <ted> It's all clean, as long as you only use the right characters in the right place. What's wrong with doing things right? ;-)
[16:48:23] <ev> heh
[16:48:32] <ted> So, I don't know if you want the API versioned include directory
[16:48:46] <ted> If you do, I'd recommend moving the files to their own directory in the source tree as well.
[16:49:06] <ev> could you put that in the MP? :)
[16:49:20] <ted> Sure, but I guess my question more was: is that your goal? :-)
[16:49:21] <ev> I like having a record of these sorts of things
[16:49:39] <ev> having a versioned include directory?
[16:49:46] <ev> hmm
[16:49:57] <ev> I guess I can't imagine us ever wanting to allow parallel installation
[16:49:58] <ted> Yeah: /usr/include/libwhoopsie-1.0/libwhoopsie/myfile.h
[16:50:20] <ev> which is presumably the use case for such things
[16:50:36] <ted> Yeah, it becomes a pain for folks like me that aren't coredev
[16:50:47] <ted> We get yelled at more for making things FTBFS :-)
[16:51:13] <ev> heh
[16:52:15] <ev> what do you mean by it being a pain for non-core dev? I don't see how not having parallel installation makes things FTBFS
[16:52:58] <ted> Because you have something like, let's say libmetrics depend on API version 1. So when version 2 gets uploaded, it breaks. Until libmetrics v2 gets uploaded.
[16:54:15] <ev> ahh

Evan (ev) wrote :

Comments from Colin and Steve:
[16:03:35] <slangasek> ev: why use c99 instead of $(CC)?
[16:03:58] <ev> slangasek: $(CC) with the c99 option?
[16:04:04] <slangasek> if you need to
[16:04:06] <cjwatson> Yeah, you should always use $(CC) for x-compiling support
[16:04:07] <ev> I do
[16:04:19] <slangasek> then yeah, especially now that there's a lib, $(CC) would be a good idea
[16:04:20] <ev> need to use c99 features, that is
[16:04:26] <cjwatson> (not that whoopsie wouldn't need more work for that)
[16:04:44] <slangasek> do you actually have to invoke gcc with -std=c99 to make use of c99 features?
[16:04:46] <cjwatson> no multiarch support?
[16:05:01] <slangasek> I thought you only have to do that to *disallow* code that's *not* c99-compliant
[16:05:02] <ev> ah yes - I hadn't considered that. I was more thinking to hell with people trying to run it under clang
[16:05:14] <cjwatson> we don't care about that for the rest of the distro ;-)
[16:05:19] <slangasek> right :)
[16:05:42] <ev> slangasek: if I run it without, it cries about variables defined in loop constructs
[16:05:43] <ev> if memory serves
[16:06:10] <slangasek> anyway, I'll try to send some more feedback on that merge request... would be good if others could as well
[16:06:15] <ev> thanks!
[16:06:18] <slangasek> it's just the addition of a shared library in C, it won't bite ;)
[16:06:21] <slangasek> anything else?
[16:06:53] <cjwatson> if you haven't already, you should nm -D the shared library to make sure only the symbols you absolutely need are exported
[16:07:21] <cjwatson> and in answer to your earlier question, you should link whoopsie dynamically against libwhoopsie rather than (effectively) shipping two copies
[16:07:53] <ev> cjwatson: ahhh, noted, thanks! dynamically link> thanks bunches for clarifying that. I couldn't find a good answer elsewhere.
[16:08:09] <cjwatson> there's basically hardly ever a good reason to link statically

lp:~ev/whoopsie/libwhoopsie updated on 2012-06-18
518. By Evan on 2012-06-18

Use $(CC) -std=c99 instead of c99.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-05-15 14:24:43 +0000
3+++ .bzrignore 2012-06-18 08:24:18 +0000
4@@ -1,6 +1,11 @@
5 src/whoopsie
6+src/libwhoopsie.so*
7+debian/tmp
8 debian/whoopsie
9+debian/libwhoopsie0
10+debian/libwhoopsie-dev
11 debian/*.debhelper*
12+debian/*.substvars
13 debian/files
14 debian/whoopsie.substvars
15 src/tests/test_parse_report
16
17=== modified file 'Makefile'
18--- Makefile 2012-05-15 14:24:43 +0000
19+++ Makefile 2012-06-18 08:24:18 +0000
20@@ -1,11 +1,23 @@
21 VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2)
22-CFLAGS=$(shell pkg-config --cflags gio-2.0 glib-2.0 libcurl) $(shell libgcrypt-config --cflags) -g -Ilib -Wall -Werror -Os -DVERSION=\"$(VERSION)\"
23-LIBS=$(shell pkg-config --libs gio-2.0 glib-2.0 libcurl) $(shell libgcrypt-config --libs) -lcap
24+
25+libwhoopsie_SOURCES=src/identifier.c
26+libwhoopsie_OBJECTS=$(libwhoopsie_SOURCES:.c=.o)
27+libwhoopsie_CFLAGS=$(shell pkg-config --cflags glib-2.0) \
28+ $(shell libgcrypt-config --cflags) \
29+ $(CFLAGS) $(CPPFLAGS)
30+libwhoopsie_LIBS=$(shell pkg-config --libs glib-2.0) \
31+ $(shell libgcrypt-config --libs) \
32+ $(LDFLAGS)
33+
34+whoopsie_CFLAGS=$(shell pkg-config --cflags gio-2.0 glib-2.0 libcurl) \
35+ -g -Ilib -Wall -Werror -Os -DVERSION=\"$(VERSION)\" \
36+ $(CFLAGS) $(CPPFLAGS)
37+whoopsie_LIBS=$(shell pkg-config --libs gio-2.0 glib-2.0 libcurl) -lcap \
38+ $(LDFLAGS)
39 SOURCES=src/whoopsie.c \
40 src/utils.c \
41 src/connectivity.c \
42 src/monitor.c \
43- src/identifier.c \
44 lib/bson/bson.c \
45 lib/bson/encoding.c \
46 lib/bson/numbers.c
47@@ -18,10 +30,18 @@
48
49 all: $(SOURCES) $(EXECUTABLE)
50
51-$(EXECUTABLE): $(OBJECTS)
52- c99 $(OBJECTS) $(LIBS) -o $@
53+$(libwhoopsie_OBJECTS): $(libwhoopsie_SOURCES)
54+ $(CC) -std=c99 -fPIC -c $(libwhoopsie_CFLAGS) -o $@ $^
55+
56+src/libwhoopsie.so.0.0: $(libwhoopsie_OBJECTS)
57+ $(CC) -std=c99 -shared -Wl,-soname,libwhoopsie.so.0 -o $@ $^ $(libwhoopsie_LIBS)
58+ ln -sf libwhoopsie.so.0.0 src/libwhoopsie.so.0
59+ ln -sf libwhoopsie.so.0.0 src/libwhoopsie.so
60+
61+$(EXECUTABLE): $(OBJECTS) src/libwhoopsie.so.0.0
62+ $(CC) -std=c99 $(OBJECTS) $(whoopsie_LIBS) -Lsrc -lwhoopsie -o $@
63 clean:
64- rm -f $(EXECUTABLE) $(OBJECTS)
65+ rm -f $(EXECUTABLE) $(OBJECTS) $(libwhoopsie_OBJECTS) src/libwhoopsie.so*
66 $(MAKE) -C src/tests clean
67 check:
68 $(MAKE) -C src/tests
69@@ -32,7 +52,7 @@
70 coverage:
71 $(MAKE) -C src/tests coverage
72 %.o: %.c
73- c99 -c $(CFLAGS) -o $@ $^
74+ $(CC) -std=c99 -c $(whoopsie_CFLAGS) -o $@ $^
75
76 install: all
77 install -d $(BIN)
78@@ -43,3 +63,11 @@
79 install -m644 data/whoopsie $(DATA)/default
80 install -d $(DESTDIR)/usr/share/apport/package-hooks
81 install -m644 data/whoopsie.py $(DESTDIR)/usr/share/apport/package-hooks
82+ install -d $(DESTDIR)/usr/lib
83+ install -m644 src/libwhoopsie.so.0.0 $(DESTDIR)/usr/lib
84+ cp -d src/libwhoopsie.so $(DESTDIR)/usr/lib
85+ cp -d src/libwhoopsie.so.0 $(DESTDIR)/usr/lib
86+ install -d $(DESTDIR)/usr/lib/pkgconfig
87+ install -m644 lib/libwhoopsie.pc $(DESTDIR)/usr/lib/pkgconfig
88+ install -d $(DESTDIR)/usr/include/libwhoopsie
89+ install -m644 src/identifier.h $(DESTDIR)/usr/include/libwhoopsie
90
91=== modified file 'debian/compat'
92--- debian/compat 2011-12-01 17:04:38 +0000
93+++ debian/compat 2012-06-18 08:24:18 +0000
94@@ -1,1 +1,1 @@
95-8
96+9
97
98=== modified file 'debian/control'
99--- debian/control 2012-05-09 23:04:30 +0000
100+++ debian/control 2012-06-18 08:24:18 +0000
101@@ -2,7 +2,7 @@
102 Section: utils
103 Priority: optional
104 Maintainer: Evan Dandrea <ev@ubuntu.com>
105-Build-Depends: debhelper (>= 8.0.0),
106+Build-Depends: debhelper (>= 9.0),
107 libglib2.0-dev (>= 2.31.6),
108 libcurl4-openssl-dev,
109 libgcrypt11-dev,
110@@ -10,15 +10,33 @@
111 libgtk-3-dev,
112 network-manager-dev (>= 0.9.4.0-0ubuntu1),
113 python,
114- pyflakes,
115- dpkg-dev
116-Standards-Version: 3.9.2
117+ pyflakes
118+Standards-Version: 3.9.3
119 Homepage: http://wiki.ubuntu.com/ErrorTracker
120 Vcs-Bzr: http://code.launchpad.net/whoopsie
121
122 Package: whoopsie
123 Architecture: any
124-Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
125+Depends: ${shlibs:Depends},
126+ ${misc:Depends},
127+ adduser,
128+ libwhoopsie0 (= ${binary:Version})
129 Pre-Depends: ${misc:Pre-Depends}
130-Description: Ubuntu crash database submission daemon
131+Description: Ubuntu error tracker submission
132 This program submits crash reports back to an Ubuntu server.
133+
134+Package: libwhoopsie0
135+Section: libs
136+Architecture: any
137+Depends: ${shlibs:Depends}, ${misc:Depends}
138+Description: Ubuntu error tracker submission - shared library
139+ This library provides methods to generate an identifier for use with the
140+ Ubuntu error tracker
141+
142+Package: libwhoopsie-dev
143+Section: libdevel
144+Architecture: any
145+Depends: libwhoopsie0 (= ${binary:Version}), ${misc:Depends}
146+Description: Ubuntu error tracker submission - library development files
147+ This library provides methods to generate an identifier for use with the
148+ Ubuntu error tracker
149
150=== modified file 'debian/copyright'
151--- debian/copyright 2012-06-14 19:52:38 +0000
152+++ debian/copyright 2012-06-18 08:24:18 +0000
153@@ -1,6 +1,6 @@
154 Format: http://dep.debian.net/deps/dep5
155-Upstream-Name: whoopsie-daisy
156-Source: http://code.launchpad.net/whoopsie-daisy
157+Upstream-Name: whoopsie
158+Source: http://code.launchpad.net/whoopsie
159
160 Files: src/*
161 Copyright: 2011-2012 Canonical Ltd.
162@@ -20,3 +20,21 @@
163 .
164 On Debian systems, the complete text of the GNU General
165 Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
166+<<<<<<< TREE
167+=======
168+
169+Files: lib/bson/*
170+Copyright: 2009, 2010 10gen Inc.
171+License: Apache-2.0
172+ Licensed under the Apache License, Version 2.0 (the "License");
173+ you may not use this file except in compliance with the License.
174+ You may obtain a copy of the License at
175+ .
176+ http://www.apache.org/licenses/LICENSE-2.0
177+ .
178+ Unless required by applicable law or agreed to in writing, software
179+ distributed under the License is distributed on an "AS IS" BASIS,
180+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181+ See the License for the specific language governing permissions and
182+ limitations under the License.
183+>>>>>>> MERGE-SOURCE
184
185=== added file 'debian/libwhoopsie-dev.install'
186--- debian/libwhoopsie-dev.install 1970-01-01 00:00:00 +0000
187+++ debian/libwhoopsie-dev.install 2012-06-18 08:24:18 +0000
188@@ -0,0 +1,3 @@
189+usr/include
190+usr/lib/pkgconfig
191+usr/lib/libwhoopsie.so
192
193=== added file 'debian/libwhoopsie0.install'
194--- debian/libwhoopsie0.install 1970-01-01 00:00:00 +0000
195+++ debian/libwhoopsie0.install 2012-06-18 08:24:18 +0000
196@@ -0,0 +1,1 @@
197+usr/lib/*.so.*
198
199=== added file 'debian/whoopsie.install'
200--- debian/whoopsie.install 1970-01-01 00:00:00 +0000
201+++ debian/whoopsie.install 2012-06-18 08:24:18 +0000
202@@ -0,0 +1,3 @@
203+etc
204+usr/bin
205+usr/share
206
207=== modified file 'debian/whoopsie.maintscript' (properties changed: +x to -x)
208=== renamed file 'debian/postinst' => 'debian/whoopsie.postinst'
209=== renamed file 'debian/postrm' => 'debian/whoopsie.postrm'
210=== added file 'lib/libwhoopsie.pc'
211--- lib/libwhoopsie.pc 1970-01-01 00:00:00 +0000
212+++ lib/libwhoopsie.pc 2012-06-18 08:24:18 +0000
213@@ -0,0 +1,13 @@
214+prefix=/usr
215+exec_prefix=${prefix}
216+libdir=${exec_prefix}/lib
217+bindir=${exec_prefix}/bin
218+includedir=${prefix}/include
219+
220+Requires: glib-2.0
221+Libs: -lwhoopsie -lgcrypt
222+
223+Name: libwhoopsie
224+Description: libwhoopsie.
225+Version: 0.0.0
226+
227
228=== modified file 'src/connectivity.c'
229--- src/connectivity.c 2012-03-30 08:59:52 +0000
230+++ src/connectivity.c 2012-06-18 08:24:18 +0000
231@@ -51,6 +51,9 @@
232 guint value = 0;
233 GError* err = NULL;
234
235+ g_return_val_if_fail (connection, FALSE);
236+ g_return_val_if_fail (path, FALSE);
237+
238 result = g_dbus_connection_call_sync (connection,
239 NETWORK_MANAGER_SERVICE,
240 path,
241@@ -86,6 +89,10 @@
242 GVariant* result = NULL;
243 GVariant* properties = NULL;
244 guint device_type;
245+
246+ g_return_val_if_fail (connection, FALSE);
247+ g_return_val_if_fail (path, FALSE);
248+
249 result = g_dbus_connection_call_sync (connection,
250 NETWORK_MANAGER_SERVICE,
251 path,
252@@ -123,6 +130,10 @@
253 GVariant* properties = NULL;
254 GVariantIter* iter = NULL;
255 gchar* device_path;
256+
257+ g_return_val_if_fail (connection, FALSE);
258+ g_return_val_if_fail (path, FALSE);
259+
260 result = g_dbus_connection_call_sync (connection,
261 NETWORK_MANAGER_SERVICE,
262 path,
263@@ -171,8 +182,8 @@
264 gboolean paid = TRUE;
265 ConnectionAvailableCallback callback = user_data;
266
267- if (!parameters)
268- return;
269+ g_return_if_fail (connection);
270+ g_return_if_fail (parameters);
271
272 g_variant_get_child (parameters, 0, "u", &connected_state);
273 if (NM_STATE_CONNECTED_GLOBAL != connected_state) {
274@@ -225,6 +236,8 @@
275 GError* err = NULL;
276 GSocketConnectable *addr = NULL;
277
278+ g_return_if_fail (nm);
279+
280 addr = g_network_address_parse_uri (connectivity_data.url, 80, &err);
281 if (!addr) {
282 g_print ("Could not parse crash database URL: %s\n", err->message);
283@@ -261,8 +274,10 @@
284 }
285
286 nm = g_network_monitor_get_default ();
287- if (!nm)
288+ if (!nm) {
289+ g_print ("Could not get the network monitor.\n");
290 return;
291+ }
292
293 route_available = (g_network_monitor_get_network_available (nm) &&
294 g_network_monitor_can_reach (nm, addr, NULL, NULL));
295@@ -281,6 +296,8 @@
296 GVariant* current_state = NULL;
297 guint value = 0;
298
299+ g_return_val_if_fail (crash_url, FALSE);
300+
301 connectivity_data.url = crash_url;
302 connectivity_data.callback = callback;
303 /* Checking whether a NetworkManager connection is not enough.
304
305=== modified file 'src/identifier.c'
306--- src/identifier.c 2012-05-15 16:45:45 +0000
307+++ src/identifier.c 2012-06-18 08:24:18 +0000
308@@ -12,11 +12,14 @@
309 #include "identifier.h"
310
311 void
312-hex_to_char (char* buf, const char *str, int len)
313+whoopsie_hex_to_char (char* buf, const char *str, int len)
314 {
315 char* p = NULL;
316 int i = 0;
317
318+ g_return_if_fail (buf);
319+ g_return_if_fail (str);
320+
321 p = buf;
322 for (i = 0; i < len; i++) {
323 snprintf(p, 3, "%02x", (unsigned char) str[i]);
324@@ -26,7 +29,7 @@
325 }
326
327 void
328-identifier_get_mac_address (char** res, GError** error)
329+whoopsie_identifier_get_mac_address (char** res, GError** error)
330 {
331 struct ifreq ifr;
332 struct ifconf ifc;
333@@ -36,6 +39,8 @@
334 struct ifreq* it;
335 int i = 0;
336
337+ g_return_if_fail (res);
338+
339 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
340 if (sock == -1) {
341 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
342@@ -79,10 +84,12 @@
343 }
344
345 void
346-identifier_get_system_uuid (char** res, GError** error)
347+whoopsie_identifier_get_system_uuid (char** res, GError** error)
348 {
349 int fp;
350
351+ g_return_if_fail (res);
352+
353 fp = open ("/sys/class/dmi/id/product_uuid", O_RDONLY);
354 if (fp < 0) {
355 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
356@@ -99,12 +106,15 @@
357 }
358
359 void
360-identifier_sha512 (char* source, char* res, GError** error)
361+whoopsie_identifier_sha512 (char* source, char* res, GError** error)
362 {
363 int md_len;
364 gcry_md_hd_t sha512 = NULL;
365 unsigned char* id = NULL;
366
367+ g_return_if_fail (source);
368+ g_return_if_fail (res);
369+
370 if (!gcry_check_version (GCRYPT_VERSION)) {
371 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
372 "libcrypt version mismatch.");
373@@ -131,6 +141,35 @@
374 gcry_md_close (sha512);
375 return;
376 }
377- hex_to_char (res, (const char*)id, md_len);
378+ whoopsie_hex_to_char (res, (const char*)id, md_len);
379 gcry_md_close (sha512);
380 }
381+
382+void
383+whoopsie_identifier_generate (char** res, GError** error)
384+{
385+ char* identifier = NULL;
386+
387+ g_return_if_fail (res);
388+
389+ whoopsie_identifier_get_system_uuid (&identifier, error);
390+ if ((!error || !(*error)) && identifier)
391+ goto out;
392+
393+ if (error && *error) {
394+ g_error_free (*error);
395+ *error = NULL;
396+ }
397+
398+ whoopsie_identifier_get_mac_address (&identifier, error);
399+ if ((!error || !(*error)) && identifier)
400+ goto out;
401+
402+ return;
403+
404+out:
405+ *res = malloc (HASHLEN + 1);
406+ whoopsie_identifier_sha512 (identifier, *res, error);
407+ free (identifier);
408+}
409+
410
411=== modified file 'src/identifier.h'
412--- src/identifier.h 2012-05-15 16:45:45 +0000
413+++ src/identifier.h 2012-06-18 08:24:18 +0000
414@@ -1,5 +1,6 @@
415-void identifier_get_mac_address (char** res, GError** error);
416-void identifier_get_system_uuid (char** res, GError** error);
417-void identifier_sha512 (char* source, char* res, GError** error);
418-void hex_to_char (char* buf, const char *str, int len);
419+void whoopsie_identifier_generate (char** res, GError** error);
420+void whoopsie_identifier_get_mac_address (char** res, GError** error);
421+void whoopsie_identifier_get_system_uuid (char** res, GError** error);
422+void whoopsie_identifier_sha512 (char* source, char* res, GError** error);
423+void whoopsie_hex_to_char (char* buf, const char *str, int len);
424 #define HASHLEN 128
425
426=== modified file 'src/monitor.c'
427--- src/monitor.c 2012-03-29 15:02:13 +0000
428+++ src/monitor.c 2012-06-18 08:24:18 +0000
429@@ -35,6 +35,8 @@
430 char* upload_file = NULL;
431 char* crash_file = NULL;
432
433+ g_return_if_fail (upload);
434+
435 crash_file = change_file_extension (upload, ".crash");
436 if (!crash_file) {
437 g_print ("Unable to parse the upload file path.\n");
438@@ -90,6 +92,8 @@
439 GError* err = NULL;
440 GFile* path = NULL;
441
442+ g_return_if_fail (directory);
443+
444 mkdir (directory, 0755);
445 path = g_file_new_for_path (directory);
446 monitor = g_file_monitor_directory (path, G_FILE_MONITOR_NONE, NULL, &err);
447
448=== modified file 'src/tests/Makefile'
449--- src/tests/Makefile 2012-05-15 14:24:43 +0000
450+++ src/tests/Makefile 2012-06-18 08:24:18 +0000
451@@ -39,22 +39,22 @@
452 $(foreach p, $^, ./$p -k;)
453
454 $(test_parse_report_EXECUTABLE): $(test_parse_report_OBJECTS)
455- c99 $^ $(LIBS) -o $@
456+ $(CC) -std=c99 $^ $(LIBS) -o $@
457 $(test_utils_EXECUTABLE): $(test_utils_OBJECTS)
458- c99 $^ $(LIBS) -o $@
459+ $(CC) -std=c99 $^ $(LIBS) -o $@
460 $(test_monitor_EXECUTABLE): $(test_monitor_OBJECTS)
461- c99 $^ $(LIBS) -o $@
462+ $(CC) -std=c99 $^ $(LIBS) -o $@
463 $(test_identifier_EXECUTABLE): $(test_identifier_OBJECTS)
464- c99 $^ $(LIBS) -o $@
465+ $(CC) -std=c99 $^ $(LIBS) -o $@
466
467 test_parse_report_coverage: $(test_parse_report_OBJECTS:.test.o=.coverage.o)
468- c99 $^ $(LIBS) -lgcov -o $@
469+ $(CC) -std=c99 $^ $(LIBS) -lgcov -o $@
470 test_utils_coverage: $(test_utils_OBJECTS:.test.o=.coverage.o)
471- c99 $^ $(LIBS) -lgcov -o $@
472+ $(CC) -std=c99 $^ $(LIBS) -lgcov -o $@
473 test_monitor_coverage: $(test_monitor_OBJECTS:.test.o=.coverage.o)
474- c99 $^ $(LIBS) -lgcov -o $@
475+ $(CC) -std=c99 $^ $(LIBS) -lgcov -o $@
476 test_identifier_coverage: $(test_identifier_OBJECTS:.test.o=.coverage.o)
477- c99 $^ $(LIBS) -lgcov -o $@
478+ $(CC) -std=c99 $^ $(LIBS) -lgcov -o $@
479 coverage: test_parse_report_coverage test_utils_coverage test_monitor_coverage test_identifier_coverage
480 $(foreach p, $^, ./$p -k;)
481 $(foreach p, $(wildcard ../*.c), gcov $p -o $(p:.c=.coverage.o);)
482@@ -78,6 +78,6 @@
483 -name '*.gcov' \) -delete
484
485 %.coverage.o: %.c
486- c99 -c -o $@ $^ $(CFLAGS) --coverage -O0
487+ $(CC) -std=c99 -c -o $@ $^ $(CFLAGS) --coverage -O0
488 %.test.o: %.c
489- c99 -c -o $@ $^ $(CFLAGS)
490+ $(CC) -std=c99 -c -o $@ $^ $(CFLAGS)
491
492=== modified file 'src/tests/test_identifier.c'
493--- src/tests/test_identifier.c 2012-05-15 16:45:45 +0000
494+++ src/tests/test_identifier.c 2012-06-18 08:24:18 +0000
495@@ -30,7 +30,7 @@
496 test_hex_to_char (void)
497 {
498 char buf[9];
499- hex_to_char (buf, "\xFF\xFF\xFF\xFF", 4);
500+ whoopsie_hex_to_char (buf, "\xFF\xFF\xFF\xFF", 4);
501 g_assert_cmpstr (buf, ==, "ffffffff");
502
503 }
504@@ -43,7 +43,7 @@
505 int fp;
506 char buf[18];
507
508- identifier_get_mac_address (&res, &error);
509+ whoopsie_identifier_get_mac_address (&res, &error);
510 g_assert (res != NULL);
511 fp = open ("/sys/class/net/eth0/address", O_RDONLY);
512 if (fp < 0) {
513@@ -70,7 +70,7 @@
514 {
515 /* DEADBEEF-1234-1234-1234-DEADBEEF1234 */
516 char* res = NULL;
517- identifier_get_system_uuid (&res, NULL);
518+ whoopsie_identifier_get_system_uuid (&res, NULL);
519 if (getuid () != 0) {
520 g_print ("Need root to run this complete test: ");
521 return;
522@@ -100,11 +100,27 @@
523 const char* expected = "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382"
524 "d624741d0dc6638326e282c41be5e4254d8820772c5518a"
525 "2c5a8c0c7f7eda19594a7eb539453e1ed7";
526- identifier_sha512 ("foo", res, NULL);
527- //if (strcmp (res, expected) != 0)
528- // g_test_fail ();
529-}
530-
531+ whoopsie_identifier_sha512 ("foo", res, NULL);
532+ if (strcmp (res, expected) != 0)
533+ g_test_fail ();
534+}
535+
536+static void
537+test_identifier_generate (void)
538+{
539+ char* result = NULL;
540+ char* expected = NULL;
541+ char hashed[HASHLEN + 1];
542+
543+ whoopsie_identifier_generate (&result, NULL);
544+ if (getuid () != 0)
545+ whoopsie_identifier_get_mac_address (&expected, NULL);
546+ else
547+ whoopsie_identifier_get_system_uuid (&expected, NULL);
548+ whoopsie_identifier_sha512 (expected, hashed, NULL);
549+ if (strcmp (result, hashed) != 0)
550+ g_test_fail ();
551+}
552 int
553 main (int argc, char** argv)
554 {
555@@ -117,6 +133,7 @@
556 g_test_add_func ("/whoopsie/hex-to-char", test_hex_to_char);
557 g_test_add_func ("/whoopsie/get-mac-address", test_get_mac_address);
558 g_test_add_func ("/whoopsie/sha512", test_sha512);
559+ g_test_add_func ("/whoopsie/identifier-generate", test_identifier_generate);
560
561 /* Do not consider warnings to be fatal. */
562 g_log_set_always_fatal (G_LOG_FATAL_MASK);
563
564=== modified file 'src/utils.c'
565--- src/utils.c 2012-03-29 21:19:59 +0000
566+++ src/utils.c 2012-06-18 08:24:18 +0000
567@@ -29,6 +29,8 @@
568 void
569 init_response_string (struct response_string* resp)
570 {
571+ g_return_if_fail (resp);
572+
573 resp->length = 0;
574 resp->p = g_malloc (1);
575 resp->p[0] = '\0';
576@@ -37,7 +39,12 @@
577 void
578 grow_response_string (struct response_string* resp, char* str, size_t length)
579 {
580- size_t new_length = resp->length + length;
581+ size_t new_length;
582+
583+ g_return_if_fail (resp);
584+ g_return_if_fail (str);
585+
586+ new_length = resp->length + length;
587 resp->p = g_realloc (resp->p, new_length + 1);
588 memcpy (resp->p + resp->length, str, length);
589 resp->p[new_length] = '\0';
590@@ -96,6 +103,8 @@
591 struct stat upload_stat;
592 struct stat crash_stat;
593
594+ g_return_val_if_fail (crash_file, FALSE);
595+
596 if (stat (crash_file, &crash_stat) < 0)
597 /* .crash doesn't exist; don't process. */
598 return TRUE;
599@@ -112,6 +121,10 @@
600 free (upload_file);
601
602 uploaded_file = change_file_extension (crash_file, ".uploaded");
603+ if (!uploaded_file)
604+ /* Bogus crash file; don't process. */
605+ return TRUE;
606+
607 if (stat (uploaded_file, &uploaded_stat) < 0) {
608 /* .uploaded doesn't exist. */
609 free (uploaded_file);
610@@ -131,6 +144,8 @@
611 char* uploaded_file = NULL;
612 int fd;
613
614+ g_return_val_if_fail (crash_file, FALSE);
615+
616 uploaded_file = change_file_extension (crash_file, ".uploaded");
617 if (!uploaded_file)
618 return FALSE;
619
620=== modified file 'src/whoopsie.c'
621--- src/whoopsie.c 2012-05-15 16:45:45 +0000
622+++ src/whoopsie.c 2012-06-18 08:24:18 +0000
623@@ -60,8 +60,10 @@
624 /* The URL of the crash database. */
625 static char* crash_db_url = NULL;
626
627-/* The system UUID, taken from the DMI tables and SHA-512 hashed */
628-static char sha512_system_uuid[HASHLEN + 1] = {0};
629+/* The database identifier. Either:
630+ * - The system UUID, taken from the DMI tables and SHA-512 hashed
631+ * - The MAC address of the first non-loopback device, SHA-512 hashed */
632+static char* whoopsie_identifier = NULL;
633
634 /* The URL for sending the initial crash report */
635 static char* crash_db_submit_url = NULL;
636@@ -141,7 +143,11 @@
637 static gboolean
638 is_acceptable_field (const char* field)
639 {
640- const char** p = acceptable_fields;
641+ const char** p;
642+
643+ g_return_val_if_fail (field, FALSE);
644+
645+ p = acceptable_fields;
646 while (*p) {
647 if (strcmp (*p, field) == 0)
648 return TRUE;
649@@ -195,6 +201,9 @@
650 void
651 split_string (char* head, char** tail)
652 {
653+ g_return_if_fail (head);
654+ g_return_if_fail (tail);
655+
656 *tail = strchr (head, ' ');
657 if (*tail) {
658 **tail = '\0';
659@@ -216,7 +225,7 @@
660 *bson_message = NULL;
661 *bson_message_len = 0;
662
663- assert (report != NULL);
664+ g_return_val_if_fail (report, FALSE);
665
666 bson_init (b);
667 if (!bson_data (b))
668@@ -246,6 +255,8 @@
669 long response_code = 0;
670 struct curl_slist* list = NULL;
671
672+ g_return_val_if_fail (message_data, -1);
673+
674 if ((curl = curl_easy_init ()) == NULL) {
675 printf ("Couldn't init curl.\n");
676 return FALSE;
677@@ -312,6 +323,8 @@
678 int value_pos;
679 gboolean ignore_field = FALSE;
680
681+ g_return_val_if_fail (report_path, NULL);
682+
683 if (g_file_test (report_path, G_FILE_TEST_IS_SYMLINK) ||
684 !g_file_test (report_path, G_FILE_TEST_IS_REGULAR)) {
685 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
686@@ -479,8 +492,13 @@
687 char* crash_db_core_url = NULL;
688 struct response_string s;
689
690+
691+ g_return_val_if_fail (uuid, FALSE);
692+ g_return_val_if_fail (arch, FALSE);
693+ g_return_val_if_fail (core_data, FALSE);
694+
695 if (asprintf (&crash_db_core_url, "%s/%s/submit-core/%s/%s",
696- crash_db_url, uuid, arch, sha512_system_uuid) < 0)
697+ crash_db_url, uuid, arch, whoopsie_identifier) < 0)
698 g_error ("Unable to allocate memory.");
699
700 /* TODO use CURLOPT_READFUNCTION to transparently compress data with
701@@ -523,6 +541,8 @@
702 char* core = NULL;
703 char* arch = NULL;
704
705+ g_return_if_fail (report);
706+
707 /* Command could be CORE, which requests the core dump, BUG ######, if in a
708 * development release, which points to the bug report, or UPDATE, if this
709 * is fixed in an update. */
710@@ -618,6 +638,9 @@
711 while ((file = g_dir_read_name (dir)) != NULL) {
712
713 upload_file = g_build_filename ("/var/crash", file, NULL);
714+ if (!upload_file)
715+ continue;
716+
717 ext = strrchr (upload_file, '.');
718 if (ext && strcmp(++ext, "upload") != 0) {
719 free (upload_file);
720@@ -626,10 +649,11 @@
721
722 crash_file = change_file_extension (upload_file, ".crash");
723 if (!crash_file) {
724- /* FIXME this would be bad - we'd keep uploading it */
725- if (!mark_handled (crash_file))
726- g_print ("Unable to mark report as seen (%s)\n", crash_file);
727- } else if (already_handled_report (crash_file)) {
728+ free (upload_file);
729+ continue;
730+ }
731+
732+ if (already_handled_report (crash_file)) {
733 if (!mark_handled (crash_file))
734 g_print ("Unable to mark report as seen (%s)\n", crash_file);
735 } else if (online_state && parse_and_upload_report (crash_file)) {
736@@ -813,8 +837,6 @@
737 main (int argc, char** argv)
738 {
739 GError* err = NULL;
740- char* system_uuid = NULL;
741- char* mac_address = NULL;
742
743 setup_signals ();
744 parse_arguments (&argc, &argv);
745@@ -824,34 +846,16 @@
746 exit (EXIT_FAILURE);
747 }
748
749- identifier_get_system_uuid (&system_uuid, &err);
750+ whoopsie_identifier_generate (&whoopsie_identifier, &err);
751 if (err) {
752 g_print ("%s\n", err->message);
753 g_error_free (err);
754 err = NULL;
755- }
756- if (system_uuid) {
757- identifier_sha512 (system_uuid, sha512_system_uuid, NULL);
758- free (system_uuid);
759- } else {
760- identifier_get_mac_address (&mac_address, &err);
761- if (err) {
762- g_print ("%s\n", err->message);
763- g_error_free (err);
764- err = NULL;
765- }
766- if (mac_address) {
767- identifier_sha512 (mac_address, sha512_system_uuid, NULL);
768- free (mac_address);
769- }
770- }
771-
772- if (*sha512_system_uuid != '\0') {
773- if (asprintf (&crash_db_submit_url, "%s/%s",
774- crash_db_url, sha512_system_uuid) < 0)
775- g_error ("Unable to allocate memory.");
776- } else {
777 crash_db_submit_url = strdup (crash_db_url);
778+
779+ } else if (asprintf (&crash_db_submit_url, "%s/%s", crash_db_url,
780+ whoopsie_identifier) < 0) {
781+ g_error ("Unable to allocate memory.");
782 }
783
784 drop_privileges (&err);

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: