NetBSD port by Thomas Runge.
This commit is contained in:
@@ -7,6 +7,14 @@
|
|||||||
|
|
||||||
#include "shared/sockets.h"
|
#include "shared/sockets.h"
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <machine/apmvar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mode.h"
|
#include "mode.h"
|
||||||
#include "batt.h"
|
#include "batt.h"
|
||||||
@@ -18,6 +26,44 @@ static int get_batt_stat (int *acstat, int *battstat, int *battflag, int *percen
|
|||||||
static int
|
static int
|
||||||
get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent)
|
get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
struct apm_power_info apmi;
|
||||||
|
int apmd;
|
||||||
|
|
||||||
|
if((apmd = open("/dev/apm", O_RDONLY)) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memset(&apmi, 0, sizeof(apmi));
|
||||||
|
if(ioctl(apmd, APM_IOC_GETPOWER, &apmi) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "APM_IOC_GETPOWER failed in get_batt_stat(): %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* don't know, what the Linux counterparts exactly mean */
|
||||||
|
switch(apmi.ac_state)
|
||||||
|
{
|
||||||
|
case APM_AC_OFF:
|
||||||
|
*acstat = 0;
|
||||||
|
break;
|
||||||
|
case APM_AC_ON:
|
||||||
|
*acstat = 1;
|
||||||
|
break;
|
||||||
|
case APM_AC_BACKUP:
|
||||||
|
*acstat = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*acstat = apmi.ac_state;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*battstat = 0;
|
||||||
|
*battflag = apmi.battery_state;
|
||||||
|
*percent = apmi.battery_life;
|
||||||
|
|
||||||
|
close(apmd);
|
||||||
|
#else
|
||||||
char str[64];
|
char str[64];
|
||||||
|
|
||||||
if (!batt_fd)
|
if (!batt_fd)
|
||||||
@@ -34,6 +80,7 @@ get_batt_stat (int *acstat, int *battstat, int *battflag, int *percent)
|
|||||||
if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
|
if (3 > sscanf (str + 13, "0x%x 0x%x 0x%x %d", acstat, battstat, battflag, percent))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -133,6 +180,27 @@ battery_screen (int rep, int display)
|
|||||||
sock_send_string (sock, tmp);
|
sock_send_string (sock, tmp);
|
||||||
|
|
||||||
sprintf (tmp, "widget_set B two 1 3 {");
|
sprintf (tmp, "widget_set B two 1 3 {");
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
switch(battflag)
|
||||||
|
{
|
||||||
|
case APM_BATT_HIGH:
|
||||||
|
sprintf (tmp + strlen (tmp), "Batt: High");
|
||||||
|
break;
|
||||||
|
case APM_BATT_LOW:
|
||||||
|
sprintf (tmp + strlen (tmp), "Batt: Low");
|
||||||
|
break;
|
||||||
|
case APM_BATT_CRITICAL:
|
||||||
|
sprintf (tmp + strlen (tmp), "Batt: Critical");
|
||||||
|
break;
|
||||||
|
case APM_BATT_CHARGING:
|
||||||
|
sprintf (tmp + strlen (tmp), "Batt: Charging");
|
||||||
|
break;
|
||||||
|
case APM_BATT_UNKNOWN:
|
||||||
|
default:
|
||||||
|
sprintf (tmp + strlen (tmp), "Batt: Unknown");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (battflag == 0xff) {
|
if (battflag == 0xff) {
|
||||||
sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
|
sprintf (tmp + strlen (tmp), "Battery Stat Unknown");
|
||||||
} else {
|
} else {
|
||||||
@@ -148,6 +216,7 @@ battery_screen (int rep, int display)
|
|||||||
if (battflag & 128)
|
if (battflag & 128)
|
||||||
sprintf (tmp + strlen (tmp), " (NONE)");
|
sprintf (tmp + strlen (tmp), " (NONE)");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
sprintf (tmp + strlen (tmp), "}\n");
|
sprintf (tmp + strlen (tmp), "}\n");
|
||||||
if (display)
|
if (display)
|
||||||
sock_send_string (sock, tmp);
|
sock_send_string (sock, tmp);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ int uptime_fd = 0;
|
|||||||
#if FREEBSD
|
#if FREEBSD
|
||||||
static double freebsd_get_uptime(double *up, double *idle);
|
static double freebsd_get_uptime(double *up, double *idle);
|
||||||
#define get_uptime freebsd_get_uptime
|
#define get_uptime freebsd_get_uptime
|
||||||
#elif (NETBSD || OPENBSD)
|
#elif (__NetBSD__ || OPENBSD)
|
||||||
static double opennetbsd_get_uptime(double *up, double *idle);
|
static double opennetbsd_get_uptime(double *up, double *idle);
|
||||||
#define get_uptime opennetbsd_get_uptime
|
#define get_uptime opennetbsd_get_uptime
|
||||||
#elif LINUX
|
#elif LINUX
|
||||||
@@ -196,7 +196,7 @@ static long get_openbsd_idle_time() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (NETBSD || OPENBSD)
|
#if (__NetBSD__ || OPENBSD)
|
||||||
static double opennetbsd_get_uptime(double *up, double *idle) {
|
static double opennetbsd_get_uptime(double *up, double *idle) {
|
||||||
double uptime = 0;
|
double uptime = 0;
|
||||||
struct timeval boottime;
|
struct timeval boottime;
|
||||||
@@ -204,7 +204,7 @@ static double opennetbsd_get_uptime(double *up, double *idle) {
|
|||||||
time_t now, uuptime;
|
time_t now, uuptime;
|
||||||
size_t size;
|
size_t size;
|
||||||
int mib[2];
|
int mib[2];
|
||||||
#if NETBSD
|
#if __NetBSD__
|
||||||
u_int64_t cp_time[CPUSTATES];
|
u_int64_t cp_time[CPUSTATES];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ kstat_ctl_t *kc;
|
|||||||
|
|
||||||
int load_fd = 0;
|
int load_fd = 0;
|
||||||
|
|
||||||
#ifdef NETBSD
|
#ifdef __NetBSD__
|
||||||
static void netbsd_get_load (struct load * result, struct load * last_load );
|
static void netbsd_get_load (struct load * result, struct load * last_load );
|
||||||
#define get_load netbsd_get_load
|
#define get_load netbsd_get_load
|
||||||
#elif defined OPENBSD || FREEBSD
|
#elif defined OPENBSD || FREEBSD
|
||||||
@@ -141,7 +141,7 @@ static void linuxsolaris_get_load (struct load *result, struct load * last_load
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NETBSD
|
#ifdef __NetBSD__
|
||||||
static void netbsd_get_load(struct load * result, struct load * last_load) {
|
static void netbsd_get_load(struct load * result, struct load * last_load) {
|
||||||
struct load curr_load;
|
struct load curr_load;
|
||||||
u_int64_t cp_time[CPUSTATES];
|
u_int64_t cp_time[CPUSTATES];
|
||||||
@@ -153,7 +153,7 @@ static void netbsd_get_load(struct load * result, struct load * last_load) {
|
|||||||
size = sizeof(cp_time);
|
size = sizeof(cp_time);
|
||||||
|
|
||||||
if(sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
|
if(sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
|
||||||
//fprintf(stderr, "sysctl kern.cp_time failed: %s\n", strerror(errno));
|
fprintf(stderr, "sysctl kern.cp_time failed: %s\n", strerror(errno));
|
||||||
curr_load.user = 1;
|
curr_load.user = 1;
|
||||||
curr_load.nice = 1;
|
curr_load.nice = 1;
|
||||||
curr_load.system = 1;
|
curr_load.system = 1;
|
||||||
|
|||||||
@@ -64,6 +64,12 @@
|
|||||||
#ifdef HAVE_LIBKSTAT
|
#ifdef HAVE_LIBKSTAT
|
||||||
#include <kstat.h>
|
#include <kstat.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/sched.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAX_CPUS 8
|
#define MAX_CPUS 8
|
||||||
|
|
||||||
@@ -79,14 +85,65 @@ static int load_fd = 0;
|
|||||||
|
|
||||||
static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six", "seven", "eight" };
|
static char *numnames[MAX_CPUS] = { "one", "two", "three", "four", "five", "six", "seven", "eight" };
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
static void
|
||||||
|
get_netbsd_load (struct load *result, int *numcpus)
|
||||||
|
{
|
||||||
|
int mib[2], i, num;
|
||||||
|
size_t size;
|
||||||
|
struct load curr_load;
|
||||||
|
u_int64_t cp_time[CPUSTATES];
|
||||||
|
|
||||||
|
mib[0] = CTL_HW;
|
||||||
|
mib[1] = HW_NCPU;
|
||||||
|
size = sizeof(int);
|
||||||
|
|
||||||
|
if(sysctl(mib, 2, &num, &size, NULL, 0) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "sysctl kern.boottime failed: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
mib[0] = CTL_KERN;
|
||||||
|
mib[1] = KERN_CP_TIME;
|
||||||
|
size = sizeof(cp_time);
|
||||||
|
|
||||||
|
if(sysctl(mib, 2, cp_time, &size, NULL, 0) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "sysctl kern.cp_time failed: %s\n", strerror(errno));
|
||||||
|
curr_load.user = 1;
|
||||||
|
curr_load.nice = 1;
|
||||||
|
curr_load.system = 1;
|
||||||
|
curr_load.idle = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_load.user = cp_time[CP_USER];
|
||||||
|
curr_load.nice = cp_time[CP_NICE];
|
||||||
|
curr_load.system = cp_time[CP_SYS] + cp_time[CP_INTR];
|
||||||
|
curr_load.idle = cp_time[CP_IDLE];
|
||||||
|
}
|
||||||
|
curr_load.total = curr_load.user + curr_load.nice + curr_load.system + curr_load.idle;
|
||||||
|
|
||||||
|
*numcpus = num;
|
||||||
|
num = num > 8 ? 8 : num;
|
||||||
|
/* we can not get per-cpu-load values */
|
||||||
|
for(i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
result[i] = curr_load;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_load (struct load *result, int *numcpus)
|
get_load (struct load *result, int *numcpus)
|
||||||
{
|
{
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
get_netbsd_load(result, numcpus);
|
||||||
|
#else
|
||||||
char *token;
|
char *token;
|
||||||
static struct load last_load[MAX_CPUS];
|
static struct load last_load[MAX_CPUS];
|
||||||
struct load curr_load[MAX_CPUS];
|
struct load curr_load[MAX_CPUS];
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_LIBKSTAT
|
#ifndef HAVE_LIBKSTAT
|
||||||
*numcpus = 0;
|
*numcpus = 0;
|
||||||
|
|
||||||
@@ -155,11 +212,13 @@ get_load (struct load *result, int *numcpus)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cpu_smp_init ()
|
cpu_smp_init ()
|
||||||
{
|
{
|
||||||
|
#ifndef __NetBSD__
|
||||||
#ifndef HAVE_LIBKSTAT
|
#ifndef HAVE_LIBKSTAT
|
||||||
if (!load_fd) {
|
if (!load_fd) {
|
||||||
load_fd = open ("/proc/stat", O_RDONLY);
|
load_fd = open ("/proc/stat", O_RDONLY);
|
||||||
@@ -170,6 +229,7 @@ cpu_smp_init ()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -177,6 +237,7 @@ cpu_smp_init ()
|
|||||||
int
|
int
|
||||||
cpu_smp_close ()
|
cpu_smp_close ()
|
||||||
{
|
{
|
||||||
|
#ifndef __NetBSD__
|
||||||
#ifndef HAVE_LIBKSTAT
|
#ifndef HAVE_LIBKSTAT
|
||||||
if (load_fd)
|
if (load_fd)
|
||||||
close (load_fd);
|
close (load_fd);
|
||||||
@@ -186,6 +247,7 @@ cpu_smp_close ()
|
|||||||
|
|
||||||
load_fd = 0;
|
load_fd = 0;
|
||||||
|
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+60
-1
@@ -33,7 +33,13 @@
|
|||||||
#include "mode.h"
|
#include "mode.h"
|
||||||
#include "disk.h"
|
#include "disk.h"
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ucred.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#else
|
||||||
FILE *mtab_fd;
|
FILE *mtab_fd;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct mounts {
|
typedef struct mounts {
|
||||||
char dev[256], type[64], mpoint[256];
|
char dev[256], type[64], mpoint[256];
|
||||||
@@ -43,6 +49,58 @@ typedef struct mounts {
|
|||||||
static int
|
static int
|
||||||
get_fs (mounts fs[])
|
get_fs (mounts fs[])
|
||||||
{
|
{
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
struct statfs *mntbuf;
|
||||||
|
struct statfs *pp;
|
||||||
|
int statcnt, cnt, i;
|
||||||
|
|
||||||
|
cnt = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
|
if(cnt == 0)
|
||||||
|
{
|
||||||
|
perror("getmntinfo");
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
for(statcnt = 0, pp = mntbuf, i = 0; i < cnt; pp++, i++)
|
||||||
|
{
|
||||||
|
if(strcmp(pp->f_fstypename, "procfs")
|
||||||
|
&& strcmp(pp->f_fstypename, "kernfs")
|
||||||
|
&& strcmp(pp->f_fstypename, "linprocfs")
|
||||||
|
#ifndef STAT_NFS
|
||||||
|
&& strcmp(pp->f_fstypename, "nfs")
|
||||||
|
#endif
|
||||||
|
#ifndef STAT_SMBFS
|
||||||
|
&& strcmp(pp->f_fstypename, "smbfs")
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
printf("mount point: %s\n", pp->f_mntonname);
|
||||||
|
printf("fs name : %s\n", pp->f_mntfromname);
|
||||||
|
printf("fs type : %s\n", pp->f_fstypename);
|
||||||
|
*/
|
||||||
|
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
||||||
|
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
||||||
|
snprintf(fs[statcnt].type, 255, "%s", pp->f_fstypename);
|
||||||
|
|
||||||
|
fs[statcnt].blocks = pp->f_blocks;
|
||||||
|
if(fs[statcnt].blocks > 0)
|
||||||
|
{
|
||||||
|
fs[statcnt].bsize = pp->f_bsize;
|
||||||
|
fs[statcnt].bfree = pp->f_bfree;
|
||||||
|
fs[statcnt].files = pp->f_files;
|
||||||
|
fs[statcnt].ffree = pp->f_ffree;
|
||||||
|
|
||||||
|
/*
|
||||||
|
printf("bsize : %ld\n", pp->f_bsize);
|
||||||
|
printf("blocks: %ld\n", pp->f_blocks);
|
||||||
|
printf("free : %ld\n", pp->f_bfree);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
statcnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(statcnt);
|
||||||
|
#else
|
||||||
#ifdef STAT_STATVFS
|
#ifdef STAT_STATVFS
|
||||||
struct statvfs fsinfo;
|
struct statvfs fsinfo;
|
||||||
#else
|
#else
|
||||||
@@ -99,6 +157,7 @@ get_fs (mounts fs[])
|
|||||||
|
|
||||||
fclose (mtab_fd);
|
fclose (mtab_fd);
|
||||||
return x;
|
return x;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -178,7 +237,7 @@ disk_screen (int rep, int display)
|
|||||||
sprintf (table[i].dev, "%s", mnt[i].mpoint);
|
sprintf (table[i].dev, "%s", mnt[i].mpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
//table[i].full = (lcd.cellwid * 4)
|
//table[i].full = (lcd_cellwid * 4);
|
||||||
table[i].full = (huge) (lcd_cellwid * 4)
|
table[i].full = (huge) (lcd_cellwid * 4)
|
||||||
* (huge) (mnt[i].blocks - mnt[i].bfree)
|
* (huge) (mnt[i].blocks - mnt[i].bfree)
|
||||||
/ (huge) mnt[i].blocks;
|
/ (huge) mnt[i].blocks;
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
# include <sys/loadavg.h>
|
# include <sys/loadavg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#define USE_GETLOADAVG
|
||||||
|
#define LOADAVG_NSTATS 1
|
||||||
|
#define LOADAVG_1MIN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
int loadavg_fd = 0;
|
int loadavg_fd = 0;
|
||||||
|
|
||||||
|
|||||||
+134
-15
@@ -26,6 +26,17 @@
|
|||||||
# include <sys/procfs.h>
|
# include <sys/procfs.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <uvm/uvm_extern.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <kvm.h>
|
||||||
|
static int pageshift;
|
||||||
|
#define pagetok(size) ((size) << pageshift)
|
||||||
|
#define PROCSIZE(pp) ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
|
||||||
|
static void netbsd_get_procs(LinkedList *procs);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct meminfo {
|
struct meminfo {
|
||||||
@@ -40,16 +51,7 @@ static void
|
|||||||
get_mem_info (struct meminfo *result)
|
get_mem_info (struct meminfo *result)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef SOLARIS
|
#ifdef SOLARIS
|
||||||
reread (meminfo_fd, "get_meminfo:");
|
|
||||||
result[0].total = getentry ("MemTotal:", buffer);
|
|
||||||
result[0].free = getentry ("MemFree:", buffer);
|
|
||||||
result[0].shared = getentry ("MemShared:", buffer);
|
|
||||||
result[0].buffers = getentry ("Buffers:", buffer);
|
|
||||||
result[0].cache = getentry ("Cached:", buffer);
|
|
||||||
result[1].total = getentry ("SwapTotal:", buffer);
|
|
||||||
result[1].free = getentry ("SwapFree:", buffer);
|
|
||||||
#else
|
|
||||||
#define MAXSTRSIZE 80
|
#define MAXSTRSIZE 80
|
||||||
swaptbl_t *s=NULL;
|
swaptbl_t *s=NULL;
|
||||||
int i, n, num;
|
int i, n, num;
|
||||||
@@ -105,13 +107,65 @@ again:
|
|||||||
result[1].total = result[1].total + s->swt_ent[i].ste_pages * sysconf(_SC_PAGESIZE) / 1024;
|
result[1].total = result[1].total + s->swt_ent[i].ste_pages * sysconf(_SC_PAGESIZE) / 1024;
|
||||||
result[1].free = result[1].free + s->swt_ent[i].ste_free * sysconf(_SC_PAGESIZE) / 1024;
|
result[1].free = result[1].free + s->swt_ent[i].ste_free * sysconf(_SC_PAGESIZE) / 1024;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
size_t size;
|
||||||
|
int mib[2];
|
||||||
|
struct uvmexp_sysctl uvmexp;
|
||||||
|
|
||||||
|
mib[0] = CTL_VM;
|
||||||
|
mib[1] = VM_UVMEXP2;
|
||||||
|
size = sizeof(uvmexp);
|
||||||
|
if(sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "sysctl vm.uvmexp2 failed: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* memory */
|
||||||
|
result[0].total = pagetok(uvmexp.npages);
|
||||||
|
result[0].free = pagetok(uvmexp.free);
|
||||||
|
/* not really */
|
||||||
|
result[0].shared = pagetok(uvmexp.wired);
|
||||||
|
result[0].buffers = pagetok(uvmexp.execpages);
|
||||||
|
result[0].cache = pagetok(uvmexp.filepages);
|
||||||
|
|
||||||
|
/* swap */
|
||||||
|
result[1].total = uvmexp.pagesize * uvmexp.swpages;
|
||||||
|
result[1].free = uvmexp.pagesize * uvmexp.swpginuse;
|
||||||
|
result[1].free = result[1].total - result[1].free;
|
||||||
|
#else
|
||||||
|
reread (meminfo_fd, "get_meminfo:");
|
||||||
|
result[0].total = getentry ("MemTotal:", buffer);
|
||||||
|
result[0].free = getentry ("MemFree:", buffer);
|
||||||
|
result[0].shared = getentry ("MemShared:", buffer);
|
||||||
|
result[0].buffers = getentry ("Buffers:", buffer);
|
||||||
|
result[0].cache = getentry ("Cached:", buffer);
|
||||||
|
result[1].total = getentry ("SwapTotal:", buffer);
|
||||||
|
result[1].free = getentry ("SwapFree:", buffer);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mem_init ()
|
mem_init ()
|
||||||
{
|
{
|
||||||
#ifndef SOLARIS
|
#ifdef SOLARIS
|
||||||
|
#else
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
/* get the page size with "getpagesize" and calculate pageshift from it */
|
||||||
|
int pagesize = getpagesize();
|
||||||
|
pageshift = 0;
|
||||||
|
while(pagesize > 1)
|
||||||
|
{
|
||||||
|
pageshift++;
|
||||||
|
pagesize >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we only need the amount of log(2)1024 for our conversion */
|
||||||
|
pageshift -= 10;
|
||||||
|
#else
|
||||||
if (!meminfo_fd) {
|
if (!meminfo_fd) {
|
||||||
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
|
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
|
||||||
if (meminfo_fd < 0) {
|
if (meminfo_fd < 0) {
|
||||||
@@ -119,7 +173,7 @@ mem_init ()
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -127,12 +181,16 @@ mem_init ()
|
|||||||
int
|
int
|
||||||
mem_close ()
|
mem_close ()
|
||||||
{
|
{
|
||||||
#ifndef SOLARIS
|
#ifdef SOLARIS
|
||||||
|
#else
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
#else
|
||||||
if (meminfo_fd)
|
if (meminfo_fd)
|
||||||
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
|
meminfo_fd = open ("/proc/meminfo", O_RDONLY);
|
||||||
|
|
||||||
meminfo_fd = 0;
|
meminfo_fd = 0;
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -330,6 +388,7 @@ sort_procs (void *a, void *b)
|
|||||||
int
|
int
|
||||||
mem_top_screen (int rep, int display)
|
mem_top_screen (int rep, int display)
|
||||||
{
|
{
|
||||||
|
#ifndef __NetBSD__
|
||||||
// Much of this code was ripped from "gmemusage"
|
// Much of this code was ripped from "gmemusage"
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
@@ -344,8 +403,9 @@ mem_top_screen (int rep, int display)
|
|||||||
*NameLine = "Name:", *VmSizeLine = "VmSize:", *VmRSSLine = "VmRSS", *VmDataLine = "VmData", *VmStkLine = "VmStk", *VmExeLine = "VmExe";
|
*NameLine = "Name:", *VmSizeLine = "VmSize:", *VmRSSLine = "VmRSS", *VmDataLine = "VmData", *VmStkLine = "VmStk", *VmExeLine = "VmExe";
|
||||||
const int
|
const int
|
||||||
NameLineLen = strlen (NameLine), VmSizeLineLen = strlen (VmSizeLine), VmDataLineLen = strlen (VmDataLine), VmStkLineLen = strlen (VmStkLine), VmExeLineLen = strlen (VmExeLine), VmRSSLineLen = strlen (VmRSSLine);
|
NameLineLen = strlen (NameLine), VmSizeLineLen = strlen (VmSizeLine), VmDataLineLen = strlen (VmDataLine), VmStkLineLen = strlen (VmStkLine), VmExeLineLen = strlen (VmExeLine), VmRSSLineLen = strlen (VmRSSLine);
|
||||||
|
|
||||||
int threshold = 400, unique;
|
int threshold = 400, unique;
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
proc_mem_info *p;
|
proc_mem_info *p;
|
||||||
LinkedList *procs;
|
LinkedList *procs;
|
||||||
@@ -377,6 +437,9 @@ mem_top_screen (int rep, int display)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
netbsd_get_procs(procs);
|
||||||
|
#else
|
||||||
if ((proc = opendir ("/proc")) == NULL) {
|
if ((proc = opendir ("/proc")) == NULL) {
|
||||||
fprintf (stderr, "mem_top_screen: unable to open /proc");
|
fprintf (stderr, "mem_top_screen: unable to open /proc");
|
||||||
perror ("");
|
perror ("");
|
||||||
@@ -476,6 +539,8 @@ mem_top_screen (int rep, int display)
|
|||||||
|
|
||||||
}
|
}
|
||||||
closedir (proc);
|
closedir (proc);
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
// Now, print some info...
|
// Now, print some info...
|
||||||
LL_Rewind (procs);
|
LL_Rewind (procs);
|
||||||
LL_Sort (procs, sort_procs);
|
LL_Sort (procs, sort_procs);
|
||||||
@@ -501,7 +566,9 @@ mem_top_screen (int rep, int display)
|
|||||||
LL_Next (procs);
|
LL_Next (procs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __NetBSD__
|
||||||
end: // Ack! I hate using labels!
|
end: // Ack! I hate using labels!
|
||||||
|
#endif
|
||||||
// Now clean it all up...
|
// Now clean it all up...
|
||||||
LL_Rewind (procs);
|
LL_Rewind (procs);
|
||||||
do {
|
do {
|
||||||
@@ -515,4 +582,56 @@ mem_top_screen (int rep, int display)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} // End mem_top_screen()
|
}
|
||||||
|
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
static void netbsd_get_procs(LinkedList *procs)
|
||||||
|
{
|
||||||
|
kvm_t *kvmd = NULL;
|
||||||
|
struct kinfo_proc2 *kprocs = NULL;
|
||||||
|
struct kinfo_proc2 *pp;
|
||||||
|
int nproc, i;
|
||||||
|
proc_mem_info *p;
|
||||||
|
|
||||||
|
if((kvmd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "kvm_openfiles\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
kprocs = kvm_getproc2(kvmd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &nproc);
|
||||||
|
|
||||||
|
if(kprocs == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "kvm_getproc2\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(pp = kprocs, i = 0; i < nproc; pp++, i++)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
printf("proc: %s (%ld) size: %ld K\n", pp->p_comm,
|
||||||
|
(long) (pp->p_pid),
|
||||||
|
(long) (PROCSIZE(pp) << pageshift));
|
||||||
|
*/
|
||||||
|
|
||||||
|
p = malloc(sizeof(proc_mem_info));
|
||||||
|
if(!p)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "mem_top_screen: Error allocating process entry\n");
|
||||||
|
kvm_close(kvmd);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
strncpy(p->name, pp->p_comm, 15);
|
||||||
|
p->name[15] = '\0';
|
||||||
|
p->totl = (PROCSIZE(pp) << pageshift);
|
||||||
|
p->number = pp->p_pid;
|
||||||
|
/* TODO: Check for errors here? */
|
||||||
|
LL_Push(procs, (void *)p);
|
||||||
|
|
||||||
|
kprocs++;
|
||||||
|
}
|
||||||
|
kvm_close(kvmd);
|
||||||
|
}
|
||||||
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
|
|||||||
@@ -280,12 +280,20 @@ credit_screen (int rep, int display)
|
|||||||
sock_send_string (sock, "widget_add A one string\n");
|
sock_send_string (sock, "widget_add A one string\n");
|
||||||
sock_send_string (sock, "widget_add A two string\n");
|
sock_send_string (sock, "widget_add A two string\n");
|
||||||
sock_send_string (sock, "widget_add A three string\n");
|
sock_send_string (sock, "widget_add A three string\n");
|
||||||
sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
|
#ifdef __NetBSD__
|
||||||
|
sock_send_string (sock, "widget_set A one 1 2 { for Linux & NetBSD}\n");
|
||||||
|
#else
|
||||||
|
sock_send_string (sock, "widget_set A one 1 2 { for Linux }\n");
|
||||||
|
#endif
|
||||||
sock_send_string (sock, "widget_set A two 1 3 { by William Ferrell}\n");
|
sock_send_string (sock, "widget_set A two 1 3 { by William Ferrell}\n");
|
||||||
sock_send_string (sock, "widget_set A three 1 4 { and Scott Scriven}\n");
|
sock_send_string (sock, "widget_set A three 1 4 { and Scott Scriven}\n");
|
||||||
} else {
|
} else {
|
||||||
sock_send_string (sock, "widget_add A text scroller\n");
|
sock_send_string (sock, "widget_add A text scroller\n");
|
||||||
|
#ifdef __NetBSD__
|
||||||
|
sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux & NetBSD by William Ferrell and Scott Scriven}\n");
|
||||||
|
#else
|
||||||
sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
|
sock_send_string (sock, "widget_set A text 1 2 20 2 v 8 { for Linux by William Ferrell and Scott Scriven}\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -290,7 +290,6 @@ process_command_line (int argc, char **argv)
|
|||||||
debug( RPT_DEBUG, "%s( argc=%d, argv=...)", __FUNCTION__, argc );
|
debug( RPT_DEBUG, "%s( argc=%d, argv=...)", __FUNCTION__, argc );
|
||||||
|
|
||||||
/* Reset getopt */
|
/* Reset getopt */
|
||||||
optind = 0;
|
|
||||||
opterr = 0; /* Prevent some messages to stderr */
|
opterr = 0; /* Prevent some messages to stderr */
|
||||||
|
|
||||||
/* Analyze options here.. (please try to keep list of options the
|
/* Analyze options here.. (please try to keep list of options the
|
||||||
|
|||||||
Reference in New Issue
Block a user