APC UPS Power Management under Linux, Unix, and Windows
Author: Kern Sibbald
Description: Apcupsd a Linux/Win32 daemon for controlling APC UPSes
Keywords: apcupsd, UPS, APC, Power Mangement, American Power Corporation, Uninterruptable Power Supplies

# Apcupsd Bugs

# Apcupsd Version 3.8.5 Bugs

All known bugs have been corrected in this version.

# Apcupsd Version 3.8.4 Bugs

Version 3.8.4 is a bug fix version to 3.8.3 that corrects improper placement of the subsystem lock file that crept in between 3.8.2 and 3.8.3. It also corrects an oversite in the multimoncss.c code that didn't include the temperature and humidity columns in the Normal class.

# Apcupsd Version 3.8.3 Bugs

All known bugs in version 3.8.2 have been fixed with the exception of the following two:

## Networking may not work in a mixed vendor setup

Bug: In a mixed vendor setup (RedHat, Debian, ...), the default networking (master/slave or Network Information Server) port assignments are different. Reason: Due to port conflicts on some machines, we set the default port numbers on each distribution to the values recommended by our experts. This solves a lot of problems, but results in incompatibilities if you use the apcupsd defaults. Fix: If you run a mixed vendor setup, either add a port specification :<port> to the machine name in hosts.conf or use the --with-nis-port=nn and --with-net-port=nn options on your ./configure command and ensure that all your machines use the same port numbers. After the ./configure, you will need to redo your make and make install. The default values for most systems are:

./configure --with-nis-port=7000 --with-net-port=6666

## Unusual Case of Apcupsd Hanging during Boot

On some systems (kernel version 2.4.5-acxx), apcupsd may hang during the boot process. This appears to be a probably of invoking apcupsd before the network is initialized. The simplest solution is to ensure that apcupsd is started after the network functions, or to put an explicit background (ampersand) request in the apcupsd startup script.

If this occurs and your apcupsd is a master, the problem can be because you master/slave networking port is used by another program on the slave machine. The master/slave networking code has been modified to timout in 10 seconds in this case.

# Apcupsd Version 3.8.2 Bugs

All version 3.8.0 and 3.8.1 bugs have been corrected in version 3.8.2.

## The Lock Directory in the Solaris is Incorrect

Bug: The apcupsd script is using /var/lock as the directory for lock files even though the configure script figures out that it is supposed to be /var/spool/locks (/var/lock does not exist).

Fix: Apply the following patch then re-run your ./configure:

    --- distributions/sun/old.apcupsd.in    Sat Jul  7 10:20:30 2001
    +++ distributions/sun/apcupsd.in        Sat Jul  7 10:18:59 2001
    @@ -17,7 +17,7 @@
             rm -f @PWRFAILDIR@/powerfail
             echo "Starting apcupsd power management ...\c"
             @sbindir@/apcupsd || return="  Failed."
    -        touch /var/lock/apcupsd
    +        touch @LOCKDIR@/apcupsd
             echo "$return"
         ;;
         stop)
    @@ -29,7 +29,7 @@
             else
                     return=" Failed."
             fi
    -        rm -f /var/lock/apcupsd
    +        rm -f @LOCKDIR@/apcupsd
             echo "$return"
         ;;
         restart)

## Solaris doesn't Shutdown

Bug: Solaris detects power failures and seems to work fine, but the machine is not shutdown.

Reason: You probably executed the ./configure for apcupsd with /usr/ucb on your path before /usr/sbin. Thus apcupsd is using the Berkeley shutdown program but with SysV arguments.

Fix: remove /usr/ucb from your path and rerun your ./configure, make, and make install. Alternative: edit /etc/apcupsd/apccontrol and set the correct path for the SysV shutdown. We are working on a permanent solution.

## examples/safe.apccontrol has bad wall command

Bug: On non-Linux systems, the examples/safe.apccontrol doesn't work because it uses wall "message" whereas on other systems wall only accepts the message from stdin.

Fix: We have modified examples/safe.apccontrol to use wall <<EOF input, which should work fine on all systems. You can download the new version of safe.apccontrol from safe.apccontrol.tar.gz, but you may want to edit the paths to correspond to your system.

Future: For the next version of apcupsd, we have also created a examples/safe.apccontrol.in so that all the paths will be correctly set by configure for your system.

## Networking does not work in a mixed vendor setup

Bug: In a mix vendor setup (RedHat, Debian, ...), the default networking (master/slave or Network Information Server) port assignments are different. Reason: Due to port conflicts on some machines, we set the default port numbers on each distribution to the values recommended by our experts. This solves a lot of problems, but results in incompatibilities if you use the apcupsd defaults. Fix: If you run a mixed vendor setup, use the --with-nis-port=nn and --with-net-port=nn options on your ./configure command and ensure that all your machines use the same port numbers. After the ./configure, you will need to redo your make and make install. The default values for most systems are:

