[tracker-miners/wip/carlosg/tracker-process-readlink] tracker: Double check readlink result to find out process names
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/tracker-process-readlink] tracker: Double check readlink result to find out process names
- Date: Tue, 25 Aug 2020 15:26:41 +0000 (UTC)
commit 83000f1183d52877f47fc894d0478088596b0d3e
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Aug 25 17:24:46 2020 +0200
tracker: Double check readlink result to find out process names
Handle errors, ensure the string is \0 terminated, and ensure to trim
the " (deleted)" suffix that links get when you replace the executable
(eg. us developers doing ninja install again).
src/tracker/tracker-process.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/tracker/tracker-process.c b/src/tracker/tracker-process.c
index 9827320f9..7f3d4d0eb 100644
--- a/src/tracker/tracker-process.c
+++ b/src/tracker/tracker-process.c
@@ -69,9 +69,21 @@ static gchar *
find_command (pid_t pid)
{
gchar *proc_path, path[PATH_MAX];
+ ssize_t len;
proc_path = g_strdup_printf ("/proc/%d/exe", pid);
- readlink (proc_path, path, PATH_MAX);
+ len = readlink (proc_path, path, PATH_MAX);
+
+ if (len < 0)
+ return NULL;
+
+ path[len] = '\0';
+
+ /* Trim the " (deleted)" suffix, if the miner happened to be reinstalled */
+ if (g_str_has_suffix (path, " (deleted)")) {
+ len -= strlen (" (deleted)");
+ path[len] = '\0';
+ }
return g_path_get_basename (path);
}
@@ -121,18 +133,25 @@ tracker_process_find_all (void)
pid_t miner_fs, miner_rss;
GSList *processes = NULL;
TrackerProcessData *data;
+ gchar *command;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
miner_fs = get_pid_for_service (connection, "org.freedesktop.Tracker3.Miner.Files");
if (miner_fs > 0) {
- data = process_data_new (find_command (miner_fs), miner_fs);
- processes = g_slist_prepend (processes, data);
+ command = find_command (miner_fs);
+ if (command) {
+ data = process_data_new (command, miner_fs);
+ processes = g_slist_prepend (processes, data);
+ }
}
miner_rss = get_pid_for_service (connection, "org.freedesktop.Tracker3.Miner.RSS");
if (miner_rss > 0) {
- data = process_data_new (find_command (miner_rss), miner_rss);
- processes = g_slist_prepend (processes, data);
+ command = find_command (miner_rss);
+ if (command) {
+ data = process_data_new (command, miner_rss);
+ processes = g_slist_prepend (processes, data);
+ }
}
g_object_unref (connection);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]