APC UPS: Building apcupsd ver. 3.14.8 / need help

Hi all,

I recently bought 2 of those UPS devices from APC (model RS-550). I was impressed how APC supports Linux systems with source code for the daemon and a GUI control tool. Thumbs up for them. There is even a package in the openSUSE standard repo. However, it’s still ver. 3.14.6, so I thought I would build the latest release.

Basically all went well. I just had to adapt the patches to the new version. It builds for 11.1 and for 11.2 (which I use) and works perfect. Unfortunately it did not build for 11.3. I hope with some help from the community we can make it a package for all 11.3 users too.

This is the issue: The build for 11.3 fails during the configure step when looking for the shutdown command. The log says:

checking for gawk... gawk
checking for library containing strerror... none required
checking for shutdown... no
checking for shutdown.bsd... no
configure: error: Missing required tool; need any one of: shutdown shutdown.bsd
error: Bad exit status from /var/tmp/rpm-tmp.DDCThN (%build)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.DDCThN (%build)
SysRq : Power Off
Power down.

In case anyone wants to have a look at the project: https://build.opensuse.org/package/show?package=apcupsd&project=home%3Avodoo

I can’t find a reason why 11.3 fails here. configure.in specifies:

dnl Now check for programs
AC_REQ_PATH_PROGS(SHUTDOWN, shutdown shutdown.bsd)

and this leads to the following tests in configure (indentation edited to make it readable):

for ac_prog in shutdown shutdown.bsd
do
  # Extract the first word of "$ac_prog", so it can be a program name with args.
  set dummy $ac_prog; ac_word=$2
  echo "$as_me:$LINENO: checking for $ac_word" >&5
  echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
  if test "${ac_cv_path_SHUTDOWN+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
    case $SHUTDOWN in
      \\/]* | ?:\\/]*)
        ac_cv_path_SHUTDOWN="$SHUTDOWN" # Let the user override the test with a path.
        ;;
      *)
        as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
        for as_dir in $PATH
        do
          IFS=$as_save_IFS
          test -z "$as_dir" && as_dir=.
          for ac_exec_ext in '' $ac_executable_extensions; do
            if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
              ac_cv_path_SHUTDOWN="$as_dir/$ac_word$ac_exec_ext"
              echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
              break 2
            fi
          done
        done
        ;;
    esac
  fi
  SHUTDOWN=$ac_cv_path_SHUTDOWN
  if test -n "$SHUTDOWN"; then
    echo "$as_me:$LINENO: result: $SHUTDOWN" >&5
    echo "${ECHO_T}$SHUTDOWN" >&6
  else
    echo "$as_me:$LINENO: result: no" >&5
    echo "${ECHO_T}no" >&6
  fi

  test -n "$SHUTDOWN" && break
done

if test "$SHUTDOWN" = "" ; then
  { { echo "$as_me:$LINENO: error: Missing required tool; need any one of: shutdown shutdown.bsd" >&5
      echo "$as_me: error: Missing required tool; need any one of: shutdown shutdown.bsd" >&2;}
    { (exit 1); exit 1; }; }
fi

Any help is appreciated.

Hi
I wonder if it’s the change from sysvinit in 11.3? In the
build log for 11.2 you have sysvinit, but 11.3 has sysvinit-tools.


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.13-0.5-default
up 11:13, 2 users, load average: 0.02, 0.03, 0.00
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

Hi
Created request id 45852, added sysvinit to build requires, still fails
but looks like you have some patching to do… You could try
exporting the compiler flags to use an earlier version of gcc?


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.13-0.5-default
up 11:28, 3 users, load average: 0.46, 0.39, 0.15
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

Thank you for spotting this. Adding ‘sysvinit’ to BuildRequires: did the trick here.

And now for something completely different:

configure runs ok now but compiling fails:

