[gnome-system-monitor] ProcInfo now has std::string fields
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] ProcInfo now has std::string fields
- Date: Mon, 22 May 2017 16:35:10 +0000 (UTC)
commit 42d939e1eb28f8a2ba626c8cdfc2722795a3944c
Author: Artem Vorotnikov <artem vorotnikov me>
Date: Wed Dec 28 16:07:43 2016 +0300
ProcInfo now has std::string fields
Signed-off-by: Artem Vorotnikov <artem vorotnikov me>
https://bugzilla.gnome.org/show_bug.cgi?id=776653
src/application.h | 31 ++++++++++-------------------
src/cgroups.cpp | 3 +-
src/lsof.cpp | 2 +-
src/memmaps.cpp | 2 +-
src/openfiles.cpp | 2 +-
src/prettytable.cpp | 10 ++++----
src/procdialogs.cpp | 8 +++---
src/procproperties.cpp | 12 +++++-----
src/proctable.cpp | 49 ++++++++++++++++++-----------------------------
9 files changed, 49 insertions(+), 70 deletions(-)
---
diff --git a/src/application.h b/src/application.h
index b31e398..9b70c9c 100644
--- a/src/application.h
+++ b/src/application.h
@@ -7,7 +7,6 @@
#include <algorithm>
-class ProcInfo;
struct LoadGraph;
#include "smooth_refresh.h"
@@ -73,8 +72,7 @@ struct MutableProcInfo
{
MutableProcInfo()
- : user(),
- vmsize(0UL),
+ : vmsize(0UL),
memres(0UL),
memshared(0UL),
memwritable(0UL),
@@ -86,19 +84,13 @@ MutableProcInfo()
cpu_time(0ULL),
status(0U),
pcpu(0U),
- nice(0),
- cgroup_name(NULL),
- unit(NULL),
- session(NULL),
- seat(NULL),
- owner()
+ nice(0)
{
- wchan[0] = '\0';
}
std::string user;
- gchar wchan[40];
+ std::string wchan;
// all these members are filled with libgtop which uses
// guint64 (to have fixed size data) but we don't need more
@@ -120,11 +112,11 @@ MutableProcInfo()
guint status;
guint pcpu;
gint nice;
- gchar *cgroup_name;
+ std::string cgroup_name;
- gchar *unit;
- gchar *session;
- gchar *seat;
+ std::string unit;
+ std::string session;
+ std::string seat;
std::string owner;
};
@@ -137,7 +129,6 @@ class ProcInfo
ProcInfo& operator=(const ProcInfo&) = delete;
ProcInfo(const ProcInfo&) = delete;
ProcInfo(pid_t pid);
- ~ProcInfo();
// adds one more ref to icon
void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
void set_user(guint uid);
@@ -145,11 +136,11 @@ class ProcInfo
GtkTreeIter node;
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
- gchar *tooltip;
- gchar *name;
- gchar *arguments;
+ std::string tooltip;
+ std::string name;
+ std::string arguments;
- gchar *security_context;
+ std::string security_context;
const pid_t pid;
pid_t ppid;
diff --git a/src/cgroups.cpp b/src/cgroups.cpp
index 075e4a8..8091195 100644
--- a/src/cgroups.cpp
+++ b/src/cgroups.cpp
@@ -112,7 +112,6 @@ void get_process_cgroup_info(ProcInfo& info) {
return;
const auto& cgroup_string = get_process_cgroup_string(info.pid);
- g_free(info.cgroup_name);
- info.cgroup_name = g_strdup(cgroup_string.c_str());
+ info.cgroup_name = cgroup_string;
}
diff --git a/src/lsof.cpp b/src/lsof.cpp
index 8c94bd2..15c3a59 100644
--- a/src/lsof.cpp
+++ b/src/lsof.cpp
@@ -153,7 +153,7 @@ namespace
gtk_list_store_append(this->model, &file);
gtk_list_store_set(this->model, &file,
PROCMAN_LSOF_COL_PIXBUF, info.pixbuf->gobj(),
- PROCMAN_LSOF_COL_PROCESS, info.name,
+ PROCMAN_LSOF_COL_PROCESS, info.name.c_str(),
PROCMAN_LSOF_COL_PID, info.pid,
PROCMAN_LSOF_COL_FILENAME, match.c_str(),
-1);
diff --git a/src/memmaps.cpp b/src/memmaps.cpp
index 78ffd17..02053c7 100644
--- a/src/memmaps.cpp
+++ b/src/memmaps.cpp
@@ -448,7 +448,7 @@ create_single_memmaps_dialog (GtkTreeModel *model, GtkTreePath *path,
label = procman_make_label_for_mmaps_or_ofiles (
_("_Memory maps for process “%s” (PID %u):"),
- info->name,
+ info->name.c_str(),
info->pid);
gtk_box_pack_start (dialog_box, GTK_WIDGET (label), FALSE, TRUE, 0);
diff --git a/src/openfiles.cpp b/src/openfiles.cpp
index 1fce282..1f6b5d2 100644
--- a/src/openfiles.cpp
+++ b/src/openfiles.cpp
@@ -333,7 +333,7 @@ create_single_openfiles_dialog (GtkTreeModel *model, GtkTreePath *path,
label = procman_make_label_for_mmaps_or_ofiles (
_("_Files opened by process “%s” (PID %u):"),
- info->name,
+ info->name.c_str(),
info->pid);
gtk_container_add (GTK_CONTAINER (cmd_grid), GTK_WIDGET (label));
diff --git a/src/prettytable.cpp b/src/prettytable.cpp
index 06e3b28..fe99f1a 100644
--- a/src/prettytable.cpp
+++ b/src/prettytable.cpp
@@ -165,7 +165,7 @@ void PrettyTable::file_monitor_event(Glib::RefPtr<Gio::File>,
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_theme(const ProcInfo &info)
{
- return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name, APP_ICON_SIZE,
(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
+ return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name.c_str(),
APP_ICON_SIZE, (GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
}
@@ -211,7 +211,7 @@ PrettyTable::get_icon_from_default(const ProcInfo &info)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_gio(const ProcInfo &info)
{
- gchar **cmdline = g_strsplit(info.name, " ", 2);
+ gchar **cmdline = g_strsplit(info.name.c_str(), " ", 2);
const gchar *executable = cmdline[0];
Glib::RefPtr<Gdk::Pixbuf> icon;
@@ -253,7 +253,7 @@ PrettyTable::get_icon_from_wnck(const ProcInfo &info)
Glib::RefPtr<Gdk::Pixbuf>
PrettyTable::get_icon_from_name(const ProcInfo &info)
{
-return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name, APP_ICON_SIZE,
(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
+return Glib::wrap(gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), info.name.c_str(), APP_ICON_SIZE,
(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_FORCE_SIZE), NULL));
}
@@ -325,11 +325,11 @@ PrettyTable::set_icon(ProcInfo &info)
icon = (this->*getters[i])(info);
}
catch (std::exception& e) {
- g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what());
+ g_warning("Failed to load icon for %s(%u) : %s", info.name.c_str(), info.pid, e.what());
continue;
}
catch (Glib::Exception& e) {
- g_warning("Failed to load icon for %s(%u) : %s", info.name, info.pid, e.what().c_str());
+ g_warning("Failed to load icon for %s(%u) : %s", info.name.c_str(), info.pid, e.what().c_str());
continue;
}
}
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index cec89dc..be6b6f4 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -74,19 +74,19 @@ procdialog_create_kill_dialog (GsmApplication *app, int signal)
case SIGKILL:
/*xgettext: primary alert message for killing single process*/
primary = g_strdup_printf (_("Are you sure you want to kill the selected process “%s” (PID:
%u)?"),
- selected_process->name,
+ selected_process->name.c_str(),
selected_process->pid);
break;
case SIGTERM:
/*xgettext: primary alert message for ending single process*/
primary = g_strdup_printf (_("Are you sure you want to end the selected process “%s” (PID:
%u)?"),
- selected_process->name,
+ selected_process->name.c_str(),
selected_process->pid);
break;
default: // SIGSTOP
/*xgettext: primary alert message for stopping single process*/
primary = g_strdup_printf (_("Are you sure you want to stop the selected process “%s” (PID:
%u)?"),
- selected_process->name,
+ selected_process->name.c_str(),
selected_process->pid);
break;
}
@@ -216,7 +216,7 @@ procdialog_create_renice_dialog (GsmApplication *app)
renice_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "renice_dialog"));
if ( selected_count == 1 ) {
dialog_title = g_strdup_printf (_("Change Priority of Process “%s” (PID: %u)"),
- info->name, info->pid);
+ info->name.c_str(), info->pid);
} else {
dialog_title = g_strdup_printf (ngettext("Change Priority of the selected process", "Change Priority
of %d selected processes", selected_count),
selected_count);
diff --git a/src/procproperties.cpp b/src/procproperties.cpp
index 7f2c461..216e1b2 100644
--- a/src/procproperties.cpp
+++ b/src/procproperties.cpp
@@ -64,7 +64,7 @@ fill_proc_properties (GtkTreeView *tree, ProcInfo *info)
get_process_memory_writable (info);
proc_arg proc_props[] = {
- { N_("Process Name"), g_strdup_printf("%s", info->name)},
+ { N_("Process Name"), g_strdup_printf("%s", info->name.c_str())},
{ N_("User"), g_strdup_printf("%s (%d)", info->user.c_str(), info->uid)},
{ N_("Status"), g_strdup(format_process_state(info->status))},
{ N_("Memory"), format_memsize(info->mem)},
@@ -81,10 +81,10 @@ fill_proc_properties (GtkTreeView *tree, ProcInfo *info)
{ N_("Nice"), g_strdup_printf("%d", info->nice)},
{ N_("Priority"), g_strdup_printf("%s", procman::get_nice_level(info->nice)) },
{ N_("ID"), g_strdup_printf("%d", info->pid)},
- { N_("Security Context"), info->security_context?g_strdup_printf("%s",
info->security_context):g_strdup(_("N/A"))},
- { N_("Command Line"), g_strdup_printf("%s", info->arguments)},
- { N_("Waiting Channel"), g_strdup_printf("%s", info->wchan)},
- { N_("Control Group"), info->cgroup_name?g_strdup_printf("%s",
info->cgroup_name):g_strdup(_("N/A"))},
+ { N_("Security Context"), not info->security_context.empty()?g_strdup_printf("%s",
info->security_context.c_str()):g_strdup(_("N/A"))},
+ { N_("Command Line"), g_strdup_printf("%s", info->arguments.c_str())},
+ { N_("Waiting Channel"), g_strdup_printf("%s", info->wchan.c_str())},
+ { N_("Control Group"), not info->cgroup_name.empty()?g_strdup_printf("%s",
info->cgroup_name.c_str()):g_strdup(_("N/A"))},
{ NULL, NULL}
};
@@ -196,7 +196,7 @@ create_single_procproperties_dialog (GtkTreeModel *model, GtkTreePath *path,
procpropdialog = GTK_DIALOG (g_object_new (GTK_TYPE_DIALOG,
"use-header-bar", TRUE, NULL));
- label = g_strdup_printf( _("%s (PID %u)"), info->name, info->pid);
+ label = g_strdup_printf( _("%s (PID %u)"), info->name.c_str(), info->pid);
gtk_window_set_title (GTK_WINDOW (procpropdialog), label);
g_free (label);
diff --git a/src/proctable.cpp b/src/proctable.cpp
index 10eb328..4255262 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -596,21 +596,6 @@ proctable_new (GsmApplication * const app)
return proctree;
}
-ProcInfo::~ProcInfo()
-{
- g_free(this->name);
- g_free(this->tooltip);
- g_free(this->arguments);
- g_free(this->security_context);
- g_free(this->cgroup_name);
- // The following are allocated inside of the sd_pid_get_*
- // functions using malloc(). Free with free() instead of g_free()
- // to insure proper clean up.
- free(this->unit);
- free(this->session);
- free(this->seat);
-}
-
static void
get_process_name (ProcInfo *info,
const gchar *cmd, const GStrv args)
@@ -631,7 +616,7 @@ get_process_name (ProcInfo *info,
g_free(basename);
}
}
- info->name = g_strdup (cmd);
+ info->name = cmd;
}
std::pair<ProcList::Iterator, bool> ProcList::emplace(pid_t pid) {
@@ -788,11 +773,11 @@ update_info_mutable_cols(ProcInfo *info)
tree_store_update(model, &info->node, COL_START_TIME, info->start_time);
tree_store_update(model, &info->node, COL_NICE, info->nice);
tree_store_update(model, &info->node, COL_MEM, info->mem);
- tree_store_update(model, &info->node, COL_WCHAN, info->wchan);
- tree_store_update(model, &info->node, COL_CGROUP, info->cgroup_name);
- tree_store_update(model, &info->node, COL_UNIT, info->unit);
- tree_store_update(model, &info->node, COL_SESSION, info->session);
- tree_store_update(model, &info->node, COL_SEAT, info->seat);
+ tree_store_update(model, &info->node, COL_WCHAN, info->wchan.c_str());
+ tree_store_update(model, &info->node, COL_CGROUP, info->cgroup_name.c_str());
+ tree_store_update(model, &info->node, COL_UNIT, info->unit.c_str());
+ tree_store_update(model, &info->node, COL_SESSION, info->session.c_str());
+ tree_store_update(model, &info->node, COL_SEAT, info->seat.c_str());
tree_store_update(model, &info->node, COL_OWNER, info->owner.c_str());
}
@@ -842,11 +827,11 @@ insert_info_to_tree (ProcInfo *info, GsmApplication *app, bool forced = false)
gtk_tree_store_set (GTK_TREE_STORE (model), &info->node,
COL_POINTER, info,
- COL_NAME, info->name,
- COL_ARGS, info->arguments,
- COL_TOOLTIP, info->tooltip,
+ COL_NAME, info->name.c_str(),
+ COL_ARGS, info->arguments.c_str(),
+ COL_TOOLTIP, info->tooltip.c_str(),
COL_PID, info->pid,
- COL_SECURITYCONTEXT, info->security_context,
+ COL_SECURITYCONTEXT, info->security_context.c_str(),
-1);
app->pretty_table->set_icon(*info);
@@ -890,6 +875,14 @@ remove_info_from_tree (GsmApplication *app, GtkTreeModel *model,
}
+static std::string
+get_proc_kernel_wchan(glibtop_proc_kernel& obj) {
+ char buf[40] = {0};
+ g_strlcpy(buf, obj.wchan, sizeof(buf));
+ buf[sizeof(buf)-1] = '\0';
+ return buf;
+}
+
static void
update_info (GsmApplication *app, ProcInfo *info)
{
@@ -899,7 +892,7 @@ update_info (GsmApplication *app, ProcInfo *info)
glibtop_proc_kernel prockernel;
glibtop_get_proc_kernel(&prockernel, info->pid);
- g_strlcpy(info->wchan, prockernel.wchan, sizeof info->wchan);
+ info->wchan = get_proc_kernel_wchan(prockernel);
glibtop_get_proc_state (&procstate, info->pid);
info->status = procstate.state;
@@ -943,10 +936,6 @@ update_info (GsmApplication *app, ProcInfo *info)
ProcInfo::ProcInfo(pid_t pid)
: node(),
pixbuf(),
- tooltip(NULL),
- name(NULL),
- arguments(NULL),
- security_context(NULL),
pid(pid),
ppid(-1),
uid(-1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]