Commit 42d939e1 authored by Artem Vorotnikov's avatar Artem Vorotnikov Committed by Robert Roth

ProcInfo now has std::string fields

Signed-off-by: Artem Vorotnikov's avatarArtem Vorotnikov <artem@vorotnikov.me>

https://bugzilla.gnome.org/show_bug.cgi?id=776653
parent 143a9070
......@@ -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;
......
......@@ -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;
}
......@@ -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);
......
......@@ -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);
......
......@@ -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));
......
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment