Check-in [d1232b819a]
Overview
Comment:Applied patch to freecolor from T. Bishop, fixing out of bounds array indexing and larger memory configurations. Freecolor really needs a rewrite.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d1232b819ab3cf80b9e483e97fd6de2a3a0d172d
User & Date: rkeene on 2009-05-31 02:45:28
Other Links: manifest | tags
Context
2009-05-31
02:46
Freecolor 0.8.8 check-in: 1001b63010 user: rkeene tags: trunk, 0.8.8
02:45
Applied patch to freecolor from T. Bishop, fixing out of bounds array indexing and larger memory configurations. Freecolor really needs a rewrite. check-in: d1232b819a user: rkeene tags: trunk
2005-10-18
15:10
Updated freecolor to work with libstatgrab 0.10.0 or greater. freecolor 0.8.7 check-in: 1022f63a36 user: rkeene tags: trunk, 0.8.7
Changes

Modified freecolor.c from [7a3654fcb8] to [db1aeb86d8].

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#define HEADERLEN 14
#define VERSION "0.8.7"


extern char *optarg;
extern int optind, opterr, optopt;

void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN],int usefull) {
  char percentone[BARLEN], percenttwo[BARLEN], remain[BARLEN];
  unsigned int numberofmarks, numofmarkstwo, remainnum;
  numberofmarks=(int) ((float) (BARLEN*(percent/100)));
  if (!usefull) numofmarkstwo=(int) ((float) (BARLEN*(secondper/100))); else numofmarkstwo=(BARLEN-numberofmarks);
  remainnum=BARLEN-(numberofmarks+numofmarkstwo);
  memset(percentone, '#', numberofmarks);
  memset(percenttwo, '%', numofmarkstwo);
  memset(remain, '.', remainnum);
  percentone[numberofmarks]=0;
  percenttwo[numofmarkstwo]=0;
  remain[remainnum]=0;
  sprintf(marks,"%s\033[1;31m%s\033[1;37m%s",percentone, percenttwo, remain);
  return;
}

