Package: apcupsd
Version: 3.14.14-3.1+b1
Severity: normal
Tags: patch upstream
X-Debbugs-Cc: li...@rainbow-software.org

Dear Maintainer,
there are old bugs in apcupsd preventing it from getting almost any data from 
SmartUPS v/s 650:
# apcaccess
APC      : 001,018,0451
DATE     : 2023-07-02 19:43:10 +0200
HOSTNAME : router
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : router
CABLE    : Custom Cable Smart
DRIVER   : APC Smart UPS (any)
UPSMODE  : Stand Alone
STARTTIME: 2023-07-02 19:35:08 +0200
STATUS   : ONLINE
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
STATFLAG : 0x05000008
END APC  : 2023-07-02 19:43:41 +0200

It used to work long ago. I already posted patches here but upstream does not 
care:
https://sourceforge.net/p/apcupsd/mailman/apcupsd-users/thread/202007312117.55508.li...@zary.sk/#msg37074883

Can they be applied to the Debian package?

After patches applied:
# apcaccess
APC      : 001,025,0603
DATE     : 2023-07-02 21:50:53 +0200
HOSTNAME : router
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : router
CABLE    : Custom Cable Smart
DRIVER   : APC Smart UPS (any)
UPSMODE  : Stand Alone
STARTTIME: 2023-07-02 21:50:47 +0200
MODEL    : Smart-UPS v/s 650
STATUS   : ONLINE
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : NO
STATFLAG : 0x05000008
REG1     : 0x00
REG2     : 0x00
REG3     : 0x00
FIRMWARE : 62.J.I
END APC  : 2023-07-02 21:51:21 +0200

-- System Information:
Debian Release: 12.0
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 6.1.0-9-686-pae (SMP w/1 CPU thread; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages apcupsd depends on:
ii  libc6                      2.36-9
ii  libgcc-s1                  12.2.0-14
ii  libusb-0.1-4               2:0.1.12-32
ii  libwrap0                   7.6.q-32
ii  lsb-base                   11.6
ii  sysvinit-utils [lsb-base]  3.06-4

Versions of packages apcupsd recommends:
pn  apcupsd-doc     <none>
pn  s-nail | mailx  <none>

Versions of packages apcupsd suggests:
pn  apcupsd-cgi  <none>
ii  udev         252.6-1

-- debconf-show failed
Description: fix get_capabilities and getline
fixes SmartUPS v/s support

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2023-07-02

--- apcupsd-3.14.14.orig/src/drivers/apcsmart/apcsmart.h
+++ apcupsd-3.14.14/src/drivers/apcsmart/apcsmart.h
@@ -46,7 +46,7 @@ public:
 
    // Public for apctest
    char *smart_poll(char cmd);
-   int getline(char *s, int len);
+   int getline(char *s, int len, bool no_action = false);
    void writechar(char a);
 
 private:
--- apcupsd-3.14.14.orig/src/drivers/apcsmart/smart.c
+++ apcupsd-3.14.14/src/drivers/apcsmart/smart.c
@@ -150,7 +150,7 @@ char *ApcSmartUpsDriver::smart_poll(char
 
    do {
       write(_ups->fd, &cmd, 1);
-      stat = getline(answer, sizeof answer);
+      stat = getline(answer, sizeof answer, cmd == APC_CMD_UPS_CAPS);
 
       /* If nothing returned, the link is probably down */
       if (*answer == 0 && stat == FAILURE) {
@@ -168,7 +168,7 @@ char *ApcSmartUpsDriver::smart_poll(char
  *
  * If s == NULL there is a much more fine-grained locking.
  */
-int ApcSmartUpsDriver::getline(char *s, int len)
+int ApcSmartUpsDriver::getline(char *s, int len, bool no_action)
 {
    int i = 0;
    int ending = 0;
@@ -231,7 +231,7 @@ int ApcSmartUpsDriver::getline(char *s,
          return FAILURE;
       }
 
-      switch (c) {
+      switch (no_action ? 0 : c) {
          /*
           * Here we can be called in two ways:
           * 
--- apcupsd-3.14.14.orig/src/drivers/apcsmart/smartsetup2.c
+++ apcupsd-3.14.14/src/drivers/apcsmart/smartsetup2.c
@@ -91,7 +91,7 @@ const char *ApcSmartUpsDriver::get_model
 bool ApcSmartUpsDriver::get_capabilities()
 {
    char answer[1000];              /* keep this big to handle big string */
-   char caps[1000], *cmds, *p;
+   char caps[1000], *cmds;
    int i;
 
    write_lock(_ups);
@@ -102,15 +102,15 @@ bool ApcSmartUpsDriver::get_capabilities
       _ups->UPS_Cap[CI_UPS_CAPS] = TRUE;
 
       /* skip version */
-      for (p = caps; *p && *p != '.'; p++)
-         ;
-
-      /* skip alert characters */
-      for (; *p && *p != '.'; p++)
-         ;
-
-      cmds = p;                    /* point to commands */
-      if (!*cmds) {                /* oops, none */
+      cmds = strchr(caps, '.');
+      if (cmds && cmds[0] != '\0') {
+         cmds++;
+         /* skip alert characters */
+         cmds = strchr(cmds, '.');
+         if (cmds && cmds[0] != '\0')
+            cmds++;
+      }
+      if (!cmds || strlen(cmds) < 5) {                /* no commands or very 
short list */
          cmds = NULL;
          _ups->UPS_Cap[CI_UPS_CAPS] = FALSE;
       }

Reply via email to