Update memory sizes to 64 bit and fix compilation warnings.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Mon, 15 Sep 2014 21:32:42 +0000 (00:32 +0300)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Mon, 15 Sep 2014 21:46:16 +0000 (00:46 +0300)
src/callbacks.c
src/callbacks.h
src/functions.c
src/interface.c
src/interface.h
src/main.c
src/types.h
src/xfce-taskmanager-linux.c

index ce27ca7..dfaff57 100644 (file)
@@ -110,9 +110,11 @@ void handle_prio_menu(GtkWidget *widget, gchar *prio)
     }
 }
 
-void on_show_tasks_toggled (GtkMenuItem *menuitem, gint uid)
+void on_show_tasks_toggled (GtkMenuItem *menuitem, gpointer data)
 {
-    if(uid == own_uid)
+    gssize uid = (gssize)data;
+
+    if(uid == (gssize)own_uid)
         show_user_tasks = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem));
     else if(uid == 0)
         show_root_tasks = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem));
@@ -128,7 +130,7 @@ void on_show_tasks_toggled (GtkMenuItem *menuitem, gint uid)
     change_task_view();
 }
 
-void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gint uid)
+void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gpointer data)
 {
     show_cached_as_free = !show_cached_as_free;
     change_task_view();
index 323b569..cfc3177 100644 (file)
@@ -38,8 +38,8 @@ void on_button3_toggled_event(GtkButton *button, GdkEventButton *event);
 gboolean on_treeview1_button_press_event(GtkButton *button, GdkEventButton *event);
 void handle_task_menu(GtkWidget *widget, gchar *signal);
 void handle_prio_menu(GtkWidget *widget, gchar *prio);
-void on_show_tasks_toggled (GtkMenuItem *menuitem, gint uid);
-void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gint uid);
+void on_show_tasks_toggled (GtkMenuItem *menuitem, gpointer uid);
+void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gpointer uid);
 
 void on_quit(void);
 
index 4272571..76b32bb 100644 (file)
 
 #include "functions.h"
 
