5050 static OVERLAPPED connect_overlapped ;
5151 static char * pipename = NULL ;
5252#endif /* WIN32 */
53- static int stale = 1 , alarm_active = 0 , alarm_status = 0 , ignorelb = 0 ;
53+ static int stale = 1 , alarm_active = 0 , alarm_status = 0 , ignorelb = 0 ,
54+ alarm_legacy_status = 0 ;
5455 static char status_buf [ST_MAX_VALUE_LEN ], alarm_buf [ST_MAX_VALUE_LEN ],
5556 buzzmode_buf [ST_MAX_VALUE_LEN ];
5657 static conn_t * connhead = NULL ;
@@ -1772,6 +1773,7 @@ void status_init(void)
17721773
17731774 memset (status_buf , 0 , sizeof (status_buf ));
17741775 alarm_status = 0 ;
1776+ alarm_legacy_status = 0 ;
17751777}
17761778
17771779/* check if a status element has been set, return 0 if not, 1 if yes
@@ -1795,16 +1797,7 @@ static int status_set_callback(char *tgt, size_t tgtsize, const char *token)
17951797 }
17961798
17971799 if (!strcasecmp (token , "ALARM" )) {
1798- /* Drivers really should not raise alarms this way,
1799- * but for the sake of third-party forks, we handle
1800- * the possibility...
1801- */
1802- upsdebugx (2 , "%s: (almost) ignoring ALARM set as a status" , __func__ );
1803- if (!alarm_status && !alarm_active && strlen (alarm_buf ) == 0 ) {
1804- alarm_init (); /* no-op currently, but better be proper about it */
1805- alarm_set ("[N/A]" );
1806- }
1807- alarm_status ++ ;
1800+ alarm_legacy_status = 1 ;
18081801 return 0 ;
18091802 }
18101803
@@ -1848,36 +1841,11 @@ void status_commit(void)
18481841 break ;
18491842 }
18501843
1851- /* NOTE: Not sure if any clients rely on ALARM being first if raised,
1852- * but note that if someone also uses status_set("ALARM") we can end
1853- * up with a "[N/A]" alarm value injected (if no other alarm was set)
1854- * and only add the token here so it remains first.
1855- *
1856- * NOTE: alarm_commit() must be executed before status_commit() for
1857- * this report to work!
1858- * * If a driver only called status_set("ALARM") and did not bother
1859- * with alarm_commit(), the "ups.alarm" value queries would have
1860- * returned NULL if not for the "sloppy driver" fix below, although
1861- * the "ups.status" value would report an ALARM token.
1862- * * If a driver properly used alarm_init() and alarm_set(), but then
1863- * called status_commit() before alarm_commit(), the "ups.status"
1864- * value would not know to report an ALARM token, as before.
1865- * * If a driver used both status_set("ALARM") and alarm_set() later,
1866- * the injected "[N/A]" value of the alarm (if that's its complete
1867- * value) would be overwritten by the explicitly assigned contents,
1868- * and an explicit alarm_commit() would be required for proper
1869- * reporting from a non-sloppy driver.
1870- */
1871-
1872- if (!alarm_active && alarm_status && !strcmp (alarm_buf , "[N/A]" )) {
1873- upsdebugx (2 , "%s: Assume sloppy driver coding that ignored alarm methods and used status_set(\"ALARM\") instead: commit the injected N/A ups.alarm value" , __func__ );
1874- alarm_commit ();
1875- }
1876-
1877- if (alarm_active ) {
1844+ if (alarm_active || alarm_legacy_status ) {
18781845 dstate_setinfo ("ups.status" , "ALARM %s" , status_buf );
18791846 } else {
18801847 dstate_setinfo ("ups.status" , "%s" , status_buf );
1848+ alarm_legacy_status = 0 ; /* just to be sure */
18811849 }
18821850}
18831851
0 commit comments