Merge lp:~ogayot/whoopsie/whoopsie into lp:whoopsie

Proposed by Olivier Gayot
Status: Merged
Merge reported by: Brian Murray
Merged at revision: not available
Proposed branch: lp:~ogayot/whoopsie/whoopsie
Merge into: lp:whoopsie
Diff against target: 141 lines (+56/-10)
3 files modified
debian/changelog (+10/-0)
src/whoopsie.c (+45/-9)
src/whoopsie.h (+1/-1)
To merge this branch: bzr merge lp:~ogayot/whoopsie/whoopsie
Reviewer Review Type Date Requested Status
Brian Murray Needs Information
Daisy Pluckers Pending
Review via email: mp+414804@code.launchpad.net

Commit message

Add option for exiting right after processing existing files.

Description of the change

Hello,

This merge proposal is a preliminary step for moving to path-based activation of whoopsie should we decide to.

The main idea is to add to whoopsie the option to process existing reports and then exit immediately.

It consists of two different commits:
 1, stop calling process_existing_files if we know we are offline ; and therefore are not going to do any operation (rev 723)
 2. add the --no-polling switch so that whoopsie can process existing files and exit directly (rev 724)

This PR should have no incidence on the way whoopsie operates by default (i.e. without the --no-polling option).

In a subsequent merge proposal, we can move to path-based activation by changing the systemd unit files. More work might be needed in whoopsie itself if we want to improve the integration with apport though.

To post a comment you must log in.
lp:~ogayot/whoopsie/whoopsie updated
723. By Olivier Gayot

Don't call process_existing_files if not considered online

When online_status if false, a call to process_existing_files is more or less a
no-op. We are just looping through all the report files and ignoring them (i.e.
either by calling "continue" or by reaching the end of the iteration ; without
calling either parse_and_upload_report or mark_handled a single time).

Therefore, I removed the check for online_status from inside
process_existing_files and stop calling the function if online_status is false.

724. By Olivier Gayot

Add option to process existing files and exit

The new --no-polling option can be used to process existing files and exit
directly. This new option implies --assume-online for the following reason:
 * No matter what value assume_online takes, the first call to
process_existing_files always ignores it because we have online_status set to
true at the start of the process.

Therefore, if we exit after a single call to process_existing_files, the
variable assume_online is irrelevant. But theoretically, we _are_ assuming that
the network is online so it makes sense to set the value to true.

725. By Olivier Gayot

Bump version number to 0.2.77

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

This looks great and I'm happy to upload it, but I have one question which appears in the diff.

review: Needs Information
Revision history for this message
Olivier Gayot (ogayot) wrote :

> This looks great and I'm happy to upload it, but I have one question which
> appears in the diff.

Thanks for the feedback, I appreciate it!

Although whoopsie is not single-threaded strictly speaking, both `process_existing_files` and `network_changed` are callbacks managed by a single event-loop. Therefore, they shouldn't have the opportunity to execute in parallel.

I wanted to confirm that my understanding was correct so I ran a quick test where whoopsie sleeps for 5 seconds between each crash report it tries to process (there are 3 crash reports). I brought the network down while whoopsie was slowly reading the crash directory and it did not detect the network change until it finishes processing the files, so it should be good :)

[22:08:30] Not a paid data plan: /org/freedesktop/NetworkManager/ActiveConnection/15
[22:08:30] Found usable connection: /org/freedesktop/NetworkManager/ActiveConnection/15
[22:08:35] Now moving on to file _usr_bin_devnull-http.0.crash [ online_state is 1 ]
$ nmcli networking off
[22:08:40] Now moving on to file _usr_bin_debdiff-apply.1000.crash [ online_state is 1 ]
[22:08:45] Now moving on to file _usr_lib_chromium-browser_chromium-browser.1000.crash [ online_state is 1 ]
[22:08:45] offline

Thanks,
Olivier

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

