~ubuntu-branches/ubuntu/saucy/htop/saucy-proposed

« back to all changes in this revision

Viewing changes to ProcessList.c

  • Committer: Package Import Robot
  • Author(s): Eugene V. Lyubimkin
  • Date: 2012-02-19 10:24:46 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20120219102446-3uor37shuh5qch7n
Tags: 1.0.1-1
* New upstream release.
  - Don't crash when trying to kill already finished process.
    (Closes: #652563, 657675)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
in the source distribution for its full text.
6
6
*/
7
7
 
8
 
#ifndef CONFIG_H
9
 
#define CONFIG_H
10
 
#include "config.h"
11
 
#endif
12
 
 
13
8
#include "ProcessList.h"
14
 
#include "Process.h"
15
 
#include "Vector.h"
16
 
#include "UsersTable.h"
17
 
#include "Hashtable.h"
 
9
 
 
10
#include "CRT.h"
18
11
#include "String.h"
19
12
 
20
 
#include <sys/types.h>
 
13
#include <sys/time.h>
 
14
#include <sys/utsname.h>
21
15
#include <sys/stat.h>
22
16
#include <unistd.h>
23
17
#include <dirent.h>
25
19
#include <stdio.h>
26
20
#include <signal.h>
27
21
#include <stdbool.h>
28
 
#include <sys/utsname.h>
29
22
#include <stdarg.h>
30
23
#include <math.h>
31
 
 
32
 
#include "debug.h"
 
24
#include <string.h>
 
25
#include <time.h>
33
26
#include <assert.h>
34
27
 
35
28
/*{
 
29
#include "Vector.h"
 
30
#include "Hashtable.h"
 
31
#include "UsersTable.h"
 
32
#include "Panel.h"
 
33
#include "Process.h"
 
34
#include <sys/types.h>
36
35
 
37
36
#ifndef PROCDIR
38
37
#define PROCDIR "/proc"
109
108
   Hashtable* processTable;
110
109
   UsersTable* usersTable;
111
110
 
 
111
   Panel* panel;
 
112
   int following;
 
113
   bool userOnly;
 
114
   uid_t userId;
 
115
   bool filtering;
 
116
   const char* incFilter;
 
117
 
112
118
   int cpuCount;
113
119
   int totalTasks;
114
120
   int userlandThreads;
243
249
   free(this);
244
250
}
245
251
 
 
252
void ProcessList_setPanel(ProcessList* this, Panel* panel) {
 
253
   this->panel = panel;
 
254
}
 
255
 
246
256
void ProcessList_invertSortOrder(ProcessList* this) {
247
257
   if (this->direction == 1)
248
258
      this->direction = -1;
605
615
   command[amtRead] = '\0';
606
616
   fclose(file);
607
617
   free(process->comm);
608
 
   process->comm = String_copy(command);
 
618
   process->comm = strdup(command);
609
619
   return true;
610
620
}
611
621
 
698
708
 
699
709
      if (process->state == 'Z') {
700
710
         free(process->comm);
701
 
         process->comm = String_copy(command);
 
711
         process->comm = strdup(command);
702
712
      } else if (Process_isThread(process)) {
703
713
         if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
704
714
            free(process->comm);
705
 
            process->comm = String_copy(command);
 
715
            process->comm = strdup(command);
706
716
         } else if (this->showingThreadNames) {
707
717
            if (! ProcessList_readCmdlineFile(process, dirname, name))
708
718
               goto errorReadingProcess;
888
898
      process->showChildren = true;
889
899
   }
890
900
}
 
901
 
 
902
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, bool userOnly, uid_t userId, bool filtering, const char* incFilter) {
 
903
   if (!flags) {
 
904
      following = this->following;
 
905
      userOnly = this->userOnly;
 
906
      userId = this->userId;
 
907
      filtering = this->filtering;
 
908
      incFilter = this->incFilter;
 
909
   } else {
 
910
      this->following = following;
 
911
      this->userOnly = userOnly;
 
912
      this->userId = userId;
 
913
      this->filtering = filtering;
 
914
      this->incFilter = incFilter;
 
915
   }
 
916
 
 
917
   int currPos = Panel_getSelectedIndex(this->panel);
 
918
   pid_t currPid = following ? following : 0;
 
919
   int currScrollV = this->panel->scrollV;
 
920
 
 
921
   Panel_prune(this->panel);
 
922
   int size = ProcessList_size(this);
 
923
   int idx = 0;
 
924
   for (int i = 0; i < size; i++) {
 
925
      bool hidden = false;
 
926
      Process* p = ProcessList_get(this, i);
 
927
 
 
928
      if ( (!p->show)
 
929
         || (userOnly && (p->st_uid != userId))
 
930
         || (filtering && !(String_contains_i(p->comm, incFilter))) )
 
931
         hidden = true;
 
932
 
 
933
      if (!hidden) {
 
934
         Panel_set(this->panel, idx, (Object*)p);
 
935
         if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) {
 
936
            Panel_setSelected(this->panel, idx);
 
937
            this->panel->scrollV = currScrollV;
 
938
         }
 
939
         idx++;
 
940
      }
 
941
   }
 
942
}