./configure --with-nis-port=7000 --with-net-port=6666

## Unusual Case of Apcupsd Hanging during Boot

On some systems (kernel version 2.4.5-acxx), apcupsd may hang during the boot process. This appears to be a probably of invoking apcupsd before the network is initialized. The simplest solution is to ensure that apcupsd is started after the network functions, or to put an explicit background (ampersand) request in the apcupsd startup script.

# Apcupsd Version 3.8.1 Bugs

Unfortunately, it seems that every program has some bugs. We do our best to keep the bugs to a minimum by extensive testing. However, because of our inherent nature to occasionally overlook things and the fact that we don't have all the UPS models nor the APC documentation on those models, apcupsd will have some bug.

As the bugs become known to us, we will post them here with any possible fixes or workarounds that we have.

## Apcupsd may Hang when Attempting to Initialize the Serial Port

This problem has been reported on NetBSD systems and on a Solaris8 (64bit) UltraSparc60 system. The problem is that the open() of the serial port does not return. The solution is to use the O_NDELAY flag when opening the port. The open() at 85 of apcserial.c should be replaced with the following:

           if ((ups->fd = open(ups->device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
                    Error_abort2(_("Cannot open UPS tty %s: %s\n"),
                                            ups->device, strerror(errno));
            }
            /* Cancel the no delay we just set */
            cmd = fcntl(ups->fd, F_GETFL, 0);
            fcntl(ups->fd, F_SETFL, cmd & ~O_NDELAY);

Please note the addition of the two fcntl() calls to remove the O_NDELAY so that apcupsd will function properly. The patch relative to apcupsd-3.8.1 is:

    @@ -77,18 +81,21 @@
                     Error_abort0(_("Serial port already initialized.\n"));
            }

    -       /* Open the the device */
    -       if ((ups->fd = open(ups->device ,O_RDWR | O_NOCTTY )) < 0) {
    +       /* Open the serial port device */
    +       if ((ups->fd = open(ups->device, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) {
                     Error_abort2(_("Cannot open UPS tty %s: %s\n"),
                                            ups->device, strerror(errno));
            }
    +       /* Cancel the no delay we just set */
    +       cmd = fcntl(ups->fd, F_GETFL, 0);
    +       fcntl(ups->fd, F_SETFL, cmd & ~O_NDELAY);

## Version 3.8.1 May Cause Networking Problems on Win95

We have a report by a user that installing version 3.8.1 on a Windows 95 machine caused the loss of all networking capabilities on that machine. Reinstallation of version 3.8.0 restored the networking capabilities. It should be noted that the major difference between the two versions was addition of support on Win32 for simple signaling UPSes (no change for Smart UPSes or networking) and upgrading from version 1.1.2 to version 1.1.5 of CYGWIN. We would appreciate hearing of your experiences with Win95 and apcupsd.

## STATUS Output for BackUPS Pro and SmartUPS VS Incorrect

The STATUS Output for the BackUPS Pro and SmartUPS VS was unfortunately truncated due to a misplaced "break" statement. To fix this problem and restore the full STATUS output, for version 3.8.1, delete line 161 of apcstatus.c, which should be "break;"

                } else {
                          s_write("LINEFAIL : DOWN\n");
                          if (ups->BattLow == 0) {
                                  s_write("BATTSTAT : RUNNING\n");
                                  ups->Status = UPS_ONBATT;
                          } else {
                                  s_write("BATTSTAT : FAILING\n");
                                  ups->Status = UPS_BATTLOW;
                          }
                  }
                  s_write("STATFLAG : 0x%02X Status Flag\n", ups->Status);
                  break;                                       <=========== delete this line
               case NBKPRO:
               case SMART:
               case SHARESMART:
               case MATRIX:
                  if (ups->UPS_Cap[CI_IDEN]) {
                          s_write("UPSNAME  : %s\n", ups->name);
                  } else {
                          s_write("UPSNAME  : N/A\n");
                  }

Thanks to Joe Acosta for reporting this bug and testing the fix. The patch relative to apcupsd-3.8.1 is:

    @@ -158,7 +158,7 @@
                          }
                  }
                   s_write("STATFLAG : 0x%02X Status Flag\n", ups->Status);
    -             break;
    +             /* Note! Fall through is wanted */
               case NBKPRO:
               case SMART:
               case SHARESMART:

## Automatic Self Test is Reported as Power failure

Depending on your EEPROM setting, the UPS will enter an automatic self test mode for approximately 30 seconds every two weeks (the default). The self test involves a switch to battery power, and apcupsd reports this as a power failure. We hope to correct this in a future version.

## Improper Shutdown of Apcupsd on WinNT Systems

If you attempt to shutdown apcpusd on a WinNT system either through the system tray icon or via the Services Manager, two of the three apcupsd processes may become stuck in the computer. One of this processes may consume all available CPU time. Even as the system administrator, you will be unable to kill these processes (that's Microsoft for you!). Normally, there should be no need to stop apcupsd. However, should you want to do so, for example, to make an upgrade, go to the Services dialog from the Control Panel, and deactivate apcupsd then reboot your computer.

## Name Resolution Does Not Work on Win32 Systems

In a master/slave configuration, normally one uses the master and slave machine names as a qualified domain name in apcupsd.conf. Unfortunately, on Win32 systems, apcupsd is unable to resolve these names to an IP address needed to communicate with the other end. To resolve the problem, please use an explicit IP address written as a dotted quadruple (e.g. 192.168.1.100) instead of the machine name.

## The apccontrol Script Doesn't Work with All User Scripts

apcupsd allows customization of the actions taken during events (e.g. onbattery, mainsback, etc). One method is to modify the /etc/apcupsd/apccontrol script directly. However, this makes it more difficult to upgrade to a new version of apcupsd. An alternate method is to place your own script in the /etc/apcupsd directory with the name of the event that you wish to control. For example, you may want to shutdown an Oracle database prior to issuing the system shutdown command. If the script you create is a shell script, everything is OK. However, if you use a perl script the script may not run. To correct this problem, change the following line in apccontrol:

          ${SCRIPTSHELL} ${SCRIPTDIR}/${1}

at line 38 of apccontrol (depending on your version), to:

          ${SCRIPTDIR}/${1}

For this to work, your script file must have the executable bit set.

## Denial of Service Security Problem

One of our users emailed us with the following information (with which, we agree):

> I noticed that its (apcupsd's) handling of temp files during e-mail notification was prone to denial-of-service attacks. I found this vulnerability within these scripts found in the /etc/apcupsd directory in the above RPM:

>             changeme
>             commfailure
>             commok
>             mainsback
>             onbattery

> Since the notification scripts blindly write to a $$-selected /tmp filename, any user on the box could cause root to overwrite any file on the system (/etc/passwd, /boot/vmlinuz) with the UPS error message by making lots and lots of /tmp/apcupsd.onbattery.##### symlinks which point to the victim file and waiting. (Yes, it's fairly unlikely, but a hole's a hole.)

> As work-arounds, I'd recommend either moving the temp file to within /etc/apcupsd (which is writable only by root or else the sysadmin has bigger problems than temp file creation) or piping from a subshell like this:

>             (
>                     echo "$MSG"
>                     echo " "
>                     /sbin/apcaccess status
>             ) | $MAIL -s "$MSG" $SYSADMIN

# Apcupsd version 3.8.0 Bugs

In addition to the bugs reported above, version 3.8.0 has the following problems. Please note that all of these bugs have been corrected in version 3.8.1.

## Win32 apcupsd Does Not Work with Simple Signaling UPSes

The Win32 version of apcupsd will not support simple signaling UPSes (sometimes called dumb UPSes) such as the Back-UPS. Please do not attempt to use it as if there is a power failure, it will most likely cause the UPS to suddenly shut off the power to your computer. This is due to the fact that CYGWIN does not support serial line signal level IOCTL calls. We hope to rectify this situation in the not so distant future (no promises because of the inadequacies of the Windows API in this area, which is probably why CYGWIN does not support the signal level IOCTLs).

## Bad Path to Shutdown in apccontrol Script

A Japanese user has reported that the call to /usr/bin/shutdown in the apccontrol script must be changed to /sbin/shutdown on his RedHat 6.2J system (/usr/bin/shutdown is valid on my English RedHat 5.2, 6.0, 6.1, and 7.0 systems). This kind of problem underscores the necessity to test the installation, as this user wisely did.

## CGI Programs May Error When Called Directly

If instead of calling the CGI program multimon.cgi, the user calls one of the helper programs directly, that program may detect bad arguments and error. This causes Apache to report an "Internal Error" to the user. This is a bit unpleasant for some users but it causes no harm. All the CGI programs have been reworked to provide less dramatic error messages, and they will be posted to this site as updates shortly.

## Alpha Tru64 32/64 Bit Bug

On Alpha machines, one instance of a 32/64 bit problem escaped our notice during the port. It apparently only affects the CGI programs, and causes apcupsd to be unable to resolve names. A fix to this problem will be posted.