In file included from drv_powernet.c:27:0:
snmp.h:82:10: error: expected unqualified-id before numeric constant
snmp.h:82:10: error: expected ';' before numeric constant
drv_powernet.c: In function 'int powernet_check_comm_lost(UPSINFO*)':
drv_powernet.c:37:50: error: expected unqualified-id before numeric constant
drv_powernet.c:37:50: error: expected ',' or ';' before numeric constant
drv_powernet.c: In function 'int powernet_snmp_ups_read_static_data(UPSINFO*)':
drv_powernet.c:164:50: error: expected unqualified-id before numeric constant
drv_powernet.c:164:50: error: expected ',' or ';' before numeric constant
drv_powernet.c: In function 'int powernet_snmp_ups_read_volatile_data(UPSINFO*)':
drv_powernet.c:303:50: error: expected unqualified-id before numeric constant
drv_powernet.c:303:50: error: expected ',' or ';' before numeric constant
make[4]: *** .obj/drv_powernet.o] Error 1
make[3]: *** [all] Error 2
make[2]: *** [snmp_DIR] Error 2
make[2]: *** Waiting for unfinished jobs....
  CXX   src/drivers/usb/usb.c
  CXX   src/lib/asys.c
  CXX   src/lib/newups.c
  CXX   src/lib/md5.c
make[1]: *** [drivers_DIR] Error 2
make[1]: *** Waiting for unfinished jobs....
  CXX   src/lib/statmgr.cpp
  CXX   src/lib/gethostname.c
  CXX   src/lib/amutex.cpp
  CXX   src/lib/astring.cpp
  CXX   src/lib/autil.cpp
  CXX   src/lib/atimer.cpp
  CXX   src/lib/athread.cpp
  AR    src/lib/libapc.a
  LD    src/gapcmon/gapcmon
make: *** [src_DIR] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.gxzfgb (%build)

It does not like snmp.h. Somehow the compiler in 11.3 is more strict that in 11.2. The relevant part of snmp.h reads like:

/*********************************************************************/
/* Internal structures                                               */
/*********************************************************************/

struct snmp_ups_internal_data {
   struct snmp_session session;        /* snmp session struct */
   char device[MAXSTRING];             /* Copy of ups->device */
   char *peername;                     /* hostname|IP of peer */
   unsigned short remote_port;         /* Remote socket, usually 161 */
   char *DeviceVendor;                 /* Vendor (ex. APC|RFC) */
   char *community;                    /* Community name */
   void *MIB;                          /* Pointer to MIB data */
   struct snmp_session *trap_session;  /* snmp session for traps */
   bool trap_received;                 /* Have we seen a trap? */
};

Line #82 is the one with void *MIB;. I guess another patch is required, but this is way above my C programming skills.

Last question @malcolmlewis: what am I supposed to do about the ‘open request’ appearing in my build home?

Hi
You could just have accepted and it would have updated your spec :wink: Just decline it…

Do you need snmp? If not, just disable in the configure?

You could just have accepted and it would have updated your spec

Amazing; I didn’t know that this feature even exists. Good for next time.

Do you need snmp? If not, just disable in the configure?

No, I do not need it. My case is a simple 1 computer to 1 UPS setup, connected via USB. And it is 11.2 which builds and works fine. But I thought that when I build, then I should build for others too, who might use 11.3. But I am very reluctant to publish a build with snmp disabled; people might jump on the newer version number and miss features they possibly need, instead of using apcupsd-3.14.6 which works. Even better to disable the 11.3 build when I can’t get it right. But I’m not giving up yet. My next task is to have a look at the compiler flags, as you suggested.

Hi
Yup :wink: just using osc from my machine here, it’s much quicker to build locally and iron ot the bugs before building on OBS. I just branched your package and built here. You should try it…?

You should try it…?

Eventually I will do so. But for now I am sitting in my branch office south of the Alps where I have a beautiful view on the lake but very limited hardware. I assume that I need a good 11.3 install to use osc for 11.3 builds.

