[tracker-miners/wip/carlosg/cli-improvements: 21/30] tracker: Simplify miner termination code




commit cf72247f735c41cb3e8f2026515d943aadd9d388
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 17 18:53:31 2020 +0200

    tracker: Simplify miner termination code
    
    Just pass an unix signal ID to send the processes through, instead
    of 2 sets of enums.

 src/tracker/tracker-daemon.c  |  4 ++--
 src/tracker/tracker-process.c | 56 +++++++++++--------------------------------
 src/tracker/tracker-process.h |  8 +------
 src/tracker/tracker-reset.c   |  2 +-
 4 files changed, 18 insertions(+), 52 deletions(-)
---
diff --git a/src/tracker/tracker-daemon.c b/src/tracker/tracker-daemon.c
index 4f0fa6ab4..3860d5258 100644
--- a/src/tracker/tracker-daemon.c
+++ b/src/tracker/tracker-daemon.c
@@ -957,9 +957,9 @@ daemon_run (void)
                gint retval = 0;
 
                if (kill_miners)
-                       retval = tracker_process_stop (TRACKER_PROCESS_TYPE_NONE, 
TRACKER_PROCESS_TYPE_MINERS);
+                       retval = tracker_process_stop (SIGKILL);
                else if (terminate_miners)
-                       retval = tracker_process_stop (TRACKER_PROCESS_TYPE_MINERS, 
TRACKER_PROCESS_TYPE_NONE);
+                       retval = tracker_process_stop (SIGTERM);
 
                return retval;
        }
diff --git a/src/tracker/tracker-process.c b/src/tracker/tracker-process.c
index bd86f648b..9827320f9 100644
--- a/src/tracker/tracker-process.c
+++ b/src/tracker/tracker-process.c
@@ -141,17 +141,11 @@ tracker_process_find_all (void)
 }
 
 gint
-tracker_process_stop (TrackerProcessTypes daemons_to_term,
-                      TrackerProcessTypes daemons_to_kill)
+tracker_process_stop (gint signal_id)
 {
        GSList *pids, *l;
        gchar *str;
 
-       if (daemons_to_kill == TRACKER_PROCESS_TYPE_NONE &&
-           daemons_to_term == TRACKER_PROCESS_TYPE_NONE) {
-               return 0;
-       }
-
        pids = tracker_process_find_all ();
 
        str = g_strdup_printf (g_dngettext (NULL,
@@ -170,41 +164,19 @@ tracker_process_stop (TrackerProcessTypes daemons_to_term,
                pd = l->data;
                basename = pd->cmd;
                pid = pd->pid;
-               
-               if (daemons_to_term == TRACKER_PROCESS_TYPE_MINERS) {
-                       if (!strstr (basename, "tracker-miner"))
-                               continue;
-
-                       if (kill (pid, SIGTERM) == -1) {
-                               const gchar *errstr = g_strerror (errno);
-                                               
-                               str = g_strdup_printf (_("Could not terminate process %d — “%s”"), pid, 
basename);
-                               g_printerr ("  %s: %s\n",
-                                           str,
-                                           errstr ? errstr : _("No error given"));
-                               g_free (str);
-                       } else {
-                               str = g_strdup_printf (_("Terminated process %d — “%s”"), pid, basename);
-                               g_print ("  %s\n", str);
-                               g_free (str);
-                       }
-               } else if (daemons_to_kill == TRACKER_PROCESS_TYPE_MINERS) {
-                       if (!strstr (basename, "tracker-miner"))
-                               continue;
-
-                       if (kill (pid, SIGKILL) == -1) {
-                               const gchar *errstr = g_strerror (errno);
-
-                               str = g_strdup_printf (_("Could not kill process %d — “%s”"), pid, basename);
-                               g_printerr ("  %s: %s\n",
-                                           str,
-                                           errstr ? errstr : _("No error given"));
-                               g_free (str);
-                       } else {
-                               str = g_strdup_printf (_("Killed process %d — “%s”"), pid, basename);
-                               g_print ("  %s\n", str);
-                               g_free (str);
-                       }
+
+               if (kill (pid, signal_id) == -1) {
+                       const gchar *errstr = g_strerror (errno);
+
+                       str = g_strdup_printf (_("Could not kill process %d — “%s”"), pid, basename);
+                       g_printerr ("  %s: %s\n",
+                                   str,
+                                   errstr ? errstr : _("No error given"));
+                       g_free (str);
+               } else {
+                       str = g_strdup_printf (_("Killed process %d — “%s”"), pid, basename);
+                       g_print ("  %s\n", str);
+                       g_free (str);
                }
        }
 
diff --git a/src/tracker/tracker-process.h b/src/tracker/tracker-process.h
index 6b86d015c..2e62b48dc 100644
--- a/src/tracker/tracker-process.h
+++ b/src/tracker/tracker-process.h
@@ -29,15 +29,9 @@ typedef struct {
        pid_t pid;
 } TrackerProcessData;
 
-typedef enum {
-       TRACKER_PROCESS_TYPE_NONE,
-       TRACKER_PROCESS_TYPE_MINERS
-} TrackerProcessTypes;
-
 void     tracker_process_data_free       (TrackerProcessData *pd);
 
 GSList * tracker_process_find_all        (void);
-gint     tracker_process_stop            (TrackerProcessTypes    daemons_to_term,
-                                          TrackerProcessTypes    daemons_to_kill);
+gint     tracker_process_stop            (gint signal_id);
 
 #endif /* __TRACKER_PROCESS_H__ */
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index 3bc3bdb97..1359363c1 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -191,7 +191,7 @@ reset_run (void)
        /* KILL processes first... */
        if (files || rss) {
                /* FIXME: we might selectively kill affected miners */
-               tracker_process_stop (TRACKER_PROCESS_TYPE_NONE, TRACKER_PROCESS_TYPE_MINERS);
+               tracker_process_stop (SIGKILL);
        }
 
        if (files) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]