-extern guint refresh_interval;
+extern gint refresh_interval;
 
 static system_status *sys_stat =NULL;
 
 gboolean refresh_task_list(void)
 {
-    gint i, j;
+    guint i, j;
     GArray *new_task_list;
     gdouble cpu_usage;
     guint num_cpus;
@@ -70,11 +70,11 @@ gboolean refresh_task_list(void)
 
                 new_tmp->time_percentage = (gfloat)(tmp->time - tmp->old_time) * (gfloat)(1000.0f / (refresh_interval * 1000 * num_cpus));
                 if(
-                    (gint)tmp->ppid != (gint)new_tmp->ppid ||
+                    tmp->ppid != new_tmp->ppid ||
                     tmp->state[0]!=new_tmp->state[0] ||
-                    (unsigned int)tmp->size != (unsigned int)new_tmp->size ||
-                    (unsigned int)tmp->rss != (unsigned int)new_tmp->rss ||
-                    (unsigned int)tmp->time_percentage != (unsigned int)new_tmp->time_percentage ||
+                    tmp->size != new_tmp->size ||
+                    tmp->rss != new_tmp->rss ||
+                    tmp->time_percentage != new_tmp->time_percentage ||
                     tmp->prio != new_tmp->prio
                  )
                 {
@@ -109,7 +109,7 @@ gboolean refresh_task_list(void)
 
         if(!tmp->checked)
         {
-            remove_list_item((gint)tmp->pid);
+            remove_list_item(tmp->pid);
             g_array_remove_index(task_array, i);
             tasks--;
         }
@@ -171,7 +171,7 @@ gdouble get_cpu_usage(system_status *sys_stat)
 
     if ( get_cpu_usage_from_proc( sys_stat ) == FALSE )
     {
-        gint i = 0;
+        guint i = 0;
 
         for(i = 0; i < task_array->len; i++)
         {
@@ -279,7 +279,7 @@ static int check_config(void)
                res=1;
                goto out;
        }
-       gtk_window_get_size(GTK_WINDOW (main_window), (gint *) &win_width, (gint *) &win_height);
+       gtk_window_get_size(GTK_WINDOW (main_window), &win_width, &win_height);
        if(win_width != key_file_get_int(rc_file, group, "win_width", 500 ))
        {
                res=1;
@@ -322,7 +322,7 @@ void save_config(void)
 
     fprintf( rc_file, "full_view=%d\n", full_view);
 
-    gtk_window_get_size(GTK_WINDOW (main_window), (gint *) &win_width, (gint *) &win_height);
+    gtk_window_get_size(GTK_WINDOW (main_window), &win_width, &win_height);
 
     fprintf( rc_file, "win_width=%d\n", win_width);
     fprintf( rc_file, "win_height=%d\n", win_height);
index 1f98351..d56cbdf 100644 (file)
@@ -34,7 +34,7 @@
   g_object_set_data (G_OBJECT (component), name, widget)
 
 void show_preferences(void);
-extern guint refresh_interval;
+extern gint refresh_interval;
 extern guint rID;
 GtkWidget *refresh_spin;
 
@@ -429,7 +429,7 @@ void change_list_store_view(void)
         gtk_tree_view_column_set_visible (gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), COLUMN_UNAME), TRUE);
 }
 
-void fill_list_item(gint i, GtkTreeIter *iter)
+void fill_list_item(guint i, GtkTreeIter *iter)
 {
     if(iter != NULL)
     {
@@ -437,17 +437,17 @@ void fill_list_item(gint i, GtkTreeIter *iter)
         struct task *task = &g_array_index(task_array, struct task, i);
 
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_NAME, task->name, -1);
-        sprintf(buf,"%d",task->pid);
+        sprintf(buf,"%u",(guint)task->pid);
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PID, buf, -1);
-        sprintf(buf,"%d",task->ppid);
+        sprintf(buf,"%u",(guint)task->ppid);
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PPID, buf, -1);
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_STATE, task->state, -1);
 
         /* size */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, ((guint64)task->size)*1024), -1);
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, (task->size)*1024), -1);
 
         /* rss */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, ((guint64)task->rss)*1024), -1);
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, (task->rss)*1024), -1);
 
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_UNAME, task->uname, -1);
         sprintf(buf,"%0d%%", (guint)task->time_percentage);
@@ -457,7 +457,7 @@ void fill_list_item(gint i, GtkTreeIter *iter)
     }
 }
 
-void add_new_list_item(gint i)
+void add_new_list_item(guint i)
 {
         GtkTreeIter iter;
         gtk_tree_store_append(GTK_TREE_STORE(list_store), &iter, NULL);
@@ -465,7 +465,7 @@ void add_new_list_item(gint i)
         fill_list_item(i, &iter);
 }
 
-void refresh_list_item(gint i)
+void refresh_list_item(guint i)
 {
     GtkTreeIter iter;
     gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
@@ -475,7 +475,7 @@ void refresh_list_item(gint i)
         gchar *str_data = NULL;
         gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
 
-        if(str_data && task->pid == atoi(str_data))
+        if(str_data && task->pid == atol(str_data))
         {
             g_free(str_data);
             fill_list_item(i, &iter);
@@ -487,7 +487,7 @@ void refresh_list_item(gint i)
     }
 }
 
-void remove_list_item(gint pid)
+void remove_list_item(pid_t pid)
 {
     GtkTreeIter iter;
     gboolean valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
@@ -497,7 +497,7 @@ void remove_list_item(gint pid)
         gchar *str_data = NULL;
         gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, COLUMN_PID, &str_data, -1);
 
