% patch to xmbmon107pl1 for Linux % From: Michael Lenzen % diff -u --recursive --new-file xmbmon107pl1/Makefile.in xmbmon107pl1.new/Makefile.in --- xmbmon107pl1/Makefile.in Sun Feb 10 16:43:27 2002 +++ xmbmon107pl1.new/Makefile.in Sun May 5 13:32:01 2002 @@ -50,16 +50,16 @@ $(CC) $(CFLAGSX) $(LDFLAGS) -o $@ xmbmon.c getMBinfo.o getMB-isa.o getMB-smb.o getMB-via.o pci_hwm.o $(LIBS) testpci: testpci.c pci_hwm.c pci_hwm.h - $(CC) -O $(LDFLAGS) -o $@ testpci.c + $(CC) -O $(CFLAGS) $(LDFLAGS) -o $@ testpci.c testsmb: testsmb.c pci_hwm.c pci_hwm.h smb_io.c smb_io.h - $(CC) -O $(LDFLAGS) -o $@ testsmb.c + $(CC) -O $(CFLAGS) $(LDFLAGS) -o $@ testsmb.c testhwm: testhwm.c pci_hwm.c pci_hwm.h smb_io.c smb_io.h - $(CC) -O $(LDFLAGS) -o $@ testhwm.c + $(CC) -O $(CFLAGS) $(LDFLAGS) -o $@ testhwm.c testfan: testhwm.c pci_hwm.c pci_hwm.h smb_io.c smb_io.h - $(CC) -DFAN_DIV_CHK -O $(LDFLAGS) -o $@ testhwm.c + $(CC) -DFAN_DIV_CHK -O $(CFLAGS) $(LDFLAGS) -o $@ testhwm.c clean: $(RM) *.o *.bak *.BAK *.CKP a.out core errs *~ $(PROGRAM) diff -u --recursive --new-file xmbmon107pl1/mbmon.c xmbmon107pl1.new/mbmon.c --- xmbmon107pl1/mbmon.c Sat Mar 2 17:31:42 2002 +++ xmbmon107pl1.new/mbmon.c Sun May 5 13:39:25 2002 @@ -68,6 +68,12 @@ #include #include +#ifdef LINUX +#include +#include +#include +#endif + #define DEFAULT_SEC 5 /* Fahrenheit flag used in getTemp() */ @@ -84,7 +90,7 @@ " -V|S|I: access method (using \"VIA686 HWM directly\"|\"SMBus\"|\"ISA I/O port\")\n"\ " -f: temperature in Fahrenheit\n"\ " -d: debug mode (any other option will be ignored)\n"\ - " -h: print help message(this) and exit\n" + " -h: print help message(this) and exit\n"\ " -c count: repeat times and exit\n"\ " -T|F [1-7]: print Temperature|Fanspeed according to following styles\n"\ " style1: data1\\n\n"\ @@ -104,7 +110,115 @@ uptime(time_t now) { -#ifndef LINUX /* FreeBSD */ +#ifdef LINUX + +#define PROC_UPTIME "/proc/uptime" +#define PROC_LOADAVG "/proc/loadavg" + + char print_buf[128]; + static char file_buf[1024]; + int print_buf_pos; + + struct tm *local_time; + + static int fd, bytes; + + struct utmp *utmp_record; + int up_minutes, up_hours, up_days; + double uptime_seconds, ilde_seconds; + + int count_user; + + double avg[3]; + + /* get current time */ + + local_time = localtime(&now); + + print_buf_pos = sprintf(print_buf, "%02d:%02d%s ", + local_time->tm_hour%12 ? local_time->tm_hour%12 : 12, + local_time->tm_min, local_time->tm_hour > 11 ? "pm" : "am"); + + /* compute uptime */ + + if ((fd = open(PROC_UPTIME, O_RDONLY)) == -1) { + fprintf(stderr, "Error: /proc file system must be mounted\n"); + close(fd); + exit(1); + } + lseek(fd, 0L, SEEK_SET); + if ((bytes = read(fd, file_buf, sizeof file_buf - 1)) < 0) { + fprintf(stderr, "Error: can't read file \"%s\"\n", + PROC_UPTIME); + close(fd); + exit(1); + } + file_buf[bytes] = '\0'; + close(fd); + + if (sscanf(file_buf, "%lf %lf", &uptime_seconds, &ilde_seconds) < 2) { + fprintf(stderr, "bad data in file \"%s\"\n", PROC_UPTIME); + exit(1); + } + + up_days = (int) uptime_seconds / (60*60*24); + strcat (print_buf, "up "); + print_buf_pos += 3; + + + if (up_days) + print_buf_pos += sprintf(print_buf + print_buf_pos, + "%d day%s, ", up_days, (up_days != 1) ? "s" : ""); + up_minutes = (int) uptime_seconds / 60; + up_hours = up_minutes / 60; + up_hours = up_hours % 24; + up_minutes = up_minutes % 60; + if(up_hours) + print_buf_pos += sprintf(print_buf + print_buf_pos, + "%2d:%02d, ", up_hours, up_minutes); + else + print_buf_pos += sprintf(print_buf + print_buf_pos, + "%d min, ", up_minutes); + + count_user = 0; + setutent(); + while ((utmp_record = getutent())) { + if ((utmp_record->ut_type == USER_PROCESS) && + (utmp_record->ut_name[0] != '\0')) + count_user++; + } + endutent(); + + print_buf_pos += sprintf(print_buf + print_buf_pos, "%2d user%s, ", + count_user, count_user == 1 ? "" : "s"); + + if ((fd = open(PROC_LOADAVG, O_RDONLY)) == -1) { + fprintf(stderr, "Error: /proc file system must be mounted\n"); + close(fd); + exit(1); + } + lseek(fd, 0L, SEEK_SET); + if ((bytes = read(fd, file_buf, sizeof file_buf - 1)) < 0) { + fprintf(stderr, "Error: can't read file \"%s\"\n", + PROC_LOADAVG); + close(fd); + exit(1); + } + file_buf[bytes] = '\0'; + close(fd); + + if (sscanf(file_buf, "%lf %lf %lf", &avg[0], &avg[1], &avg[2]) < 3) { + fprintf(stderr, "bad data in file \"%s\"\n", PROC_LOADAVG); + exit(1); + } + + print_buf_pos += sprintf(print_buf + print_buf_pos, + " load average: %.2f, %.2f, %.2f", avg[0], avg[1], avg[2]); + + printf("%s\n", print_buf); + +#else /* FreeBSD */ + struct timeval boottime; time_t uptime; int days, hrs, mins, secs; @@ -143,12 +257,23 @@ hostname(int sh_flag) { char *p, hostname[MAXHOSTNAMELEN]; - +#ifdef LINUX + char domainname[MAXHOSTNAMELEN]; + if (gethostname(hostname, (int)sizeof(hostname))) + err(1, "gethostname"); + if (getdomainname(domainname, (int)sizeof(domainname))) + err(1, "getdomainname"); + if (sh_flag) + printf("%s\n", hostname); + else + printf("%s.%s\n", hostname, domainname); +#else if (gethostname(hostname, (int)sizeof(hostname))) err(1, "gethostname"); if (sh_flag && (p = strchr(hostname, '.'))) *p = '\0'; printf("%s\n", hostname); +#endif } @@ -162,7 +287,12 @@ extern char *optarg; extern int optind; char *name; +#ifdef LINUX + /* format "%+" is not supported by glibc2 on linux systems */ + char *format = "%a %b %d %T %Z %Y", buf[256]; +#else char *format = "%+", buf[256]; +#endif int ch, method=' '; struct tm lt; time_t now; @@ -280,9 +410,10 @@ /* print data */ if(temperature == 0 && fanspeed == 0) { + printf("\n"); printf("Temp.= %4.1f, %4.1f, %4.1f;",temp1, temp2, temp3); printf(" Rot.= %4d, %4d, %4d\n", rot1, rot2, rot3); - printf(" Vcore = %4.2f, %4.2f; Volt. = %4.2f, %4.2f, %5.2f, %6.2f, %5.2f\n", vc0, vc1, v33, v50p, v12p, v12n, v50n); + printf("Vcore = %4.2f, %4.2f; Volt. = %4.2f, %4.2f, %5.2f, %6.2f, %5.2f\n", vc0, vc1, v33, v50p, v12p, v12n, v50n); } else if(fanspeed == 0) { if(integer_flag == 0) { if(temperature == 1)