arrfab / rpms / abrt

Forked from rpms/abrt 5 years ago
Clone

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

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