-        if(str_data && pid == atoi(str_data))
+        if(str_data && pid == atol(str_data))
         {
             g_free(str_data);
             gtk_tree_store_remove(GTK_TREE_STORE(list_store), &iter);
@@ -596,7 +596,7 @@ void change_task_view(void)
 
 void change_full_path(void)
 {
-    gint i;
+    guint i;
     GArray *new_task_list;
 
     /* gets the new task list */
index ba67bf1..e5be610 100644 (file)
@@ -73,14 +73,14 @@ GtkWidget *create_prio_submenu(void);
 
 void show_about_dialog(void);
 
-void fill_list_item(gint i, GtkTreeIter *iter);
-void add_new_list_item(gint i);
+void fill_list_item(guint i, GtkTreeIter *iter);
+void add_new_list_item(guint i);
 gint compare_list_item(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data);
 gint compare_int_list_item(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data);
 gint compare_size_list_item(GtkTreeModel *model, GtkTreeIter *iter1, GtkTreeIter *iter2, gpointer column);
 gint compare_string_list_item(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data);
-void remove_list_item(gint i);
-void refresh_list_item(gint i);
+void remove_list_item(pid_t i);
+void refresh_list_item(guint i);
 
 void change_task_view(void);
 void change_full_path(void);
index 0421387..9f8815f 100644 (file)
@@ -38,7 +38,7 @@ GtkWidget *main_window;
 
 GArray *task_array;
 gint tasks;
-gint own_uid;
+uid_t own_uid;
 
 gchar *config_file;
 
@@ -52,9 +52,9 @@ gboolean show_cached_as_free; /* Show memory used Cache as free memory */
 gboolean full_view;
 
 
-guint win_width;
-guint win_height;
-guint refresh_interval;
+gint win_width;
+gint win_height;
+gint refresh_interval;
 guint rID;
 
 int PAGE_SIZE;
index fa08c0e..c622380 100644 (file)
 
 struct task
 {
-    gint pid;
-    gint ppid;
-    gint uid;
+    pid_t pid;
+    pid_t ppid;
+    uid_t uid;
     gchar uname[64];
     gchar name[255];
     gchar state[16];
-    glong size;
-    glong rss;
+    guint64 size;
+    guint64 rss;
     gboolean checked;
     gint time;
     gint old_time;
@@ -61,7 +61,7 @@ extern GtkWidget *main_window;
 
 extern GArray *task_array;
 extern gint tasks;
-extern gint own_uid;
+extern uid_t own_uid;
 
 extern gchar *config_file;
 
@@ -74,8 +74,8 @@ extern gboolean show_cached_as_free; /* Show memory used Cache as free memory */
 
 extern gboolean full_view;
 
-extern guint win_width;
-extern guint win_height;
+extern gint win_width;
+extern gint win_height;
 
 const gchar *custom_signal_0;
 const gchar *custom_signal_1;
index 497d84a..1823f9f 100644 (file)
 #include "xfce-taskmanager-linux.h"
 
 
-void get_task_details(gint pid,struct task *task)
+void get_task_details(pid_t pid,struct task *task)
 {
        int fd;
        gchar line[256];
+       gulong t_size, t_rss;
+       ssize_t ret;
 
        task->pid=-1;
        task->checked=FALSE;
        task->size=0;
 
-       sprintf(line,"/proc/%d/statm",pid);
+       sprintf(line,"/proc/%d/statm",(int)pid);
         fd=open(line,O_RDONLY);
         if(fd==-1) return;
-        read(fd,line,256);
-       sscanf(line,"%ld %ld",&task->size,&task->rss);
+        ret = read(fd,line,255);
+        if (ret <= 0)
+        {
+            close(fd);
+            return;
+        }
+        line[ret] = '\0';
+       sscanf(line,"%lu %lu",&t_size,&t_rss);
        close(fd);
-       if(!task->size) return;
-       task->size*=PAGE_SIZE;
-       task->rss*=PAGE_SIZE;
+       if(t_size == 0) return;
+       task->size = t_size * PAGE_SIZE;
+       task->rss = t_rss * PAGE_SIZE;
 
-       sprintf(line,"/proc/%d/stat",pid);
+       sprintf(line,"/proc/%d/stat",(gint)pid);
        fd=open(line,O_RDONLY);
        if(fd!=-1)
        {
                struct passwd *passwdp;
                struct stat st;
                char buf[2048],*p;
-               ssize_t ret;
                size_t len;
                gint utime = 0;
                gint stime = 0;
+               glong ppid;
 
                task->pid=pid;
                
@@ -82,7 +90,7 @@ void get_task_details(gint pid,struct task *task)
                if(show_full_path)
                {
                        FILE *fp;
-                       sprintf(line,"/proc/%d/cmdline",pid);
+                       sprintf(line,"/proc/%d/cmdline",(int)pid);
                        fp=fopen(line,"r");
                        if(fp)
                        {
@@ -90,15 +98,15 @@ void get_task_details(gint pid,struct task *task)
                                size=fread(task->name,1,sizeof(task->name)-1,fp);
                                if(size>0)
                                {
-                                       int i;
+                                       size_t x;
                                        task->name[size]=0;
-                                       for(i=0;i<size;i++)
+                                       for(x=0;x<size;x++)
                                        {
-                                               if(task->name[i]=='\0')
+                                               if(task->name[x]=='\0')
                                                {
-                                                       if(task->name[i+1]=='\n')
+                                                       if(task->name[x+1]=='\n')
                                                                break;
-                                                       task->name[i]=' ';
+                                                       task->name[x]=' ';
                                                }
                                        }
                                }
@@ -108,24 +116,27 @@ void get_task_details(gint pid,struct task *task)
                else if(len>=15)
                {
                        FILE *fp;
-                       sprintf(line,"/proc/%d/cmdline",pid);
+                       sprintf(line,"/proc/%d/cmdline",(int)pid);
                        fp=fopen(line,"r");
                        if(fp)
                        {
                                char *p;
-                               fscanf(fp, "%255s", line);
+                               if (fscanf(fp, "%255s", line) > 0)
+                               {
+                                   p=strrchr(line,'/');
+                                   if(p != NULL)
+                                       strncpy(task->name, p+1, sizeof(task->name)-1);
+                                   else
+                                       strncpy(task->name, line, sizeof(task->name)-1);
+                                   task->name[sizeof(task->name)-1] = '\0';
+                               }
                                fclose(fp);
-                               p=strrchr(line,'/');
-                               if(p != NULL)
-                                       strcpy(task->name, p+1);
-                               else
-                                       strcpy(task->name, line);
                        }
                }
 
-               sscanf(p, "%1s %i %s %s %s %s %s %s %s %s %s %i %i %s %s %s %i",
+               sscanf(p, "%1s %ld %s %s %s %s %s %s %s %s %s %i %i %s %s %s %i",
                         task->state, // processstate
-                        &task->ppid, // parentid
+                        &ppid,     // parentid
                         line,      // processs groupid
 
                         line,      // session id
@@ -148,6 +159,7 @@ void get_task_details(gint pid,struct task *task)
                task->time = stime + utime;
                task->old_time = task->time;
                task->time_percentage = 0;
+               task->ppid = ppid;
 
                fstat(fd,&st);
                task->uid=st.st_uid;
@@ -180,11 +192,11 @@ GArray *get_task_list(void)
     g_array_set_size(task_list,n);
     while(n--)
     {
-        int pid=atoi(namelist[n]->d_name);
+        pid_t pid = atol(namelist[n]->d_name);
         struct task *task=&g_array_index(task_list, struct task, count);
        free(namelist[n]);
         get_task_details(pid,task);
-        if(task->pid != -1 && task->size>0)    // don't show error or kenerl threads
+        if(task->pid > 0 && task->size > 0)    // don't show error or kenerl threads
         {
             count++;
         }