Put most of the Debian patches in
added a lot of cvsignore files
This commit is contained in:
parent
03a9b5a30f
commit
e4c67b2724
18
.cvsignore
Normal file
18
.cvsignore
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
*.o
|
||||||
|
free
|
||||||
|
kill
|
||||||
|
oldps
|
||||||
|
pgrep
|
||||||
|
pkill
|
||||||
|
proc
|
||||||
|
ps
|
||||||
|
skill
|
||||||
|
snice
|
||||||
|
sysctl
|
||||||
|
t
|
||||||
|
tload
|
||||||
|
top
|
||||||
|
uptime
|
||||||
|
vmstat
|
||||||
|
w
|
||||||
|
watch
|
11
ChangeLog
Normal file
11
ChangeLog
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Version ????
|
||||||
|
|
||||||
|
/proc/tty/drivers correctly parsed. Debian #108654
|
||||||
|
(Thanks russell*AT*coker.com.au)
|
||||||
|
|
||||||
|
oldps doesn't FPE because of no shared mem Debian #101917
|
||||||
|
(Thanks David Murn <davey*AT*vision.doa.org>)
|
||||||
|
|
||||||
|
Put most of the Debian diffs in.
|
||||||
|
|
||||||
|
|
5
oldps.c
5
oldps.c
@ -209,6 +209,8 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
} while (argc > 1);
|
} while (argc > 1);
|
||||||
|
|
||||||
|
meminfo();
|
||||||
|
|
||||||
if (!CL_sort) /* since the unsorted mode is intended to be speedy */
|
if (!CL_sort) /* since the unsorted mode is intended to be speedy */
|
||||||
CL_forest = 0; /* turn off the expensive forest option as well. */
|
CL_forest = 0; /* turn off the expensive forest option as well. */
|
||||||
|
|
||||||
@ -425,7 +427,8 @@ static void show_jobs(char *s, proc_t *p) {
|
|||||||
|
|
||||||
/*****************************/
|
/*****************************/
|
||||||
static void show_user(char *s, proc_t *p) {
|
static void show_user(char *s, proc_t *p) {
|
||||||
long pmem, total_time, seconds;
|
long pmem, total_time;
|
||||||
|
long long seconds;
|
||||||
time_t start;
|
time_t start;
|
||||||
unsigned int pcpu;
|
unsigned int pcpu;
|
||||||
|
|
||||||
|
4
pgrep.c
4
pgrep.c
@ -70,9 +70,9 @@ static int
|
|||||||
usage (int opt)
|
usage (int opt)
|
||||||
{
|
{
|
||||||
if (i_am_pkill)
|
if (i_am_pkill)
|
||||||
fprintf (stderr, "Usage: pgrep [-flnvx] [-d DELIM] ");
|
|
||||||
else
|
|
||||||
fprintf (stderr, "Usage: pkill [-SIGNAL] [-fnvx] ");
|
fprintf (stderr, "Usage: pkill [-SIGNAL] [-fnvx] ");
|
||||||
|
else
|
||||||
|
fprintf (stderr, "Usage: pgrep [-flnvx] [-d DELIM] ");
|
||||||
fprintf (stderr, "[-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
|
fprintf (stderr, "[-P PPIDLIST] [-g PGRPLIST] [-s SIDLIST]\n"
|
||||||
"\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] "
|
"\t[-u EUIDLIST] [-U UIDLIST] [-G GIDLIST] [-t TERMLIST] "
|
||||||
"[PATTERN]\n");
|
"[PATTERN]\n");
|
||||||
|
2
proc/.cvsignore
Normal file
2
proc/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
libproc.so*
|
||||||
|
*.o
|
@ -33,7 +33,9 @@
|
|||||||
typedef struct tty_map_node {
|
typedef struct tty_map_node {
|
||||||
struct tty_map_node *next;
|
struct tty_map_node *next;
|
||||||
int major_number; /* not unsigned! Ugh... */
|
int major_number; /* not unsigned! Ugh... */
|
||||||
char name[4];
|
int minor_first, minor_last;
|
||||||
|
char name[16];
|
||||||
|
char devfs_type;
|
||||||
} tty_map_node;
|
} tty_map_node;
|
||||||
|
|
||||||
static tty_map_node *tty_map = NULL;
|
static tty_map_node *tty_map = NULL;
|
||||||
@ -46,25 +48,46 @@ static void load_drivers(void){
|
|||||||
int bytes;
|
int bytes;
|
||||||
fd = open("/proc/tty/drivers",O_RDONLY);
|
fd = open("/proc/tty/drivers",O_RDONLY);
|
||||||
if(fd == -1) goto fail;
|
if(fd == -1) goto fail;
|
||||||
bytes = read(fd, buf, 9999);
|
bytes = read(fd, buf, sizeof(buf) - 1);
|
||||||
if(bytes == -1) goto fail;
|
if(bytes == -1) goto fail;
|
||||||
buf[bytes] = '\0';
|
buf[bytes] = '\0';
|
||||||
p = buf;
|
p = buf;
|
||||||
while(( p = strstr(p, " /dev/tty") )){
|
while(( p = strstr(p, " /dev/") )){
|
||||||
tty_map_node *tmn;
|
tty_map_node *tmn;
|
||||||
int len;
|
int len;
|
||||||
p += 9;
|
char *end;
|
||||||
len = strspn(p, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
int rc;
|
||||||
if(!len) continue;
|
p += 6;
|
||||||
if(len>3) continue;
|
end = strchr(p, ' ');
|
||||||
if((len=1) && (*p=='S')) continue;
|
if(!end) continue;
|
||||||
tmn = malloc(sizeof(tty_map_node));
|
len = end - p;
|
||||||
|
tmn = calloc(1, sizeof(tty_map_node));
|
||||||
tmn->next = tty_map;
|
tmn->next = tty_map;
|
||||||
tty_map = tmn;
|
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);
|
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);
|
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:
|
fail:
|
||||||
if(fd != -1) close(fd);
|
if(fd != -1) close(fd);
|
||||||
@ -80,11 +103,19 @@ static int driver_name(char * const buf, int maj, int min){
|
|||||||
tmn = tty_map;
|
tmn = tty_map;
|
||||||
for(;;){
|
for(;;){
|
||||||
if(!tmn) return 0;
|
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;
|
tmn = tmn->next;
|
||||||
}
|
}
|
||||||
sprintf(buf, "/dev/tty%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
|
sprintf(buf, "/dev/%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */
|
||||||
|
if(tmn->devfs_type)
|
||||||
|
{
|
||||||
if(stat(buf, &sbuf) < 0) return 0;
|
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(min != minor(sbuf.st_rdev)) return 0;
|
||||||
if(maj != major(sbuf.st_rdev)) return 0;
|
if(maj != major(sbuf.st_rdev)) return 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -170,10 +201,10 @@ int dev_to_tty(char *ret, int chop, int dev, int pid, unsigned int flags) {
|
|||||||
int c;
|
int c;
|
||||||
if((short)dev == (short)-1) goto fail;
|
if((short)dev == (short)-1) goto fail;
|
||||||
if( link_name(tmp, major(dev), minor(dev), pid, "tty" )) goto abbrev;
|
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( link_name(tmp, major(dev), minor(dev), pid, "fd/2" )) goto abbrev;
|
||||||
if( guess_name(tmp, major(dev), minor(dev) )) 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( link_name(tmp, major(dev), minor(dev), pid, "fd/255")) goto abbrev;
|
||||||
if(driver_name(tmp, major(dev), minor(dev) )) goto abbrev;
|
|
||||||
fail:
|
fail:
|
||||||
strcpy(ret, "?");
|
strcpy(ret, "?");
|
||||||
return 1;
|
return 1;
|
||||||
@ -181,7 +212,10 @@ abbrev:
|
|||||||
if((flags&ABBREV_DEV) && !strncmp(tmp,"/dev/",5) && tmp[5]) tmp += 5;
|
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_TTY) && !strncmp(tmp,"tty", 3) && tmp[3]) tmp += 3;
|
||||||
if((flags&ABBREV_PTS) && !strncmp(tmp,"pts/", 4) && tmp[4]) tmp += 4;
|
if((flags&ABBREV_PTS) && !strncmp(tmp,"pts/", 4) && tmp[4]) tmp += 4;
|
||||||
|
/* gotta check before we chop or we may chop someone else's memory */
|
||||||
|
if(tmp + chop - buf <= PAGE_SIZE)
|
||||||
tmp[chop] = '\0';
|
tmp[chop] = '\0';
|
||||||
|
/* replace non-ASCII characters with '?' and return the number of chars */
|
||||||
for(;;){
|
for(;;){
|
||||||
c = *tmp;
|
c = *tmp;
|
||||||
tmp++;
|
tmp++;
|
||||||
|
@ -300,7 +300,7 @@ static char** file2strvec(char* directory, char* what) {
|
|||||||
proc_t* readproc(PROCTAB* PT, proc_t* rbuf) {
|
proc_t* readproc(PROCTAB* PT, proc_t* rbuf) {
|
||||||
static struct direct *ent; /* dirent handle */
|
static struct direct *ent; /* dirent handle */
|
||||||
static struct stat sb; /* stat buffer */
|
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 */
|
int allocated = 0, matched = 0; /* flags */
|
||||||
proc_t *p = NULL;
|
proc_t *p = NULL;
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ next_proc: /* get next PID for consideration */
|
|||||||
proc_t* ps_readproc(PROCTAB* PT, proc_t* rbuf) {
|
proc_t* ps_readproc(PROCTAB* PT, proc_t* rbuf) {
|
||||||
static struct direct *ent; /* dirent handle */
|
static struct direct *ent; /* dirent handle */
|
||||||
static struct stat sb; /* stat buffer */
|
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 */
|
int allocated = 0 /* , matched = 0 */ ; /* flags */
|
||||||
proc_t *p = NULL;
|
proc_t *p = NULL;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -68,12 +69,17 @@ static char buf[1024];
|
|||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
int uptime(double *uptime_secs, double *idle_secs) {
|
int uptime(double *uptime_secs, double *idle_secs) {
|
||||||
double up=0, idle=0;
|
double up=0, idle=0;
|
||||||
|
char *savelocale;
|
||||||
|
|
||||||
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
|
FILE_TO_BUF(UPTIME_FILE,uptime_fd);
|
||||||
|
savelocale = setlocale(LC_NUMERIC, NULL);
|
||||||
|
setlocale(LC_NUMERIC,"C");
|
||||||
if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
|
if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
|
||||||
|
setlocale(LC_NUMERIC,savelocale);
|
||||||
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
|
fprintf(stderr, "bad data in " UPTIME_FILE "\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
setlocale(LC_NUMERIC,savelocale);
|
||||||
SET_IF_DESIRED(uptime_secs, up);
|
SET_IF_DESIRED(uptime_secs, up);
|
||||||
SET_IF_DESIRED(idle_secs, idle);
|
SET_IF_DESIRED(idle_secs, idle);
|
||||||
return up; /* assume never be zero seconds in practice */
|
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) */
|
unsigned long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */
|
||||||
double up_1, up_2, seconds;
|
double up_1, up_2, seconds;
|
||||||
unsigned long jiffies, h;
|
unsigned long jiffies, h;
|
||||||
|
char *savelocale;
|
||||||
|
|
||||||
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF);
|
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{
|
do{
|
||||||
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1);
|
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1);
|
||||||
/* uptime(&up_1, NULL); */
|
/* 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);
|
FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_2);
|
||||||
/* uptime(&up_2, NULL); */
|
/* uptime(&up_2, NULL); */
|
||||||
} while((long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */
|
} 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;
|
jiffies = user_j + nice_j + sys_j + other_j;
|
||||||
seconds = (up_1 + up_2) / 2;
|
seconds = (up_1 + up_2) / 2;
|
||||||
h = (unsigned long)( (double)jiffies/seconds/smp_num_cpus );
|
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 124 ... 132 : Hertz = 128; break; /* MIPS, ARM */
|
||||||
case 195 ... 204 : Hertz = 200; break; /* normal << 1 */
|
case 195 ... 204 : Hertz = 200; break; /* normal << 1 */
|
||||||
case 253 ... 260 : Hertz = 256; break;
|
case 253 ... 260 : Hertz = 256; break;
|
||||||
|
case 295 ... 304 : Hertz = 300; break; /* 3 cpus */
|
||||||
case 393 ... 408 : Hertz = 400; break; /* normal << 2 */
|
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 790 ... 808 : Hertz = 800; break; /* normal << 3 */
|
||||||
|
case 895 ... 904 : Hertz = 900; break; /* 9 cpus */
|
||||||
case 990 ... 1010 : Hertz = 1000; break; /* ARM */
|
case 990 ... 1010 : Hertz = 1000; break; /* ARM */
|
||||||
case 1015 ... 1035 : Hertz = 1024; break; /* Alpha, ia64 */
|
case 1015 ... 1035 : Hertz = 1024; break; /* Alpha, ia64 */
|
||||||
|
case 1095 ... 1104 : Hertz = 1100; break; /* 11 cpus */
|
||||||
case 1180 ... 1220 : Hertz = 1200; break; /* Alpha */
|
case 1180 ... 1220 : Hertz = 1200; break; /* Alpha */
|
||||||
default:
|
default:
|
||||||
#ifdef HZ
|
#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) {
|
void loadavg(double *av1, double *av5, double *av15) {
|
||||||
double avg_1=0, avg_5=0, avg_15=0;
|
double avg_1=0, avg_5=0, avg_15=0;
|
||||||
|
char *savelocale;
|
||||||
|
|
||||||
FILE_TO_BUF(LOADAVG_FILE,loadavg_fd);
|
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) {
|
if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) {
|
||||||
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
|
fprintf(stderr, "bad data in " LOADAVG_FILE "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
setlocale(LC_NUMERIC, savelocale);
|
||||||
SET_IF_DESIRED(av1, avg_1);
|
SET_IF_DESIRED(av1, avg_1);
|
||||||
SET_IF_DESIRED(av5, avg_5);
|
SET_IF_DESIRED(av5, avg_5);
|
||||||
SET_IF_DESIRED(av15, avg_15);
|
SET_IF_DESIRED(av15, avg_15);
|
||||||
|
@ -40,9 +40,8 @@ char *sprint_uptime(void) {
|
|||||||
|
|
||||||
time(&realseconds);
|
time(&realseconds);
|
||||||
realtime = localtime(&realseconds);
|
realtime = localtime(&realseconds);
|
||||||
pos = sprintf(buf, " %2d:%02d%s ",
|
pos = sprintf(buf, " %02d:%02d:%02d ",
|
||||||
realtime->tm_hour%12 ? realtime->tm_hour%12 : 12,
|
realtime->tm_hour, realtime->tm_min, realtime->tm_sec);
|
||||||
realtime->tm_min, realtime->tm_hour > 11 ? "pm" : "am");
|
|
||||||
|
|
||||||
/* read and calculate the amount of uptime */
|
/* read and calculate the amount of uptime */
|
||||||
|
|
||||||
|
3
ps/.cvsignore
Normal file
3
ps/.cvsignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
p
|
||||||
|
ps
|
||||||
|
*.o
|
@ -1,5 +0,0 @@
|
|||||||
diff -Naur procps-2.0.6/ps/.cvsignore procps-2.0.7/ps/.cvsignore
|
|
||||||
--- procps-2.0.6/ps/.cvsignore Wed Dec 31 19:00:00 1969
|
|
||||||
+++ procps-2.0.7/ps/.cvsignore Fri Jul 14 16:45:01 2000
|
|
||||||
@@ -0,0 +1 @@
|
|
||||||
+ps
|
|
30
top.c
30
top.c
@ -101,6 +101,7 @@
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#include "proc/sysinfo.h"
|
#include "proc/sysinfo.h"
|
||||||
#include "proc/procps.h"
|
#include "proc/procps.h"
|
||||||
@ -235,25 +236,33 @@ static void get_options(void)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *pt;
|
char *pt;
|
||||||
char rcfile[MAXNAMELEN];
|
char *rcfile = NULL; /* path to rc file... */
|
||||||
|
char *home = NULL; /* path of user's home directory... */
|
||||||
|
size_t home_length = 0; /* length of path... */
|
||||||
char Options[256] = "";
|
char Options[256] = "";
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
nr_cpu = sysconf (_SC_NPROCESSORS_ONLN);
|
nr_cpu = sysconf (_SC_NPROCESSORS_ONLN);
|
||||||
|
if (nr_cpu < 1) nr_cpu = 1;
|
||||||
cpu_mapping = (int *) xmalloc (sizeof (int) * nr_cpu);
|
cpu_mapping = (int *) xmalloc (sizeof (int) * nr_cpu);
|
||||||
/* read cpuname */
|
/* read cpuname */
|
||||||
for (i=0; i< nr_cpu; i++) cpu_mapping[i]=i;
|
for (i=0; i< nr_cpu; i++) cpu_mapping[i]=i;
|
||||||
header_lines = 6 + nr_cpu;
|
header_lines = 6 + nr_cpu;
|
||||||
strcpy(rcfile, SYS_TOPRC);
|
fp = fopen(SYS_TOPRC, "r");
|
||||||
fp = fopen(rcfile, "r");
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
fgets(Options, 254, fp);
|
fgets(Options, 254, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
parse_options(Options, 0);
|
parse_options(Options, 0);
|
||||||
strcpy(Options, "");
|
strcpy(Options, "");
|
||||||
if (getenv("HOME")) {
|
|
||||||
strcpy(rcfile, getenv("HOME"));
|
if ( (home = getenv("HOME")) != NULL) {
|
||||||
|
home_length = strlen(home);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (rcfile = malloc(home_length + strlen(RCFILE) + 2))) {
|
||||||
|
if (home != NULL) {
|
||||||
|
strcpy(rcfile, home);
|
||||||
strcat(rcfile, "/");
|
strcat(rcfile, "/");
|
||||||
}
|
}
|
||||||
strcat(rcfile, RCFILE);
|
strcat(rcfile, RCFILE);
|
||||||
@ -268,6 +277,9 @@ static void get_options(void)
|
|||||||
fgets(Options, 254, fp);
|
fgets(Options, 254, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(rcfile);
|
||||||
|
}
|
||||||
parse_options(Options, getuid()? Secure : 0);
|
parse_options(Options, getuid()? Secure : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,6 +734,7 @@ static float getfloat(void)
|
|||||||
char *line;
|
char *line;
|
||||||
int i;
|
int i;
|
||||||
float r;
|
float r;
|
||||||
|
char *savelocale;
|
||||||
|
|
||||||
line = getstr();
|
line = getstr();
|
||||||
|
|
||||||
@ -736,7 +749,10 @@ static float getfloat(void)
|
|||||||
if (!line[0])
|
if (!line[0])
|
||||||
return (BAD_INPUT);
|
return (BAD_INPUT);
|
||||||
|
|
||||||
|
savelocale = setlocale(LC_NUMERIC, NULL);
|
||||||
|
setlocale(LC_NUMERIC, "C");
|
||||||
sscanf(line, "%f", &r);
|
sscanf(line, "%f", &r);
|
||||||
|
setlocale(LC_NUMERIC, savelocale);
|
||||||
return (r);
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1625,6 +1641,9 @@ static void do_key(char c)
|
|||||||
change_order();
|
change_order();
|
||||||
break;
|
break;
|
||||||
case 'W':
|
case 'W':
|
||||||
|
if (Secure)
|
||||||
|
SHOWMESSAGE(("\aCan't write configuration in secure mode"));
|
||||||
|
else {
|
||||||
if (getenv("HOME")) {
|
if (getenv("HOME")) {
|
||||||
strcpy(rcfile, getenv("HOME"));
|
strcpy(rcfile, getenv("HOME"));
|
||||||
strcat(rcfile, "/");
|
strcat(rcfile, "/");
|
||||||
@ -1663,6 +1682,7 @@ static void do_key(char c)
|
|||||||
} else {
|
} else {
|
||||||
SHOWMESSAGE(("Couldn't get $HOME -- not saving"));
|
SHOWMESSAGE(("Couldn't get $HOME -- not saving"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SHOWMESSAGE(("\aUnknown command `%c' -- hit `h' for help", c));
|
SHOWMESSAGE(("\aUnknown command `%c' -- hit `h' for help", c));
|
||||||
|
12
uptime.c
12
uptime.c
@ -1,9 +1,17 @@
|
|||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "proc/whattime.h"
|
#include "proc/whattime.h"
|
||||||
#include "proc/version.h"
|
#include "proc/version.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if(argc == 1) print_uptime();
|
if(argc == 1) {
|
||||||
if((argc == 2) && (!strcmp(argv[1], "-V"))) display_version();
|
print_uptime();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
if((argc == 2) && (!strcmp(argv[1], "-V"))) {
|
||||||
|
display_version();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "usage: w -V\n -V display version\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
10
w.c
10
w.c
@ -104,8 +104,6 @@ static void print_logintime(time_t logt, FILE* fout) {
|
|||||||
"Aug", "Sep", "Oct", "Nov", "Dec" };
|
"Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||||
time_t curt;
|
time_t curt;
|
||||||
struct tm *logtm, *curtm;
|
struct tm *logtm, *curtm;
|
||||||
int hour;
|
|
||||||
char *merid; /* meridian indicator */
|
|
||||||
int today;
|
int today;
|
||||||
|
|
||||||
curt = time(NULL);
|
curt = time(NULL);
|
||||||
@ -113,18 +111,14 @@ static void print_logintime(time_t logt, FILE* fout) {
|
|||||||
/* localtime returns a pointer to static memory */
|
/* localtime returns a pointer to static memory */
|
||||||
today = curtm->tm_yday;
|
today = curtm->tm_yday;
|
||||||
logtm = localtime(&logt);
|
logtm = localtime(&logt);
|
||||||
hour = logtm->tm_hour;
|
|
||||||
merid = (hour < 12) ? "am" : "pm";
|
|
||||||
if (hour >= 12) hour -= 12;
|
|
||||||
if (hour == 0) hour = 12;
|
|
||||||
if (curt - logt > 12*60*60 && logtm->tm_yday != today) {
|
if (curt - logt > 12*60*60 && logtm->tm_yday != today) {
|
||||||
if (curt - logt > 6*24*60*60)
|
if (curt - logt > 6*24*60*60)
|
||||||
fprintf(fout, " %02d%3s%02d", logtm->tm_mday, month[logtm->tm_mon],
|
fprintf(fout, " %02d%3s%02d", logtm->tm_mday, month[logtm->tm_mon],
|
||||||
logtm->tm_year % 100);
|
logtm->tm_year % 100);
|
||||||
else
|
else
|
||||||
fprintf(fout, " %3s%02d%s", weekday[logtm->tm_wday], hour, merid);
|
fprintf(fout, " %3s%02d ", weekday[logtm->tm_wday], logtm->tm_hour);
|
||||||
} else {
|
} else {
|
||||||
fprintf(fout, " %02d:%02d%s", hour, logtm->tm_min, merid);
|
fprintf(fout, " %02d:%02d ", logtm->tm_hour, logtm->tm_min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
watch.c
36
watch.c
@ -21,7 +21,7 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
static struct option longopts[] =
|
static struct option longopts[] =
|
||||||
{
|
{
|
||||||
@ -105,7 +105,10 @@ main(int argc, char *argv[])
|
|||||||
int interval=2;
|
int interval=2;
|
||||||
char *command;
|
char *command;
|
||||||
int command_length=0; /* not including final \0 */
|
int command_length=0; /* not including final \0 */
|
||||||
|
int s;
|
||||||
|
char *endp;
|
||||||
|
|
||||||
|
setlocale(LC_ALL,"");
|
||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
|
|
||||||
while ((optc = getopt_long(argc, argv, "+d::hn:v", longopts, (int *) 0))
|
while ((optc = getopt_long(argc, argv, "+d::hn:v", longopts, (int *) 0))
|
||||||
@ -123,9 +126,9 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
char *s;
|
char *str;
|
||||||
interval = strtol(optarg, &s, 10);
|
interval = strtol(optarg, &str, 10);
|
||||||
if (!*optarg || *s)
|
if (!*optarg || *str)
|
||||||
do_usage();
|
do_usage();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -159,16 +162,19 @@ main(int argc, char *argv[])
|
|||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
do_usage();
|
do_usage();
|
||||||
|
|
||||||
command = strdup(argv[optind++]);
|
command_length = strlen(argv[optind]);
|
||||||
command_length = strlen(command);
|
command = (char*)malloc(command_length + 1); /* space or \0 */
|
||||||
|
memcpy(command, argv[optind++], command_length);
|
||||||
|
command[command_length] = '\0';
|
||||||
for (;optind<argc;optind++)
|
for (;optind<argc;optind++)
|
||||||
{
|
{
|
||||||
int s = strlen(argv[optind]);
|
s = strlen(argv[optind]);
|
||||||
char *endp = &command[command_length];
|
command = realloc(command, command_length+s+2); /* space and \0 */
|
||||||
|
endp = command + command_length;
|
||||||
*endp = ' ';
|
*endp = ' ';
|
||||||
command_length += s + 1;
|
memcpy(endp+1, argv[optind],s);
|
||||||
command = realloc(command, command_length+1);
|
command_length += 1+s; /* space then string length */
|
||||||
strcpy(endp+1, argv[optind]);
|
command[command_length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
get_terminal_size();
|
get_terminal_size();
|
||||||
@ -208,9 +214,9 @@ main(int argc, char *argv[])
|
|||||||
/* left justify interval and command, right justify time, clipping all
|
/* left justify interval and command, right justify time, clipping all
|
||||||
to fit window width */
|
to fit window width */
|
||||||
asprintf(&header, "Every %ds: %.*s",
|
asprintf(&header, "Every %ds: %.*s",
|
||||||
interval, max(width-1, command_length), command);
|
interval, min(width-1, command_length), command);
|
||||||
mvaddstr(0, 0, header);
|
mvaddstr(0, 0, header);
|
||||||
if (strlen(header) > width - tsl - 1)
|
if (strlen(header) > (size_t)(width - tsl - 1))
|
||||||
mvaddstr(0, width - tsl - 4, "... ");
|
mvaddstr(0, width - tsl - 4, "... ");
|
||||||
mvaddstr(0, width - tsl + 1, ts);
|
mvaddstr(0, width - tsl + 1, ts);
|
||||||
free(header);
|
free(header);
|
||||||
@ -238,6 +244,10 @@ main(int argc, char *argv[])
|
|||||||
c = getc(p);
|
c = getc(p);
|
||||||
while (c != EOF && !isprint(c) && c != '\n' && c != '\t');
|
while (c != EOF && !isprint(c) && c != '\n' && c != '\t');
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
|
if (x == 0) {
|
||||||
|
x=-1;
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
eolseen = 1;
|
eolseen = 1;
|
||||||
else if (c == '\t')
|
else if (c == '\t')
|
||||||
tabpending = 1;
|
tabpending = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user