Subject: Linux UPS program on NetBSD
To: None <port-i386@netbsd.org>
From: Ray Phillips <r.phillips@jkmrc.com>
List: port-i386
Date: 04/18/2005 22:36:53
I'd like to use a Powerware 5115 UPS with an i386 machine running 
NetBSD.  Powerware supples its LanSafe software (which allows the UPS 
to shut down the PC gracefully when there's an extended power outage) 
with each UPS, but there isn't a version for NetBSD, and Nut doesn't 
support the 5115.  However, there is a version of Lansafe for Redhat 
Linux on the Powerware CD and I thought it might work with NetBSD 
because of its ability to run Linux programs.

I installed the character-based version of LanSafe 3 on a linux 
machine and verified the PC and UPS could interact, then mimicked the 
installer's behaviour on a NetBSD/i386 machine by copying these 
directories from the linux machine to /emul/linux on it:

/etc
/usr/ls3                    (a directory containing the main parts of Lansafe)
/usr/lib/hyperhelp/hoh.hlp  (a TeX font metric data (\377\372\330) file
                              according to /usr/bin/file)
/usr/lib/terminfo           (a sym link to /usr/share/terminfo)

(actually both machines were the same one, I just used a different 
hard disk for the two OS's).

The installer also added these lines to /etc/rc.local:

if [ -f /usr/ls3/ls3 ]; then
        /usr/ls3/ls3&
        echo "ls3 (LanSafe III Power Monitor)"
fi

and these to /etc/services:

ls3           3069/tcp                        # LanSafe III for Unix
ls3           3069/udp                        # LanSafe III for Unix

/usr/bin/files says the binary program files in /usr/ls3 are all this type:

ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU
/Linux 2.2.5, statically linked, stripped

so I didn't put any Linux library files into /emul/linux but I 
created sym links to /dev/tty00 and /dev/tty01 named ttyS0 and ttyS1, 
respectively, in /emul/linux/dev.

/usr/ls3/ls3 calls a shell script to broadcast a message announcing a 
shutdown is imminent and another to call /sbin/shutdown so I added 
sections for NetBSD to them.

I edited tty00's line in /etc/ttys to:

tty00   "/usr/libexec/getty std.9600"   unknown off secure local

and executed  kill -s HUP 1  followed by  ttyflags -v tty00

Unfortunately, although executing /emul/linux/ls3/ls3 doesn't produce 
errors, unplugging the power cord from the UPS doesn't cause the PC 
to shutdown after the desired interval; in fact there's no sign of 
interaction between them.

ls3 does change tty00's settings though.  Before running ls3:

% stty -f /dev/tty00
ispeed 0 baud; ospeed 9600 baud;
lflags: echoe echoke echoctl
oflags: onocr onlret
cflags: cs8 -parenb clocal

When ls3 is running:

% stty -f /dev/tty00
speed 1200 baud;
lflags: -icanon -isig -echo
iflags: -icrnl -ixon -imaxbel ignbrk -brkint ignpar
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb -hupcl clocal
discard eof     eol     eol2    erase   intr    kill    lnext   quit
^@      ^@      ^@      ^@      ^@      ^@      ^@      ^@      ^@
reprint start   stop    susp    werase
^@      ^@      ^@      ^@      ^@

So, I'm hoping it's very close to working but I'm out of ideas.  I 
haven't really used a serial port with NetBSD before.

I'd be grateful if someone could point out a mistake I've made or 
suggest something which might get this to work.


Ray


PS: What's the idea of the ttyflags command?  Does it just provide finer
     grain control over ttys than  kill -s HUP 1  ?  Are there occasions when
     it's prefereable to use ttyflags after editing /etc/ttys instead of
     "HUP"ing process 1?