home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
pc.louisiana.edu/pub/unix/
/
Louisiana_UNIX.tar
/
Louisiana_UNIX
/
apcupsd-3.5.8.solaris-patches
< prev
next >
Wrap
Text File
|
2000-07-20
|
25KB
|
931 lines
Changes to apcupsd-3.5.8 to allow use under Solaris 2.x. Tested under 2.6.
Note that Andre's patch of Wed Apr 7 18:15:48 CDT 1999 was applied BEFORE
any of my changes were made.
1. Makefile needs mods to specify needed libraries, and also to generate a
statically-linked program (apckillpwr) that implements apcd killpower
(Solaris unmounts all dirs during a halt, so no dynamic libs are
available.) This is adequate but what a kludge! Would it make
more sense to rework the Solaris shutdown scripts? Nahhhh.
2. Solaris uses a different lockfile naming convention, since it is derived
from SVR4, so apcconfig.c was modified. Solaris is tested for
by #ifdef __SVR4 and this probably works for other System V variants.
Note there is no getopt.h under Solaris so a few other .c files were
changed..
3. Solaris stores pid files in /etc not /var/run, so include/apc_defines.h
was modified accordingly.
4. Because apcnet.c makes calls to routines that are only present in shared
libraries, it can't be part of a statically-linked version of apcupsd.
So, I added empty routines that do nothing, when NONETSUPPORT is
#define'd. Thus, a static-suitable .o can be produced as long as no
network access is needed. This is fine, as the only needed action
is during a system halt, to tell the local APC unit to power off.
5. There is a race condition in apcupsd.c, where the code forks off a child
process, and then assumes the child process can relock the serial
port before the parent process has unlocked that port and terminated.
This assumption is invalid generally, and under Solaris in particular.
I changed the code to have the child process await the parent process'
death, then relock the serial port.
6. I put Solaris versions of powersc, halt, apcupsd.conf, and apcups into
the installs subdirectory. All the docs apply, except that instead
of calling apcupsd with killpower, you call apckillpwr with the same
argument. apckillpwr has been statically linked (uses the no-op
version of apcnet.o). Note that the halt script for solaris is
actually /sbin/rc0, which itself is hardlinked to rc5 and rc6.
script will
-- James Dugal, jpd@louisiana.edu
*** apcupsd-3.5.8.ull.src/include/apc_defines.h.orig Thu Jul 20 18:55:01 2000
--- apcupsd-3.5.8.ull.src/include/apc_defines.h Wed Jun 21 13:05:54 2000
***************
*** 66,71 ****
--- 66,75 ----
#define PWRFAIL "/var/run/powerfail"
#endif /* __freebsd__ */
+ #ifdef __SVR4
+ #define APCPID "/etc/apcupsd.pid"
+ #endif
+
#ifndef APCCONF
#define APCCONF "/etc/apcupsd.conf"
#endif
***************
*** 79,85 ****
--- 83,91 ----
#endif
#define NOLOGIN "/etc/nologin"
+ #ifndef APCPID
#define APCPID "/var/run/apcupsd.pid"
+ #endif
#define LOG_FILE "/var/log/apcupsd.log"
#define APC_RE_NET "/tmp/apcupsd.re-net"
#define APC_LOCK_PREFIX "/LCK.."
*** apcupsd-3.5.8.ull.src/installs/apcups.solaris.orig Thu Jul 20 19:09:31 2000
--- apcupsd-3.5.8.ull.src/installs/apcups.solaris Mon Jun 26 19:04:51 2000
***************
*** 0 ****
--- 1,30 ----
+ #! /bin/sh
+ #
+ # For Solaris 2.x
+ #
+ #
+ # /etc/init.d/apcups
+ # Symlink this with /etc/rc2.d/S98ups and ../rc0.d/K98ups
+ #
+ POWERSC=/sbin/powersc
+
+
+ case "$1" in
+ start)
+ if [ -x $POWERSC ]; then
+ $POWERSC INIT
+ ## touch /var/lock/subsys/apcups
+ fi
+ ;;
+ stop)
+ if [ -x $POWERSC ]; then
+ $POWERSC STOP
+ ## rm -f /var/lock/subsys/apcups
+ fi
+ ;;
+ *)
+ echo "Usage: $0 {start|stop}"
+ exit 1
+ esac
+
+ exit 0
*** apcupsd-3.5.8.ull.src/installs/apcupsd.conf.solaris.orig Thu Jul 20 19:09:31 2000
--- apcupsd-3.5.8.ull.src/installs/apcupsd.conf.solaris Mon Jun 26 17:38:56 2000
***************
*** 0 ****
--- 1,138 ----
+ ## apcupsd.conf v1.0 ##
+ #
+ # "apcupsd" POSIX config file
+ #
+ # CONTROL <string>
+ CONTROL /sbin/powersc
+ #
+ # UPSCABLE [ simple | smart | 940-00(20B,23A,24B,24C,24G,95A,95C) | ether ]
+ UPSCABLE 940-0024C
+ #
+ # UPSTYPE [ backups | sharebasic | netups |
+ # backupspro | smartvsups |
+ # newbackupspro | backupspropnp |
+ # smartups | matrixups | sharesmart ]
+ #
+ UPSTYPE backupspro
+ #
+ # UPSCLASS [ standalone | shareslave | sharemaster | netslave | netmaster ]
+ UPSCLASS standalone
+ #
+ # UPSMODE [ disable | share | net | sharenet ]
+ UPSMODE disable
+ #
+ #DEVICE <string> /dev/<serial port>
+ DEVICE /dev/cua/b
+ #
+ #LOCKFILE <path to lockfile>
+ LOCKFILE /var/spool/locks
+ #
+ #ACCESS <string> [ true | false ] Enable Access Support
+ ACCESS true
+ #
+ # ANNOY <int> <30> <0> disables
+ ANNOY 30
+ #
+ # DELAY <int> <60> <0> disables
+ DELAY 60
+ #
+ # NOLOGON <string> [ disable | timeout | percent | minutes | always ]
+ NOLOGON disable
+ #
+ # PROCFS <int> <120> <0> disables <update rate procfs-type of current status>
+ # jpd: use "apcaccess status" cmd instead.
+ PROCFS 0
+ #
+ # LOGGING <int> <500> <0> disables <rate update log file of current status>
+ LOGGING 600
+ #
+ # TIMEOUT <time is seconds to run on UPS, powerfails>
+ TIMEOUT 5000
+ #
+ # BATTERYLEVEL <percent of battery charge for shutdown> 10
+ BATTERYLEVEL 10
+ #
+ # MINUTES <time in minutes of remainning battery charge before shutdown> 5
+ MINUTES 5
+ #
+ # SENSITIVITY <char> H,M,L default H
+ SENSITIVITY H
+ #
+ # WAKEUP <int> 0,60,180,300 Cycles default 0
+ WAKEUP 60
+ #
+ # SLEEP <int> 20,180,300,600 Cycles default 20
+ SLEEP 20
+ #
+ # LOTRANSFER <int> 0,1,2,3 default 2
+ LOTRANSFER 2
+ #
+ # HITRANSFER <int> 0,1,2,3 default 2
+ HITRANSFER 3
+ #
+ # RETURNCHARGE <int> 0,1,2,3 default 3
+ RETURNCHARGE 1
+ #
+ # BEEPSTATE <char> 0,T,L,N default 0
+ BEEPSTATE L
+ #
+ # SELFTEST <string> 336,168,ON,OFF default 336
+ SELFTEST 336
+ #
+ # UPSNAME <string>
+ UPSNAME SUZEUPS
+ #
+ # BATTCMD <string>
+ #BATTCMD
+ #
+ # TIMECMD <string>
+ #TIMECMD
+ #
+ # LOADCMD <string>
+ #LOADCMD
+ #
+ # LIMITCMD <string>
+ #LIMITCMD
+ #
+ # PWRCMD <string>
+ #PWRCMD
+ #
+ # RETCMD <string>
+ #RETCMD
+ #
+ # REMOTECMD <string>
+ #REMOTECMD
+ #
+ # REBOOTCMD <string>
+ #REBOOTCMD
+ #
+ # NETTIME <int>
+ #NETTIME 100
+ #
+ # NETPORT <int>
+ #NETPORT 6666
+ #
+ # MASTER <string>
+ #MASTER
+ #
+ # SLAVE <string>
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #SLAVE
+ #
+ # USERMAGIC <string>
+ #USERMAGIC
+ #
+ # HTTPACCESS [ true | false ] enable web-interface - defaults to false
+ HTTPACCESS false
+ #
+ # HTTPPORT <port> port to use for interface - defaults to 1999
+ #HTTPPORT 1999
+ #
*** apcupsd-3.5.8.ull.src/installs/halt.solaris.orig Thu Jul 20 19:09:31 2000
--- apcupsd-3.5.8.ull.src/installs/halt.solaris Thu Jul 20 18:35:46 2000
***************
*** 0 ****
--- 1,94 ----
+ #!/sbin/sh
+ # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+ # All Rights Reserved
+
+ # THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
+ # The copyright notice above does not evidence any
+ # actual or intended publication of such source code.
+
+ #ident "@(#)rc0.sh 1.16 94/11/30 SMI" SVr4.0 1.15.4.1
+
+ # "Run Commands" for init states 0, 5 and 6.
+
+ PATH=/usr/sbin:/usr/bin
+
+ echo 'The system is coming down. Please wait.'
+
+ # make sure /usr is mounted before proceeding since init scripts
+ # and this shell depend on things on /usr file system
+ /sbin/mount /usr > /dev/null 2>&1
+
+ # The following segment is for historical purposes.
+ # There should be nothing in /etc/shutdown.d.
+ if [ -d /etc/shutdown.d ]
+ then
+ for f in /etc/shutdown.d/*
+ {
+ if [ -s $f ]
+ then
+ /sbin/sh ${f}
+ fi
+ }
+ fi
+ # End of historical section
+
+ if [ -d /etc/rc0.d ]
+ then
+ for f in /etc/rc0.d/K*
+ {
+ if [ -s ${f} ]
+ then
+ case ${f} in
+ *.sh) . ${f} ;; # source it
+ *) /sbin/sh ${f} stop ;; # sub shell
+ esac
+ fi
+ }
+
+ # system cleanup functions ONLY (things that end fast!)
+
+ for f in /etc/rc0.d/S*
+ {
+ if [ -s ${f} ]
+ then
+ case ${f} in
+ *.sh) . ${f} ;; # source it
+ *) /sbin/sh ${f} start ;; # sub shell
+ esac
+ fi
+ }
+ fi
+
+ trap "" 15
+
+ # kill all processes, first gently, then with prejudice.
+ /usr/sbin/killall
+ /usr/bin/sleep 5
+ /usr/sbin/killall 9
+ /usr/bin/sleep 10
+ /sbin/sync; /sbin/sync; /sbin/sync
+
+ # unmount file systems. /usr, /var and /var/adm are not unmounted by umountall
+ # because they are mounted by rcS (for single user mode) rather than
+ # mountall.
+ # If this is changed, mountall, umountall and rcS should also change.
+ # jpd 11/98: restrict umountall to local filsystems, since we are having problems
+ # with some autofs/nfs mounts that stay busy (probably until the killall 9
+ # above, but then it's too late to deal with network and NFS)
+ /sbin/umountall -l
+ /sbin/umount /var/adm >/dev/null 2>&1
+ /sbin/umount /var >/dev/null 2>&1
+ /sbin/umount /usr >/dev/null 2>&1
+
+ # jpd@louisiana.edu: We may want to tell the APC UPS to power itself off now
+ # Note that the /sbin/powersc script relyies on /usr being mounted, so we
+ # must call apcupsd directly. Makes more sense anyhow.
+ # See if this is a powerfail situation.
+ if [ -f /etc/powerfail -a -x /sbin/apckillpwr ]; then
+ echo "APCKILLPWR invoked to kill power"
+ echo
+ /sbin/apckillpwr killpower
+ echo
+ fi
+
+ echo 'The system is down.'
*** apcupsd-3.5.8.ull.src/installs/powersc.solaris.orig Thu Jul 20 19:09:31 2000
--- apcupsd-3.5.8.ull.src/installs/powersc.solaris Mon Jun 26 17:36:36 2000
***************
*** 0 ****
--- 1,140 ----
+ #!/bin/sh
+ #
+
+ POWERPID=/etc/shut.pid
+ APCPID=/etc/apcupsd.pid
+
+ # Solaris needs the SysV shutdown to issue the -i5 poweroff option:
+ SHUTARGS="-i 5 -g 0 -y" # "-h now" for bsd shutdown
+ if [ -x /sbin/shutdown ]; then
+ SHUTDOWN=/sbin/shutdown
+ elif [ -x /usr/sbin/shutdown ]; then
+ SHUTDOWN=/usr/sbin/shutdown
+ # elif [ -x /sbin/shutdown.bsd ]; then
+ # SHUTDOWN=/sbin/shutdown.bsd
+ else
+ echo Command shutdown or shutdown.bsd not found!
+ exit 1
+ fi
+
+ if [ -x /usr/local/sbin/apcupsd ]; then
+ APCUPSD=/usr/local/sbin/apcupsd
+ elif [ -x /opt/apcups/apcupsd ]; then
+ APCUPSD=/opt/apcups/apcupsd
+ elif [ -x /usr/sbin/apcupsd ]; then
+ APCUPSD=/usr/sbin/apcupsd
+ elif [ -x /sbin/apcupsd ]; then
+ APCUPSD=/sbin/apcupsd
+ else
+ echo Command apcupsd not found!
+ exit 1
+ fi
+
+ if [ `/usr/xpg4/bin/id -u` != "0" ]; then
+ printf "Sorry, you must be root to run this script.\n" | wall
+ exit 1
+ fi
+
+ case "$1" in
+ POWEROUT)
+ printf "Warning: there are Power problems.\n" | wall
+ ;;
+ ONBATTERY)
+ printf "Power Failed; running on UPS.\n" | wall
+ ;;
+ FAILING)
+ printf "Battery Power Failing; Normal Shutdown.\n" | wall
+ ;;
+ TIMEOUT)
+ printf "On-Battery timeout; Normal Shutdown.\n" | wall
+ ;;
+ LOADLIMIT)
+ printf "Battery Load Limits Reached; Normal Shutdown.\n" | wall
+ ;;
+ RUNLIMIT)
+ printf "Battery RunTime Limits Reached; Normal Shutdown.\n" | wall
+ ;;
+ DOSHUTDOWN)
+ printf "Beginning Shutdown Sequence!!!!!;\n" | wall
+ runlevel=`ps -ef -o pid,tty,s,time,args | nawk '{ if (($5 == "init") && ($1 == "1")) print $6 }' \
+ | cut -f2 -d[ | cut -f1 -d] `
+ if [ "$runlevel" = "" -o "$runlevel" = "-" ]; then
+ runlevel=`nawk -F: '$1 == "is" { print $2 }' /etc/inittab`
+ fi
+ echo $runlevel > /tmp/run.level.power
+ if [ -f $POWERPID ]
+ then
+ exit 0
+ else
+ echo $$ > $POWERPID
+ $SHUTDOWN $SHUTARGS
+ fi
+ ;;
+ MAINSBACK | WAITASEC)
+ if [ -f $POWERPID ]; then
+ printf "Attempting to cancel shutdown."
+ kill `cat $POWERPID`
+ rm -f $POWERPID
+ init `cat /tmp/run.level.power`
+ fi
+ printf "Power has returned...\n" | wall
+ ;;
+ ANNOYME)
+ printf "Power Problems - Please Log Off Now!!!!\n" | wall
+ ;;
+ EMERGENCY)
+ printf "Emergency Shutdown, Possible Battery Failure!!!!\n" | wall
+ $SHUTDOWN $SHUTARGS
+ ;;
+ CHANGEME)
+ printf "Emergency, Batteries Have Failed!!!!\nChange Them NOW!!!!\n" | wall
+ ;;
+ REMOTE)
+ printf "Remote Shutdown request received.\nBeginning Shutdown Sequence!!!!!\n" | wall
+ $SHUTDOWN $SHUTARGS
+ ;;
+ KILL) sleep 1
+ $APCUPSD killpower
+ sleep 10
+ ;;
+ INIT) rm -f $POWERPID
+ #
+ # apcupsd should be doing its own cleaning of lock and pid files.
+ # -BSC
+ #
+ # if [ -f $APCPID ]; then
+ # kill $(cat $APCPID) 1> /dev/null 2> /dev/null
+ # rm -f $APCPID
+ # fi
+ rm -f /etc/powerfail
+ rm -f /etc/powerstatus
+ rm -f /etc/nologin
+ printf "Starting APCUPSD Power Management: "
+ $APCUPSD
+ echo "apcupsd"
+ ;;
+ STOP)
+ printf "Stopping APCUPSD Power Management: "
+ if [ -f $APCPID ]; then
+ kill `cat $APCPID`
+ rm -f $APCPID
+ fi
+ echo "apcupsd"
+ ;;
+ RESTARTME)
+ printf "Restarting APCUPSD Power Management: "
+ kill `cat $APCPID`
+ rm -f $APCPID
+ rm -f $POWERPID
+ rm -f /etc/powerfail
+ rm -f /etc/powerstatus
+ rm -f /etc/nologin
+ sleep 10
+ $APCUPSD
+ echo "apcupsd"
+ ;;
+ *) echo "Usage: ${0##*/} [POWEROUT | ONBATTERY | FAILING | TIMEOUT | LOADLIMIT | RUNLIMIT | DOSHUTDOWN | MAINSBACK | WAITASEC | ANNOYME | EMERGENCY | CHANGEME | REMOTE | KILL | INIT | STOP | RESTARTME]"
+ exit 1
+ ;;
+ esac
+ exit 0
*** apcupsd-3.5.8.ull.src/Makefile.orig Thu Jul 20 18:40:49 2000
--- apcupsd-3.5.8.ull.src/Makefile Thu Jul 20 17:01:12 2000
***************
*** 66,80 ****
APCUPSD = apcupsd
APCACCESS = apcaccess
POWERFLUTE= powerflute
INCLUDES = -I./include
# Flags for compiler
CFLAGS = -g -O2 -Wall $(INCLUDES) $(CMDC)
# Flags for linker
LFLAGS = $(CMDL)
! OPTIONS = $(CMDC) $(INCLUDES)
ifdef THREADS
CFLAGS += -DNEW_THREADS
--- 66,82 ----
APCUPSD = apcupsd
APCACCESS = apcaccess
POWERFLUTE= powerflute
+ APCKILLPWR= apckillpwr
INCLUDES = -I./include
# Flags for compiler
CFLAGS = -g -O2 -Wall $(INCLUDES) $(CMDC)
+ OPTIONS = $(CMDC) $(INCLUDES)
# Flags for linker
LFLAGS = $(CMDL)
! STATIC = -static # -static for gcc, -B static for Sun CC, ...
ifdef THREADS
CFLAGS += -DNEW_THREADS
***************
*** 85,91 ****
SHELL = /bin/sh
ECHO = echo
! MAKE = make
CHOWN = chown
CHMOD = chmod
CP = cp
--- 87,93 ----
SHELL = /bin/sh
ECHO = echo
! MAKE = gmake
CHOWN = chown
CHMOD = chmod
CP = cp
***************
*** 112,118 ****
.c.o:
$(CC) $(CFLAGS) -c $<
.o:
! $(LD) -s -o $*.o
#****************************************************************************
#* *
--- 114,120 ----
.c.o:
$(CC) $(CFLAGS) -c $<
.o:
! $(LD) $(LFLAGS) -s -o $*.o
#****************************************************************************
#* *
***************
*** 233,245 ****
ifdef MUSIC
$(APCUPSD) : $(OBJ)
! $(CC) -o $(APCUPSD)-$(OS) $(DOBJ)
! $(CC) -o $(APCACCESS)-$(OS) $(TOBJ)
! $(CC) -o $(POWERFLUTE)-$(OS) $(POBJ) -lncurses -lmenu -lpanel
@if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
$(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
$(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
$(MV) $(POWERFLUTE)-$(OS) $(POWERFLUTE)-$(NAME); \
fi
@$(RM) -f $(OBJ)
--- 235,249 ----
ifdef MUSIC
$(APCUPSD) : $(OBJ)
! $(CC) -o $(APCUPSD)-$(OS) $(LFLAGS) $(DOBJ) $(LIBS)
! $(CC) -o $(APCACCESS)-$(OS) $(LFLAGS) $(TOBJ) $(LIBS)
! $(CC) -o $(POWERFLUTE)-$(OS) $(LFLAGS) $(POBJ) -lncurses -lmenu -lpanel $(LIBS)
! $(CC) -o $(APCKILLPWR)-$(OS) $(LFLAGS) $(STATIC) -DNONETSUPPORT apcnet.c $(DOBJ) $(LIBS)
@if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
$(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
$(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
$(MV) $(POWERFLUTE)-$(OS) $(POWERFLUTE)-$(NAME); \
+ $(MV) $(APCKILLPWR)-$(OS) $(APCKILLPWR)-$(NAME); \
fi
@$(RM) -f $(OBJ)
***************
*** 246,256 ****
else
$(APCUPSD) : $(OBJ)
! $(CC) -o $(APCUPSD)-$(OS) $(DOBJ)
! $(CC) -o $(APCACCESS)-$(OS) $(TOBJ)
@if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
$(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
$(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
fi
@$(RM) -f $(OBJ)
--- 250,263 ----
else
$(APCUPSD) : $(OBJ)
! $(CC) -o $(APCUPSD)-$(OS) $(LFLAGS) $(DOBJ) $(LIBS)
! $(CC) -o $(APCACCESS)-$(OS) $(LFLAGS) $(TOBJ) $(LIBS)
! $(CC) $(CFLAGS) -c -DNONETSUPPORT apcnet.c
! $(CC) -o $(APCKILLPWR)-$(OS) $(LFLAGS) $(STATIC) $(DOBJ) $(LIBS)
@if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
$(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
$(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
+ $(MV) $(APCKILLPWR)-$(OS) $(APCKILLPWR)-$(NAME); \
fi
@$(RM) -f $(OBJ)
***************
*** 402,407 ****
--- 409,415 ----
sun :
@$(MAKE) depend $(APCUPSD) \
+ LIBS="-lnsl -lsocket" \
OS="sun" \
CC="gcc"
***************
*** 481,487 ****
clean :
$(RM) -f `$(FIND) . \( -name '*~' -o -name '*.bak' -o -name '*.ESV' \
-o -name '*.ASV' -o -name '*.orig' -o -name 'core' \) -print`
! $(RM) -f *.lsm apcupsd-linux apcaccess-linux powerflute-linux
$(RM) -f core *.o
distclean : clobber
--- 489,495 ----
clean :
$(RM) -f `$(FIND) . \( -name '*~' -o -name '*.bak' -o -name '*.ESV' \
-o -name '*.ASV' -o -name '*.orig' -o -name 'core' \) -print`
! $(RM) -f *.lsm apcupsd-* apcaccess-* powerflute-*
$(RM) -f core *.o
distclean : clobber
*** apcupsd-3.5.8.ull.src/apcaction.c.orig Thu Jul 20 18:43:10 2000
--- apcupsd-3.5.8.ull.src/apcaction.c Tue Jun 20 15:40:54 2000
***************
*** 59,65 ****
--- 59,67 ----
#include <stdio.h>
#include <unistd.h>
+ #ifndef __SVR4
#include <getopt.h>
+ #endif
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
*** apcupsd-3.5.8.ull.src/apcconfig.c.orig Thu Jul 20 18:43:28 2000
--- apcupsd-3.5.8.ull.src/apcconfig.c Wed Jun 21 17:15:54 2000
***************
*** 75,80 ****
--- 75,102 ----
#include <errno.h>
#include <ctype.h>
+ /* Some Unix systems have a different lockfile and device path format: */
+ #if defined(SVR4) || defined(__svr4__) || defined (__SVR4) || defined(solaris)
+ #undef SVR4
+ #define SVR4
+ #define LFDEVNO
+ #endif
+
+ #ifdef LFDEVNO
+ #ifndef major /* If we didn't find it */
+ #ifdef SVR4 /* then for Sys V R4 */
+ #include <sys/mkdev.h> /* look here */
+ #else /* or for Sunos versions */
+ #ifdef SUNOS4 /* ... */
+ #include <sys/sysmacros.h> /* look here */
+ #else /* Otherwise take a chance: */
+ #define major(dev) ( (int) ( ((unsigned)(dev) >> 8) & 0xff))
+ #define minor(dev) ( (int) ( (dev) & 0xff))
+ #endif /* SUNOS4 */
+ #endif /* SVR4 */
+ #endif /* major */
+ #endif /* LFDEVNO */
+
#include <apc_version.h>
#include <apc_defines.h>
#include <apc_struct.h>
***************
*** 579,585 ****
--- 601,611 ----
char line[MAXTOKENLEN];
int errors = 0;
int erpos = 0;
+ #ifdef LFDEVNO
+ struct stat devbuf; /* For device numbers (SVR4). */
+ #endif /* LFDEVNO */
+
zero_ups_struct(ups);
sprintf(ups->argvalue, "%s", argvalue);
***************
*** 720,729 ****
--- 746,770 ----
* If APC_NET, the lockfile is not needed.
*/
if (ups->cable.type != APC_NET) {
+ #ifdef LFDEVNO /* Lockfilename has device numbers. */
+ char lockname[32];
+
+ if (stat(ups->device,&devbuf) < 0) {
+ errors++;
+ fprintf(stderr, "Can't stat %s (code %d)\n", ups->device, errno);
+ } else {
+ sprintf(lockname,"/LK.%03d.%03d.%03d",
+ major(devbuf.st_dev), /* inode */
+ major(devbuf.st_rdev), /* major device number */
+ minor(devbuf.st_rdev)); /* minor device number */
+ strcat(ups->lockpath, lockname);
+ }
+ #else /* Others... */
char *dev = strrchr(ups->device, '/');
strcat(ups->lockpath, APC_LOCK_PREFIX);
strcat(ups->lockpath, dev?++dev:ups->device);
+ #endif
} else {
ups->lockpath[0] = 0;
ups->lockfile = -1;
*** apcupsd-3.5.8.ull.src/apcnet.c.orig Thu Jul 20 18:43:57 2000
--- apcupsd-3.5.8.ull.src/apcnet.c Tue Jun 27 14:25:16 2000
***************
*** 80,86 ****
#include <apc_extern.h>
#undef DEBUG
-
/*
* these defenitions simplify code for the network communication layer
* MAGIC_PAD is the size required so that APC_MAGIC strings
--- 80,85 ----
***************
*** 112,117 ****
--- 111,199 ----
extern int debug_net;
+ #if NONETSUPPORT
+ int write_struct_net (int wsocketfd, struct netdata *write_struct, size_t size)
+ {
+ logprintf("write_struct_net() invoked!\n");
+ exit(1);
+ }
+ int read_struct_net (int rsocketfd, struct netdata *read_struct, size_t size)
+ {
+ logprintf("read_struct_net() invoked!\n");
+ exit (1);
+ }
+ void log_struct (struct netdata *logstruct)
+ {
+ }
+ int reconnect_master (UPSINFO *ups, int who)
+ {
+ logprintf("reconnect_master invoked!\n");
+ exit (1);
+ }
+ int prepare_master (UPSINFO *ups)
+ {
+ logprintf("prepare_master invoked!\n");
+ exit(1);
+ }
+ void send_to_slaves (UPSINFO *ups)
+ {
+ logprintf("send_to_slaves invoked!\n");
+ exit(1);
+ }
+ int send_to_each (UPSINFO *ups, int who)
+ {
+ logprintf("send_to_each invoked!\n");
+ exit(1);
+ }
+ int reconnect_slave(UPSINFO *ups)
+ {
+ logprintf("reconnect_slave invoked!\n");
+ exit(1);
+ }
+ int prepare_slave (UPSINFO *ups)
+ {
+ logprintf("prepare_slave invoked!\n");
+ exit(1);
+ }
+ int get_from_master (UPSINFO *ups)
+ {
+ logprintf("get_from_master invoked!\n");
+ exit(1);
+ }
+ void kill_net (UPSINFO *ups, int killpwr)
+ {
+ logprintf("kill_net invoked!\n");
+ exit(1);
+ }
+ #ifndef NEW_THREADS
+ void do_net (UPSINFO *ups)
+ {
+ logprintf("do_net invoked!\n");
+ exit(1);
+ }
+ #else
+ void timer_net (int sig)
+ {
+ logprintf("timer_net invoked!\n");
+ exit(1);
+ }
+ void do_net (UPSINFO *ups)
+ {
+ logprintf("do_net invoked!\n");
+ exit(1);
+ }
+ void timer_slaves (int sig)
+ {
+ logprintf("timer_slaves invoked!\n");
+ exit(1);
+ }
+ void do_slaves (void)
+ {
+ logprintf("do_slaves invoked!\n");
+ exit(1);
+ }
+ #endif
+ #else
/*********************************************************************/
/* write_struct_net takes a netdata structure and copies it to */
/* malloc'ed memory so that the netdata structure is properly network*/
***************
*** 1200,1202 ****
--- 1282,1285 ----
sleep_forever();
}
#endif /* NEW_THREADS */
+ #endif /* NONETSUPPORT */
*** apcupsd-3.5.8.ull.src/apcreports.c.orig Thu Jul 20 18:44:18 2000
--- apcupsd-3.5.8.ull.src/apcreports.c Tue Jun 20 15:41:05 2000
***************
*** 58,64 ****
--- 58,66 ----
#include <stdio.h>
#include <unistd.h>
+ #ifndef __SVR4
#include <getopt.h>
+ #endif
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
*** apcupsd-3.5.8.ull.src/apcserial.c.orig Thu Jul 20 18:44:33 2000
--- apcupsd-3.5.8.ull.src/apcserial.c Tue Jun 20 15:41:16 2000
***************
*** 59,65 ****
--- 59,67 ----
#include <stdio.h>
#include <unistd.h>
+ #ifndef __SVR4
#include <getopt.h>
+ #endif
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
*** apcupsd-3.5.8.ull.src/apcupsd.c.orig Thu Jul 20 18:45:02 2000
--- apcupsd-3.5.8.ull.src/apcupsd.c Wed Jun 21 13:09:19 2000
***************
*** 100,106 ****
--- 100,108 ----
#include <stdio.h>
#include <unistd.h>
+ #ifndef __SVR4
#include <getopt.h>
+ #endif
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
***************
*** 361,366 ****
--- 363,370 ----
int main (int argc, char **argv)
{
int KILL = FALSE;
+ pid_t parentpid;
+ int sleeplimiter=60;
#ifndef NEW_THREADS
***************
*** 507,512 ****
--- 511,517 ----
/*
* Become a daemon.
*/
+ parentpid = getpid();
switch(fork()) {
case 0: /* I am the child. */
setsid();
***************
*** 551,556 ****
--- 556,570 ----
* the lockfile during fork()" way.
* -RF
*/
+
+ /* Yes, BUT: the parent process may not yet have died, so we have a
+ * race condition: will it die before we read the pid from the lockfile
+ * and test the parents existence? TO be sure it tests false, we will
+ * pause here UNTIL the parent is really dead! -- jpd@louisiana.edu
+ */
+ while ( kill(parentpid, 0) == 0 && sleeplimiter--)
+ sleep (5);
+
if (create_lockfile(&myUPS, KILL) == LCKERROR) {
fprintf(stderr, "%s: failed to reacquire lock file on device %s\n", argv[0], myUPS.device);
logprintf("%s: failed to reacquire lock file on device %s\n", argv[0], myUPS.device);