This was manually merged from a debdiff that was created.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2021-03-06 01:03:04 +0000
3+++ debian/changelog 2022-02-15 16:01:51 +0000
4@@ -1,3 +1,13 @@
5+whoopsie (0.2.77) UNRELEASED; urgency=medium
6+
7+ * Added the --no-polling switch so that whoopsie can process existing files
8+ and exit directly (LP: #1424768)
9+ * Don't try to process files when we know we're offline. Eventually, we
10+ would just be ignoring each report ; which would result in useless CPU and
11+ IO usage.
12+
13+ -- Olivier Gayot <olivier.gayot@canonical.com> Tue, 15 Feb 2022 16:52:07 +0100
14+
15 whoopsie (0.2.76) hirsute; urgency=medium
16
17 * Drop build-dependency on obsolete dh-systemd
18
19=== modified file 'src/whoopsie.c'
20--- src/whoopsie.c 2021-02-02 23:56:03 +0000
21+++ src/whoopsie.c 2022-02-15 16:01:51 +0000
22@@ -97,9 +97,16 @@
23
24 #ifndef TEST
25 static int assume_online = 0;
26+
27+/*
28+ * Tells whether whoopsie will exit right after processing existing files.
29+ */
30+static int use_polling = 1;
31+
32 static GOptionEntry option_entries[] = {
33 { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Run in the foreground", NULL },
34 { "assume-online", 'a', 0, G_OPTION_ARG_NONE, &assume_online, "Always assume there is a route to $CRASH_DB_URL.", NULL },
35+ { "no-polling", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_polling, "Process existing files and exit. Implies --assume-online.", NULL },
36 { NULL }
37 };
38 #endif
39@@ -794,7 +801,16 @@
40 return success;
41 }
42
43-gboolean
44+static gboolean
45+process_existing_files_if_online (const char* report_dir)
46+{
47+ if (online_state) {
48+ process_existing_files (report_dir);
49+ }
50+ return G_SOURCE_CONTINUE;
51+}
52+
53+void
54 process_existing_files (const char* report_dir)
55 {
56 GDir* dir = NULL;
57@@ -826,7 +842,7 @@
58 g_free (upload_file);
59 g_free (crash_file);
60 continue;
61- } else if (online_state && parse_and_upload_report (crash_file)) {
62+ } else if (parse_and_upload_report (crash_file)) {
63 if (!mark_handled (crash_file, last_uploaded_oopsid)) {
64 log_msg ("Unable to mark report as seen (%s) removing it.\n", crash_file);
65 g_unlink (crash_file);
66@@ -837,8 +853,6 @@
67 g_free (crash_file);
68 }
69 g_dir_close (dir);
70-
71- return G_SOURCE_CONTINUE;
72 }
73
74 void daemonize (void)
75@@ -1067,6 +1081,16 @@
76 sigaction (SIGINT, &action, NULL);
77 }
78
79+static void
80+start_polling (void)
81+{
82+ g_timeout_add_seconds (PROCESS_OUTSTANDING_TIMEOUT,
83+ (GSourceFunc) process_existing_files_if_online, (gpointer) report_dir);
84+
85+ loop = g_main_loop_new (NULL, FALSE);
86+ g_main_loop_run (loop);
87+}
88+
89 int
90 main (int argc, char** argv)
91 {
92@@ -1077,6 +1101,18 @@
93 setup_signals ();
94 parse_arguments (&argc, &argv);
95
96+ if (!use_polling) {
97+ /*
98+ * In non polling mode, we exit after the first invocation of
99+ * process_existing_files.
100+ * Since we start the process with online_status already set to TRUE,
101+ * the first invocation of process_existing_files will always ignore
102+ * the assume_online variable. Therefore, assume_online is irrelevant
103+ * in non polling mode.
104+ */
105+ assume_online = TRUE;
106+ }
107+
108 if (!foreground) {
109 open_log ();
110 log_msg ("whoopsie " VERSION " starting up.\n");
111@@ -1148,12 +1184,12 @@
112 if (!assume_online)
113 monitor_connectivity (crash_db_url, network_changed);
114
115- process_existing_files (report_dir);
116- g_timeout_add_seconds (PROCESS_OUTSTANDING_TIMEOUT,
117- (GSourceFunc) process_existing_files, (gpointer) report_dir);
118+ /* As long as we keep online_state to TRUE by default, this initial call
119+ * happens unconditionally. */
120+ process_existing_files_if_online (report_dir);
121
122- loop = g_main_loop_new (NULL, FALSE);
123- g_main_loop_run (loop);
124+ if (use_polling)
125+ start_polling ();
126
127 unmonitor_directory (monitor, check_online_then_upload);
128 if (!assume_online)
129
130=== modified file 'src/whoopsie.h'
131--- src/whoopsie.h 2020-08-05 22:00:17 +0000
132+++ src/whoopsie.h 2022-02-15 16:01:51 +0000
133@@ -25,7 +25,7 @@
134 gsize get_report_max_size (void);
135 void destroy_key_and_value (gpointer key, gpointer value, gpointer user_data);
136 void drop_privileges (GError** error);
137-gboolean process_existing_files (const char* report_dir);
138+void process_existing_files (const char* report_dir);
139 extern char* last_uploaded_oopsid;
140
141 #endif /* WHOOPSIE_H */

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: