From 37482a9fa90b43075a06ba6a3130bfd260203915 Mon Sep 17 00:00:00 2001 From: rim Date: Mon, 28 May 2018 03:53:08 +0300 Subject: [PATCH] Improve --- src/app-manager.c | 4 ++-- src/main.c | 3 +-- src/process-monitor.c | 14 +++++++------- src/process-tree-model.c | 40 ++++++++++++++++++++++++---------------- src/process-tree-view.c | 85 +++++++++++++++++++++++++++++++++++++++---------------------------------------------- src/process-window.c | 22 ++++++++++------------ src/settings-dialog.c | 6 +++--- src/settings.c | 5 ++--- src/task-manager-bsd.c | 12 ++++-------- src/task-manager-freebsd.c | 76 ++++++++++++++++++++++++++++++++++++---------------------------------------- src/task-manager-linux.c | 36 +++++++++++++++++++++--------------- src/task-manager-skel.c | 7 +++---- src/task-manager-solaris.c | 25 +++++++++++-------------- src/task-manager.c | 81 ++++++++++++++++++++++----------------------------------------------------------- src/task-manager.h | 20 ++++++++++---------- 15 files changed, 195 insertions(+), 241 deletions(-) diff --git a/src/app-manager.c b/src/app-manager.c index c32bb3d..fbc15d3 100644 --- a/src/app-manager.c +++ b/src/app-manager.c @@ -149,15 +149,15 @@ apps_lookup_pid (GArray *apps, gint pid) } static void -application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager) +application_opened (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager) { gint pid = app_get_pid (application); G_DEBUG_FMT ("Application opened %p %d", (void*)application, pid); apps_add_application (manager->apps, application, pid); } static void -application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager) +application_closed (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager) { G_DEBUG_FMT ("Application closed %p", (void*)application); apps_remove_application (manager->apps, application); diff --git a/src/main.c b/src/main.c index 3960f6d..69e8654 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,7 @@ static XtmSettings *settings; static GtkWidget *window; static GtkStatusIcon *status_icon; static XtmTaskManager *task_manager; -static gboolean timeout = FALSE; +static guint timeout = 0; static void status_icon_activated (void) @@ -217,7 +217,6 @@ int main (int argc, char *argv[]) #endif task_manager = xtm_task_manager_new (xtm_process_window_get_model (XTM_PROCESS_WINDOW (window))); - g_message ("Running as %s on %s", xtm_task_manager_get_username (task_manager), xtm_task_manager_get_hostname (task_manager)); init_timeout (); g_signal_connect (settings, "notify::refresh-rate", G_CALLBACK (refresh_rate_changed), NULL); diff --git a/src/process-monitor.c b/src/process-monitor.c index 4d48223..3e1bd01 100644 --- a/src/process-monitor.c +++ b/src/process-monitor.c @@ -121,22 +121,22 @@ xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr) XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget); guint minimum_history_length; - minimum_history_length = gtk_widget_get_allocated_width(widget) / monitor->step_size; + minimum_history_length = (guint)(gtk_widget_get_allocated_width(widget) / monitor->step_size); if (monitor->history->len < minimum_history_length) g_array_set_size (monitor->history, minimum_history_length + 1); xtm_process_monitor_paint (monitor, cr); return FALSE; } #else static gboolean -xtm_process_monitor_expose (GtkWidget *widget, GdkEventExpose *event) +xtm_process_monitor_expose (GtkWidget *widget, GdkEventExpose *event __unused) { XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget); guint minimum_history_length; cairo_t *cr; - minimum_history_length = widget->allocation.width / monitor->step_size; + minimum_history_length = (guint)(widget->allocation.width / monitor->step_size); if (monitor->history->len < minimum_history_length) g_array_set_size (monitor->history, minimum_history_length + 1); @@ -153,15 +153,15 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width cairo_t *cr; cairo_surface_t *graph_surface; gfloat *peak; - gfloat step_size; + gdouble step_size; gint i; if (monitor->history->len <= 1) { g_warning ("Cannot paint graph with n_peak <= 1"); return NULL; } - step_size = monitor->step_size; + step_size = (gdouble)monitor->step_size; graph_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create (graph_surface); @@ -180,7 +180,7 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width { peak = &g_array_index (monitor->history, gfloat, i); cairo_translate (cr, -step_size, 0); - cairo_line_to (cr, width, (1.0 - *peak) * height); + cairo_line_to (cr, width, (1.0 - ((gdouble)(*peak))) * height); } cairo_line_to (cr, width, height); cairo_fill (cr); @@ -201,7 +201,7 @@ xtm_process_monitor_graph_surface_create (XtmProcessMonitor *monitor, gint width { peak = &g_array_index (monitor->history, gfloat, i); cairo_translate (cr, -step_size, 0); - cairo_line_to (cr, width, (1.0 - *peak) * height); + cairo_line_to (cr, width, (1.0 - ((gdouble)(*peak))) * height); } cairo_stroke (cr); diff --git a/src/process-tree-model.c b/src/process-tree-model.c index 2e139f8..551a722 100644 --- a/src/process-tree-model.c +++ b/src/process-tree-model.c @@ -137,7 +137,7 @@ xtm_process_tree_model_init (XtmProcessTreeModel *treemodel) treemodel->c_column = XTM_PTV_COLUMN_PID; treemodel->p_column = XTM_PTV_COLUMN_PPID; - treemodel->stamp = g_random_int (); + treemodel->stamp = (gint)g_random_int (); if (treemodel->stamp == 0) treemodel->stamp = 1; } @@ -154,7 +154,7 @@ xtm_process_tree_model_finalize (GObject *object) } static void -xtm_process_tree_model_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +xtm_process_tree_model_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec __unused) { XtmProcessTreeModel *treemodel = XTM_PROCESS_TREE_MODEL (object); switch (property_id) @@ -166,7 +166,7 @@ xtm_process_tree_model_set_property (GObject *object, guint property_id, const G } static void -xtm_process_tree_model_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +xtm_process_tree_model_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec __unused) { XtmProcessTreeModel *treemodel = XTM_PROCESS_TREE_MODEL (object); switch (property_id) @@ -178,7 +178,7 @@ xtm_process_tree_model_get_property (GObject *object, guint property_id, GValue } static GtkTreeModelFlags -xtm_process_tree_model_get_flags (GtkTreeModel *model) +xtm_process_tree_model_get_flags (GtkTreeModel *model __unused) { return GTK_TREE_MODEL_ITERS_PERSIST; } @@ -215,7 +215,7 @@ xtm_process_tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTree /* Walk the tree to create the iter */ for (i = 0; i < depth; i++) { - node = g_node_nth_child (node, indices[i]); + node = g_node_nth_child (node, (guint)indices[i]); if (node == NULL) break; } @@ -231,7 +231,9 @@ xtm_process_tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter) GtkTreePath *path; GNode *child, *parent; XtmProcessTreeModel *treemodel = XTM_PROCESS_TREE_MODEL (model); + g_return_val_if_fail (iter->stamp == treemodel->stamp, NULL); + child = iter->user_data; parent = child->parent; path = gtk_tree_path_new (); @@ -260,15 +262,17 @@ xtm_process_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, gint c /* Use path for non-persistent models */ if (lnk->path) gtk_tree_model_get_iter (model, iter, lnk->path); - return gtk_tree_model_get_value (model, iter, column, value); + gtk_tree_model_get_value (model, iter, column, value); } static gboolean xtm_process_tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter) { GNode *node; XtmProcessTreeModel *treemodel = XTM_PROCESS_TREE_MODEL (model); + g_return_val_if_fail (iter->stamp == treemodel->stamp, FALSE); + node = iter->user_data; iter->user_data = g_node_next_sibling (node); /* Make iter invalid if no node has been found */ @@ -298,7 +302,9 @@ xtm_process_tree_model_iter_has_child (GtkTreeModel *model, GtkTreeIter *iter) { GNode *node; XtmProcessTreeModel *treemodel = XTM_PROCESS_TREE_MODEL (model); + g_return_val_if_fail (iter->stamp == treemodel->stamp, FALSE); + node = iter->user_data; return g_node_first_child (node) != NULL; } @@ -313,7 +319,7 @@ xtm_process_tree_model_iter_n_children (GtkTreeModel *model, GtkTreeIter *iter) node = treemodel->tree; else node = iter->user_data; - return g_node_n_children (node); + return (gint)g_node_n_children (node); } static gboolean @@ -326,7 +332,7 @@ xtm_process_tree_model_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, G node = treemodel->tree; else node = parent->user_data; - iter->user_data = g_node_nth_child (node, n); + iter->user_data = g_node_nth_child (node, (guint)n); /* Make iter only valid if a node has been found */ iter->stamp = iter->user_data ? treemodel->stamp : 0; return iter->user_data != NULL; @@ -439,7 +445,7 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath GtkTreeIter s_iter; XtmCrossLink *lnk, *c_link; GNode *node, *next_node, *old_parent; - struct find_node_struct found = {{0}}; + struct find_node_struct found; GValue c_value = {0}; GValue p_value = {0}; gboolean same = TRUE; @@ -458,6 +464,7 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath s_iter.user_data3 = NULL; /* Use the root entry as fall-back if no parent could be found */ + bzero(&found, sizeof(found)); found.parent = treemodel->tree; found.treemodel = treemodel; gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value); @@ -589,7 +596,7 @@ static void do_path (gpointer data, gpointer user_data) { XtmCrossLink *lnk = data; - void (*func) (GtkTreePath*) = user_data; + void (*func) (GtkTreePath*) = (void (*) (GtkTreePath*))user_data; /* Use path for non-persistent models */ g_return_if_fail (lnk->path); func (lnk->path); @@ -602,7 +609,7 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath GtkTreeIter s_iter; XtmCrossLink *lnk, *c_link; GNode *node, *next_node; - struct find_node_struct found = {{0}}; + struct find_node_struct found; GValue c_value = {0}; GValue p_value = {0}; gboolean same; @@ -633,8 +640,9 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath /* Need to update all path caches after the insert and increment them with one */ if (not_persist) g_sequence_foreach_range (g_sequence_iter_next (lnk->list), g_sequence_get_end_iter (treemodel->list), - do_path, gtk_tree_path_next); + do_path, (gpointer)gtk_tree_path_next); + bzero(&found, sizeof(found)); found.parent = treemodel->tree; found.treemodel = treemodel; gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value); @@ -748,7 +756,7 @@ xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath /* Need to update all path caches after the remove and decrement them with one */ if (not_persist) g_sequence_foreach_range (g_sequence_iter_next (lnk->list), g_sequence_get_end_iter (treemodel->list), - do_path, gtk_tree_path_prev); + do_path, (gpointer)gtk_tree_path_prev); del_node = lnk->tree; old_parent = del_node->parent; @@ -809,7 +817,7 @@ reorder_children (GNode *parent, gpointer data) new_order = g_new (gint, size); for (i = 0; i < size; i++) { - new_order[i] = i; + new_order[i] = (gint)i; } i = 0; /* Walk the whole list in the new order */ @@ -832,7 +840,7 @@ reorder_children (GNode *parent, gpointer data) if (c_pos > 0) { /* move the items in between to keep order list in sync with the current tree */ - memmove (new_order + i + 1, new_order + i, c_pos * sizeof(gint)); + memmove ((new_order + i + 1), (new_order + i), ((guint)c_pos * sizeof(gint))); moved = TRUE; } /* Store the old position at the new location */ @@ -857,7 +865,7 @@ reorder_children (GNode *parent, gpointer data) } static void -xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, GtkTreeModel *model) +xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path __unused, GtkTreeIter *iter __unused, gint *new_order, GtkTreeModel *model) { gint i, size; GSequence *s_list; diff --git a/src/process-tree-view.c b/src/process-tree-view.c index ca4920f..c93a391 100644 --- a/src/process-tree-view.c +++ b/src/process-tree-view.c @@ -90,14 +90,9 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview) gboolean tree; treeview->settings = xtm_settings_get_default (); + treeview->owner_uid = getuid (); g_signal_connect (treeview->settings, "notify", G_CALLBACK (settings_changed), treeview); - - { - gchar *uid_name; - get_owner_uid (&treeview->owner_uid, &uid_name); - g_free (uid_name); - g_object_get (treeview->settings, "show-all-processes", &treeview->show_all_processes_cached, "process-tree", &tree, NULL); - } + g_object_get (treeview->settings, "show-all-processes", &treeview->show_all_processes_cached, "process-tree", &tree, NULL); /* Create tree view model */ #ifdef HAVE_WNCK @@ -212,11 +207,12 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview) /* Set initial sort column */ { - guint sort_column_id; + guint sort_column_idu; + gint sort_column_id; GtkSortType sort_type; - g_object_get (treeview->settings, "sort-column-id", &sort_column_id, "sort-type", &sort_type, NULL); - treeview->sort_column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), treeview->columns_positions[sort_column_id]); + g_object_get (treeview->settings, "sort-column-id", &sort_column_idu, "sort-type", &sort_type, NULL); + treeview->sort_column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), treeview->columns_positions[sort_column_idu]); gtk_tree_view_column_set_sort_indicator (treeview->sort_column, TRUE); gtk_tree_view_column_set_sort_order (treeview->sort_column, sort_type); sort_column_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (treeview->sort_column), "sort-column-id")); @@ -267,14 +263,14 @@ xtm_process_tree_view_finalize (GObject *object) static void column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column) { - GtkCellRenderer *cell_cmdline, *cell_icon; + GtkCellRenderer *cell_cmdline; gboolean show_application_icons; g_object_get (treeview->settings, "show-application-icons", &show_application_icons, NULL); if (show_application_icons) { #ifdef HAVE_WNCK - cell_icon = gtk_cell_renderer_pixbuf_new (); + GtkCellRenderer *cell_icon = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), cell_icon, FALSE); gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), cell_icon, "pixbuf", XTM_PTV_COLUMN_ICON, "cell-background", XTM_PTV_COLUMN_BACKGROUND, NULL); #endif @@ -292,7 +288,7 @@ columns_changed (XtmProcessTreeView *treeview) GList *columns, *l; GtkTreeViewColumn *column; gint column_id; - gint i; + gushort i; columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (treeview)); if (g_list_length (columns) < N_COLUMNS) @@ -315,7 +311,7 @@ columns_changed (XtmProcessTreeView *treeview) static void read_columns_positions (XtmProcessTreeView *treeview) { - gint i; + gushort i; gchar *columns_positions; gchar **columns_positions_split; @@ -330,22 +326,22 @@ read_columns_positions (XtmProcessTreeView *treeview) { columns_positions_split = g_strsplit (columns_positions, ";", N_COLUMNS + 1); for (i = 0; i < N_COLUMNS && columns_positions_split[i] != NULL; i++) - treeview->columns_positions[i] = (gint)g_ascii_strtoll (columns_positions_split[i], NULL, 10); + treeview->columns_positions[i] = (gushort)g_ascii_strtoll (columns_positions_split[i], NULL, 10); g_strfreev (columns_positions_split); g_free (columns_positions); } } static void save_columns_positions (XtmProcessTreeView *treeview) { gint i; - gint offset = 0; + gulong offset = 0; #define COLUMNS_POSITIONS_STRLEN (N_COLUMNS * 4 + 1) gchar columns_positions[COLUMNS_POSITIONS_STRLEN] = { 0 }; for (i = 0; i < N_COLUMNS; i++) - offset += g_snprintf (&columns_positions[offset], (sizeof(columns_positions) - offset), "%d;", treeview->columns_positions[i]); + offset += (gulong)g_snprintf (&columns_positions[offset], (sizeof(columns_positions) - offset), "%d;", treeview->columns_positions[i]); g_object_set (treeview->settings, "columns-positions", columns_positions, NULL); } @@ -356,7 +352,7 @@ cb_send_signal (GtkMenuItem *mi, gpointer user_data) XtmSettings *settings; gboolean prompt_terminate_task; GtkWidget *dialog; - guint pid = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (mi), "pid")); + gint pid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mi), "pid")); gint xtm_signal = GPOINTER_TO_INT (user_data); settings = xtm_settings_get_default (); @@ -407,7 +403,7 @@ cb_send_signal (GtkMenuItem *mi, gpointer user_data) static void cb_set_priority (GtkMenuItem *mi, gpointer user_data) { - guint pid = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (mi), "pid")); + gint pid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mi), "pid")); gint priority = GPOINTER_TO_INT (user_data); if (!set_priority_to_pid (pid, priority)) @@ -424,7 +420,7 @@ cb_set_priority (GtkMenuItem *mi, gpointer user_data) } static GtkWidget * -build_context_menu (XtmProcessTreeView *treeview, guint pid) +build_context_menu (XtmProcessTreeView *treeview, gint pid) { GtkWidget *menu, *menu_priority, *mi; @@ -493,16 +489,16 @@ build_context_menu (XtmProcessTreeView *treeview, guint pid) } static void -position_menu (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, XtmProcessTreeView *treeview) +position_menu (GtkMenu *menu __unused, gint *x, gint *y, gboolean *push_in, XtmProcessTreeView *treeview) { gdk_window_get_origin (gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview)), x, y); *x += 5; *y += 5; *push_in = TRUE; } static void -popup_menu (XtmProcessTreeView *treeview, guint pid, guint activate_time, gboolean at_pointer_position) +popup_menu (XtmProcessTreeView *treeview, gint pid, guint activate_time, gboolean at_pointer_position) { static GtkWidget *menu = NULL; GtkMenuPositionFunc position_func = NULL; @@ -520,43 +516,40 @@ popup_menu (XtmProcessTreeView *treeview, guint pid, guint activate_time, gboole static gboolean treeview_clicked (XtmProcessTreeView *treeview, GdkEventButton *event) { - guint pid; + GtkTreeModel *model; + GtkTreeSelection *selection; + GtkTreePath *path; + GtkTreeIter iter; + gboolean tree; + gint pid; if (event->button != 3) return FALSE; - { - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreePath *path; - GtkTreeIter iter; - gboolean tree; - - g_object_get (treeview->settings, "process-tree", &tree, NULL); - model = GTK_TREE_MODEL (tree ? treeview->model_tree : treeview->model_filter); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), (gint)event->x, (gint)event->y, &path, NULL, NULL, NULL); + g_object_get (treeview->settings, "process-tree", &tree, NULL); + model = GTK_TREE_MODEL (tree ? treeview->model_tree : treeview->model_filter); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), (gint)event->x, (gint)event->y, &path, NULL, NULL, NULL); - if (path == NULL) - return FALSE; + if (path == NULL) + return FALSE; - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, XTM_PTV_COLUMN_PID, &pid, -1); - gtk_tree_selection_select_path (selection, path); - gtk_tree_path_free (path); + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, XTM_PTV_COLUMN_PID, &pid, -1); + gtk_tree_selection_select_path (selection, path); + gtk_tree_path_free (path); - G_DEBUG_FMT ("Found iter with pid %d", pid); - } + G_DEBUG_FMT ("Found iter with pid %d", pid); popup_menu (treeview, pid, event->time, TRUE); return TRUE; } static gboolean treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event) { - guint pid; + gint pid; GtkTreeModel *model; GtkTreeSelection *selection; @@ -664,7 +657,7 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi } static gboolean -search_func (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer user_data) +search_func (GtkTreeModel *model, gint column __unused, const gchar *key, GtkTreeIter *iter, gpointer user_data __unused) { gchar *cmdline, *cmdline_lower; gchar *key_lower; @@ -734,14 +727,14 @@ settings_changed (GObject *object, GParamSpec *pspec, XtmProcessTreeView *treevi } else { - g_signal_handlers_disconnect_by_func (treeview->model_tree, G_CALLBACK (expand_row), treeview); + g_signal_handlers_disconnect_by_func (treeview->model_tree, (gpointer)G_CALLBACK (expand_row), treeview); } } } static void -expand_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, XtmProcessTreeView *treeview) +expand_row (GtkTreeModel *model __unused, GtkTreePath *path, GtkTreeIter *iter __unused, XtmProcessTreeView *treeview) { gtk_tree_view_expand_row (GTK_TREE_VIEW (treeview), path, FALSE); } diff --git a/src/process-window.c b/src/process-window.c index b079e05..5a65505 100644 --- a/src/process-window.c +++ b/src/process-window.c @@ -81,16 +81,16 @@ static void show_about_dialog (XtmProcessWindow *window); static void filter_entry_icon_pressed_cb (GtkEntry *entry, gint position, - GdkEventButton *event, - gpointer data) + GdkEventButton *event __unused, + gpointer data __unused) { if (position == GTK_ENTRY_ICON_SECONDARY) { gtk_entry_set_text (entry, ""); gtk_widget_grab_focus(GTK_WIDGET(entry)); } } -Window +static Window Select_Window (Display *dpy, int screen) { int status; @@ -137,19 +137,17 @@ Select_Window (Display *dpy, int screen) } static void -xwininfo_clicked_cb (GtkButton *button, gpointer user_data) { +xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) { XtmProcessWindow *window = (XtmProcessWindow *) user_data; Window selected_window; - Display *dpy = NULL; - + Display *dpy; Atom atom_NET_WM_PID; unsigned long _nitems; Atom actual_type; int actual_format; unsigned char *prop; int status; unsigned long bytes_after; - guint pid = 0; dpy = XOpenDisplay (NULL); @@ -172,7 +170,7 @@ xwininfo_clicked_cb (GtkButton *button, gpointer user_data) { _("XGetWindowProperty failed"), _("XGetWindowProperty failed!")); } else { if (_nitems > 0) { - pid = (guint) *((unsigned long*)prop); + memcpy(&pid, prop, sizeof(pid)); xtm_process_tree_view_highlight_pid(XTM_PROCESS_TREE_VIEW (window->treeview), pid); } else { XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO, @@ -272,14 +270,14 @@ xtm_process_window_init (XtmProcessWindow *window) toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "graph-cpu")); window->cpu_monitor = xtm_process_monitor_new (); - xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->cpu_monitor), refresh_rate / 1000.0); + xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->cpu_monitor), refresh_rate / 1000.0f); xtm_process_monitor_set_type (XTM_PROCESS_MONITOR (window->cpu_monitor), 0); gtk_widget_show (window->cpu_monitor); gtk_container_add (GTK_CONTAINER (toolitem), window->cpu_monitor); toolitem = GTK_WIDGET (gtk_builder_get_object (window->builder, "graph-mem")); window->mem_monitor = xtm_process_monitor_new (); - xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->mem_monitor), refresh_rate / 1000.0); + xtm_process_monitor_set_step_size (XTM_PROCESS_MONITOR (window->mem_monitor), refresh_rate / 1000.0f); xtm_process_monitor_set_type (XTM_PROCESS_MONITOR (window->mem_monitor), 1); gtk_widget_show (window->mem_monitor); gtk_container_add (GTK_CONTAINER (toolitem), window->mem_monitor); @@ -393,7 +391,7 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event) gboolean ret = FALSE; if (event->keyval == GDK_KEY_Escape || - (event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK))) { + (event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK))) { emit_delete_event_signal (window, (GdkEvent*) event); ret = TRUE; } @@ -555,7 +553,7 @@ xtm_process_window_get_model (XtmProcessWindow *window) } void -xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str) +xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap __unused, gchar* swap_str) { gchar text[100]; gchar value[4]; diff --git a/src/settings-dialog.c b/src/settings-dialog.c index 46ab437..93f4891 100644 --- a/src/settings-dialog.c +++ b/src/settings-dialog.c @@ -83,7 +83,7 @@ builder_bind_toggle_button (GtkBuilder *builder, gchar *widget_name, XtmSettings static void combobox_changed (GtkComboBox *combobox, XtmSettings *settings) { - guint active = gtk_combo_box_get_active (combobox); + gint active = gtk_combo_box_get_active (combobox); gchar *setting_name = g_object_get_data (G_OBJECT (combobox), "setting-name"); g_object_set (settings, setting_name, active, NULL); } @@ -141,7 +141,7 @@ xtm_settings_dialog_init (XtmSettingsDialog *dialog) g_object_get (dialog->settings, "toolbar-style", &toolbar_style, NULL); g_object_set_data (G_OBJECT (combobox), "setting-name", "toolbar-style"); - gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), toolbar_style); + gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), (gint)toolbar_style); g_signal_connect (combobox, "changed", G_CALLBACK (combobox_changed), dialog->settings); } @@ -189,7 +189,7 @@ xtm_settings_dialog_hide (GtkWidget *widget) gtk_widget_hide (XTM_SETTINGS_DIALOG (widget)->window); gtk_window_move (GTK_WINDOW (XTM_SETTINGS_DIALOG (widget)->window), winx, winy); #if !GTK_CHECK_VERSION(3, 0, 0) - GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE); + GTK_WIDGET_UNSET_FLAGS (widget, (guint)GTK_VISIBLE); #endif } diff --git a/src/settings.c b/src/settings.c index 7c2268e..4fbf99e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -70,7 +70,6 @@ struct _XtmSettings /**/ GValue values[N_PROPS]; }; -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XTM_TYPE_SETTINGS, XtmSettingsPriv)) G_DEFINE_TYPE (XtmSettings, xtm_settings, G_TYPE_OBJECT) static void xtm_settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); @@ -189,7 +188,7 @@ transform_string_to_int (const GValue *src, GValue *dst) static void transform_string_to_uint (const GValue *src, GValue *dst) { - g_value_set_uint (dst, (gint)strtoul (g_value_get_string (src), NULL, 10)); + g_value_set_uint (dst, (guint)strtoul (g_value_get_string (src), NULL, 10)); } static void @@ -345,7 +344,7 @@ xtm_settings_save_settings (XtmSettings *settings) } data = g_key_file_to_data (rc, &length, NULL); - if (!g_file_set_contents (filename, data, length, &error)) + if (!g_file_set_contents (filename, data, (gssize)length, &error)) { g_warning ("Unable to save settings: %s", error->message); g_error_free (error); diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c index 3fc3691..e9fad9d 100644 --- a/src/task-manager-bsd.c +++ b/src/task-manager-bsd.c @@ -54,7 +54,6 @@ gboolean get_task_list (GArray *task_list) struct kinfo_proc2 *kp; #endif Task t; - struct passwd *passwdp; char **args; gchar* buf; int nproc, i; @@ -114,13 +113,14 @@ gboolean get_task_list (GArray *task_list) g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1); /* shamelessly stolen from top/machine.c */ if (!P_ZOMBIE(&p)) { - size = 128; + size = 1024; if ((args = malloc(size)) == NULL) errx(1,"failed to allocate memory for argv structures at %zu", size); bzero(args, size); for (;; size *= 2) { if ((args = realloc(args, size)) == NULL) errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid); + bzero(args, size); mib[0] = CTL_KERN; mib[1] = KERN_PROC_ARGS; mib[2] = t.pid; @@ -141,12 +141,8 @@ gboolean get_task_list (GArray *task_list) free(args); } - t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE)); + t.cpu_user = (100.0f * ((gfloat)p.p_pctcpu / FSCALE)); t.cpu_system = 0.0f; /* TODO ? */ - /* get username from uid */ - passwdp = getpwuid(t.uid); - if(passwdp != NULL && passwdp->pw_name != NULL) - g_strlcpy(t.uid_name, passwdp->pw_name, sizeof t.uid_name); g_array_append_val(task_list, t); } free(kp); @@ -157,7 +153,7 @@ gboolean get_task_list (GArray *task_list) } gboolean -pid_is_sleeping (guint pid) +pid_is_sleeping (gint pid) { int mib[6]; #ifdef __OpenBSD__ diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c index 7247690..5fddee5 100644 --- a/src/task-manager-freebsd.c +++ b/src/task-manager-freebsd.c @@ -28,7 +28,19 @@ #include "task-manager.h" -guint64 +static const gchar ki_stat2state[] = { + ' ', /* - */ + 'R', /* SIDL */ + 'R', /* SRUN */ + 'S', /* SSLEEP */ + 'T', /* SSTOP */ + 'Z', /* SZOMB */ + 'W', /* SWAIT */ + 'L' /* SLOCK */ +}; + + +static guint64 get_mem_by_bytes (const gchar *name) { guint64 buf = 0; @@ -40,14 +52,14 @@ get_mem_by_bytes (const gchar *name) return buf; } -guint64 +static guint64 get_mem_by_pages (const gchar *name) { guint64 res; res = get_mem_by_bytes (name); if (res > 0) - res *= getpagesize (); + res *= (guint64)getpagesize (); return res; } @@ -72,8 +84,8 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_c return FALSE; kvm_getswapinfo (kd, &kswap, 1, 0); - *swap_total = ((guint64)kswap.ksw_total) * getpagesize (); - *swap_free = ((guint64)(kswap.ksw_total - kswap.ksw_used)) * getpagesize (); + *swap_total = (guint64)kswap.ksw_total * (guint64)getpagesize (); + *swap_free = ((guint64)(kswap.ksw_total - kswap.ksw_used)) * (guint64)getpagesize (); kvm_close (kd); } @@ -118,24 +130,21 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) } static gboolean -get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task) +get_task_details (struct kinfo_proc *kp, Task *task) { - struct passwd *pw; - char buf[1024], *p; - size_t bufsz; int i, oid[4]; + char buf[4096], *p; + size_t bufsz; bzero(task, sizeof(Task)); task->pid = kp->ki_pid; task->ppid = kp->ki_ppid; task->cpu_user = 100.0f * ((float)kp->ki_pctcpu / FSCALE); task->cpu_system = 0.0f; task->vsz = kp->ki_size; - task->rss = kp->ki_rssize * getpagesize (); - pw = getpwuid (kp->ki_uid); + task->rss = (guint64)(kp->ki_rssize * getpagesize ()); task->uid = kp->ki_uid; - g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name)); - task->prio = (gushort)kp->ki_nice; + task->prio = (gshort)kp->ki_nice; g_strlcpy (task->name, kp->ki_comm, sizeof(task->name)); oid[0] = CTL_KERN; @@ -174,36 +183,24 @@ get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task) i = 0; switch (kp->ki_stat) { - case SSTOP: - task->state[i] = 'T'; - break; - - case SSLEEP: - if (kp->ki_tdflags & TDF_SINTR) - task->state[i] = kp->ki_slptime >= MAXSLP ? 'I' : 'S'; - else - task->state[i] = 'D'; - break; - - case SRUN: case SIDL: - task->state[i] = 'R'; - break; - + case SRUN: + case SSTOP: + case SZOMB: case SWAIT: - task->state[i] = 'W'; - break; - case SLOCK: - task->state[i] = 'L'; - break; + task->state[i] = ki_stat2state[(size_t)kp->ki_stat]; + break; - case SZOMB: - task->state[i] = 'Z'; - break; + case SSLEEP: + if (kp->ki_tdflags & TDF_SINTR) + task->state[i] = kp->ki_slptime >= MAXSLP ? 'I' : 'S'; + else + task->state[i] = 'D'; + break; default: - task->state[i] = '?'; + task->state[i] = '?'; } i++; if (!(kp->ki_sflag & PS_INMEM)) @@ -226,7 +223,6 @@ get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task) task->state[i++] = '+'; if (kp->ki_flag & P_JAILED) task->state[i++] = 'J'; - task->state[i] = '\0'; return TRUE; } @@ -250,7 +246,7 @@ get_task_list (GArray *task_list) for (i = 0; i < cnt; kp++, i++) { - get_task_details (kd, kp, &task); + get_task_details (kp, &task); g_array_append_val (task_list, task); } @@ -262,7 +258,7 @@ get_task_list (GArray *task_list) } gboolean -pid_is_sleeping (guint pid) +pid_is_sleeping (gint pid) { kvm_t *kd; struct kinfo_proc *kp; diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c index 108453d..86d5502 100644 --- a/src/task-manager-linux.c +++ b/src/task-manager-linux.c @@ -71,8 +71,13 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) static gulong jiffies_user_old = 0, jiffies_system_old = 0, jiffies_total_old = 0; gulong user = 0, user_nice = 0, system = 0, idle = 0; - if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL) + if ((file = fopen (filename, "r")) == NULL) + return FALSE; + if (fgets (buffer, sizeof(buffer), file) == NULL) + { + fclose (file); return FALSE; + } sscanf (buffer, "cpu\t%lu %lu %lu %lu", &user, &user_nice, &system, &idle); @@ -156,7 +161,7 @@ get_task_cmdline (Task *task) } static void -get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffies_system, gfloat *cpu_system) +get_cpu_percent (gint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffies_system, gfloat *cpu_system) { static GHashTable *hash_cpu_user = NULL; static GHashTable *hash_cpu_system = NULL; @@ -168,10 +173,10 @@ get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffie hash_cpu_system = g_hash_table_new (NULL, NULL); } - jiffies_user_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_user, GUINT_TO_POINTER (pid))); - jiffies_system_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_system, GUINT_TO_POINTER (pid))); - g_hash_table_insert (hash_cpu_user, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_user)); - g_hash_table_insert (hash_cpu_system, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_system)); + jiffies_user_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_user, GINT_TO_POINTER (pid))); + jiffies_system_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_system, GINT_TO_POINTER (pid))); + g_hash_table_insert (hash_cpu_user, GINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_user)); + g_hash_table_insert (hash_cpu_system, GINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_system)); if (jiffies_user < jiffies_user_old || jiffies_system < jiffies_system_old) return; @@ -188,15 +193,20 @@ get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffie } static gboolean -get_task_details (guint pid, Task *task) +get_task_details (gint pid, Task *task) { FILE *file; gchar filename[96]; gchar buffer[1024]; snprintf (filename, sizeof(filename), "/proc/%d/stat", pid); - if ((file = fopen (filename, "r")) == NULL || fgets (buffer, sizeof(buffer), file) == NULL) + if ((file = fopen (filename, "r")) == NULL) return FALSE; + if (fgets (buffer, sizeof(buffer), file) == NULL) + { + fclose (file); + return FALSE; + } fclose (file); bzero(task, sizeof(Task)); @@ -284,7 +294,6 @@ get_task_details (guint pid, Task *task) /* Parse the status file: it contains the UIDs */ { - struct passwd *pw; guint dummy; snprintf(filename, sizeof (filename), "/proc/%d/status", pid); @@ -297,9 +306,6 @@ get_task_details (guint pid, Task *task) break; } fclose (file); - - pw = getpwuid (task->uid); - g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name)); } /* Read the full command line */ @@ -314,15 +320,15 @@ get_task_list (GArray *task_list) { GDir *dir; const gchar *name; - guint pid; + gint pid; Task task; if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL) return FALSE; while ((name = g_dir_read_name(dir)) != NULL) { - if ((pid = (guint)g_ascii_strtoull (name, NULL, 0)) > 0) + if ((pid = g_ascii_strtoull (name, NULL, 0)) > 0) { if (get_task_details (pid, &task)) { @@ -339,7 +345,7 @@ get_task_list (GArray *task_list) } gboolean -pid_is_sleeping (guint pid) +pid_is_sleeping (gint pid) { FILE *file; gchar filename[96]; diff --git a/src/task-manager-skel.c b/src/task-manager-skel.c index 76d6487..ca61c29 100644 --- a/src/task-manager-skel.c +++ b/src/task-manager-skel.c @@ -48,20 +48,19 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) } static gboolean -get_task_details (guint pid, Task *task) +get_task_details (gint pid, Task *task) { bzero(task, sizeof(Task)); g_snprintf (task->name, sizeof(task->name), "foo"); g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar"); - g_snprintf (task->uid_name, sizeof(task->uid_name), "baz"); return TRUE; } gboolean get_task_list (GArray *task_list) { - guint pid = 0; + gint pid = 0; Task task; //while (/* read all PIDs */) @@ -81,7 +80,7 @@ get_task_list (GArray *task_list) } gboolean -pid_is_sleeping (guint pid) +pid_is_sleeping (gint pid) { /* Read state of PID @pid... */ diff --git a/src/task-manager-solaris.c b/src/task-manager-solaris.c index 9b733ac..51f1df0 100644 --- a/src/task-manager-solaris.c +++ b/src/task-manager-solaris.c @@ -90,7 +90,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_c } static void -get_cpu_percent (guint pid, gulong ticks_user, gfloat *cpu_user, gulong ticks_system, gfloat *cpu_system) +get_cpu_percent (gint pid, gulong ticks_user, gfloat *cpu_user, gulong ticks_system, gfloat *cpu_system) { static GHashTable *hash_cpu_user = NULL; static GHashTable *hash_cpu_system = NULL; @@ -102,10 +102,10 @@ get_cpu_percent (guint pid, gulong ticks_user, gfloat *cpu_user, gulong ticks_sy hash_cpu_system = g_hash_table_new (NULL, NULL); } - ticks_user_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_user, GUINT_TO_POINTER (pid))); - ticks_system_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_system, GUINT_TO_POINTER (pid))); - g_hash_table_insert (hash_cpu_user, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (ticks_user)); - g_hash_table_insert (hash_cpu_system, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (ticks_system)); + ticks_user_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_user, GINT_TO_POINTER (pid))); + ticks_system_old = GPOINTER_TO_UINT (g_hash_table_lookup (hash_cpu_system, GINT_TO_POINTER (pid))); + g_hash_table_insert (hash_cpu_user, GINT_TO_POINTER (pid), GUINT_TO_POINTER (ticks_user)); + g_hash_table_insert (hash_cpu_system, GINT_TO_POINTER (pid), GUINT_TO_POINTER (ticks_system)); if (ticks_user < ticks_user_old || ticks_system < ticks_system_old) return; @@ -169,11 +169,10 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) } static gboolean -get_task_details (guint pid, Task *task) +get_task_details (gint pid, Task *task) { FILE *file; gchar filename[96]; - struct passwd *pw; psinfo_t process; snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid); @@ -187,17 +186,15 @@ get_task_details (guint pid, Task *task) } bzero(task, sizeof(Task)); - task->pid = (guint)process.pr_pid; - task->ppid = (guint)process.pr_ppid; + task->pid = process.pr_pid; + task->ppid = process.pr_ppid; g_strlcpy (task->name, process.pr_fname, sizeof(task->name)); snprintf (task->cmdline, sizeof(task->cmdline), "%s", process.pr_psargs); snprintf (task->state, sizeof(task->state), "%c", process.pr_lwp.pr_sname); task->vsz = (guint64)process.pr_size * 1024; task->rss = (guint64)process.pr_rssize * 1024; task->prio = (gushort)process.pr_lwp.pr_pri; - pw = getpwuid (process.pr_uid); task->uid = (guint)process.pr_uid; - g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name)); get_cpu_percent (task->pid, (process.pr_time.tv_sec * 1000 + process.pr_time.tv_nsec / 100000), &task->cpu_user, 0, &task->cpu_system); fclose (file); @@ -210,15 +207,15 @@ get_task_list (GArray *task_list) { GDir *dir; const gchar *name; - guint pid; + gint pid; Task task; if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL) return FALSE; while ((name = g_dir_read_name(dir)) != NULL) { - if ((pid = (guint)g_ascii_strtoull (name, NULL, 0)) > 0) + if ((pid = g_ascii_strtoull (name, NULL, 0)) > 0) { if (get_task_details (pid, &task)) g_array_append_val(task_list, task); @@ -233,7 +230,7 @@ get_task_list (GArray *task_list) } gboolean -pid_is_sleeping (guint pid) +pid_is_sleeping (gint pid) { FILE *file; gchar filename[96]; diff --git a/src/task-manager.c b/src/task-manager.c index 1a005ed..5242857 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -55,9 +55,6 @@ struct _XtmTaskManager #endif GtkTreeModel * model; GArray * tasks; - guint owner_uid; - gchar * owner_uid_name; - gchar * hostname; gushort cpu_count; gfloat cpu_user; gfloat cpu_system; @@ -77,7 +74,7 @@ static void model_add_task (XtmTaskManager *manager, Task *task, glong times static void model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timestamp, gboolean update_cmd_line, Task *task); static void model_mark_tree_iter_as_removed (GtkTreeModel *model, GtkTreeIter *iter, glong timestamp); static void model_remove_tree_iter (GtkTreeModel *model, GtkTreeIter *iter); -static gboolean task_list_find_for_pid (GArray *task_list, guint pid, Task **task, guint *idx); +static gboolean task_list_find_for_pid (GArray *task_list, gint pid, Task **task, guint *idx); static glong __current_timestamp (void); @@ -97,8 +94,6 @@ xtm_task_manager_init (XtmTaskManager *manager) manager->app_manager = xtm_app_manager_new (); #endif manager->tasks = g_array_new (FALSE, FALSE, sizeof (Task)); - get_owner_uid (&(manager->owner_uid), &(manager->owner_uid_name)); - manager->hostname = get_hostname (); /* Listen to settings changes and force an update on the whole model */ settings = xtm_settings_get_default (); @@ -113,16 +108,14 @@ xtm_task_manager_finalize (GObject *object) { XtmTaskManager *manager = XTM_TASK_MANAGER (object); g_array_free (manager->tasks, TRUE); - g_free (manager->owner_uid_name); - g_free (manager->hostname); #ifdef HAVE_WNCK g_object_unref (manager->app_manager); #endif g_object_unref (settings); } static void -setting_changed (GObject *object, GParamSpec *pspec, XtmTaskManager *manager) +setting_changed (GObject *object, GParamSpec *pspec __unused, XtmTaskManager *manager __unused) { g_object_get (object, "more-precision", &more_precision, NULL); g_object_get (object, "full-command-line", &full_cmdline, NULL); @@ -166,17 +159,17 @@ model_add_task (XtmTaskManager *manager, Task *task, glong timestamp) { GtkTreeIter iter; GtkTreeModel *model = manager->model; + gchar *uid_name = get_uid_name (task->uid); gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, XTM_PTV_COLUMN_PID, task->pid, XTM_PTV_COLUMN_STATE, task->state, XTM_PTV_COLUMN_UID, task->uid, - XTM_PTV_COLUMN_UID_STR, task->uid_name, - XTM_PTV_COLUMN_BACKGROUND, NULL, - XTM_PTV_COLUMN_FOREGROUND, NULL, + XTM_PTV_COLUMN_UID_STR, uid_name, XTM_PTV_COLUMN_TIMESTAMP, timestamp, -1); + g_free(uid_name); model_update_tree_iter (manager, &iter, timestamp, TRUE, task); } @@ -274,7 +267,7 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest XTM_PTV_COLUMN_VSZ_STR, vsz, XTM_PTV_COLUMN_RSS, task->rss, XTM_PTV_COLUMN_RSS_STR, rss, - XTM_PTV_COLUMN_CPU, task->cpu_user + task->cpu_system, + XTM_PTV_COLUMN_CPU, (task->cpu_user + task->cpu_system), XTM_PTV_COLUMN_CPU_STR, cpu, XTM_PTV_COLUMN_PRIORITY, task->prio, XTM_PTV_COLUMN_BACKGROUND, background, @@ -290,7 +283,7 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest } static gboolean -task_list_find_for_pid (GArray *task_list, guint pid, Task **task, guint *idx) +task_list_find_for_pid (GArray *task_list, gint pid, Task **task, guint *idx) { Task *task_tmp, tkey; tkey.pid = pid; @@ -304,7 +297,7 @@ task_list_find_for_pid (GArray *task_list, guint pid, Task **task, guint *idx) { if (NULL != task_tmp) { - (*idx) = (((size_t)task_tmp - (size_t)task_list->data) / sizeof(Task)); + (*idx) = (guint)(((size_t)task_tmp - (size_t)task_list->data) / sizeof(Task)); } else { @@ -332,20 +325,6 @@ xtm_task_manager_new (GtkTreeModel *model) return manager; } -const gchar * -xtm_task_manager_get_username (XtmTaskManager *manager) -{ - g_return_val_if_fail (XTM_IS_TASK_MANAGER (manager), NULL); - return manager->owner_uid_name; -} - -const gchar * -xtm_task_manager_get_hostname (XtmTaskManager *manager) -{ - g_return_val_if_fail (XTM_IS_TASK_MANAGER (manager), NULL); - return manager->hostname; -} - void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu, guint64 *memory_used, guint64 *memory_total, @@ -416,10 +395,10 @@ xtm_task_manager_update_model (XtmTaskManager *manager) Task *task, *task_new; GtkTreeIter cur_iter = iter; - gtk_tree_model_get (manager->model, &iter, XTM_PTV_COLUMN_CPU_STR, &cpu_str, XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, XTM_PTV_COLUMN_PID, &pid, -1); + valid = gtk_tree_model_iter_next (manager->model, &iter); + gtk_tree_model_get (manager->model, &cur_iter, XTM_PTV_COLUMN_CPU_STR, &cpu_str, XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, XTM_PTV_COLUMN_PID, &pid, -1); found = (g_strcmp0 (cpu_str, "-") == 0); g_free (cpu_str); - valid = gtk_tree_model_iter_next (manager->model, &iter); if (found && (timestamp - old_timestamp) > TIMESTAMP_DELTA) { G_DEBUG_FMT ("Remove old task %d", pid); @@ -467,7 +446,7 @@ xtm_task_manager_update_model (XtmTaskManager *manager) } g_free (color); } - + if (need_update) { model_update_tree_iter (manager, &cur_iter, timestamp, update_cmd_line, task); @@ -495,37 +474,21 @@ xtm_task_manager_update_model (XtmTaskManager *manager) } - -void -get_owner_uid (guint *owner_uid, gchar **owner_uid_name) +gchar * +get_uid_name (guint uid) { - uid_t uid; - struct passwd *pw; - gchar *username = NULL; - - uid = getuid (); - pw = getpwuid (uid); + int error; + struct passwd *pw = NULL, pwd_buf; + char buf[4096]; - username = g_strdup ((pw != NULL) ? pw->pw_name : "nobody"); + bzero(buf, sizeof(buf)); + error = getpwuid_r(uid, &pwd_buf, buf, sizeof(buf), &pw); - *owner_uid = (guint) uid; - *owner_uid_name = username; -} - -gchar * -get_hostname (void) -{ -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 255 -#endif - char hostname[HOST_NAME_MAX]; - if (gethostname (hostname, sizeof(hostname))) - return g_strdup ("(unknown)"); - return g_strdup_printf ("%s", hostname); + return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody")); } gboolean -send_signal_to_pid (guint pid, gint xtm_signal) +send_signal_to_pid (gint pid, gint xtm_signal) { gint sig; gint res; @@ -551,7 +514,7 @@ send_signal_to_pid (guint pid, gint xtm_signal) } gboolean -set_priority_to_pid (guint pid, gint priority) +set_priority_to_pid (gint pid, gint priority) { gint prio; gint res; @@ -582,5 +545,5 @@ set_priority_to_pid (guint pid, gint priority) gint task_pid_compare_fn(gconstpointer a, gconstpointer b) { - return (((Task*)a)->pid - ((Task*)b)->pid); + return (((const Task*)a)->pid - ((const Task*)b)->pid); } diff --git a/src/task-manager.h b/src/task-manager.h index df0e1f3..210f675 100644 --- a/src/task-manager.h +++ b/src/task-manager.h @@ -25,9 +25,8 @@ typedef struct _Task Task; struct _Task { guint uid; - gchar uid_name[256]; - guint pid; - guint ppid; + gint pid; + gint ppid; gchar name[256]; gchar cmdline[1024]; gchar state[16]; @@ -45,7 +44,7 @@ struct _Task gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free); gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system); gboolean get_task_list (GArray *task_list); -gboolean pid_is_sleeping (guint pid); +gboolean pid_is_sleeping (gint pid); /** * GObject class used to update the graphical widgets. @@ -62,8 +61,6 @@ typedef struct _XtmTaskManager XtmTaskManager; GType xtm_task_manager_get_type (void); XtmTaskManager * xtm_task_manager_new (GtkTreeModel *model); -const gchar * xtm_task_manager_get_username (XtmTaskManager *manager); -const gchar * xtm_task_manager_get_hostname (XtmTaskManager *manager); void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu, guint64 *memory_used, guint64 *memory_total, guint64 *swap_used, guint64 *swap_total); @@ -92,13 +89,16 @@ enum XTM_PRIORITY_VERY_HIGH, }; -void get_owner_uid (guint *owner_uid, gchar **owner_uid_name); -gchar * get_hostname (void); -gboolean send_signal_to_pid (guint pid, gint xtm_signal); +gchar * get_uid_name (guint uid); +gboolean send_signal_to_pid (gint pid, gint xtm_signal); gint task_pid_compare_fn (gconstpointer a, gconstpointer b); -gboolean set_priority_to_pid (guint pid, gint priority); +gboolean set_priority_to_pid (gint pid, gint priority); +#ifndef __unused +# define __unused __attribute__((__unused__)) +#endif + #if DEBUG # define G_DEBUG_FMT(fmt, args...) g_debug((fmt), ##args) #else -- libgit2 0.27.0