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