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

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