Blob Blame History Raw
From 28076181217313c7e33bf88cb70eb16c2f8e737f Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Thu, 19 Jul 2018 12:38:08 -0500
Subject: [PATCH 1/4] Low: tools: enable file consolidation in crm_report

Correct a variable misspelling that resulted in file de-duplication being
skipped. Also, remove an unused variable, and avoid the unreliable "-a".
Found by static analysis.
---
 tools/crm_report.in | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/crm_report.in b/tools/crm_report.in
index 43ed646..695c1f1 100755
--- a/tools/crm_report.in
+++ b/tools/crm_report.in
@@ -27,7 +27,6 @@ eval set -- "$TEMP"
 
 progname=$(basename "$0")
 rsh="ssh -T"
-times=""
 tests=""
 nodes=""
 compress=1
@@ -243,10 +242,18 @@ EOF
 # check if files have same content in the cluster
 #
 cibdiff() {
-    d1=`dirname $1`
-    d2=`dirname $2`
-    if [ -f $d1/RUNNING -a -f $d2/RUNNING ] ||
-	[ -f $d1/STOPPED -a -f $d2/STOPPED ]; then
+    d1=$(dirname $1)
+    d2=$(dirname $2)
+
+    if [ -f "$d1/RUNNING" ] && [ ! -f "$d2/RUNNING" ]; then
+        DIFF_OK=0
+    elif [ -f "$d1/STOPPED" ] && [ ! -f "$d2/STOPPED" ]; then
+        DIFF_OK=0
+    else
+        DIFF_OK=1
+    fi
+
+    if [ $DIFF_OK -eq 1 ]; then
 	if which crm_diff > /dev/null 2>&1; then
 	    crm_diff -c -n $1 -o $2
 	else
@@ -277,7 +284,7 @@ esac
 # remove duplicates if files are same, make links instead
 #
 consolidate() {
-    for n in $NODES; do
+    for n in $nodes; do
 	if [ -f $1/$2 ]; then
 	    rm $1/$n/$2
 	else
@@ -290,7 +297,7 @@ consolidate() {
 analyze_one() {
     rc=0
     node0=""
-    for n in $NODES; do
+    for n in $nodes; do
 	if [ "$node0" ]; then
 	    diffcheck $1/$node0/$2 $1/$n/$2
 	    rc=$(($rc+$?))
-- 
1.8.3.1


From 2db3895359beb0f577c142c03ac2c8e6f44c67cf Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 4 Apr 2018 15:47:18 -0500
Subject: [PATCH 2/4] Low: tools: get sensor lun in ipmiservicelogd before
 using it

---
 tools/ipmiservicelogd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/ipmiservicelogd.c b/tools/ipmiservicelogd.c
index 47ff220..1047c9c 100644
--- a/tools/ipmiservicelogd.c
+++ b/tools/ipmiservicelogd.c
@@ -434,14 +434,14 @@ sensor_discrete_event_handler(ipmi_sensor_t * sensor,
     instance = ipmi_entity_get_entity_instance(ent);
     ipmi_sensor_get_id(sensor, name, sizeof(name));
 
+    ipmi_sensor_get_num(sensor, &sensor_lun, &sensor_number);
+
     sel_id = ipmi_entity_get_entity_id(ent);
     sel_type = ipmi_entity_get_type(ent);
     generator = ipmi_entity_get_slave_address(ent) | (sensor_lun << 5); /* LUN (2 bits) | SLAVE ADDRESS (5 bits) */
     version = 0x04;
     sensor_type = ipmi_sensor_get_sensor_type(sensor);
 
-    ipmi_sensor_get_num(sensor, &sensor_lun, &sensor_number);
-
     event_class = 0;            /* @TBD - where does this come from? */
     event_type = ipmi_event_get_type(event);
     direction = dir;
-- 
1.8.3.1


From 7a79e4ef8315842d4d1078475dab287d8f3327de Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 25 Jul 2018 15:15:38 -0500
Subject: [PATCH 3/4] Low: tools: notifyServicelogEvent FTBFS on ppc64le

---
 tools/notifyServicelogEvent.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/tools/notifyServicelogEvent.c b/tools/notifyServicelogEvent.c
index b7f672c..700f068 100644
--- a/tools/notifyServicelogEvent.c
+++ b/tools/notifyServicelogEvent.c
@@ -1,24 +1,15 @@
 /*
- * Copyright (C) 2009 International Business Machines, IBM, Mark Hamzy
+ * Copyright 2009-2018 International Business Machines, IBM, Mark Hamzy
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
  */
 
 /* gcc -o notifyServicelogEvent `pkg-config --cflags servicelog-1` `pkg-config --libs servicelog-1` notifyServicelogEvent.c
 */
 
+#include <crm_internal.h>
+
 #include <string.h>
 #include <stdio.h>
 #include <time.h>
@@ -27,9 +18,10 @@
 #include <syslog.h>
 #include <unistd.h>
 #include <config.h>
+
 #include <crm/common/xml.h>
 #include <crm/common/util.h>
-#include <crm_internal.h>
+#include <crm/attrd.h>
 
 typedef enum { STATUS_GREEN = 1, STATUS_YELLOW, STATUS_RED } STATUS;
 
@@ -91,7 +83,7 @@ main(int argc, char *argv[])
     struct sl_event *event = NULL;
     uint64_t event_id = 0;
 
-    crm_log_init_quiet("notifyServicelogEvent", LOG_INFO, FALSE, TRUE, argc, argv);
+    crm_log_cli_init("notifyServicelogEvent");
     crm_set_options(NULL, "event_id ", long_options,
                     "Gets called upon events written to servicelog database");
 
-- 
1.8.3.1


From b408a3ead462c8f02b68a164f24ba1b05bb3cad1 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 25 Jul 2018 16:07:42 -0500
Subject: [PATCH 4/4] Low: tools: ipmiservicelogd FTBFS on ppc64le

---
 tools/ipmiservicelogd.c | 53 +++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/tools/ipmiservicelogd.c b/tools/ipmiservicelogd.c
index 1047c9c..4f52865 100644
--- a/tools/ipmiservicelogd.c
+++ b/tools/ipmiservicelogd.c
@@ -9,13 +9,10 @@
  * Author: Intel Corporation
  *         Jeff Zheng <Jeff.Zheng@Intel.com>
  *
- * Copyright 2009 International Business Machines, IBM
- *
- *  This program is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public License
- *  as published by the Free Software Foundation; either version 2 of
- *  the License, or (at your option) any later version.
+ * Copyright 2009-2018 International Business Machines, IBM
  *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
  *
  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -27,10 +24,6 @@
  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this program; if not, write to the Free
- *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 /* gcc -o ipmiservicelogd -g `pkg-config --cflags --libs OpenIPMI OpenIPMIposix servicelog-1` ipmiservicelogd.c
@@ -38,6 +31,12 @@
 /* ./ipmiservicelogd smi 0
  */
 
+#include <crm_internal.h>
+
+#ifndef _GNU_SOURCE
+#  define _GNU_SOURCE
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -68,7 +67,7 @@
 
 static os_handler_t *os_hnd;
 
-char *getStringExecOutput(char *args[]);
+char *getStringExecOutput(const char *const args[]);
 char *getSerialNumber(void);
 char *getProductName(void);
 static void con_usage(const char *name, const char *help, void *cb_data);
@@ -91,7 +90,7 @@ void setup_done(ipmi_domain_t * domain, int err, unsigned int conn_num, unsigned
                 int still_connected, void *user_data);
 
 char *
-getStringExecOutput(char *args[])
+getStringExecOutput(const char *const args[])
 {
     int rc;
     pid_t pid;
@@ -201,7 +200,11 @@ getStringExecOutput(char *args[])
             crm_err("Error: child close (pipefd[1]) = %d", errno);
         }
 
-        rc = execvp(args[0], args);
+        /* execvp() takes (char *const *) for backward compatibility,
+         * but POSIX guarantees that it will not modify the strings,
+         * so the cast is safe
+         */
+        rc = execvp(args[0], (char *const *) args);
 
         if (rc == -1) {
             crm_err("Error: child execvp = %d", errno);
@@ -224,7 +227,7 @@ getStringExecOutput(char *args[])
 char *
 getSerialNumber(void)
 {
-    char *dmiArgs[] = {
+    const char *const dmiArgs[] = {
         "dmidecode",
         "--string",
         "system-serial-number",
@@ -237,7 +240,7 @@ getSerialNumber(void)
 char *
 getProductName(void)
 {
-    char *dmiArgs[] = {
+    const char *dmiArgs[] = {
         "dmidecode",
         "--string",
         "system-product-name",
@@ -313,8 +316,8 @@ ipmi2servicelog(struct sl_data_bmc *bmc_data)
     sl_event.machine_serial   = serial_number;
     sl_event.machine_model    = product_name;         /* it may not have the serial # within the first 20 chars */
     sl_event.nodename         = name.nodename;
-    sl_event.refcode          = "ipmi";
-    sl_event.description      = "ipmi event";
+    sl_event.refcode          = strdup("ipmi");
+    sl_event.description      = strdup("ipmi event");
     sl_event.serviceable      = 1;                    /* 1 or 0 */
     sl_event.predictive       = 0;                    /* 1 or 0 */
     sl_event.disposition      = SL_DISP_RECOVERABLE;  /* one of SL_DISP_* */
@@ -336,6 +339,8 @@ ipmi2servicelog(struct sl_data_bmc *bmc_data)
         crm_debug("Sending to servicelog database");
     }
 
+    free(sl_event.refcode);
+    free(sl_event.description);
     free(serial_number);
     free(product_name);
 
@@ -352,7 +357,6 @@ sensor_threshold_event_handler(ipmi_sensor_t * sensor,
                                double value, void *cb_data, ipmi_event_t * event)
 {
     ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor);
-    int id, instance;
     char name[IPMI_ENTITY_NAME_LEN];
     struct sl_data_bmc bmc_data;
     uint32_t sel_id;
@@ -366,8 +370,6 @@ sensor_threshold_event_handler(ipmi_sensor_t * sensor,
     uint8_t event_type;
     int direction;
 
-    id = ipmi_entity_get_entity_id(ent);
-    instance = ipmi_entity_get_entity_instance(ent);
     ipmi_sensor_get_id(sensor, name, sizeof(name));
 
     ipmi_sensor_get_num(sensor, &sensor_lun, &sensor_number);
@@ -416,7 +418,6 @@ sensor_discrete_event_handler(ipmi_sensor_t * sensor,
                               int severity, int prev_severity, void *cb_data, ipmi_event_t * event)
 {
     ipmi_entity_t *ent = ipmi_sensor_get_entity(sensor);
-    int id, instance;
     char name[IPMI_ENTITY_NAME_LEN];
     struct sl_data_bmc bmc_data;
     uint32_t sel_id;
@@ -430,8 +431,6 @@ sensor_discrete_event_handler(ipmi_sensor_t * sensor,
     uint8_t event_type;
     int direction;
 
-    id = ipmi_entity_get_entity_id(ent);
-    instance = ipmi_entity_get_entity_instance(ent);
     ipmi_sensor_get_id(sensor, name, sizeof(name));
 
     ipmi_sensor_get_num(sensor, &sensor_lun, &sensor_number);
@@ -501,10 +500,7 @@ static void
 entity_change(enum ipmi_update_e op, ipmi_domain_t * domain, ipmi_entity_t * entity, void *cb_data)
 {
     int rv;
-    int id, instance;
 
-    id = ipmi_entity_get_entity_id(entity);
-    instance = ipmi_entity_get_entity_instance(entity);
     if (op == IPMI_ADDED) {
         /* Register callback so that when the status of a
            sensor changes, sensor_change is called */
@@ -564,8 +560,9 @@ main(int argc, char *argv[])
 #endif
 
     crm_make_daemon("ipmiservicelogd", TRUE, "/var/run/ipmiservicelogd.pid0");
-
-    crm_log_init("ipmiservicelogd", LOG_INFO, FALSE, TRUE, argc, argv);
+    crm_log_cli_init("ipmiservicelogd");
+    // Maybe this should log like a daemon instead?
+    // crm_log_init("ipmiservicelogd", LOG_INFO, TRUE, FALSE, argc, argv, FALSE);
 
 #ifdef COMPLEX
     rv = ipmi_args_setup_con(args, os_hnd, NULL, &con);
-- 
1.8.3.1