Put most of the Debian patches in

added a lot of cvsignore files
This commit is contained in:
csmall
2002-02-01 23:40:38 +00:00
parent 03a9b5a30f
commit e4c67b2724
15 changed files with 235 additions and 117 deletions

2
proc/.cvsignore Normal file
View File

@ -0,0 +1,2 @@
libproc.so*
*.o

View File

@ -33,7 +33,9 @@
typedef struct tty_map_node {
struct tty_map_node *next;
int major_number; /* not unsigned! Ugh... */
char name[4];
int minor_first, minor_last;
char name[16];
char devfs_type;
} tty_map_node;
static tty_map_node *tty_map = NULL;
@ -46,25 +48,46 @@ static void load_drivers(void){
int bytes;
fd = open("/proc/tty/drivers",O_RDONLY);
if(fd == -1) goto fail;
bytes = read(fd, buf, 9999);
bytes = read(fd, buf, sizeof(buf) - 1);
if(bytes == -1) goto fail;
buf[bytes] = '\0';
p = buf;
while(( p = strstr(p, " /dev/tty") )){
while(( p = strstr(p, " /dev/") )){
tty_map_node *tmn;
int len;
p += 9;
len = strspn(p, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if(!len) continue;
if(len>3) continue;
if((len=1) && (*p=='S')) continue;
tmn = malloc(sizeof(tty_map_node));
char *end;
int rc;
p += 6;
end = strchr(p, ' ');
if(!end) continue;
len = end - p;
tmn = calloc(1, sizeof(tty_map_node));
tmn->next = tty_map;
tty_map = tmn;
memset(tmn->name, '\0', 4);
/* if we have a devfs type name such as /dev/tts/%d then strip the %d but
keep a flag. */
if(len >= 3 && !strncmp(end - 2, "%d", 2))
{
len -= 2;
tmn->devfs_type = 1;
}
strncpy(tmn->name, p, len);
p += len;
p = end; /* set p to point past the %d as well if there is one */
while(*p == ' ') p++;
tmn->major_number = atoi(p);
p += strspn(p, "0123456789");
while(*p == ' ') p++;
rc = sscanf(p, "%d-%d", &tmn->minor_first, &tmn->minor_last);
if(rc == 1)
{
tmn->minor_last = tmn->minor_first;
}
else if(rc == 0)
{
/* Can't finish parsing this line so we remove it from the list */
tty_map = tty_map->next;
free(tmn);
}
}
fail:
if(fd != -1) close(fd);
@ -80,11 +103,19 @@ static int driver_name(char * const buf, int maj, int min){
tmn = tty_map;
for(;;){
if(!tmn) return 0;
if(tmn->major_number == maj) break;
if(tmn->major_number == maj && tmn->minor_first <= min && tmn->minor_last >= min) break;
tmn = tmn->next;
}
sprintf(buf, "/dev/tty%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
if(stat(buf, &sbuf) < 0) return 0;
sprintf(buf, "/dev/%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
if(tmn->devfs_type)
{
if(stat(buf, &sbuf) < 0) return 0;
}
else if(stat(buf, &sbuf) < 0)
{
sprintf(buf, "/dev/%s", tmn->name); /* like "/dev/ttyZZ255" */
if(stat(buf, &sbuf) < 0) return 0;
}
if(min != minor(sbuf.st_rdev)) return 0;
if(maj != major(sbuf.st_rdev)) return 0;
return 1;
@ -170,10 +201,10 @@ int dev_to_tty(char *ret, int chop, int dev, int pid, unsigned int flags) {
int c;
if((short)dev == (short)-1) goto fail;
if( link_name(tmp, major(dev), minor(dev), pid, "tty" )) goto abbrev;
if(driver_name(tmp, major(dev), minor(dev) )) goto abbrev;
if( link_name(tmp, major(dev), minor(dev), pid, "fd/2" )) goto abbrev;
if( guess_name(tmp, major(dev), minor(dev) )) goto abbrev;
if( link_name(tmp, major(dev), minor(dev), pid, "fd/255")) goto abbrev;
if(driver_name(tmp, major(dev), minor(dev) )) goto abbrev;
fail:
strcpy(ret, "?");
return 1;
@ -181,7 +212,10 @@ abbrev:
if((flags&ABBREV_DEV) && !strncmp(tmp,"/dev/",5) && tmp[5]) tmp += 5;
if((flags&ABBREV_TTY) && !strncmp(tmp,"tty", 3) && tmp[3]) tmp += 3;
if((flags&ABBREV_PTS) && !strncmp(tmp,"pts/", 4) && tmp[4]) tmp += 4;
tmp[chop] = '\0';
/* gotta check before we chop or we may chop someone else's memory */
if(tmp + chop - buf <= PAGE_SIZE)
tmp[chop] = '\0';
/* replace non-ASCII characters with '?' and return the number of chars */
for(;;){
c = *tmp;
tmp++;

View File

@ -300,7 +300,7 @@ static char** file2strvec(char* directory, char* what) {
proc_t* readproc(PROCTAB* PT, proc_t* rbuf) {
static struct direct *ent; /* dirent handle */
static struct stat sb; /* stat buffer */
static char path[32], sbuf[512]; /* bufs for stat,statm */
static char path[32], sbuf[1024]; /* bufs for stat,statm */
int allocated = 0, matched = 0; /* flags */
proc_t *p = NULL;
@ -400,7 +400,7 @@ next_proc: /* get next PID for consideration */
proc_t* ps_readproc(PROCTAB* PT, proc_t* rbuf) {
static struct direct *ent; /* dirent handle */
static struct stat sb; /* stat buffer */
static char path[32], sbuf[512]; /* bufs for stat,statm */
static char path[32], sbuf[1024]; /* bufs for stat,statm */
int allocated = 0 /* , matched = 0 */ ; /* flags */
proc_t *p = NULL;

View File

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
#include <unistd.h>
#include <fcntl.h>
@ -68,12 +69,17 @@ static char buf[1024];
/***********************************************************************/
int uptime(double *uptime_secs, double *idle_secs) {
double up=0, idle=0;
char *savelocale;
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
savelocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC,"C");
if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
return 0;
setlocale(LC_NUMERIC,savelocale);
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
return 0;
}
setlocale(LC_NUMERIC,savelocale);
SET_IF_DESIRED(uptime_secs, up);
SET_IF_DESIRED(idle_secs, idle);
return up; /* assume never be zero seconds in practice */
@ -109,8 +115,12 @@ static void init_Hertz_value(void){
unsigned long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */
double up_1, up_2, seconds;
unsigned long jiffies, h;
char *savelocale;
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF);
if(smp_num_cpus==-1) smp_num_cpus=1;
if(smp_num_cpus<1) smp_num_cpus=1;
savelocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
do{
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1);
/* uptime(&up_1, NULL); */
@ -119,6 +129,7 @@ static void init_Hertz_value(void){
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_2);
/* uptime(&up_2, NULL); */
} while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
setlocale(LC_NUMERIC, savelocale);
jiffies = user_j + nice_j + sys_j + other_j;
seconds = (up_1 + up_2) / 2;
h = (unsigned long)( (double)jiffies/seconds/smp_num_cpus );
@ -132,10 +143,16 @@ static void init_Hertz_value(void){
case 124 ... 132 : Hertz = 128; break; /* MIPS, ARM */
case 195 ... 204 : Hertz = 200; break; /* normal << 1 */
case 253 ... 260 : Hertz = 256; break;
case 295 ... 304 : Hertz = 300; break; /* 3 cpus */
case 393 ... 408 : Hertz = 400; break; /* normal << 2 */
case 495 ... 504 : Hertz = 500; break; /* 5 cpus */
case 595 ... 604 : Hertz = 600; break; /* 6 cpus */
case 695 ... 704 : Hertz = 700; break; /* 7 cpus */
case 790 ... 808 : Hertz = 800; break; /* normal << 3 */
case 895 ... 904 : Hertz = 900; break; /* 9 cpus */
case 990 ... 1010 : Hertz = 1000; break; /* ARM */
case 1015 ... 1035 : Hertz = 1024; break; /* Alpha, ia64 */
case 1095 ... 1104 : Hertz = 1100; break; /* 11 cpus */
case 1180 ... 1220 : Hertz = 1200; break; /* Alpha */
default:
#ifdef HZ
@ -194,12 +211,16 @@ void four_cpu_numbers(double *uret, double *nret, double *sret, double *iret){
/***********************************************************************/
void loadavg(double *av1, double *av5, double *av15) {
double avg_1=0, avg_5=0, avg_15=0;
char *savelocale;
FILE_TO_BUF(LOADAVG_FILE,loadavg_fd);
savelocale = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, "C");
if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) {
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
exit(1);
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
exit(1);
}
setlocale(LC_NUMERIC, savelocale);
SET_IF_DESIRED(av1, avg_1);
SET_IF_DESIRED(av5, avg_5);
SET_IF_DESIRED(av15, avg_15);

View File

@ -40,9 +40,8 @@ char *sprint_uptime(void) {
time(&realseconds);
realtime = localtime(&realseconds);
pos = sprintf(buf, " %2d:%02d%s ",
realtime->tm_hour%12 ? realtime->tm_hour%12 : 12,
realtime->tm_min, realtime->tm_hour > 11 ? "pm" : "am");
pos = sprintf(buf, " %02d:%02d:%02d ",
realtime->tm_hour, realtime->tm_min, realtime->tm_sec);
/* read and calculate the amount of uptime */