From 5ff47b847da59c424a9199997d0732f48e11bb42 Mon Sep 17 00:00:00 2001 From: root <root@dgod.(none)> Date: Thu, 5 Jan 2012 15:05:28 +0800 Subject: [PATCH] support to show full cmdline --- src/callbacks.c | 10 ++- src/functions.c | 3 + src/interface.c | 27 ++++++ src/interface.h | 1 + src/main.c | 1 + src/types.h | 3 +- src/xfce-taskmanager-linux.c | 189 ++++++------------------------------------ 69 files changed, 1376 insertions(+), 1227 deletions(-) diff --git a/src/functions.c b/src/functions.c index c47546d..282baa6 100644 --- a/src/functions.c +++ b/src/functions.c @@ -230,6 +230,7 @@ void load_config(void) show_user_tasks = key_file_get_bool(rc_file, group, "show_user_tasks", TRUE); show_root_tasks = key_file_get_bool(rc_file, group, "show_root_tasks", FALSE); show_other_tasks = key_file_get_bool(rc_file, group, "show_other_tasks", FALSE); + show_full_path = key_file_get_bool(rc_file, group, "show_full_path", FALSE); show_cached_as_free = key_file_get_bool(rc_file, group, "show_cached_as_free", TRUE); full_view = key_file_get_bool(rc_file, group, "full_view", TRUE); @@ -244,11 +245,13 @@ void load_config(void) void save_config(void) { FILE* rc_file = fopen( config_file, "w" ); + if(!rc_file) return; fputs( "[General]\n", rc_file ); fprintf( rc_file, "show_user_tasks=%d\n", show_user_tasks); fprintf( rc_file, "show_root_tasks=%d\n", show_root_tasks); fprintf( rc_file, "show_other_tasks=%d\n", show_other_tasks); + fprintf( rc_file, "show_full_path=%d\n", show_full_path); fprintf( rc_file, "show_cached_as_free=%d\n", show_cached_as_free); diff --git a/src/interface.c b/src/interface.c index 76c41e8..91d4fc6 100644 --- a/src/interface.c +++ b/src/interface.c @@ -174,6 +174,7 @@ void create_list_store(void) column = gtk_tree_view_column_new_with_attributes(_("Command"), cell_renderer, "text", COLUMN_NAME, NULL); gtk_tree_view_column_set_resizable(column, TRUE); + gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_sort_column_id(column, COLUMN_NAME); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list_store), COLUMN_NAME, compare_string_list_item, (void *)COLUMN_NAME, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); @@ -310,6 +311,7 @@ GtkWidget* create_mainmenu (void) GtkWidget *show_root_tasks1; GtkWidget *show_other_tasks1; GtkWidget *show_cached_as_free1; + GtkWidget *show_full_path1; GtkWidget *separator1; GtkAccelGroup *accel_group; @@ -332,6 +334,11 @@ GtkWidget* create_mainmenu (void) gtk_widget_show (show_other_tasks1); gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_other_tasks1); + show_full_path1 = gtk_check_menu_item_new_with_mnemonic (_("Show full cmdline")); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_full_path1), show_full_path); + gtk_widget_show (show_full_path1); + gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_full_path1); + show_cached_as_free1 = gtk_check_menu_item_new_with_mnemonic (_("Show memory used by cache as free")); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_cached_as_free1), show_cached_as_free); gtk_widget_show (show_cached_as_free1); @@ -349,6 +356,7 @@ GtkWidget* create_mainmenu (void) g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)own_uid); g_signal_connect ((gpointer) show_root_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)0); g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-1); + g_signal_connect ((gpointer) show_full_path1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-2); g_signal_connect ((gpointer) show_cached_as_free1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0); gtk_menu_set_accel_group (GTK_MENU (mainmenu), accel_group); @@ -573,6 +581,25 @@ void change_task_view(void) refresh_task_list(); } +void change_full_path(void) +{ + gint i; + GArray *new_task_list; + + /* gets the new task list */ + new_task_list = (GArray*) get_task_list(); + + /* check if task is new and marks the task that its checked*/ + for(i = 0; i < task_array->len; i++) + { + struct task *tmp = &g_array_index(task_array, struct task, i); + struct task *new_tmp = &g_array_index(new_task_list, struct task, i); + g_strlcpy(tmp->name, new_tmp->name, 255); + refresh_list_item(i); + } + + g_array_free(new_task_list, TRUE); +} void apply_prefs() { diff --git a/src/interface.h b/src/interface.h index 308178f..ba67bf1 100644 --- a/src/interface.h +++ b/src/interface.h @@ -83,5 +83,6 @@ void remove_list_item(gint i); void refresh_list_item(gint i); void change_task_view(void); +void change_full_path(void); #endif diff --git a/src/main.c b/src/main.c index 2fbe20b..0421387 100644 --- a/src/main.c +++ b/src/main.c @@ -45,6 +45,7 @@ gchar *config_file; gboolean show_user_tasks; gboolean show_root_tasks; gboolean show_other_tasks; +gboolean show_full_path; gboolean show_cached_as_free; /* Show memory used Cache as free memory */ diff --git a/src/types.h b/src/types.h index 7a9e812..a28f78c 100644 --- a/src/types.h +++ b/src/types.h @@ -30,7 +30,7 @@ struct task gint ppid; gint uid; gchar uname[64]; - gchar name[64]; + gchar name[255]; gchar state[16]; gint size; gint rss; @@ -68,6 +68,7 @@ extern gchar *config_file; extern gboolean show_user_tasks; extern gboolean show_root_tasks; extern gboolean show_other_tasks; +extern gboolean show_full_path; extern gboolean show_cached_as_free; /* Show memory used Cache as free memory */ diff --git a/src/xfce-taskmanager-linux.c b/src/xfce-taskmanager-linux.c index 858ea30..9941ebb 100644 --- a/src/xfce-taskmanager-linux.c +++ b/src/xfce-taskmanager-linux.c @@ -30,7 +30,6 @@ #include "xfce-taskmanager-linux.h" -#if 1 void get_task_details(gint pid,struct task *task) { int fd; @@ -67,7 +66,33 @@ void get_task_details(gint pid,struct task *task) p=strchr(buf,'(');p++; for(len=0;*p!=')';len++) task->name[len]=*p++; task->name[len]=0;p++; - if(len>=15) + if(show_full_path) + { + FILE *fp; + sprintf(line,"/proc/%d/cmdline",pid); + fp=fopen(line,"r"); + if(fp) + { + size_t size; + size=fread(task->name,1,sizeof(task->name)-1,fp); + if(size>0) + { + int i; + task->name[size]=0; + for(i=0;i<size;i++) + { + if(task->name[i]=='\0') + { + if(task->name[i+1]=='\n') + break; + task->name[i]=' '; + } + } + } + fclose(fp); + } + } + else if(len>=15) { FILE *fp; sprintf(line,"/proc/%d/cmdline",pid); @@ -121,165 +146,6 @@ void get_task_details(gint pid,struct task *task) } } -#else - -struct task get_task_details(gint pid) -{ - FILE *task_file; - FILE *cmdline_file; - gchar dummy[255]; - gint idummy; - gchar buffer_status[255]; - struct task task; - struct passwd *passwdp; - struct stat status; - gchar filename[255]; - gchar cmdline_filename[255]; - - sprintf(filename, "/proc/%i/stat", pid); - sprintf(cmdline_filename, "/proc/%i/cmdline", pid); - - stat(filename, &status); - - task.pid = -1; - task.checked = FALSE; - - if((task_file = fopen(filename,"r")) != NULL) - { - while(fgets(buffer_status, sizeof(buffer_status), task_file) != NULL) - { - gint utime = 0; - gint stime = 0; - - sscanf(buffer_status, "%i (%255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %i %i %i %i %i %i %i %i %i %i %i %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s", - &task.pid, // processid - task.name, // processname - task.state, // processstate - &task.ppid, // parentid - &idummy, // processs groupid - - &idummy, // session id - &idummy, // tty id - &idummy, // tpgid: The process group ID of the process running on tty of the process - dummy, // flags - dummy, // minflt minor faults the process has maid - - dummy, // cminflt - dummy, // majflt - dummy, // cmajflt - &utime, // utime the number of jiffies that this process has scheduled in user mode - &stime, // stime " kernel mode - - &idummy, // cutime " waited for children in user - &idummy, // cstime " kernel mode - &idummy, // priority (nice value + fifteen) - &task.prio, // nice range from 19 to -19 /* my change */ - &idummy, // hardcoded 0 - - &idummy, // itrealvalue time in jiffies to next SIGALRM send to this process - &idummy, // starttime jiffies the process startet after system boot - &task.size, // vsize in bytes - &task.rss, // rss - dummy, // rlim limit in bytes for rss - - dummy, // startcode - dummy, // endcode - &idummy, // startstack - dummy, // kstkesp value of esp (stack pointer) - dummy, // kstkeip value of EIP (instruction pointer) - - dummy, // signal. bitmap of pending signals - dummy, // blocked: bitmap of blocked signals - dummy, // sigignore: bitmap of ignored signals - dummy, // sigcatch: bitmap of catched signals - dummy, // wchan - - dummy, // nswap - dummy, // cnswap - dummy, // exit_signal - &idummy, // CPU number last executed on - dummy, - - dummy - ); - task.time = stime + utime; - task.old_time = task.time; - task.time_percentage = 0; - task.size = task.size / 1024; - } - task.uid = status.st_uid; - passwdp = getpwuid(task.uid); - if(passwdp != NULL && passwdp->pw_name != NULL) - g_strlcpy(task.uname, passwdp->pw_name, sizeof task.uname); - } - - - if(task_file != NULL) - fclose(task_file); - - if((cmdline_file = fopen(cmdline_filename,"r")) != NULL) - { - gchar dummy[255]; - strcpy(dummy, ""); - fscanf(cmdline_file, "%255s", dummy); - if(strcmp(dummy, "") != 0) - { - if(g_strrstr(dummy,"/") != NULL) - g_strlcpy(task.name, g_strrstr(dummy,"/")+1, 255); - else - g_strlcpy(task.name, dummy, 255); - - // workaround for cmd-line entries with leading "-" - if(g_str_has_prefix(task.name, "-")) - sscanf(task.name, "-%255s", task.name); - } - } - - if(cmdline_file != NULL) - fclose(cmdline_file); - - if(g_str_has_suffix(task.name, ")")) - *g_strrstr(task.name, ")") = '\0'; - - return task; -} -#endif - -#if 0 -GArray *get_task_list(void) -{ - DIR *dir; - struct dirent *dir_entry; - GArray *task_list; - int count=0; - - if((dir = opendir("/proc/")) == NULL) - { - fprintf(stderr, "Error: couldn't load the /proc directory\n"); - return NULL; - } - - task_list = g_array_sized_new (FALSE, FALSE, sizeof (struct task), 128); - - while((dir_entry = readdir(dir)) != NULL) - { - if(atoi(dir_entry->d_name) != 0) - { - struct task task; - get_task_details(atoi(dir_entry->d_name),&task); - if(task.pid != -1 && task.size>0) // don't show error or kenerl threads - { - g_array_append_val(task_list, task); - count++; - } - } - } - - closedir(dir); - - return task_list; -} -#else static int proc_filter(const struct dirent *d) { int c=d->d_name[0]; @@ -314,7 +180,6 @@ GArray *get_task_list(void) free(namelist); return task_list; } -#endif gboolean get_cpu_usage_from_proc(system_status *sys_stat) { -- 1.7.4.1