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 >
Text File  |  2000-07-20  |  25KB  |  931 lines

  1. Changes to apcupsd-3.5.8 to allow use under Solaris 2.x.  Tested under 2.6.
  2. Note that Andre's patch of Wed Apr 7 18:15:48 CDT 1999 was applied BEFORE
  3. any of my changes were made.
  4.  
  5. 1. Makefile needs mods to specify needed libraries, and also to generate a
  6.     statically-linked program (apckillpwr) that implements apcd killpower
  7.     (Solaris unmounts all dirs during a halt, so no dynamic libs are
  8.     available.)  This is adequate but what a kludge!  Would it make
  9.     more sense to rework the Solaris shutdown scripts?  Nahhhh.
  10.  
  11. 2. Solaris uses a different lockfile naming convention, since it is derived
  12.     from SVR4, so apcconfig.c was modified.  Solaris is tested for
  13.     by #ifdef __SVR4 and this probably works for other System V variants.
  14.     Note there is no getopt.h under Solaris so a few other .c files were
  15.     changed..
  16.  
  17. 3. Solaris stores pid files in /etc not /var/run, so include/apc_defines.h
  18.     was modified accordingly.
  19.  
  20. 4. Because apcnet.c makes calls to routines that are only present in shared
  21.     libraries, it can't be part of a statically-linked version of apcupsd.
  22.     So, I added empty routines that do nothing, when NONETSUPPORT is
  23.     #define'd.  Thus, a static-suitable .o can be produced as long as no
  24.     network access is needed.  This is fine, as the only needed action
  25.     is during a system halt, to tell the local APC unit to power off.
  26.  
  27. 5. There is a race condition in apcupsd.c, where the code forks off a child
  28.     process, and then assumes the child process can relock the serial
  29.     port before the parent process has unlocked that port and terminated.
  30.     This assumption is invalid generally, and under Solaris in particular.
  31.     I changed the code to have the child process await the parent process'
  32.     death, then relock the serial port.
  33.  
  34. 6. I put Solaris versions of powersc, halt, apcupsd.conf, and apcups into
  35.     the installs subdirectory.  All the docs apply, except that instead
  36.     of calling apcupsd with killpower, you call apckillpwr with the same
  37.     argument.  apckillpwr has been statically linked (uses the no-op
  38.      version of apcnet.o).  Note that the halt script for solaris is
  39.     actually /sbin/rc0, which itself is hardlinked to rc5 and rc6.
  40.     script will 
  41.  
  42. -- James Dugal, jpd@louisiana.edu
  43.  
  44. *** apcupsd-3.5.8.ull.src/include/apc_defines.h.orig    Thu Jul 20 18:55:01 2000
  45. --- apcupsd-3.5.8.ull.src/include/apc_defines.h    Wed Jun 21 13:05:54 2000
  46. ***************
  47. *** 66,71 ****
  48. --- 66,75 ----
  49.   #define PWRFAIL            "/var/run/powerfail"
  50.   #endif /* __freebsd__ */
  51.   
  52. + #ifdef __SVR4
  53. + #define APCPID            "/etc/apcupsd.pid"
  54. + #endif
  55.   #ifndef APCCONF
  56.   #define APCCONF            "/etc/apcupsd.conf"
  57.   #endif
  58. ***************
  59. *** 79,85 ****
  60. --- 83,91 ----
  61.   #endif
  62.   
  63.   #define NOLOGIN            "/etc/nologin"
  64. + #ifndef APCPID
  65.   #define APCPID            "/var/run/apcupsd.pid"
  66. + #endif
  67.   #define LOG_FILE        "/var/log/apcupsd.log"
  68.   #define APC_RE_NET        "/tmp/apcupsd.re-net"
  69.   #define APC_LOCK_PREFIX        "/LCK.."
  70. *** apcupsd-3.5.8.ull.src/installs/apcups.solaris.orig    Thu Jul 20 19:09:31 2000
  71. --- apcupsd-3.5.8.ull.src/installs/apcups.solaris    Mon Jun 26 19:04:51 2000
  72. ***************
  73. *** 0 ****
  74. --- 1,30 ----
  75. + #! /bin/sh
  76. + #
  77. + # For Solaris 2.x
  78. + #
  79. + #
  80. + # /etc/init.d/apcups
  81. + # Symlink this with /etc/rc2.d/S98ups and ../rc0.d/K98ups
  82. + #
  83. + POWERSC=/sbin/powersc
  84. + case "$1" in
  85. +     start)
  86. +     if [ -x $POWERSC ]; then
  87. +         $POWERSC INIT
  88. + ##        touch /var/lock/subsys/apcups
  89. +     fi
  90. +     ;;
  91. +     stop)
  92. +     if [ -x $POWERSC ]; then
  93. +         $POWERSC STOP
  94. + ##        rm -f /var/lock/subsys/apcups
  95. +     fi
  96. +     ;;
  97. +     *)
  98. +     echo "Usage: $0 {start|stop}"
  99. +     exit 1
  100. + esac
  101. + exit 0
  102. *** apcupsd-3.5.8.ull.src/installs/apcupsd.conf.solaris.orig    Thu Jul 20 19:09:31 2000
  103. --- apcupsd-3.5.8.ull.src/installs/apcupsd.conf.solaris    Mon Jun 26 17:38:56 2000
  104. ***************
  105. *** 0 ****
  106. --- 1,138 ----
  107. + ## apcupsd.conf v1.0 ##
  108. + #
  109. + # "apcupsd" POSIX config file
  110. + #
  111. + # CONTROL <string>
  112. + CONTROL /sbin/powersc
  113. + #
  114. + # UPSCABLE [ simple | smart | 940-00(20B,23A,24B,24C,24G,95A,95C) | ether ]
  115. + UPSCABLE 940-0024C
  116. + #
  117. + # UPSTYPE [ backups | sharebasic | netups |
  118. + #           backupspro | smartvsups |
  119. + #           newbackupspro | backupspropnp |
  120. + #           smartups | matrixups | sharesmart ]
  121. + #
  122. + UPSTYPE backupspro
  123. + #
  124. + # UPSCLASS [ standalone | shareslave | sharemaster | netslave | netmaster ]
  125. + UPSCLASS standalone
  126. + #
  127. + # UPSMODE [ disable | share | net | sharenet ]
  128. + UPSMODE disable
  129. + #
  130. + #DEVICE <string> /dev/<serial port>
  131. + DEVICE /dev/cua/b
  132. + #
  133. + #LOCKFILE <path to lockfile>
  134. + LOCKFILE /var/spool/locks
  135. + #
  136. + #ACCESS <string> [ true | false ] Enable Access Support
  137. + ACCESS true
  138. + #
  139. + # ANNOY <int> <30> <0> disables
  140. + ANNOY 30
  141. + #
  142. + # DELAY <int> <60> <0> disables
  143. + DELAY 60
  144. + #
  145. + # NOLOGON <string> [ disable | timeout | percent | minutes | always ]
  146. + NOLOGON disable
  147. + #
  148. + # PROCFS <int> <120> <0> disables <update rate procfs-type of current status>
  149. + # jpd: use "apcaccess status" cmd instead.
  150. + PROCFS 0
  151. + #
  152. + # LOGGING <int> <500> <0> disables <rate update log file of current status>
  153. + LOGGING 600
  154. + #
  155. + # TIMEOUT <time is seconds to run on UPS, powerfails>
  156. + TIMEOUT 5000
  157. + #
  158. + # BATTERYLEVEL <percent of battery charge for shutdown> 10
  159. + BATTERYLEVEL 10
  160. + #
  161. + # MINUTES <time in minutes of remainning battery charge before shutdown> 5
  162. + MINUTES 5
  163. + #
  164. + # SENSITIVITY <char> H,M,L default H
  165. + SENSITIVITY H
  166. + #
  167. + # WAKEUP <int> 0,60,180,300 Cycles default 0
  168. + WAKEUP 60
  169. + #
  170. + # SLEEP <int> 20,180,300,600 Cycles default 20
  171. + SLEEP 20
  172. + #
  173. + # LOTRANSFER <int> 0,1,2,3 default 2
  174. + LOTRANSFER 2
  175. + #
  176. + # HITRANSFER <int> 0,1,2,3 default 2
  177. + HITRANSFER 3
  178. + #
  179. + # RETURNCHARGE <int> 0,1,2,3 default 3
  180. + RETURNCHARGE 1
  181. + #
  182. + # BEEPSTATE <char> 0,T,L,N default 0
  183. + BEEPSTATE L
  184. + #
  185. + # SELFTEST <string> 336,168,ON,OFF default 336
  186. + SELFTEST 336
  187. + #
  188. + # UPSNAME <string>
  189. + UPSNAME SUZEUPS
  190. + #
  191. + # BATTCMD <string>
  192. + #BATTCMD
  193. + #
  194. + # TIMECMD <string>
  195. + #TIMECMD 
  196. + #
  197. + # LOADCMD <string>
  198. + #LOADCMD 
  199. + #
  200. + # LIMITCMD <string>
  201. + #LIMITCMD
  202. + #
  203. + # PWRCMD <string>
  204. + #PWRCMD
  205. + #
  206. + # RETCMD <string>
  207. + #RETCMD
  208. + #
  209. + # REMOTECMD <string>
  210. + #REMOTECMD
  211. + #
  212. + # REBOOTCMD <string>
  213. + #REBOOTCMD
  214. + #
  215. + # NETTIME <int>
  216. + #NETTIME 100
  217. + #
  218. + # NETPORT <int>
  219. + #NETPORT 6666
  220. + #
  221. + # MASTER <string>
  222. + #MASTER
  223. + #
  224. + # SLAVE <string>
  225. + #SLAVE
  226. + #SLAVE
  227. + #SLAVE
  228. + #SLAVE
  229. + #SLAVE
  230. + #SLAVE
  231. + #SLAVE
  232. + #SLAVE
  233. + #SLAVE
  234. + #SLAVE
  235. + #
  236. + # USERMAGIC <string>
  237. + #USERMAGIC
  238. + #
  239. + # HTTPACCESS [ true | false ]   enable web-interface - defaults to false
  240. + HTTPACCESS false
  241. + #
  242. + # HTTPPORT <port>  port to use for interface - defaults to 1999
  243. + #HTTPPORT 1999
  244. + #
  245. *** apcupsd-3.5.8.ull.src/installs/halt.solaris.orig    Thu Jul 20 19:09:31 2000
  246. --- apcupsd-3.5.8.ull.src/installs/halt.solaris    Thu Jul 20 18:35:46 2000
  247. ***************
  248. *** 0 ****
  249. --- 1,94 ----
  250. + #!/sbin/sh
  251. + #    Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  252. + #      All Rights Reserved
  253. + #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
  254. + #    The copyright notice above does not evidence any
  255. + #    actual or intended publication of such source code.
  256. + #ident    "@(#)rc0.sh    1.16    94/11/30 SMI"    SVr4.0 1.15.4.1
  257. + #    "Run Commands" for init states 0, 5 and 6.
  258. + PATH=/usr/sbin:/usr/bin
  259. + echo 'The system is coming down.  Please wait.'
  260. + # make sure /usr is mounted before proceeding since init scripts
  261. + # and this shell depend on things on /usr file system
  262. + /sbin/mount /usr > /dev/null 2>&1
  263. + #    The following segment is for historical purposes.
  264. + #    There should be nothing in /etc/shutdown.d.
  265. + if [ -d /etc/shutdown.d ]
  266. + then
  267. +     for f in /etc/shutdown.d/*
  268. +     {
  269. +         if [ -s $f ]
  270. +         then
  271. +             /sbin/sh ${f}
  272. +         fi
  273. +     }
  274. + fi
  275. + #    End of historical section
  276. + if [ -d /etc/rc0.d ]
  277. + then
  278. +     for f in /etc/rc0.d/K*
  279. +     {
  280. +         if [ -s ${f} ]
  281. +         then
  282. +             case ${f} in
  283. +                 *.sh)    .     ${f} ;;    # source it
  284. +                 *)    /sbin/sh ${f} stop ;;    # sub shell
  285. +             esac
  286. +         fi
  287. +     }
  288. + #    system cleanup functions ONLY (things that end fast!)    
  289. +     for f in /etc/rc0.d/S*
  290. +     {
  291. +         if [ -s ${f} ]
  292. +         then
  293. +             case ${f} in
  294. +                 *.sh)    .     ${f} ;;    # source it
  295. +                 *)    /sbin/sh ${f} start ;;    # sub shell
  296. +             esac
  297. +         fi
  298. +     }
  299. + fi
  300. + trap "" 15
  301. + # kill all processes, first gently, then with prejudice.
  302. + /usr/sbin/killall
  303. + /usr/bin/sleep 5
  304. + /usr/sbin/killall 9
  305. + /usr/bin/sleep 10
  306. + /sbin/sync; /sbin/sync; /sbin/sync
  307. + # unmount file systems. /usr, /var and /var/adm are not unmounted by umountall
  308. + # because they are mounted by rcS (for single user mode) rather than
  309. + # mountall.
  310. + # If this is changed, mountall, umountall and rcS should also change.
  311. + # jpd 11/98: restrict umountall to local filsystems, since we are having problems
  312. + #    with some autofs/nfs mounts that stay busy (probably until the killall 9
  313. + #    above, but then it's too late to deal with network and NFS)
  314. + /sbin/umountall -l
  315. + /sbin/umount /var/adm >/dev/null 2>&1
  316. + /sbin/umount /var >/dev/null 2>&1
  317. + /sbin/umount /usr >/dev/null 2>&1
  318. + # jpd@louisiana.edu: We may want to tell the APC UPS to power itself off now
  319. + # Note that the /sbin/powersc script relyies on /usr being mounted, so we
  320. + # must call apcupsd directly.  Makes more sense anyhow.
  321. + # See if this is a powerfail situation.
  322. + if [ -f /etc/powerfail -a -x /sbin/apckillpwr ]; then
  323. +   echo "APCKILLPWR invoked to kill power"
  324. +   echo
  325. +   /sbin/apckillpwr killpower
  326. +   echo
  327. + fi
  328. + echo 'The system is down.'
  329. *** apcupsd-3.5.8.ull.src/installs/powersc.solaris.orig    Thu Jul 20 19:09:31 2000
  330. --- apcupsd-3.5.8.ull.src/installs/powersc.solaris    Mon Jun 26 17:36:36 2000
  331. ***************
  332. *** 0 ****
  333. --- 1,140 ----
  334. + #!/bin/sh
  335. + #
  336. + POWERPID=/etc/shut.pid
  337. + APCPID=/etc/apcupsd.pid
  338. + # Solaris needs the SysV shutdown to issue the -i5 poweroff option:
  339. + SHUTARGS="-i 5 -g 0 -y"        # "-h now" for bsd shutdown
  340. + if [ -x /sbin/shutdown ]; then
  341. +     SHUTDOWN=/sbin/shutdown
  342. + elif [ -x /usr/sbin/shutdown ]; then
  343. +     SHUTDOWN=/usr/sbin/shutdown
  344. + # elif [ -x /sbin/shutdown.bsd ]; then
  345. + #    SHUTDOWN=/sbin/shutdown.bsd
  346. + else
  347. +     echo Command shutdown or shutdown.bsd not found!
  348. +     exit 1
  349. + fi
  350. + if [ -x /usr/local/sbin/apcupsd ]; then
  351. +     APCUPSD=/usr/local/sbin/apcupsd
  352. + elif [ -x /opt/apcups/apcupsd ]; then
  353. +     APCUPSD=/opt/apcups/apcupsd
  354. + elif [ -x /usr/sbin/apcupsd ]; then
  355. +     APCUPSD=/usr/sbin/apcupsd
  356. + elif [ -x /sbin/apcupsd ]; then
  357. +     APCUPSD=/sbin/apcupsd
  358. + else
  359. +     echo Command apcupsd not found!
  360. +     exit 1
  361. + fi
  362. + if [ `/usr/xpg4/bin/id -u` != "0" ]; then
  363. +     printf "Sorry, you must be root to run this script.\n" | wall
  364. +     exit 1
  365. + fi
  366. + case "$1" in
  367. +     POWEROUT)
  368. +         printf "Warning: there are Power problems.\n" | wall
  369. +         ;;
  370. +     ONBATTERY)
  371. +         printf "Power Failed; running on UPS.\n" | wall
  372. +         ;;
  373. +     FAILING)
  374. +         printf "Battery Power Failing; Normal Shutdown.\n" | wall
  375. +         ;;
  376. +     TIMEOUT)
  377. +         printf "On-Battery timeout; Normal Shutdown.\n" | wall
  378. +         ;;
  379. +     LOADLIMIT)
  380. +         printf "Battery Load Limits Reached; Normal Shutdown.\n" | wall
  381. +         ;;
  382. +     RUNLIMIT)
  383. +         printf "Battery RunTime Limits Reached; Normal Shutdown.\n" | wall
  384. +         ;;
  385. +     DOSHUTDOWN)
  386. +         printf "Beginning Shutdown Sequence!!!!!;\n" | wall
  387. +         runlevel=`ps -ef -o pid,tty,s,time,args | nawk '{ if (($5 == "init") && ($1 == "1")) print $6 }' \
  388. +             | cut -f2 -d[ | cut -f1 -d] `
  389. +         if [ "$runlevel" = "" -o "$runlevel" = "-" ]; then
  390. +             runlevel=`nawk -F: '$1 == "is" { print $2 }' /etc/inittab`
  391. +         fi
  392. +         echo $runlevel    > /tmp/run.level.power
  393. +         if [ -f $POWERPID ]
  394. +         then
  395. +             exit 0
  396. +         else
  397. +             echo $$ > $POWERPID
  398. +             $SHUTDOWN $SHUTARGS
  399. +         fi
  400. +         ;;
  401. +     MAINSBACK | WAITASEC)
  402. +         if [ -f $POWERPID ]; then
  403. +             printf "Attempting to cancel shutdown."
  404. +             kill `cat $POWERPID`
  405. +             rm -f $POWERPID
  406. +             init `cat /tmp/run.level.power`
  407. +         fi
  408. +         printf "Power has returned...\n" | wall
  409. +         ;;
  410. +     ANNOYME)
  411. +         printf "Power Problems - Please Log Off Now!!!!\n" | wall
  412. +         ;;
  413. +     EMERGENCY)
  414. +         printf "Emergency Shutdown, Possible Battery Failure!!!!\n" | wall
  415. +         $SHUTDOWN $SHUTARGS
  416. +         ;;
  417. +     CHANGEME)
  418. +         printf "Emergency, Batteries Have Failed!!!!\nChange Them NOW!!!!\n" | wall
  419. +         ;;
  420. +     REMOTE)
  421. +         printf "Remote Shutdown request received.\nBeginning Shutdown Sequence!!!!!\n" | wall
  422. +         $SHUTDOWN $SHUTARGS
  423. +         ;;
  424. +     KILL)    sleep 1
  425. +         $APCUPSD killpower
  426. +         sleep 10
  427. +         ;;
  428. +     INIT)    rm -f $POWERPID
  429. + #
  430. + # apcupsd should be doing its own cleaning of lock and pid files.
  431. + # -BSC
  432. + #
  433. + #        if [ -f $APCPID ]; then
  434. + #            kill $(cat $APCPID) 1> /dev/null 2> /dev/null
  435. + #            rm -f $APCPID
  436. + #        fi
  437. +         rm -f /etc/powerfail
  438. +         rm -f /etc/powerstatus
  439. +         rm -f /etc/nologin
  440. +         printf "Starting APCUPSD Power Management: "
  441. +         $APCUPSD
  442. +         echo "apcupsd"
  443. +         ;;
  444. +     STOP)
  445. +         printf "Stopping APCUPSD Power Management: "
  446. +         if [ -f $APCPID ]; then
  447. +             kill `cat $APCPID`
  448. +             rm -f $APCPID
  449. +         fi
  450. +         echo "apcupsd"
  451. +         ;;
  452. +     RESTARTME)
  453. +         printf "Restarting APCUPSD Power Management: "
  454. +         kill `cat $APCPID`
  455. +         rm -f $APCPID
  456. +         rm -f $POWERPID
  457. +         rm -f /etc/powerfail
  458. +         rm -f /etc/powerstatus
  459. +         rm -f /etc/nologin
  460. +         sleep 10
  461. +         $APCUPSD
  462. +         echo "apcupsd"
  463. +         ;;
  464. +     *)    echo "Usage:   ${0##*/} [POWEROUT | ONBATTERY | FAILING | TIMEOUT | LOADLIMIT | RUNLIMIT | DOSHUTDOWN | MAINSBACK | WAITASEC | ANNOYME | EMERGENCY | CHANGEME | REMOTE | KILL | INIT | STOP | RESTARTME]"
  465. +         exit 1
  466. +         ;;
  467. + esac
  468. + exit 0
  469. *** apcupsd-3.5.8.ull.src/Makefile.orig    Thu Jul 20 18:40:49 2000
  470. --- apcupsd-3.5.8.ull.src/Makefile    Thu Jul 20 17:01:12 2000
  471. ***************
  472. *** 66,80 ****
  473.   APCUPSD   = apcupsd
  474.   APCACCESS = apcaccess
  475.   POWERFLUTE= powerflute
  476.   
  477.   INCLUDES  = -I./include
  478.   
  479.   # Flags for compiler
  480.   CFLAGS    = -g -O2 -Wall $(INCLUDES) $(CMDC)
  481.   
  482.   # Flags for linker
  483.   LFLAGS    = $(CMDL)
  484. ! OPTIONS   = $(CMDC) $(INCLUDES)
  485.   
  486.   ifdef THREADS
  487.   CFLAGS   += -DNEW_THREADS
  488. --- 66,82 ----
  489.   APCUPSD   = apcupsd
  490.   APCACCESS = apcaccess
  491.   POWERFLUTE= powerflute
  492. + APCKILLPWR= apckillpwr
  493.   
  494.   INCLUDES  = -I./include
  495.   
  496.   # Flags for compiler
  497.   CFLAGS    = -g -O2 -Wall $(INCLUDES) $(CMDC)
  498. + OPTIONS   = $(CMDC) $(INCLUDES)
  499.   
  500.   # Flags for linker
  501.   LFLAGS    = $(CMDL)
  502. ! STATIC    = -static   # -static for gcc, -B static for Sun CC, ...
  503.   
  504.   ifdef THREADS
  505.   CFLAGS   += -DNEW_THREADS
  506. ***************
  507. *** 85,91 ****
  508.   
  509.   SHELL     = /bin/sh
  510.   ECHO      = echo
  511. ! MAKE      = make
  512.   CHOWN     = chown
  513.   CHMOD     = chmod
  514.   CP        = cp
  515. --- 87,93 ----
  516.   
  517.   SHELL     = /bin/sh
  518.   ECHO      = echo
  519. ! MAKE      = gmake
  520.   CHOWN     = chown
  521.   CHMOD     = chmod
  522.   CP        = cp
  523. ***************
  524. *** 112,118 ****
  525.   .c.o:
  526.       $(CC) $(CFLAGS) -c $<
  527.   .o:
  528. !     $(LD) -s -o $*.o
  529.   
  530.   #****************************************************************************
  531.   #*                                                                          *
  532. --- 114,120 ----
  533.   .c.o:
  534.       $(CC) $(CFLAGS) -c $<
  535.   .o:
  536. !     $(LD) $(LFLAGS) -s -o $*.o
  537.   
  538.   #****************************************************************************
  539.   #*                                                                          *
  540. ***************
  541. *** 233,245 ****
  542.   ifdef MUSIC
  543.   
  544.   $(APCUPSD) : $(OBJ)
  545. !     $(CC) -o $(APCUPSD)-$(OS) $(DOBJ)
  546. !     $(CC) -o $(APCACCESS)-$(OS) $(TOBJ)
  547. !     $(CC) -o $(POWERFLUTE)-$(OS) $(POBJ) -lncurses -lmenu -lpanel
  548.       @if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
  549.           $(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
  550.           $(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
  551.           $(MV) $(POWERFLUTE)-$(OS) $(POWERFLUTE)-$(NAME); \
  552.       fi
  553.       @$(RM) -f $(OBJ)
  554.   
  555. --- 235,249 ----
  556.   ifdef MUSIC
  557.   
  558.   $(APCUPSD) : $(OBJ)
  559. !     $(CC) -o $(APCUPSD)-$(OS) $(LFLAGS) $(DOBJ) $(LIBS)
  560. !     $(CC) -o $(APCACCESS)-$(OS) $(LFLAGS) $(TOBJ) $(LIBS)
  561. !     $(CC) -o $(POWERFLUTE)-$(OS) $(LFLAGS) $(POBJ) -lncurses -lmenu -lpanel $(LIBS)
  562. !     $(CC) -o $(APCKILLPWR)-$(OS) $(LFLAGS) $(STATIC) -DNONETSUPPORT apcnet.c $(DOBJ) $(LIBS)
  563.       @if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
  564.           $(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
  565.           $(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
  566.           $(MV) $(POWERFLUTE)-$(OS) $(POWERFLUTE)-$(NAME); \
  567. +         $(MV) $(APCKILLPWR)-$(OS) $(APCKILLPWR)-$(NAME); \
  568.       fi
  569.       @$(RM) -f $(OBJ)
  570.   
  571. ***************
  572. *** 246,256 ****
  573.   else
  574.   
  575.   $(APCUPSD) : $(OBJ)
  576. !     $(CC) -o $(APCUPSD)-$(OS) $(DOBJ)
  577. !     $(CC) -o $(APCACCESS)-$(OS) $(TOBJ)
  578.       @if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
  579.           $(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
  580.           $(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
  581.       fi
  582.       @$(RM) -f $(OBJ)
  583.   
  584. --- 250,263 ----
  585.   else
  586.   
  587.   $(APCUPSD) : $(OBJ)
  588. !     $(CC) -o $(APCUPSD)-$(OS) $(LFLAGS) $(DOBJ) $(LIBS)
  589. !     $(CC) -o $(APCACCESS)-$(OS) $(LFLAGS) $(TOBJ) $(LIBS)
  590. !     $(CC) $(CFLAGS) -c -DNONETSUPPORT apcnet.c
  591. !     $(CC) -o $(APCKILLPWR)-$(OS) $(LFLAGS) $(STATIC) $(DOBJ) $(LIBS)
  592.       @if [ ! "`$(ECHO) $(NAME)`" = "" ]; then \
  593.           $(MV) $(APCUPSD)-$(OS) $(APCUPSD)-$(NAME); \
  594.           $(MV) $(APCACCESS)-$(OS) $(APCACCESS)-$(NAME); \
  595. +         $(MV) $(APCKILLPWR)-$(OS) $(APCKILLPWR)-$(NAME); \
  596.       fi
  597.       @$(RM) -f $(OBJ)
  598.   
  599. ***************
  600. *** 402,407 ****
  601. --- 409,415 ----
  602.   
  603.   sun :
  604.       @$(MAKE) depend $(APCUPSD) \
  605. +         LIBS="-lnsl -lsocket" \
  606.           OS="sun" \
  607.           CC="gcc"
  608.   
  609. ***************
  610. *** 481,487 ****
  611.   clean :
  612.       $(RM) -f `$(FIND) . \( -name '*~' -o -name '*.bak' -o -name '*.ESV' \
  613.           -o -name '*.ASV' -o -name '*.orig' -o -name 'core' \) -print`
  614. !     $(RM) -f *.lsm apcupsd-linux apcaccess-linux powerflute-linux
  615.       $(RM) -f core *.o
  616.   
  617.   distclean : clobber
  618. --- 489,495 ----
  619.   clean :
  620.       $(RM) -f `$(FIND) . \( -name '*~' -o -name '*.bak' -o -name '*.ESV' \
  621.           -o -name '*.ASV' -o -name '*.orig' -o -name 'core' \) -print`
  622. !     $(RM) -f *.lsm apcupsd-* apcaccess-* powerflute-*
  623.       $(RM) -f core *.o
  624.   
  625.   distclean : clobber
  626. *** apcupsd-3.5.8.ull.src/apcaction.c.orig    Thu Jul 20 18:43:10 2000
  627. --- apcupsd-3.5.8.ull.src/apcaction.c    Tue Jun 20 15:40:54 2000
  628. ***************
  629. *** 59,65 ****
  630. --- 59,67 ----
  631.   
  632.   #include <stdio.h>
  633.   #include <unistd.h>
  634. + #ifndef __SVR4
  635.   #include <getopt.h>
  636. + #endif
  637.   #include <stdlib.h>
  638.   #include <stdarg.h>
  639.   #include <fcntl.h>
  640. *** apcupsd-3.5.8.ull.src/apcconfig.c.orig    Thu Jul 20 18:43:28 2000
  641. --- apcupsd-3.5.8.ull.src/apcconfig.c    Wed Jun 21 17:15:54 2000
  642. ***************
  643. *** 75,80 ****
  644. --- 75,102 ----
  645.   #include <errno.h>
  646.   #include <ctype.h>
  647.   
  648. + /* Some Unix systems have a different lockfile and device path format: */
  649. + #if defined(SVR4) || defined(__svr4__) || defined (__SVR4) || defined(solaris)
  650. + #undef SVR4
  651. + #define SVR4
  652. + #define LFDEVNO
  653. + #endif
  654. + #ifdef LFDEVNO
  655. + #ifndef major                /* If we didn't find it */
  656. + #ifdef SVR4                /* then for Sys V R4 */
  657. + #include <sys/mkdev.h>            /* look here */
  658. + #else                    /* or for Sunos versions */
  659. + #ifdef SUNOS4                /* ... */
  660. + #include <sys/sysmacros.h>        /* look here */
  661. + #else                    /* Otherwise take a chance: */
  662. + #define    major(dev) ( (int) ( ((unsigned)(dev) >> 8) & 0xff))
  663. + #define    minor(dev) ( (int) ( (dev) & 0xff))
  664. + #endif /* SUNOS4 */
  665. + #endif /* SVR4 */
  666. + #endif /* major */
  667. + #endif /* LFDEVNO */
  668.   #include <apc_version.h>
  669.   #include <apc_defines.h>
  670.   #include <apc_struct.h>
  671. ***************
  672. *** 579,585 ****
  673. --- 601,611 ----
  674.       char line[MAXTOKENLEN];
  675.       int errors = 0;
  676.       int erpos = 0;
  677. + #ifdef LFDEVNO
  678. +     struct stat devbuf;        /* For device numbers (SVR4). */
  679. + #endif /* LFDEVNO */
  680.   
  681.       zero_ups_struct(ups);
  682.       sprintf(ups->argvalue, "%s", argvalue);
  683.   
  684. ***************
  685. *** 720,729 ****
  686. --- 746,770 ----
  687.        * If APC_NET, the lockfile is not needed.
  688.        */
  689.       if (ups->cable.type != APC_NET) {
  690. + #ifdef LFDEVNO                /* Lockfilename has device numbers. */
  691. +         char lockname[32];
  692. +         if (stat(ups->device,&devbuf) < 0) {
  693. +             errors++;
  694. +             fprintf(stderr, "Can't stat %s (code %d)\n", ups->device, errno);
  695. +         } else {
  696. +             sprintf(lockname,"/LK.%03d.%03d.%03d",
  697. +                 major(devbuf.st_dev),    /* inode */
  698. +                 major(devbuf.st_rdev),    /* major device number */
  699. +                 minor(devbuf.st_rdev));    /* minor device number */
  700. +              strcat(ups->lockpath, lockname);
  701. +         }
  702. + #else                    /* Others... */
  703.           char *dev = strrchr(ups->device, '/');
  704.   
  705.           strcat(ups->lockpath, APC_LOCK_PREFIX);
  706.           strcat(ups->lockpath, dev?++dev:ups->device);
  707. + #endif
  708.       } else {
  709.           ups->lockpath[0] = 0;
  710.           ups->lockfile = -1;
  711. *** apcupsd-3.5.8.ull.src/apcnet.c.orig    Thu Jul 20 18:43:57 2000
  712. --- apcupsd-3.5.8.ull.src/apcnet.c    Tue Jun 27 14:25:16 2000
  713. ***************
  714. *** 80,86 ****
  715.   #include <apc_extern.h>
  716.   
  717.   #undef DEBUG
  718.   /*
  719.    * these defenitions simplify code for the network communication layer
  720.    * MAGIC_PAD is the size required so that APC_MAGIC strings
  721. --- 80,85 ----
  722. ***************
  723. *** 112,117 ****
  724. --- 111,199 ----
  725.   
  726.   extern int debug_net;
  727.   
  728. + #if NONETSUPPORT
  729. + int write_struct_net (int wsocketfd, struct netdata *write_struct, size_t size)
  730. + {
  731. +   logprintf("write_struct_net() invoked!\n");
  732. +   exit(1);
  733. + }
  734. + int read_struct_net (int rsocketfd, struct netdata *read_struct, size_t size)
  735. + {
  736. +   logprintf("read_struct_net() invoked!\n");
  737. +   exit (1);
  738. + }
  739. + void log_struct (struct netdata *logstruct)
  740. + {
  741. + }
  742. + int reconnect_master (UPSINFO *ups, int who)
  743. + {
  744. +   logprintf("reconnect_master invoked!\n");
  745. +   exit (1);
  746. + }
  747. + int prepare_master (UPSINFO *ups)
  748. + {
  749. +   logprintf("prepare_master invoked!\n");
  750. +   exit(1);
  751. + }
  752. + void send_to_slaves (UPSINFO *ups)
  753. + {
  754. +   logprintf("send_to_slaves invoked!\n");
  755. +   exit(1);
  756. + }
  757. + int send_to_each (UPSINFO *ups, int who)
  758. + {
  759. +   logprintf("send_to_each invoked!\n");
  760. +   exit(1);
  761. + }
  762. + int reconnect_slave(UPSINFO *ups)
  763. + {
  764. +   logprintf("reconnect_slave invoked!\n");
  765. +   exit(1);
  766. + }
  767. + int prepare_slave (UPSINFO *ups)
  768. + {
  769. +   logprintf("prepare_slave invoked!\n");
  770. +   exit(1);
  771. + }
  772. + int get_from_master (UPSINFO *ups)
  773. + {
  774. +   logprintf("get_from_master invoked!\n");
  775. +   exit(1);
  776. + }
  777. + void kill_net (UPSINFO *ups, int killpwr)
  778. + {
  779. +   logprintf("kill_net invoked!\n");
  780. +   exit(1);
  781. + }
  782. + #ifndef NEW_THREADS
  783. + void do_net (UPSINFO *ups)
  784. + {
  785. +   logprintf("do_net invoked!\n");
  786. +   exit(1);
  787. + }
  788. + #else
  789. + void timer_net (int sig)
  790. + {
  791. +   logprintf("timer_net invoked!\n");
  792. +   exit(1);
  793. + }
  794. + void do_net (UPSINFO *ups)
  795. + {
  796. +   logprintf("do_net invoked!\n");
  797. +   exit(1);
  798. + }
  799. + void timer_slaves (int sig)
  800. + {
  801. +   logprintf("timer_slaves invoked!\n");
  802. +   exit(1);
  803. + }
  804. + void do_slaves (void)
  805. + {
  806. +   logprintf("do_slaves invoked!\n");
  807. +   exit(1);
  808. + }
  809. + #endif
  810. + #else
  811.   /*********************************************************************/
  812.   /* write_struct_net takes a netdata structure and copies it to       */
  813.   /* malloc'ed memory so that the netdata structure is properly network*/
  814. ***************
  815. *** 1200,1202 ****
  816. --- 1282,1285 ----
  817.       sleep_forever();
  818.   }
  819.   #endif /* NEW_THREADS */
  820. + #endif /* NONETSUPPORT */
  821. *** apcupsd-3.5.8.ull.src/apcreports.c.orig    Thu Jul 20 18:44:18 2000
  822. --- apcupsd-3.5.8.ull.src/apcreports.c    Tue Jun 20 15:41:05 2000
  823. ***************
  824. *** 58,64 ****
  825. --- 58,66 ----
  826.   
  827.   #include <stdio.h>
  828.   #include <unistd.h>
  829. + #ifndef __SVR4
  830.   #include <getopt.h>
  831. + #endif
  832.   #include <stdlib.h>
  833.   #include <stdarg.h>
  834.   #include <fcntl.h>
  835. *** apcupsd-3.5.8.ull.src/apcserial.c.orig    Thu Jul 20 18:44:33 2000
  836. --- apcupsd-3.5.8.ull.src/apcserial.c    Tue Jun 20 15:41:16 2000
  837. ***************
  838. *** 59,65 ****
  839. --- 59,67 ----
  840.   
  841.   #include <stdio.h>
  842.   #include <unistd.h>
  843. + #ifndef __SVR4
  844.   #include <getopt.h>
  845. + #endif
  846.   #include <stdlib.h>
  847.   #include <stdarg.h>
  848.   #include <fcntl.h>
  849. *** apcupsd-3.5.8.ull.src/apcupsd.c.orig    Thu Jul 20 18:45:02 2000
  850. --- apcupsd-3.5.8.ull.src/apcupsd.c    Wed Jun 21 13:09:19 2000
  851. ***************
  852. *** 100,106 ****
  853. --- 100,108 ----
  854.   
  855.   #include <stdio.h>
  856.   #include <unistd.h>
  857. + #ifndef __SVR4
  858.   #include <getopt.h>
  859. + #endif
  860.   #include <stdlib.h>
  861.   #include <stdarg.h>
  862.   #include <fcntl.h>
  863. ***************
  864. *** 361,366 ****
  865. --- 363,370 ----
  866.   int main (int argc, char **argv)
  867.   {
  868.       int KILL = FALSE;
  869. +     pid_t  parentpid;
  870. +     int    sleeplimiter=60;
  871.   
  872.   #ifndef NEW_THREADS
  873.   
  874. ***************
  875. *** 507,512 ****
  876. --- 511,517 ----
  877.       /*
  878.        *  Become a daemon.
  879.        */
  880. +     parentpid = getpid();
  881.       switch(fork()) {
  882.           case 0:                       /* I am the child. */
  883.               setsid();
  884. ***************
  885. *** 551,556 ****
  886. --- 556,570 ----
  887.        * the lockfile during fork()" way.
  888.        * -RF
  889.        */
  890. +     /* Yes, BUT: the parent process may not yet have died, so we have a
  891. +      * race condition: will it die before we read the pid from the lockfile
  892. +      * and test the parents existence?  TO be sure it tests false, we will
  893. +      * pause here UNTIL the parent is really dead!  -- jpd@louisiana.edu
  894. +      */
  895. +     while ( kill(parentpid, 0) == 0  && sleeplimiter--)
  896. +       sleep (5);
  897.       if (create_lockfile(&myUPS, KILL) == LCKERROR) {
  898.           fprintf(stderr, "%s: failed to reacquire lock file on device %s\n", argv[0], myUPS.device);
  899.           logprintf("%s: failed to reacquire lock file on device %s\n", argv[0], myUPS.device);
  900.