Blame SOURCES/0033-upload-watch-remove-busy-wait-for-SIGUSR1.patch

a60cd7
From b23cb1c47c7acb28a002162cd2dcf897e9f0f019 Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Fri, 7 Feb 2014 17:54:14 +0100
a60cd7
Subject: [ABRT PATCH 33/34] upload-watch: remove busy-wait for SIGUSR1
a60cd7
a60cd7
Unconditional checking of SIGUSR1 flag in the idle source of main loop
a60cd7
causes 100% CPU usage.
a60cd7
a60cd7
hanle_sigusr() function and got_sigusr flag are not necessary because
a60cd7
abrt-upload-watch already implements signal handling based on usage of
a60cd7
GIO Channels.
a60cd7
a60cd7
Closes rhbz#1063317
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 src/daemon/abrt-upload-watch.c | 37 +++++++++----------------------------
a60cd7
 1 file changed, 9 insertions(+), 28 deletions(-)
a60cd7
a60cd7
diff --git a/src/daemon/abrt-upload-watch.c b/src/daemon/abrt-upload-watch.c
a60cd7
index 59bfbe4..a42b285 100644
a60cd7
--- a/src/daemon/abrt-upload-watch.c
a60cd7
+++ b/src/daemon/abrt-upload-watch.c
a60cd7
@@ -27,7 +27,6 @@
a60cd7
 #define DEFAULT_CACHE_MIB_SIZE 4
a60cd7
 
a60cd7
 static int g_signal_pipe[2];
a60cd7
-static sig_atomic_t got_sigusr;
a60cd7
 
a60cd7
 struct queue
a60cd7
 {
a60cd7
@@ -122,24 +121,11 @@ handle_new_path(struct process *proc, char *name)
a60cd7
     }
a60cd7
 }
a60cd7
 
a60cd7
-static gboolean
a60cd7
+static void
a60cd7
 print_stats(struct process *proc)
a60cd7
 {
a60cd7
-    /* there is a race, because we run this function from 2 different places
a60cd7
-     * 1st when a child dies
a60cd7
-     * 2nd as idle source from mainloop
a60cd7
-     * if it happens the stats will be printed twice, which I think
a60cd7
-     * is not a big deal, because it's only for debug and tests
a60cd7
-     */
a60cd7
-    if (got_sigusr == 1)
a60cd7
-    {
a60cd7
-        got_sigusr = 0;
a60cd7
-        /* this is meant only for debugging, so not marking it as translatable */
a60cd7
-        fprintf(stderr, "%i archives to process, %i active workers\n", g_queue_get_length(&proc->queue.q), proc->children);
a60cd7
-    }
a60cd7
-
a60cd7
-    /* don't remove this source from glib */
a60cd7
-    return true;
a60cd7
+    /* this is meant only for debugging, so not marking it as translatable */
a60cd7
+    fprintf(stderr, "%i archives to process, %i active workers\n", g_queue_get_length(&proc->queue.q), proc->children);
a60cd7
 }
a60cd7
 
a60cd7
 static void
a60cd7
@@ -157,13 +143,6 @@ process_next_in_queue(struct process *proc)
a60cd7
 }
a60cd7
 
a60cd7
 static void
a60cd7
-handle_sigusr(int signo)
a60cd7
-{
a60cd7
-    /* just set the flag and process it synchronously */
a60cd7
-    got_sigusr = 1;
a60cd7
-}
a60cd7
-
a60cd7
-static void
a60cd7
 handle_signal(int signo)
a60cd7
 {
a60cd7
     int save_errno = errno;
a60cd7
@@ -200,7 +179,11 @@ handle_signal_pipe_cb(GIOChannel *gio, GIOCondition condition, gpointer user_dat
a60cd7
         {
a60cd7
             /* we did receive a signal */
a60cd7
             log_debug("Got signal %d through signal pipe", signals[signo]);
a60cd7
-            if (signals[signo] != SIGCHLD)
a60cd7
+            if (signals[signo] == SIGUSR1)
a60cd7
+            {
a60cd7
+                print_stats(proc);
a60cd7
+            }
a60cd7
+            else if (signals[signo] != SIGCHLD)
a60cd7
             {
a60cd7
                 process_quit(proc);
a60cd7
                 return FALSE; /* remove this event */
a60cd7
@@ -363,7 +346,7 @@ main(int argc, char **argv)
a60cd7
     close_on_exec_on(g_signal_pipe[1]);
a60cd7
     ndelay_on(g_signal_pipe[0]);
a60cd7
     ndelay_on(g_signal_pipe[1]);
a60cd7
-    signal(SIGUSR1, handle_sigusr);
a60cd7
+    signal(SIGUSR1, handle_signal);
a60cd7
     signal(SIGTERM, handle_signal);
a60cd7
     signal(SIGINT, handle_signal);
a60cd7
     signal(SIGCHLD, handle_signal);
a60cd7
@@ -373,7 +356,6 @@ main(int argc, char **argv)
a60cd7
                 handle_signal_pipe_cb,
a60cd7
                 &proc;;
a60cd7
 
a60cd7
-    int status_callback_source_id = g_idle_add((GSourceFunc)print_stats, &proc;;
a60cd7
     log_info("Starting glib main loop");
a60cd7
 
a60cd7
     g_main_loop_run(proc.main_loop);
a60cd7
@@ -381,7 +363,6 @@ main(int argc, char **argv)
a60cd7
     log_info("Glib main loop finished");
a60cd7
 
a60cd7
     g_source_remove(channel_signal_source_id);
a60cd7
-    g_source_remove(status_callback_source_id);
a60cd7
 
a60cd7
     GError *error = NULL;
a60cd7
     g_io_channel_shutdown(channel_signal, FALSE, &error);
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7