Merge lp:~xnox/whoopsie/stable-id-through-boot into lp:whoopsie

Proposed by Dimitri John Ledkov
Status: Merged
Merged at revision: 634
Proposed branch: lp:~xnox/whoopsie/stable-id-through-boot
Merge into: lp:whoopsie
Diff against target: 187 lines (+94/-2)
4 files modified
src/identifier.c (+33/-1)
src/identifier.h (+4/-0)
src/tests/test_identifier.c (+53/-0)
src/whoopsie.c (+4/-1)
To merge this branch: bzr merge lp:~xnox/whoopsie/stable-id-through-boot
Reviewer Review Type Date Requested Status
Brian Murray Approve
John Lenton (community) Needs Fixing
Review via email: mp+229593@code.launchpad.net
To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) wrote :

A bug and a question, inline.

review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Replied inline.

627. By Dimitri John Ledkov

Make whoopsie_identifier_generate() stable throughout the system boot.

That means, whilst whoopsied is running that api call will return the
current ID used by whoopsie itself, irrespective if the caller is root
or non-root, and additional MAC network interfaces or IMEI modems
appearing, and takes into consideration if custom system id was set.

628. By Dimitri John Ledkov

Drop unlink.

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

It seems to me that in whoopsie.c we could check to see if whoopsie_identifier is the same as the one in the existing WHOOPSIE_ID_PATH (if it exists) rather than writing it again. Otherwise, this looks good and I'll merge and upload it. Thanks!

review: Approve
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

did I change the cache path from /run to somewhere persistent? if not, do
update it. I recall discussing /var/lib/ or some such.
On 17 Sep 2014 20:48, "Brian Murray" <email address hidden> wrote:

> Review: Approve
>
> It seems to me that in whoopsie.c we could check to see if
> whoopsie_identifier is the same as the one in the existing WHOOPSIE_ID_PATH
> (if it exists) rather than writing it again. Otherwise, this looks good
> and I'll merge and upload it. Thanks!
> --
>
> https://code.launchpad.net/~xnox/whoopsie/stable-id-through-boot/+merge/229593
> You are the owner of lp:~xnox/whoopsie/stable-id-through-boot.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/identifier.c'
--- src/identifier.c 2014-06-12 22:47:27 +0000
+++ src/identifier.c 2014-08-05 13:49:18 +0000
@@ -11,6 +11,7 @@
11#include "identifier.h"11#include "identifier.h"
1212
13static char* ofono_name = "org.ofono";13static char* ofono_name = "org.ofono";
14static char* cache_file = WHOOPSIE_ID_PATH;
14static gint fail_next_get_mac = 0;15static gint fail_next_get_mac = 0;
15static gint fail_next_get_uuid = 0;16static gint fail_next_get_uuid = 0;
1617
@@ -18,6 +19,10 @@
18 ofono_name = name;19 ofono_name = name;
19}20}
2021
22void whoopsie_identifier_set_cache_file (char *filename) {
23 cache_file = filename;
24}
25
21void26void
22whoopsie_hex_to_char (char* buf, const char *str, int len)27whoopsie_hex_to_char (char* buf, const char *str, int len)
23{28{
@@ -64,12 +69,30 @@
64}69}
6570
66void71void
72whoopsie_identifier_get_cached (char** res, GError** error)
73{
74 g_return_if_fail (res);
75
76 gsize length = 0;
77
78 if (!g_file_get_contents (cache_file, res, &length, NULL)) {
79 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
80 "Could not load cached identifier file.");
81 } else if (length != HASHLEN) {
82 g_set_error (error, g_quark_from_static_string ("whoopsie-quark"), 0,
83 "Got an unexpected length reading cached id.");
84 g_free (*res);
85 *res = NULL;
86 }
87 return;
88}
89
90void
67whoopsie_identifier_get_mac_address (char** res, GError** error)91whoopsie_identifier_get_mac_address (char** res, GError** error)
68{92{
69 glob_t globbuf;93 glob_t globbuf;
70 char data[200] = {0};94 char data[200] = {0};
71 gboolean success = FALSE;95 gboolean success = FALSE;
72 int i = 0;
7396
74 g_return_if_fail (res);97 g_return_if_fail (res);
7598
@@ -250,6 +273,15 @@
250273
251 g_return_if_fail (res);274 g_return_if_fail (res);
252275
276 whoopsie_identifier_get_cached (res, error);
277 if ((!error || !(*error)) && *res)
278 return;
279
280 if (error && *error) {
281 g_error_free (*error);
282 *error = NULL;
283 }
284
253 whoopsie_identifier_get_system_uuid (&identifier, error);285 whoopsie_identifier_get_system_uuid (&identifier, error);
254 if ((!error || !(*error)) && identifier)286 if ((!error || !(*error)) && identifier)
255 goto out;287 goto out;
256288
=== modified file 'src/identifier.h'
--- src/identifier.h 2014-06-12 22:47:27 +0000
+++ src/identifier.h 2014-08-05 13:49:18 +0000
@@ -8,8 +8,12 @@
88
9/* for testing: */9/* for testing: */
10void whoopsie_identifier_set_ofono_name (char* name) __attribute__ ((__warning__ ("Only for testing")));10void whoopsie_identifier_set_ofono_name (char* name) __attribute__ ((__warning__ ("Only for testing")));
11void whoopsie_identifier_set_cache_file (char* filename) __attribute__ ((__warning__ ("Only for testing")));
11void whoopsie_identifier_fail_next_get_mac (gint how) __attribute__ ((__warning__ ("Only for testing")));12void whoopsie_identifier_fail_next_get_mac (gint how) __attribute__ ((__warning__ ("Only for testing")));
12void whoopsie_identifier_fail_next_get_uuid () __attribute__ ((__warning__ ("Only for testing")));13void whoopsie_identifier_fail_next_get_uuid () __attribute__ ((__warning__ ("Only for testing")));
13#define WHOOPSIE_FAIL_GENERIC 114#define WHOOPSIE_FAIL_GENERIC 1
14#define WHOOPSIE_FAIL_NO_IFACES 215#define WHOOPSIE_FAIL_NO_IFACES 2
15#define WHOOPSIE_FAILED_BY_REQUEST 4216#define WHOOPSIE_FAILED_BY_REQUEST 42
17
18/* The file path for publishing whoopsie_identifier */
19#define WHOOPSIE_ID_PATH "/run/whoopsie-id"
1620
=== modified file 'src/tests/test_identifier.c'
--- src/tests/test_identifier.c 2014-06-12 22:47:27 +0000
+++ src/tests/test_identifier.c 2014-08-05 13:49:18 +0000
@@ -469,6 +469,55 @@
469 brofono_stop ();469 brofono_stop ();
470}470}
471471
472static void
473test_identifier_cache (void)
474{
475 const char* expected = "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382"
476 "d624741d0dc6638326e282c41be5e4254d8820772c5518a"
477 "2c5a8c0c7f7eda19594a7eb539453e1ed7";
478 char* res = NULL;
479 GError* error = NULL;
480
481 gchar *test_path = NULL;
482 gchar *test_dir = NULL;
483 gchar test_tmpl[PATH_MAX] = "/tmp/whoopsie-test-XXXXXX";
484 test_dir = g_mkdtemp (test_tmpl);
485 g_assert (test_dir != NULL);
486
487 /* Check non-existent id file fails lookup */
488 test_path = g_strdup_printf ("%s/non-existant", test_dir);
489 whoopsie_identifier_set_cache_file (test_path);
490 whoopsie_identifier_get_cached (&res, &error);
491 g_assert_null (res);
492 g_assert_error (error, g_quark_from_static_string ("whoopsie-quark"), 0);
493 g_free (test_path);
494 g_error_free (error);
495 error = NULL;
496
497 /* Check good cache is loaded */
498 test_path = g_strdup_printf ("%s/good", test_dir);
499 g_assert (g_file_set_contents (test_path, expected, -1, NULL));
500 whoopsie_identifier_set_cache_file (test_path);
501 whoopsie_identifier_get_cached (&res, &error);
502 g_assert_nonnull (res);
503 g_assert_no_error (error);
504 g_assert_cmpstr (res, ==, expected);
505 g_unlink (test_path);
506 g_free (test_path);
507
508 /* Check bad cache is not loaded */
509 test_path = g_strdup_printf ("%s/good", test_dir);
510 g_assert (g_file_set_contents (test_path, expected, HASHLEN-3, NULL));
511 whoopsie_identifier_set_cache_file (test_path);
512 whoopsie_identifier_get_cached (&res, &error);
513 g_assert_null (res);
514 g_assert_error (error, g_quark_from_static_string ("whoopsie-quark"), 0);
515 g_unlink (test_path);
516 g_free (test_path);
517
518 g_assert (g_rmdir (test_dir) == 0);
519}
520
472int521int
473main (int argc, char** argv)522main (int argc, char** argv)
474{523{
@@ -478,6 +527,9 @@
478#endif527#endif
479 g_test_init (&argc, &argv, NULL);528 g_test_init (&argc, &argv, NULL);
480529
530 /* Prevent reading currently running system id */
531 whoopsie_identifier_set_cache_file ("/tmp");
532
481 g_test_add_func ("/whoopsie/get-system-uuid", test_get_system_uuid);533 g_test_add_func ("/whoopsie/get-system-uuid", test_get_system_uuid);
482 g_test_add_func ("/whoopsie/get-uuid-fails-when-told", test_get_system_uuid_fail_when_told_to);534 g_test_add_func ("/whoopsie/get-uuid-fails-when-told", test_get_system_uuid_fail_when_told_to);
483 g_test_add_func ("/whoopsie/hex-to-char", test_hex_to_char);535 g_test_add_func ("/whoopsie/hex-to-char", test_hex_to_char);
@@ -493,6 +545,7 @@
493 g_test_add_func ("/whoopsie/imei-empty-reply", test_get_imei_empty_reply);545 g_test_add_func ("/whoopsie/imei-empty-reply", test_get_imei_empty_reply);
494 g_test_add_func ("/whoopsie/imei-bad", test_get_imei_bad_imei);546 g_test_add_func ("/whoopsie/imei-bad", test_get_imei_bad_imei);
495 g_test_add_func ("/whoopsie/imei-missing", test_get_imei_no_imei);547 g_test_add_func ("/whoopsie/imei-missing", test_get_imei_no_imei);
548 g_test_add_func ("/whoopsie/get-cached", test_identifier_cache);
496549
497 /* Do not consider warnings to be fatal. */550 /* Do not consider warnings to be fatal. */
498 g_log_set_always_fatal (G_LOG_FATAL_MASK);551 g_log_set_always_fatal (G_LOG_FATAL_MASK);
499552
=== modified file 'src/whoopsie.c'
--- src/whoopsie.c 2014-07-29 20:49:35 +0000
+++ src/whoopsie.c 2014-08-05 13:49:18 +0000
@@ -964,6 +964,9 @@
964 whoopsie_identifier);964 whoopsie_identifier);
965 }965 }
966966
967 /* Publish whoopsie-id */
968 g_file_set_contents (WHOOPSIE_ID_PATH, whoopsie_identifier, -1, NULL);
969
967 create_crash_directory ();970 create_crash_directory ();
968971
969 drop_privileges (&err);972 drop_privileges (&err);
@@ -1011,6 +1014,6 @@
10111014
1012 g_free (crash_db_url);1015 g_free (crash_db_url);
1013 g_free (crash_db_submit_url);1016 g_free (crash_db_submit_url);
1014 return 0;1017 return 0;
1015}1018}
1016#endif1019#endif

Subscribers

People subscribed via source and target branches

to status/vote changes: