Import of pkgsrc-2013Q2

This commit is contained in:
2013-09-26 17:14:40 +02:00
commit 785076ae39
74991 changed files with 4380255 additions and 0 deletions

1
sysutils/lambd/DESCR Normal file
View File

@@ -0,0 +1 @@
shutdown switch monitoring daemon for Wildlab LAMB

24
sysutils/lambd/Makefile Normal file
View File

@@ -0,0 +1,24 @@
# $NetBSD: Makefile,v 1.16 2012/10/23 19:51:09 asau Exp $
DISTNAME= lambd-20010719
PKGREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= # none
DISTFILES= # none
MAINTAINER= pkgsrc-users@NetBSD.org
COMMENT= Shutdown switch monitoring daemon for Wildlab LAMB
ONLY_FOR_PLATFORM= NetBSD-*-i386
USE_BSD_MAKEFILE= yes
USE_TOOLS+= groff nroff
INSTALLATION_DIRS= sbin ${PKGMANDIR}/cat8 ${PKGMANDIR}/man8
do-extract:
${MKDIR} ${WRKSRC}
${CP} ${FILESDIR}/*.[ch8] ${WRKSRC}
${CP} ${FILESDIR}/Makefile ${WRKSRC}
.include "../../mk/bsd.pkg.mk"

4
sysutils/lambd/PLIST Normal file
View File

@@ -0,0 +1,4 @@
@comment $NetBSD: PLIST,v 1.2 2007/12/31 03:04:00 obache Exp $
man/cat8/lambd.0
man/man8/lambd.8
sbin/lambd

View File

@@ -0,0 +1,14 @@
# $NetBSD: Makefile,v 1.3 2007/12/31 03:09:31 obache Exp $
PROG= lambd
SRCS= lambd.c lambio.c
MAN= lambd.8
WARNS?= 2
BINDIR= ${PREFIX}/sbin
LDSTATIC= -static
LDADD+= -li386
DPADD+= /usr/lib/libi386.a
.include <bsd.prog.mk>

View File

@@ -0,0 +1,79 @@
.\" $NetBSD: lambd.8,v 1.5 2001/12/03 19:03:24 wiz 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 Ldfn
.Op Fl M Ar str
.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
The following options are available:
.Bl -tag -width indent
.It Fl L
Instead of heartbeat, LED will present the current load average.
A single blink means 0.5 in load average.
therefore, if you see 4 blinks, the current load average would be 2.
.Ar usec
argument decides the interval between LED blinks.
.It Fl M Ar str
Show an alphanumeric string,
.Ar str ,
in morse code on LED.
.Ar usec
argument decides the speed of the morse code.
.It Fl d
The flag lets
.Nm
generate more messages, and forbids it from shutting down the machine
even if the shutdown button is pressed.
.It Fl f
.Nm
will run in foreground mode
.Pq do not become daemon .
.It Fl n
Avoid any hardware I/O accesses from
.Nm Ns .
.El
.Sh SEE ALSO
.Pa http://www.wildlab.com/

View File

@@ -0,0 +1,326 @@
/* $NetBSD: lambd.c,v 1.6 2007/12/23 00:32:49 tnn 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>
#include <ctype.h>
#include "lambio.h"
#define BASEPORT (0x378)
int main __P((int, char **));
void usage __P((void));
void mainloop __P((void));
void lsleep __P((unsigned long));
int monitor __P((void));
void led __P((int));
int cycle __P((void));
int loadavg __P((void));
int morse __P((void));
int foreground = 0;
int debug = 0;
#ifdef __i386__
int nohw = 0;
#else
const int nohw = 1;
#endif
unsigned long delay = 1 * 1000000;
const char *morsestr = "LAMB";
int (*func) __P((void)) = cycle;
int
main(argc, argv)
int argc;
char **argv;
{
int ch;
char *p, *ep;
while ((ch = getopt(argc, argv, "LM:dfn")) != -1) {
switch (ch) {
case 'L':
func = loadavg;
break;
case 'M':
func = morse;
morsestr = optarg;
break;
case 'd':
debug++;
break;
case 'f':
foreground++;
break;
case 'n':
nohw++;
break;
default:
usage();
exit(1);
}
}
if (!islamb()) {
if (debug)
fprintf(stderr, "it is not lamb\n");
nohw++;
} else
if (debug)
fprintf(stderr, "it is indeed lamb\n");
argc -= optind;
argv += optind;
switch (argc) {
case 0:
break;
case 1:
p = *argv;
ep = NULL;
delay = strtoul(*argv, &ep, 10);
if (ep && !*ep)
break;
/* FALLTHROUGH */
default:
usage();
exit(1);
}
if (!nohw) {
if (lamb_open() < 0) {
err(1, "lamb_open");
/* NOTREACHED */
}
}
if (!foreground)
daemon(0, 0);
if (debug)
fprintf(stderr, "delay=%lu\n", delay);
mainloop();
/* NOTREACHED */
exit(0); /* silent gcc */
}
void
usage()
{
fprintf(stderr, "usage: lambd [-LMdfn] [usec]\n");
}
void
mainloop()
{
led(0);
while (1) {
if ((*func)())
break;
}
led(0);
if (debug) {
fprintf(stderr, "shutdown -h now\n");
exit(0);
} else {
execl("/sbin/shutdown", "shutdown", "-h", "now", NULL);
/* NOTREACHED */
}
}
void
lsleep(usec)
unsigned long usec;
{
sleep(usec / 1000000);
usleep(usec % 1000000);
}
int
monitor()
{
int i;
if (nohw)
return 0;
for (i = 0; i < 10; i++)
if (!lamb_reboot())
return 0;
return 1;
}
void
led(on)
int on;
{
if (debug)
fprintf(stderr, "led=%d\n", on);
if (nohw)
return;
lamb_led(on);
}
/*
* define a interesting functions below!
*/
int
cycle()
{
if (monitor())
return 1;
led(1);
lsleep(delay / 2);
if (monitor())
return 1;
led(0);
lsleep(delay / 2);
return 0;
}
int
loadavg()
{
double v;
int i;
unsigned long t = delay / 10;
getloadavg(&v, 1);
if (debug)
fprintf(stderr, "loadavg=%g\n", v);
for (i = 0; i < v * 2; i++) {
if (monitor())
return 1;
led(1);
lsleep(t);
led(0);
lsleep(t);
}
lsleep(t * 5);
return 0;
}
static const char *const digit[] = {
"-----",
".----",
"..---",
"...--",
"....-",
".....",
"-....",
"--...",
"---..",
"----.",
};
static const char *const alph[] = {
".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..",
};
int
morse()
{
unsigned const char *p, *q;
int mark, blank;
unsigned long t = delay / 10;
for (p = (unsigned char*)morsestr; *p; p++) {
if (monitor())
return 1;
if (isdigit(*p))
q = (unsigned char*)digit[*p - '0'];
else if (isalpha(*p) && isupper(*p))
q = (unsigned char*)alph[*p - 'A'];
else if (isalpha(*p) && islower(*p))
q = (unsigned char*)alph[*p - 'a'];
else
q = NULL;
if (debug)
printf("%c <%s>\n", *p, q);
for (/*nothing*/; *q; q++) {
switch (*q) {
case '-':
mark = 3; blank = 1; break;
case '.':
mark = 1; blank = 1; break;
default:
mark = 0; blank = 3; break;
}
led(1);
lsleep(mark * t);
led(0);
lsleep(blank * t);
}
lsleep(1 * t);
}
lsleep(10 * t);
return 0;
}