#ifndef HAVE_LIBSTATGRAB
/*
  Extracted alot from sysinfo.c (part of the procps package?) by
  Michael K. Johnson <johnsonm@redhat.com>
................................................................................
  return(results);
}
#endif

int main(int argc, char *argv[]) {
  float percentram, percentswap, percentbuffer, percentused, percentfree;
  float ramfree, ramtotal, swapfree, swaptotal, doloop=0, cachedbuffer, totaltotal;
  char realbarchart[BARLEN+HEADERLEN], swapbarchart[BARLEN+HEADERLEN], totalbarchart[BARLEN+HEADERLEN];
  int i, divisor=1024, dototals=0, doold=0, linestoup=2;
  unsigned long meminfo_cached;
#ifndef HAVE_LIBSTATGRAB
  struct sysinfo sinfo;

  meminfo_cached=get_meminfo("Cached:");
#else
  sg_mem_stats *mem_stats=NULL;
  sg_swap_stats *swap_stats=NULL;
................................................................................
    percentfree=(float) (((sinfo.freeram+sinfo.freeswap+meminfo_cached+sinfo.bufferram)/totaltotal)*100);
    percentused=(int) (100-((int) percentfree));
    if (!(swaptotal==0)) { percentswap=(float) ((swapfree/swaptotal)*100); } else { percentswap=0; }
    bargraph(percentswap,0,swapbarchart,0);
    bargraph(percentram,percentbuffer,realbarchart,0);
    bargraph((int) percentfree,(int) percentused,totalbarchart,1);
    if (!doold) {
      printf("Physical  : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%i/%i)\n", realbarchart ,(int) (percentram+percentbuffer), (int) (ramfree+cachedbuffer)/divisor, (int) ramtotal/divisor);
      printf("Swap      : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%i/%i)\n",swapbarchart ,(int) percentswap,(int) swapfree/divisor, (int) swaptotal/divisor);
      if (dototals) 
      printf("Total     : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%i=%i+%i)\n", totalbarchart, (int) (sinfo.totalram+sinfo.totalswap)/divisor,(int) ((sinfo.freeram+sinfo.freeswap)/divisor), (int) ((totaltotal-((sinfo.freeram+sinfo.freeswap+cachedbuffer)))/divisor));
    } else {
      printf("             total       used       free     shared    buffers     cached\n");
      printf("Mem:  %12lu %10lu %10lu %10lu %10lu %10lu\n",(sinfo.totalram/divisor), (sinfo.totalram-sinfo.freeram)/divisor, (sinfo.freeram/divisor), (sinfo.sharedram/divisor), (sinfo.bufferram/divisor), (((unsigned long) cachedbuffer)/divisor)); 
      printf("Swap: %12lu %10lu %10lu\n",(sinfo.totalswap/divisor), ((sinfo.totalswap-sinfo.freeswap)/divisor), (sinfo.freeswap/divisor));
      if (dototals) printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",(long) totaltotal/divisor,(((long) totaltotal)-((sinfo.freeram+sinfo.freeswap)))/divisor,(sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer))/divisor);
    }
    if (doloop==0) { return(0); } else { usleep(doloop*1000000); printf("\033[%iA",linestoup); }
  }
  return(0);
}







|
|










|







 







|
|
|







 







|
|

|










69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#define HEADERLEN 14
#define VERSION "0.8.7"


extern char *optarg;
extern int optind, opterr, optopt;

void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN+1],int usefull) {
  char percentone[BARLEN+1], percenttwo[BARLEN+1], remain[BARLEN+1];
  unsigned int numberofmarks, numofmarkstwo, remainnum;
  numberofmarks=(int) ((float) (BARLEN*(percent/100)));
  if (!usefull) numofmarkstwo=(int) ((float) (BARLEN*(secondper/100))); else numofmarkstwo=(BARLEN-numberofmarks);
  remainnum=BARLEN-(numberofmarks+numofmarkstwo);
  memset(percentone, '#', numberofmarks);
  memset(percenttwo, '%', numofmarkstwo);
  memset(remain, '.', remainnum);
  percentone[numberofmarks]=0;
  percenttwo[numofmarkstwo]=0;
  remain[remainnum]=0;
  snprintf(marks, BARLEN+HEADERLEN+1, "%s\033[1;31m%s\033[1;37m%s", percentone, percenttwo, remain);
  return;
}

#ifndef HAVE_LIBSTATGRAB
/*
  Extracted alot from sysinfo.c (part of the procps package?) by
  Michael K. Johnson <johnsonm@redhat.com>
................................................................................
  return(results);
}
#endif

int main(int argc, char *argv[]) {
  float percentram, percentswap, percentbuffer, percentused, percentfree;
  float ramfree, ramtotal, swapfree, swaptotal, doloop=0, cachedbuffer, totaltotal;
  char realbarchart[BARLEN+HEADERLEN+1], swapbarchart[BARLEN+HEADERLEN+1], totalbarchart[BARLEN+HEADERLEN+1];
  int i, dototals=0, doold=0, linestoup=2;
  unsigned long meminfo_cached, divisor=1024;
#ifndef HAVE_LIBSTATGRAB
  struct sysinfo sinfo;

  meminfo_cached=get_meminfo("Cached:");
#else
  sg_mem_stats *mem_stats=NULL;
  sg_swap_stats *swap_stats=NULL;
................................................................................
    percentfree=(float) (((sinfo.freeram+sinfo.freeswap+meminfo_cached+sinfo.bufferram)/totaltotal)*100);
    percentused=(int) (100-((int) percentfree));
    if (!(swaptotal==0)) { percentswap=(float) ((swapfree/swaptotal)*100); } else { percentswap=0; }
    bargraph(percentswap,0,swapbarchart,0);
    bargraph(percentram,percentbuffer,realbarchart,0);
    bargraph((int) percentfree,(int) percentused,totalbarchart,1);
    if (!doold) {
      printf("Physical  : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n", realbarchart ,(int) (percentram+percentbuffer), (unsigned long) (ramfree+cachedbuffer)/divisor, (unsigned long) ramtotal/divisor);
      printf("Swap      : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",swapbarchart ,(int) percentswap,(unsigned long) swapfree/divisor, (unsigned long) swaptotal/divisor);
      if (dototals) 
      printf("Total     : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n", totalbarchart, (unsigned long) (sinfo.totalram+sinfo.totalswap)/divisor,(unsigned long) ((sinfo.freeram+sinfo.freeswap)/divisor), (unsigned long) ((totaltotal-((sinfo.freeram+sinfo.freeswap+cachedbuffer)))/divisor));
    } else {
      printf("             total       used       free     shared    buffers     cached\n");
      printf("Mem:  %12lu %10lu %10lu %10lu %10lu %10lu\n",(sinfo.totalram/divisor), (sinfo.totalram-sinfo.freeram)/divisor, (sinfo.freeram/divisor), (sinfo.sharedram/divisor), (sinfo.bufferram/divisor), (((unsigned long) cachedbuffer)/divisor)); 
      printf("Swap: %12lu %10lu %10lu\n",(sinfo.totalswap/divisor), ((sinfo.totalswap-sinfo.freeswap)/divisor), (sinfo.freeswap/divisor));
      if (dototals) printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",(long) totaltotal/divisor,(((long) totaltotal)-((sinfo.freeram+sinfo.freeswap)))/divisor,(sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer))/divisor);
    }
    if (doloop==0) { return(0); } else { usleep(doloop*1000000); printf("\033[%iA",linestoup); }
  }
  return(0);
}