Hi
No, by default it will build factory. My system doesn’t have VT so I just use a chroot environment. Either a reasonable download speed, or iso’s of the platform your wanting to build to cache the rpms is the only limitation. The only thing is if you have 32bit, you can only build 32bit. 64bit can build either. For example to build yours as 32bit it would be;


osc build openSUSE_11.3 i586

Hi
Should build now… I created request id 45875 have a look accept or decline :wink:

Wow, you guys are amazing (malcolmlewis & vodoo). I am impressed a lot. Should you need a volunteer to test your new compiled version, just let me know how to get it. I can try it out on a couple of APC units. But you got to be quick, as I will be off line for a few weeks in the near future.

Thank You,

Hi
I enabled publishing on my branch;
http://software.opensuse.org/search?q=apcupsd&baseproject=openSUSE%3A11.3&lang=en&exclude_debug=true

may take a little while to appear, but should be in
home:malcolmlewis:branches:home:vodoo


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.13-0.5-default
up 22:03, 2 users, load average: 0.10, 0.33, 0.46
GPU GeForce 8600 GTS Silent - Driver Version: 256.44

Yea, I am not see 3.14.8 there just yet, but I will check back for sure.

Thank You so much.

Try here then;
Index of /repositories/home:/malcolmlewis:/branches:/home:/vodoo/openSUSE_11.3

That did it and it works just fine. I checked the version and it says 3.14.8 as it should. To install the files I added the repository you gave me, but first I shutdown the gui and stopped the apc service. I then updated both apc files in Software Management using the versions tab, restarted the service and reloaded the gui. It seems to working like a champ. Is there anything specific I should look for or is just working fine good enough?

Thank You,

It seems to working like a champ. Is there anything specific I should look for or is just working fine good enough?

Not good enough at all. The crucial point is what happens when your system is going down after a long power outage. I strongly suggest to run the tests described in APCUPSD User Manual.

As far as I can see so far it will fail miserably due to a bug. This is what probably happens: the deamon will shut the system down according to the configuration in /etc/apcupsd/apcupsd.conf and will be killed itself like any other process. So far, so good.

In the script /etc/init.d/halt you should find a line close to the end:

test -n "$HALT_POWERDOWN_INSERT" && $HALT_POWERDOWN_INSERT

This is defined in /etc/sysconfig/shutdown and executes:

/etc/init.d/apcupsd try-powerdown

which in turn executes:

if test "$RUNLEVEL" = "0" -a -f /etc/apcupsd/powerfail ; then
            exec $0 powerdown
fi

where $0 expands to /etc/init.d/apcupsd. It calls itself again, but his time with the ‘powerdown’ argument. It does:

$APCUPSD_LITE --killpower >/dev/null 2>&1 || rc_failed

Look at the very beginning of /etc/init.d/apcupsd. You will see:

APCUPSD_LITE=/usr/sbin/apcupsd-lite

but apcupsd-lite is installed as /sbin/apcupsd-lite. The bug is the wrong path in the /etc/init.d/apcupsd init script. apcupsd-lite was correctly moved to /sbin in order to make it available even when /usr has already been umounted. But probably someone forgot to adapt the init script as well. This has possibly been broken for a long time (since sept. 2006). I will fix this in my build (on my todo list).

Why is all of this essential? It is not just good enough to bring the system down upon a power outage when batteries are weak. The UPS must be instructed to cut the power to the computer just before the kernel is brought down (sounds brutal) and go into hibernate mode (the UPS is hibernating, the PC is just dead and powerless). This gives you the possibility to set your BIOS to start the computer again when power is restored. As soon as there is power available the sleeping UPS will wake up and will power up the computer making it boot. This is a very good thing for unattended servers, where no one will push the start button after a poweroff.

@jdmcdaniel3: I have rebuilt the apcupsd package with the bugfix mentioned above. It is available here:

Index of /repositories/home:/vodoo

I got the new update and I will try to test this on the weekend. I am down to a few days before I will be offline, but I will give this a priority this weekend.

Thank You,