View File

@@ -0,0 +1,137 @@
/* $NetBSD: lambio.c,v 1.4 2010/10/12 22:28:54 joerg 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 <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_ether.h>
#include <ifaddrs.h>
#include <string.h>
#include <machine/sysarch.h>
#include <machine/pio.h>
#include "lambio.h"
#define BASEPORT (0x378)
/* We get these from libi386.so, but there are no public prototypes. */
int i386_get_ioperm(u_long *);
int i386_set_ioperm(u_long *);
/*
* These used to be provided by machine/pio.h as inline functions,
* but that's not true anymore, so use a local copy.
*/
static void
lamb_outb(unsigned port, u_int8_t data)
{
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
}
static u_int8_t
lamb_inb(unsigned port)
{
u_int8_t data;
__asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
return data;
}
int
lamb_open()
{
unsigned long ioperm[1024 / sizeof(unsigned long) / 8];
int off, bit;
int i;
if (i386_get_ioperm(ioperm) < 0)
return -1;
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)
return -1;
return 0;
}
/* returns 1 if shutdown button is pressed */
int
lamb_reboot()
{
if ((lamb_inb(BASEPORT + 1) & 0x20) == 0)
return 1;
else
return 0;
}
void
lamb_led(on)
int on;
{
lamb_outb(BASEPORT + 2, on ? 8 : 0);
}
/*
* check MAC address against IEEE-registered Wildlab MAC address
*/
int
islamb()
{
struct ifaddrs *ifa, *ifap;
struct sockaddr_dl *sdl;
const u_int8_t wildlab[] = { 0x00, 0x30, 0xf5 };
if (getifaddrs(&ifap) < 0)
return 0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family != AF_LINK)
continue;
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
if (sdl->sdl_alen != sizeof(struct ether_addr))
continue;
if (memcmp(LLADDR(sdl), wildlab, sizeof(wildlab)) != 0)
continue;
freeifaddrs(ifap);
return 1;
}
freeifaddrs(ifap);
return 0;
}

View File

@@ -0,0 +1,34 @@
/* $NetBSD: lambio.h,v 1.1 2001/07/18 06:47:37 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.
*/
int lamb_open __P((void));
int lamb_reboot __P((void));
void lamb_led __P((int));
extern int islamb __P((void));