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
=== modified file 'debian/changelog'
--- debian/changelog 2021-03-06 01:03:04 +0000
+++ debian/changelog 2022-02-15 16:01:51 +0000
@@ -1,3 +1,13 @@
1whoopsie (0.2.77) UNRELEASED; urgency=medium
2
3 * Added the --no-polling switch so that whoopsie can process existing files
4 and exit directly (LP: #1424768)
5 * Don't try to process files when we know we're offline. Eventually, we
6 would just be ignoring each report ; which would result in useless CPU and
7 IO usage.
8
9 -- Olivier Gayot <olivier.gayot@canonical.com> Tue, 15 Feb 2022 16:52:07 +0100
10
1whoopsie (0.2.76) hirsute; urgency=medium11whoopsie (0.2.76) hirsute; urgency=medium
212
3 * Drop build-dependency on obsolete dh-systemd13 * Drop build-dependency on obsolete dh-systemd
414
=== modified file 'src/whoopsie.c'
--- src/whoopsie.c 2021-02-02 23:56:03 +0000
+++ src/whoopsie.c 2022-02-15 16:01:51 +0000
@@ -97,9 +97,16 @@
9797
98#ifndef TEST98#ifndef TEST
99static int assume_online = 0;99static int assume_online = 0;
100
101/*
102 * Tells whether whoopsie will exit right after processing existing files.
103 */
104static int use_polling = 1;
105
100static GOptionEntry option_entries[] = {106static GOptionEntry option_entries[] = {
101 { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Run in the foreground", NULL },107 { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Run in the foreground", NULL },
102 { "assume-online", 'a', 0, G_OPTION_ARG_NONE, &assume_online, "Always assume there is a route to $CRASH_DB_URL.", NULL },108 { "assume-online", 'a', 0, G_OPTION_ARG_NONE, &assume_online, "Always assume there is a route to $CRASH_DB_URL.", NULL },
109 { "no-polling", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_polling, "Process existing files and exit. Implies --assume-online.", NULL },
103 { NULL }110 { NULL }
104};111};
105#endif112#endif
@@ -794,7 +801,16 @@
794 return success;801 return success;
795}802}
796803
797gboolean804static gboolean
805process_existing_files_if_online (const char* report_dir)
806{
807 if (online_state) {
808 process_existing_files (report_dir);
809 }
810 return G_SOURCE_CONTINUE;
811}
812
813void
798process_existing_files (const char* report_dir)814process_existing_files (const char* report_dir)
799{815{
800 GDir* dir = NULL;816 GDir* dir = NULL;
@@ -826,7 +842,7 @@
826 g_free (upload_file);842 g_free (upload_file);
827 g_free (crash_file);843 g_free (crash_file);
828 continue;844 continue;
829 } else if (online_state && parse_and_upload_report (crash_file)) {845 } else if (parse_and_upload_report (crash_file)) {
830 if (!mark_handled (crash_file, last_uploaded_oopsid)) {846 if (!mark_handled (crash_file, last_uploaded_oopsid)) {
831 log_msg ("Unable to mark report as seen (%s) removing it.\n", crash_file);847 log_msg ("Unable to mark report as seen (%s) removing it.\n", crash_file);
832 g_unlink (crash_file);848 g_unlink (crash_file);
@@ -837,8 +853,6 @@
837 g_free (crash_file);853 g_free (crash_file);
838 }854 }
839 g_dir_close (dir);855 g_dir_close (dir);
840
841 return G_SOURCE_CONTINUE;
842}856}
843857
844void daemonize (void)858void daemonize (void)
@@ -1067,6 +1081,16 @@
1067 sigaction (SIGINT, &action, NULL);1081 sigaction (SIGINT, &action, NULL);
1068}1082}
10691083
1084static void
1085start_polling (void)
1086{
1087 g_timeout_add_seconds (PROCESS_OUTSTANDING_TIMEOUT,
1088 (GSourceFunc) process_existing_files_if_online, (gpointer) report_dir);
1089
1090 loop = g_main_loop_new (NULL, FALSE);
1091 g_main_loop_run (loop);
1092}
1093
1070int1094int
1071main (int argc, char** argv)1095main (int argc, char** argv)
1072{1096{
@@ -1077,6 +1101,18 @@
1077 setup_signals ();1101 setup_signals ();
1078 parse_arguments (&argc, &argv);1102 parse_arguments (&argc, &argv);
10791103
1104 if (!use_polling) {
1105 /*
1106 * In non polling mode, we exit after the first invocation of
1107 * process_existing_files.
1108 * Since we start the process with online_status already set to TRUE,
1109 * the first invocation of process_existing_files will always ignore
1110 * the assume_online variable. Therefore, assume_online is irrelevant
1111 * in non polling mode.
1112 */
1113 assume_online = TRUE;
1114 }
1115
1080 if (!foreground) {1116 if (!foreground) {
1081 open_log ();1117 open_log ();
1082 log_msg ("whoopsie " VERSION " starting up.\n");1118 log_msg ("whoopsie " VERSION " starting up.\n");
@@ -1148,12 +1184,12 @@
1148 if (!assume_online)1184 if (!assume_online)
1149 monitor_connectivity (crash_db_url, network_changed);1185 monitor_connectivity (crash_db_url, network_changed);
11501186
1151 process_existing_files (report_dir);1187 /* As long as we keep online_state to TRUE by default, this initial call
1152 g_timeout_add_seconds (PROCESS_OUTSTANDING_TIMEOUT,1188 * happens unconditionally. */
1153 (GSourceFunc) process_existing_files, (gpointer) report_dir);1189 process_existing_files_if_online (report_dir);
11541190
1155 loop = g_main_loop_new (NULL, FALSE);1191 if (use_polling)
1156 g_main_loop_run (loop);1192 start_polling ();
11571193
1158 unmonitor_directory (monitor, check_online_then_upload);1194 unmonitor_directory (monitor, check_online_then_upload);
1159 if (!assume_online)1195 if (!assume_online)
11601196
=== modified file 'src/whoopsie.h'
--- src/whoopsie.h 2020-08-05 22:00:17 +0000
+++ src/whoopsie.h 2022-02-15 16:01:51 +0000
@@ -25,7 +25,7 @@
25gsize get_report_max_size (void);25gsize get_report_max_size (void);
26void destroy_key_and_value (gpointer key, gpointer value, gpointer user_data);26void destroy_key_and_value (gpointer key, gpointer value, gpointer user_data);
27void drop_privileges (GError** error);27void drop_privileges (GError** error);
28gboolean process_existing_files (const char* report_dir);28void process_existing_files (const char* report_dir);
29extern char* last_uploaded_oopsid;29extern char* last_uploaded_oopsid;
3030
31#endif /* WHOOPSIE_H */31#endif /* WHOOPSIE_H */

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: