formatting, add freebsd support
This commit is contained in:
parent
06227deb08
commit
3b3d39c18c
22
Makefile
22
Makefile
@ -1,8 +1,23 @@
|
|||||||
|
OS = FreeBSD
|
||||||
PROG= xmem
|
PROG= xmem
|
||||||
VERSION= 1.26
|
VERSION= 1.26
|
||||||
LDFLAGS+= -L/usr/X11R6/lib -lX11 -lXt -lXaw -lXmu
|
FreeBSD_lflag= -lkvm
|
||||||
CFLAGS+= -Wall -I/usr/X11R6/include/
|
LDFLAGS+= -L/usr/X11R6/lib -L/usr/local/lib/ -lX11 -lXt -lXaw -lXmu
|
||||||
OBJECTS= xmem.o get_mem.o MemStripChart.o
|
LDFLAGS+= $($(OS)_lflag)
|
||||||
|
CFLAGS+= -Wall -I/usr/X11R6/include/ -I/usr/local/include/
|
||||||
|
OBJECTS= xmem.o MemStripChart.o
|
||||||
|
FreeBSD_stub = get_mem_fbsd.o
|
||||||
|
OpenBSD_stub = get_mem.o
|
||||||
|
OBJECTS += $($(OS)_stub)
|
||||||
|
|
||||||
|
|
||||||
|
all: xmem
|
||||||
|
|
||||||
|
xmem.full:
|
||||||
|
echo full
|
||||||
|
|
||||||
|
xmem.debug:
|
||||||
|
echo full
|
||||||
|
|
||||||
xmem: $(OBJECTS)
|
xmem: $(OBJECTS)
|
||||||
$(CC) -o xmem $(OBJECTS) $(LDFLAGS)
|
$(CC) -o xmem $(OBJECTS) $(LDFLAGS)
|
||||||
@ -33,6 +48,5 @@ install:
|
|||||||
install -c -o root -g bin -m 644 xmem.bit ${PREFIX}/share/${PROG}/xmem.bit
|
install -c -o root -g bin -m 644 xmem.bit ${PREFIX}/share/${PROG}/xmem.bit
|
||||||
install -c -o root -g bin -m 644 copyright ${PREFIX}/share/${PROG}/copyright
|
install -c -o root -g bin -m 644 copyright ${PREFIX}/share/${PROG}/copyright
|
||||||
|
|
||||||
all: xmem
|
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* $Id: get_mem.c,v 1.4 2017/02/26 16:03:48 bch Exp $
|
/* $Id: get_mem.c,v 1.5 2018/12/26 18:46:04 bch Exp $
|
||||||
|
*
|
||||||
* Adapted: get memory usage on OpenBSD
|
* Adapted: get memory usage on OpenBSD
|
||||||
* Author: Christian Barthel <bch@vcs.onfire.org>
|
* Author: Christian Barthel <bch@online.de>
|
||||||
*
|
*
|
||||||
* get memory usage, from get_load.c derived
|
* get memory usage, from get_load.c derived
|
||||||
*
|
*
|
||||||
@ -9,6 +10,7 @@
|
|||||||
* Modified for more recent kernels Helmut Geyer Oct. 1996
|
* Modified for more recent kernels Helmut Geyer Oct. 1996
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <sys/param.h> /* DEV_BSIZE MAXCOMLEN PZERO */
|
#include <sys/param.h> /* DEV_BSIZE MAXCOMLEN PZERO */
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/swap.h>
|
#include <sys/swap.h>
|
||||||
|
232
xmem.c
232
xmem.c
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* xmem - display memory/swap usage utility for X
|
* xmem - display memory/swap usage utility for X
|
||||||
*
|
*
|
||||||
* Updated by Christian Barthel <bch@onfire.org>
|
* Updated by Christian Barthel <bch@online.de>
|
||||||
*
|
*
|
||||||
* Copyright 1989 Massachusetts Institute of Technology
|
* Copyright 1989 Massachusetts Institute of Technology
|
||||||
*
|
*
|
||||||
@ -47,19 +47,19 @@ typedef struct _XLoadResources {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static XrmOptionDescRec options_mem[] = {
|
static XrmOptionDescRec options_mem[] = {
|
||||||
{"-scale", "*mem.minScale", XrmoptionSepArg, NULL},
|
{"-scale", "*mem.minScale", XrmoptionSepArg, NULL},
|
||||||
{"-update", "*mem.update", XrmoptionSepArg, NULL},
|
{"-update", "*mem.update", XrmoptionSepArg, NULL},
|
||||||
{"-hl", "*mem.highlight", XrmoptionSepArg, NULL},
|
{"-hl", "*mem.highlight", XrmoptionSepArg, NULL},
|
||||||
{"-highlight", "*mem.highlight", XrmoptionSepArg, NULL},
|
{"-highlight", "*mem.highlight", XrmoptionSepArg, NULL},
|
||||||
{"-codecolor", "*mem.codecolor", XrmoptionSepArg, NULL},
|
{"-codecolor", "*mem.codecolor", XrmoptionSepArg, NULL},
|
||||||
{"-cachedcolor", "*mem.cachedcolor", XrmoptionSepArg, NULL},
|
{"-cachedcolor", "*mem.cachedcolor", XrmoptionSepArg, NULL},
|
||||||
{"-buffercolor", "*mem.buffercolor", XrmoptionSepArg, NULL},
|
{"-buffercolor", "*mem.buffercolor", XrmoptionSepArg, NULL},
|
||||||
{"-freecolor", "*mem.freecolor", XrmoptionSepArg, NULL},
|
{"-freecolor", "*mem.freecolor", XrmoptionSepArg, NULL},
|
||||||
{"-swapcolor", "*mem.swapcolor", XrmoptionSepArg, NULL},
|
{"-swapcolor", "*mem.swapcolor", XrmoptionSepArg, NULL},
|
||||||
{"-jumpscroll", "*mem.jumpScroll", XrmoptionSepArg, NULL},
|
{"-jumpscroll", "*mem.jumpScroll", XrmoptionSepArg, NULL},
|
||||||
{"-label", "*label.label", XrmoptionSepArg, NULL},
|
{"-label", "*label.label", XrmoptionSepArg, NULL},
|
||||||
{"-nolabel", "*showLabel", XrmoptionNoArg, "False"},
|
{"-nolabel", "*showLabel", XrmoptionNoArg, "False"},
|
||||||
{"-lights", "*useLights", XrmoptionNoArg, "True"},
|
{"-lights", "*useLights", XrmoptionNoArg, "True"},
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -71,7 +71,7 @@ static XrmOptionDescRec options_mem[] = {
|
|||||||
|
|
||||||
static XtResource my_resources_mem[] = {
|
static XtResource my_resources_mem[] = {
|
||||||
{"showLabel", XtCBoolean, XtRBoolean, sizeof(Boolean),
|
{"showLabel", XtCBoolean, XtRBoolean, sizeof(Boolean),
|
||||||
Offset(show_label), XtRImmediate, (XtPointer) TRUE},
|
Offset(show_label), XtRImmediate, (XtPointer) TRUE},
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef Offset
|
#undef Offset
|
||||||
@ -79,7 +79,7 @@ static XtResource my_resources_mem[] = {
|
|||||||
static XLoadResources resources;
|
static XLoadResources resources;
|
||||||
|
|
||||||
static XtActionsRec xload_actions[] = {
|
static XtActionsRec xload_actions[] = {
|
||||||
{ "quit", quit },
|
{ "quit", quit },
|
||||||
};
|
};
|
||||||
static Atom wm_delete_window;
|
static Atom wm_delete_window;
|
||||||
|
|
||||||
@ -92,38 +92,38 @@ void usage(char *progname)
|
|||||||
fprintf (stderr, "usage: %s [-options ...]\n\n", progname);
|
fprintf (stderr, "usage: %s [-options ...]\n\n", progname);
|
||||||
fprintf (stderr, "where options include:\n");
|
fprintf (stderr, "where options include:\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -display dpy X server on which to display\n");
|
" -display dpy X server on which to display\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -geometry geom size and location of window\n");
|
" -geometry geom size and location of window\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -fn font font to use in label\n");
|
" -fn font font to use in label\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -update seconds interval between updates\n");
|
" -update seconds interval between updates\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -label string annotation text\n");
|
" -label string annotation text\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -bg color background color\n");
|
" -bg color background color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -fg color text color\n");
|
" -fg color text color\n");
|
||||||
|
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -hl color scale color\n");
|
" -hl color scale color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -codecolor color used code and stack memory color\n");
|
" -codecolor color used code and stack memory color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -cachedcolor color used cached memory color\n");
|
" -cachedcolor color used cached memory color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -buffercolor color used buffer memory color\n");
|
" -buffercolor color used buffer memory color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -freecolor color used free memory color\n");
|
" -freecolor color used free memory color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -swapcolor color used swap memory color\n");
|
" -swapcolor color used swap memory color\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -nolabel removes the label from above the chart.\n");
|
" -nolabel removes the label from above the chart.\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
" -jumpscroll value number of pixels to scroll on overflow\n");
|
" -jumpscroll value number of pixels to scroll on overflow\n");
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"The reference line refers to the avaible installed ram\n");
|
"The reference line refers to the avaible installed ram\n");
|
||||||
|
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -131,94 +131,96 @@ void usage(char *progname)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
XtAppContext app_con;
|
XtAppContext app_con;
|
||||||
Widget toplevel, load, pane, label_wid, load_parent;
|
Widget toplevel, load, pane, label_wid, load_parent;
|
||||||
Arg args[1];
|
Arg args[1];
|
||||||
Pixmap icon_pixmap = None;
|
Pixmap icon_pixmap = None;
|
||||||
char *label, host[256];
|
char *label, host[256];
|
||||||
|
|
||||||
/* For security reasons, we reset our uid/gid after doing the necessary
|
/* For security reasons, we reset our uid/gid after doing the necessary
|
||||||
system initialization and before calling any X routines. */
|
system initialization and before calling any X routines. */
|
||||||
|
|
||||||
if (setgid(getgid()) == -1)
|
if (setgid(getgid()) == -1)
|
||||||
errx(1, "%s: setgid failed: %s\n", argv[0], strerror(errno));
|
errx(1, "%s: setgid failed: %s\n", argv[0], strerror(errno));
|
||||||
if (setuid(getuid()) == -1)
|
if (setuid(getuid()) == -1)
|
||||||
errx(1, "%s: setuid failed: %s\n", argv[0], strerror(errno));
|
errx(1, "%s: setuid failed: %s\n", argv[0], strerror(errno));
|
||||||
|
|
||||||
toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem),
|
toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem),
|
||||||
&argc, argv, NULL, NULL, (Cardinal) 0);
|
&argc, argv, NULL, NULL, (Cardinal) 0);
|
||||||
|
|
||||||
if (argc != 1) usage(argv[0]);
|
if (argc != 1) usage(argv[0]);
|
||||||
|
|
||||||
XtGetApplicationResources( toplevel, (XtPointer) &resources,
|
XtGetApplicationResources( toplevel, (XtPointer) &resources,
|
||||||
my_resources_mem, XtNumber(my_resources_mem),
|
my_resources_mem, XtNumber(my_resources_mem),
|
||||||
NULL, (Cardinal) 0);
|
NULL, (Cardinal) 0);
|
||||||
/*
|
/*
|
||||||
* This is a hack so that f.delete will do something useful in this
|
* This is a hack so that f.delete will do something useful in this
|
||||||
* single-window application.
|
* single-window application.
|
||||||
*/
|
*/
|
||||||
XtAppAddActions (app_con, xload_actions, XtNumber(xload_actions));
|
XtAppAddActions (app_con, xload_actions, XtNumber(xload_actions));
|
||||||
XtOverrideTranslations(toplevel,
|
XtOverrideTranslations(toplevel,
|
||||||
XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
|
XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
|
||||||
|
|
||||||
XtSetArg (args[0], XtNiconPixmap, &icon_pixmap);
|
XtSetArg (args[0], XtNiconPixmap, &icon_pixmap);
|
||||||
XtGetValues(toplevel, args, ONE);
|
XtGetValues(toplevel, args, ONE);
|
||||||
if (icon_pixmap == None) {
|
if (icon_pixmap == None) {
|
||||||
XtSetArg(args[0], XtNiconPixmap,
|
XtSetArg(args[0], XtNiconPixmap,
|
||||||
XCreateBitmapFromData(XtDisplay(toplevel),
|
XCreateBitmapFromData(XtDisplay(toplevel),
|
||||||
XtScreen(toplevel)->root,
|
XtScreen(toplevel)->root,
|
||||||
(char *)xload_bits,
|
(char *)xload_bits,
|
||||||
xload_width, xload_height));
|
xload_width, xload_height));
|
||||||
XtSetValues (toplevel, args, ONE);
|
XtSetValues (toplevel, args, ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resources.show_label) {
|
if (resources.show_label) {
|
||||||
pane = XtCreateManagedWidget ("paned", panedWidgetClass,
|
pane = XtCreateManagedWidget ("paned", panedWidgetClass,
|
||||||
toplevel, NULL, ZERO);
|
toplevel, NULL, ZERO);
|
||||||
|
|
||||||
label_wid = XtCreateManagedWidget ("label", labelWidgetClass,
|
label_wid = XtCreateManagedWidget ("label", labelWidgetClass,
|
||||||
pane, NULL, ZERO);
|
pane, NULL, ZERO);
|
||||||
|
|
||||||
XtSetArg (args[0], XtNlabel, &label);
|
XtSetArg (args[0], XtNlabel, &label);
|
||||||
XtGetValues(label_wid, args, ONE);
|
XtGetValues(label_wid, args, ONE);
|
||||||
|
|
||||||
if ( strcmp("label", label) == 0 ) {
|
if ( strcmp("label", label) == 0 ) {
|
||||||
(void) XmuGetHostname (host, 255);
|
(void) XmuGetHostname (host, 255);
|
||||||
XtSetArg (args[0], XtNlabel, host);
|
XtSetArg (args[0], XtNlabel, host);
|
||||||
XtSetValues (label_wid, args, ONE);
|
XtSetValues (label_wid, args, ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
load_parent = pane;
|
load_parent = pane;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
load_parent = toplevel;
|
load_parent = toplevel;
|
||||||
|
|
||||||
|
|
||||||
load = XtCreateManagedWidget ("mem", memStripChartWidgetClass,
|
load = XtCreateManagedWidget ("mem", memStripChartWidgetClass,
|
||||||
load_parent, NULL, ZERO);
|
load_parent, NULL, ZERO);
|
||||||
XtAddCallback(load, XtNgetValue, (void*)GetMemLoadPoint, NULL);
|
XtAddCallback(load, XtNgetValue, (void*)GetMemLoadPoint, NULL);
|
||||||
|
|
||||||
XtRealizeWidget (toplevel);
|
XtRealizeWidget (toplevel);
|
||||||
wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
|
wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
|
||||||
False);
|
False);
|
||||||
(void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
|
(void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
|
||||||
&wm_delete_window, 1);
|
&wm_delete_window, 1);
|
||||||
|
|
||||||
if (pledge("ps vminfo stdio", NULL) == -1)
|
#if __OpenBSD__
|
||||||
errx(1, "pledge failed: %s", strerror(errno));
|
if (pledge("ps vminfo stdio", NULL) == -1)
|
||||||
|
errx(1, "pledge failed: %s", strerror(errno));
|
||||||
|
#endif
|
||||||
|
|
||||||
XtAppMainLoop(app_con);
|
XtAppMainLoop(app_con);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void quit (Widget w, XEvent *event, String *params, Cardinal *num_params)
|
static void quit (Widget w, XEvent *event, String *params, Cardinal *num_params)
|
||||||
{
|
{
|
||||||
if (event->type == ClientMessage &&
|
if (event->type == ClientMessage &&
|
||||||
event->xclient.data.l[0] != wm_delete_window) {
|
event->xclient.data.l[0] != wm_delete_window) {
|
||||||
XBell (XtDisplay(w), 0);
|
XBell (XtDisplay(w), 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
|
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user