diff options
author | itojun <itojun@pkgsrc.org> | 2001-07-13 21:56:01 +0000 |
---|---|---|
committer | itojun <itojun@pkgsrc.org> | 2001-07-13 21:56:01 +0000 |
commit | e24d870447f4422c440a6e9408b14aaf611e9ef0 (patch) | |
tree | 1787e81b39a4bf7e4afc1f27409700081e0c79a4 | |
parent | 373564f0681fbb3cd87ca642500df768a06e3c02 (diff) | |
download | pkgsrc-e24d870447f4422c440a6e9408b14aaf611e9ef0.tar.gz |
lambd, shutdown switch monitoring daemon for Wildlab LAMB
-rw-r--r-- | sysutils/lambd/Makefile | 23 | ||||
-rw-r--r-- | sysutils/lambd/distinfo | 2 | ||||
-rw-r--r-- | sysutils/lambd/files/Makefile | 11 | ||||
-rw-r--r-- | sysutils/lambd/files/lambd.8 | 64 | ||||
-rw-r--r-- | sysutils/lambd/files/lambd.c | 181 | ||||
-rw-r--r-- | sysutils/lambd/pkg/DESCR | 1 | ||||
-rw-r--r-- | sysutils/lambd/pkg/PLIST | 4 |
7 files changed, 286 insertions, 0 deletions
diff --git a/sysutils/lambd/Makefile b/sysutils/lambd/Makefile new file mode 100644 index 00000000000..c8b7ae9f0df --- /dev/null +++ b/sysutils/lambd/Makefile @@ -0,0 +1,23 @@ +# $NetBSD: Makefile,v 1.1.1.1 2001/07/13 21:56:01 itojun Exp $ + +DISTNAME= lambd-20010714 +CATEGORIES= sysutils +MASTER_SITES= # none +DISTFILES= # none + +MAINTAINER= itojun@netbsd.org +COMMENT= shutdown switch monitoring daemon for Wildlab LAMB + +ONLY_FOR_PLATFORM= NetBSD-*-i386 + +MAKE_ENV+= BINDIR=${PREFIX}/sbin MANDIR=${PREFIX}/man + +F= lambd.c lambd.8 Makefile + +do-extract: + ${MKDIR} ${WRKSRC} + for i in ${F}; do \ + ${CP} ${FILESDIR}/$$i ${WRKSRC}; \ + done + +.include "../../mk/bsd.pkg.mk" diff --git a/sysutils/lambd/distinfo b/sysutils/lambd/distinfo new file mode 100644 index 00000000000..2c5de7610e0 --- /dev/null +++ b/sysutils/lambd/distinfo @@ -0,0 +1,2 @@ +$NetBSD: distinfo,v 1.1.1.1 2001/07/13 21:56:01 itojun Exp $ + diff --git a/sysutils/lambd/files/Makefile b/sysutils/lambd/files/Makefile new file mode 100644 index 00000000000..f0ddf082c92 --- /dev/null +++ b/sysutils/lambd/files/Makefile @@ -0,0 +1,11 @@ +PROG= lambd +MAN= lambd.8 + +WARNS?= 2 +BINDIR?= /sbin +LDSTATIC= -static + +LDADD+= -li386 +DPADD+= /usr/lib/libi386.a + +.include <bsd.prog.mk> diff --git a/sysutils/lambd/files/lambd.8 b/sysutils/lambd/files/lambd.8 new file mode 100644 index 00000000000..4c007f148c5 --- /dev/null +++ b/sysutils/lambd/files/lambd.8 @@ -0,0 +1,64 @@ +.\" $NetBSD: lambd.8,v 1.1.1.1 2001/07/13 21:56:02 itojun Exp $ +.\" +.\" Copyright (C) 2001 WIDE Project. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the project nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd July 14, 2001 +.Dt LAMBD 8 +.Os +.Sh NAME +.Nm lambd +.Nd shutdown switch monitoring daemon for Wildlab LAMB +.Sh SYNOPSIS +.Nm "" +.Op Fl df +.Op Ar usec +.Sh DESCRIPTION +.Nm +monitors shutdown switch on Wildlab LAMB, and issues +.Dq Li shutdown -h now +if pressed. +It also blinks LED every 1 second, or the interval specified by +.Ar usec . +Normally +.Nm +becomes a daemon on invocation. +.Pp +Two command line options, +.Fl df +are supplied for debugging purposes. +.Fl d +lets it generate more messages, and forbids it from shutting down the machine. +.Fl f +runs +.Nm +in foreground mode. +.Sh REFERNCES +.Pa http://www.wildlab.com/ +.Sh BUGS +.Nm +should use LED for more interesting purposes, +like indicating load average, morse code and such. diff --git a/sysutils/lambd/files/lambd.c b/sysutils/lambd/files/lambd.c new file mode 100644 index 00000000000..bb11c07426c --- /dev/null +++ b/sysutils/lambd/files/lambd.c @@ -0,0 +1,181 @@ +/* $NetBSD: lambd.c,v 1.1.1.1 2001/07/13 21:56:02 itojun Exp $ */ + +/* + * Copyright (C) 2001 WIDE Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <machine/sysarch.h> +#include <machine/pio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <err.h> + +#define BASEPORT (0x378) + +int main __P((int, char **)); +void usage __P((void)); +void mainloop __P((unsigned long)); +int monitor __P((void)); +void led __P((int)); + +int foreground = 0; +int debug = 0; + +int +main(argc, argv) + int argc; + char **argv; +{ + int ch; + unsigned long delay; + char *p, *ep; + unsigned long ioperm[1024 / sizeof(unsigned long) / 8]; + int i, off, bit; + + while ((ch = getopt(argc, argv, "df")) != -1) { + switch (ch) { + case 'd': + debug++; + break; + case 'f': + foreground++; + break; + default: + usage(); + exit(1); + } + } + + argc -= optind; + argv += optind; + + switch (argc) { + case 0: + delay = 1 * 1000000; + break; + case 1: + p = *argv; + ep = NULL; + delay = strtoul(*argv, &ep, 10); + if (ep && !*ep) + break; + /* FALLTHROUGH */ + default: + usage(); + exit(1); + } + + if (i386_get_ioperm(ioperm) < 0) { + err(1, "i386_get_ioperm"); + /* NOTREACHED */ + } + for (i = 0; i < 3; i++) { + off = (BASEPORT + i); + bit = off % (sizeof(ioperm[0]) * 8); + off /= (sizeof(ioperm[0]) * 8); + ioperm[off] &= ~(1 << bit); + } + if (i386_set_ioperm(ioperm) < 0) { + err(1, "i386_set_ioperm"); + /* NOTREACHED */ + } + + if (!foreground) + daemon(0, 0); + + if (debug) + fprintf(stderr, "delay=%lu\n", delay); + mainloop(delay); + /* NOTREACHED */ + + exit(0); /* silent gcc */ +} + +void +usage() +{ + fprintf(stderr, "usage: lambd [-f] [usec]\n"); +} + +void +mainloop(delay) + unsigned long delay; +{ + unsigned int sec; + + delay /= 2; + sec = delay / 1000000; + delay %= 1000000; + + led(0); + while (1) { + if (monitor()) + break; + led(1); + if (sec) + sleep(sec); + usleep(delay); + + if (monitor()) + break; + led(0); + if (sec) + sleep(sec); + usleep(delay); + } + + led(0); + if (debug) { + fprintf(stderr, "shutdown -h now\n"); + exit(0); + } else { + execl("/sbin/shutdown", "shutdown", "-h", "now", NULL); + /* NOTREACHED */ + } +} + +/* returns 1 if shutdown button is pressed */ +int +monitor() +{ + if ((inb(BASEPORT + 1) & 0x20) == 0) + return 1; + else + return 0; +} + +void +led(on) + int on; +{ + + if (debug) + fprintf(stderr, "led=%d\n", on); + outb(BASEPORT + 2, on ? 8 : 0); +} diff --git a/sysutils/lambd/pkg/DESCR b/sysutils/lambd/pkg/DESCR new file mode 100644 index 00000000000..8e6561482bd --- /dev/null +++ b/sysutils/lambd/pkg/DESCR @@ -0,0 +1 @@ +shutdown switch monitoring daemon for Wildlab LAMB diff --git a/sysutils/lambd/pkg/PLIST b/sysutils/lambd/pkg/PLIST new file mode 100644 index 00000000000..f5e7282b698 --- /dev/null +++ b/sysutils/lambd/pkg/PLIST @@ -0,0 +1,4 @@ +@comment $NetBSD: PLIST,v 1.1.1.1 2001/07/13 21:56:02 itojun Exp $ +sbin/lambd +man/man8/lambd.8 +man/cat8/lambd.0 |