From b62bb16dfc9ebedf221ff2e44c2d05c42691096c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:36:08 +0100 Subject: [PATCH 01/48] common/parseconf.c: annotate pconf_fatal() with noreturn attr --- common/parseconf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/parseconf.c b/common/parseconf.c index 5729335d44..fe8f172b96 100644 --- a/common/parseconf.c +++ b/common/parseconf.c @@ -76,6 +76,8 @@ * */ +#include "common.h" + #include #include #include @@ -86,6 +88,7 @@ #include #include "parseconf.h" +#include "attribute.h" /* possible states */ @@ -98,6 +101,9 @@ #define STATE_ENDOFLINE 7 #define STATE_PARSEERR 8 +static void pconf_fatal(PCONF_CTX_t *ctx, const char *errtxt) + __attribute__((noreturn)); + static void pconf_fatal(PCONF_CTX_t *ctx, const char *errtxt) { if (ctx->errhandler) From 82a0bd7059687ed25f63c1334f2ff97755cc7ca8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:38:00 +0100 Subject: [PATCH 02/48] drivers/main.c: annotate forceshutdown() with noreturn attr --- drivers/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/main.c b/drivers/main.c index a01250c764..e1ea9b0958 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -20,8 +20,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "common.h" #include "main.h" #include "dstate.h" +#include "attribute.h" /* data which may be useful to the drivers */ int upsfd = -1; @@ -77,6 +79,9 @@ void upsdrv_banner (void) } /* power down the attached load immediately */ +static void forceshutdown(void) + __attribute__((noreturn)); + static void forceshutdown(void) { upslogx(LOG_NOTICE, "Initiating UPS shutdown"); From dfd4e5a5a62c12968f10f1e9a9ed82c8f07af4c8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:42:42 +0100 Subject: [PATCH 03/48] drivers/dstate.c: annotate sock_fail() with noreturn attr --- drivers/dstate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/dstate.c b/drivers/dstate.c index b2c7b893df..348890d668 100644 --- a/drivers/dstate.c +++ b/drivers/dstate.c @@ -32,6 +32,7 @@ #include "dstate.h" #include "state.h" #include "parseconf.h" +#include "attribute.h" static int sockfd = -1, stale = 1, alarm_active = 0, ignorelb = 0; static char *sockfn = NULL; @@ -43,6 +44,9 @@ struct ups_handler upsh; /* this may be a frequent stumbling point for new users, so be verbose here */ +static void sock_fail(const char *fn) + __attribute__((noreturn)); + static void sock_fail(const char *fn) { int sockerr; From 51793a8510f865ae619631d62290b41cd7e48ced Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:43:43 +0100 Subject: [PATCH 04/48] drivers/serial.c: annotate ser_open_error() with noreturn attr --- drivers/serial.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/serial.c b/drivers/serial.c index 7725eea1d1..c2dd23fb77 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -21,6 +21,7 @@ #include "timehead.h" #include "serial.h" #include "main.h" +#include "attribute.h" #include #include @@ -36,6 +37,9 @@ static unsigned int comm_failures = 0; +static void ser_open_error(const char *port) + __attribute__((noreturn)); + static void ser_open_error(const char *port) { struct stat fs; From f2cf2922e9f1ed4d0b5d885294fb4c9f81041a9c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:44:50 +0100 Subject: [PATCH 05/48] drivers/liebert.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/liebert.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/liebert.c b/drivers/liebert.c index 3e8a025ce9..4df8b74a65 100644 --- a/drivers/liebert.c +++ b/drivers/liebert.c @@ -21,8 +21,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" #include "main.h" #include "serial.h" +#include "attribute.h" #define DRIVER_NAME "Liebert MultiLink UPS driver" #define DRIVER_VERSION "1.02" @@ -39,6 +41,9 @@ upsdrv_info_t upsdrv_info = { #define ML_ONBATTERY 0x55 +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { /* XXX: replace with a proper shutdown function (raise DTR) */ From 626fd101cab3ac4c62602a24260941dd99333a74 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:45:50 +0100 Subject: [PATCH 06/48] drivers/skel.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/skel.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/skel.c b/drivers/skel.c index dc778ff28d..f3e0dba44d 100644 --- a/drivers/skel.c +++ b/drivers/skel.c @@ -12,7 +12,9 @@ * or docs/snmp-subdrivers.txt for SNMP devices */ +#include "config.h" #include "main.h" +#include "attribute.h" /* #include "serial.h" */ @@ -92,6 +94,9 @@ void upsdrv_updateinfo(void) */ } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ From 5189f3e255396f4102dd500e3f844e2ecd9e1dd1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:46:28 +0100 Subject: [PATCH 07/48] drivers/clone.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/clone.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/clone.c b/drivers/clone.c index b9aec2478f..052184ecee 100644 --- a/drivers/clone.c +++ b/drivers/clone.c @@ -18,8 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" #include "main.h" #include "parseconf.h" +#include "attribute.h" #include #include @@ -520,6 +522,9 @@ void upsdrv_updateinfo(void) } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { fatalx(EXIT_FAILURE, "shutdown not supported"); From 8ceb6f3875728c6e2ff85f1ac872fd0f96b0e886 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:47:03 +0100 Subject: [PATCH 08/48] drivers/ivtscd.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/ivtscd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/ivtscd.c b/drivers/ivtscd.c index b69864857a..fb483d0bbc 100644 --- a/drivers/ivtscd.c +++ b/drivers/ivtscd.c @@ -18,8 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" #include "main.h" #include "serial.h" +#include "attribute.h" #define DRIVER_NAME "IVT Solar Controller driver" #define DRIVER_VERSION "0.02" @@ -177,6 +179,9 @@ void upsdrv_updateinfo(void) dstate_dataok(); } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { while (1) { From 810188152633bd5ee524f052b66c993b968c6d61 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:47:47 +0100 Subject: [PATCH 09/48] drivers/apcupsd-ups.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/apcupsd-ups.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/apcupsd-ups.c b/drivers/apcupsd-ups.c index d1b2d3369a..32e2013a92 100644 --- a/drivers/apcupsd-ups.c +++ b/drivers/apcupsd-ups.c @@ -16,6 +16,8 @@ */ +#include "config.h" + #include #include #include @@ -24,6 +26,7 @@ #include "main.h" #include "apcupsd-ups.h" +#include "attribute.h" #define DRIVER_NAME "apcupsd network client UPS driver" #define DRIVER_VERSION "0.5" @@ -257,6 +260,9 @@ void upsdrv_updateinfo(void) poll_interval = (poll_interval > POLL_INTERVAL_MIN) ? POLL_INTERVAL_MIN : poll_interval; } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { fatalx(EXIT_FAILURE, "shutdown not supported"); From dfe756b9db24617b9cf06a73deb643f9c9b87cf0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:48:35 +0100 Subject: [PATCH 10/48] drivers/nutdrv_qx.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/nutdrv_qx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nutdrv_qx.c b/drivers/nutdrv_qx.c index 9771e9f29f..55ed3c1e5e 100644 --- a/drivers/nutdrv_qx.c +++ b/drivers/nutdrv_qx.c @@ -35,7 +35,9 @@ #define DRIVER_VERSION "0.28" +#include "config.h" #include "main.h" +#include "attribute.h" #include @@ -1538,6 +1540,9 @@ int setvar(const char *varname, const char *val) } /* Try to shutdown the UPS */ +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { int retry; From 836b8b738c4a6c5ffc31d5ba1eedf7816a58d73b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:49:09 +0100 Subject: [PATCH 11/48] drivers/macosx-ups.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/macosx-ups.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/macosx-ups.c b/drivers/macosx-ups.c index 4873855ad8..5057caef86 100644 --- a/drivers/macosx-ups.c +++ b/drivers/macosx-ups.c @@ -18,7 +18,9 @@ * */ +#include "config.h" #include "main.h" +#include "attribute.h" #include @@ -257,6 +259,9 @@ void upsdrv_updateinfo(void) CFRelease(power_dictionary); } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ From 89cccde5c04296a05ce59f6e71f4d66a9b970afc Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 12:49:51 +0100 Subject: [PATCH 12/48] drivers/upsdrvctl.c: annotate help() with noreturn attr --- drivers/upsdrvctl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/upsdrvctl.c b/drivers/upsdrvctl.c index 1f92f1f00f..f96652a0b1 100644 --- a/drivers/upsdrvctl.c +++ b/drivers/upsdrvctl.c @@ -28,6 +28,7 @@ #include "proto.h" #include "common.h" #include "upsconf.h" +#include "attribute.h" typedef struct { char *upsname; @@ -330,6 +331,9 @@ static void start_driver(const ups_t *ups) } } +static void help(const char *progname) + __attribute__((noreturn)); + static void help(const char *progname) { printf("Starts and stops UPS drivers via ups.conf.\n\n"); From 7d22fa84c1545feafc77b8f665752f4e6f2c36f6 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:30:41 +0100 Subject: [PATCH 13/48] clients/upslog.c: annotate help() with noreturn attr --- clients/upslog.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clients/upslog.c b/clients/upslog.c index d57b906855..653cf7a0e6 100644 --- a/clients/upslog.c +++ b/clients/upslog.c @@ -110,6 +110,9 @@ static void setup_signals(void) fatal_with_errno(EXIT_FAILURE, "Can't install SIGUSR1 handler"); } +static void help(const char *prog) + __attribute__((noreturn)); + static void help(const char *prog) { printf("UPS status logger.\n"); From 9e7c274d8cad2602886bb6d45b95add18321e0bf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:34:21 +0100 Subject: [PATCH 14/48] clients/upsimage.c: annotate drawimage() with noreturn attr --- clients/upsimage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clients/upsimage.c b/clients/upsimage.c index e9b92d38be..30c6ecc073 100644 --- a/clients/upsimage.c +++ b/clients/upsimage.c @@ -111,6 +111,9 @@ static int get_imgarg(const char *name) } /* write the HTML header then have gd dump the image */ +static void drawimage(gdImagePtr im) + __attribute__((noreturn)); + static void drawimage(gdImagePtr im) { printf("Pragma: no-cache\n"); From f82d66164e1fd0a7b3f76526b038ca9498cc9782 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:37:15 +0100 Subject: [PATCH 15/48] clients/upsset.c: annotate several routines with noreturn attrs --- clients/upsset.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clients/upsset.c b/clients/upsset.c index ba199a3010..a239426ed4 100644 --- a/clients/upsset.c +++ b/clients/upsset.c @@ -253,6 +253,10 @@ static void do_pickups(const char *currfunc) printf("\n"); } +static void error_page(const char *next, const char *title, + const char *fmt, ...) + __attribute__((noreturn)); + static void error_page(const char *next, const char *title, const char *fmt, ...) { @@ -282,6 +286,9 @@ static void error_page(const char *next, const char *title, exit(EXIT_SUCCESS); } +static void loginscreen(void) + __attribute__((noreturn)); + static void loginscreen(void) { do_header("Login"); @@ -506,6 +513,9 @@ static void send_auth(const char *next) "Password set failed: %s", upscli_strerror(&ups)); } +static void docmd(void) + __attribute__((noreturn)); + static void docmd(void) { char buf[SMALLBUF], *desc; @@ -768,6 +778,9 @@ static void print_rw(const char *upsname, const char *varname) printf("\n"); } +static void showsettings(void) + __attribute__((noreturn)); + static void showsettings(void) { int ret; @@ -910,6 +923,9 @@ static int setvar(const char *var, const char *val) } /* turn a form submission of settings into SET commands for upsd */ +static void savesettings(void) + __attribute__((noreturn)); + static void savesettings(void) { int changed = 0; @@ -956,6 +972,9 @@ static void savesettings(void) exit(EXIT_SUCCESS); } +static void initial_pickups(void) + __attribute__((noreturn)); + static void initial_pickups(void) { do_header("Select a UPS"); From 53af05e1274b00e2d3c92bf86c00f8e28e23c8f5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:40:25 +0100 Subject: [PATCH 16/48] clients/upsmon.c: help(): do not shadow global varname "progname" with same-named func argument --- clients/upsmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/upsmon.c b/clients/upsmon.c index f3d0157944..b05b440d63 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -1671,11 +1671,11 @@ static int check_pdflag(void) return EXIT_SUCCESS; } -static void help(const char *progname) +static void help(const char *arg_progname) { printf("Monitors UPS servers and may initiate shutdown if necessary.\n\n"); - printf("usage: %s [OPTIONS]\n\n", progname); + printf("usage: %s [OPTIONS]\n\n", arg_progname); printf(" -c send command to running process\n"); printf(" commands:\n"); printf(" - fsd: shutdown all master UPSes (use with caution)\n"); From aa9563065ce0240c5bd842830e4300960025b4d8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:41:22 +0100 Subject: [PATCH 17/48] clients/upsmon.c: annotate several routines with noreturn attrs --- clients/upsmon.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clients/upsmon.c b/clients/upsmon.c index b05b440d63..703595ef14 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -418,6 +418,9 @@ static void set_pdflag(void) } /* the actual shutdown procedure */ +static void doshutdown(void) + __attribute__((noreturn)); + static void doshutdown(void) { int ret; @@ -1671,6 +1674,9 @@ static int check_pdflag(void) return EXIT_SUCCESS; } +static void help(const char *arg_progname) + __attribute__((noreturn)); + static void help(const char *arg_progname) { printf("Monitors UPS servers and may initiate shutdown if necessary.\n\n"); @@ -1692,6 +1698,9 @@ static void help(const char *arg_progname) exit(EXIT_SUCCESS); } +static void runparent(int fd) + __attribute__((noreturn)); + static void runparent(int fd) { int ret; From 9318c372dbe46c1778aaa2811b8bba8a9411bd9d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:42:28 +0100 Subject: [PATCH 18/48] drivers/dummy-ups.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/dummy-ups.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/dummy-ups.c b/drivers/dummy-ups.c index 7668a1de32..4fba88ee71 100644 --- a/drivers/dummy-ups.c +++ b/drivers/dummy-ups.c @@ -188,6 +188,9 @@ void upsdrv_updateinfo(void) } } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { fatalx(EXIT_FAILURE, "shutdown not supported"); From 7768913c748c97817d2ec036e6d39be43402f778 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:43:15 +0100 Subject: [PATCH 19/48] drivers/blazer.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/blazer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/blazer.c b/drivers/blazer.c index fef9e1e4ed..c9592cc3fc 100644 --- a/drivers/blazer.c +++ b/drivers/blazer.c @@ -808,6 +808,8 @@ void upsdrv_updateinfo(void) dstate_dataok(); } +void upsdrv_shutdown(void) + __attribute__((noreturn)); void upsdrv_shutdown(void) { From 9bcad3f744e87910cddd65140efe7fb06a2dcc21 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:43:47 +0100 Subject: [PATCH 20/48] drivers/riello_ser.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/riello_ser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/riello_ser.c b/drivers/riello_ser.c index 0392259262..3b54fe2158 100644 --- a/drivers/riello_ser.c +++ b/drivers/riello_ser.c @@ -904,6 +904,9 @@ void upsdrv_updateinfo(void) */ } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ From 1f7a63e0de6758e638b63b2af94b7e3ac7bf5412 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:45:51 +0100 Subject: [PATCH 21/48] drivers/bcmxcp_usb.c: fix indenting whitespace --- drivers/bcmxcp_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 242feaa22c..0e5274c356 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -195,7 +195,7 @@ int get_answer(unsigned char *data, unsigned char command) } if (need_data > 0) /* We need more data */ - continue; + continue; /* Now validate XCP frame */ /* Check header */ @@ -204,7 +204,7 @@ int get_answer(unsigned char *data, unsigned char command) /* Sometime we read something wrong. bad cables? bad ports? */ my_buf = memchr(my_buf, PW_COMMAND_START_BYTE, bytes_read); if (!my_buf) - return -1; + return -1; } /* Read block number byte */ @@ -263,9 +263,9 @@ int get_answer(unsigned char *data, unsigned char command) end_length += length; tail = bytes_read - (length + PW_HEADER_SIZE); if (tail > 0) - my_buf = memmove(&buf[0], my_buf + length + PW_HEADER_SIZE, tail); + my_buf = memmove(&buf[0], my_buf + length + PW_HEADER_SIZE, tail); else if (tail == 0) - my_buf = &buf[0]; + my_buf = &buf[0]; bytes_read = tail; } @@ -432,7 +432,7 @@ usb_dev_handle *nutusb_open(const char *port) { upsdebugx(1, "Can't reset POWERWARE USB endpoint: %s", usb_strerror()); if (dev_claimed) - usb_release_interface(dev_h, 0); + usb_release_interface(dev_h, 0); usb_reset(dev_h); sleep(5); /* Wait reconnect */ errout = 1; From ba1fd29564735c7efec66b3974287bcbf0b81d82 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:46:21 +0100 Subject: [PATCH 22/48] drivers/bcmxcp_usb.c: annotate nutusb_open_error() with noreturn attr --- drivers/bcmxcp_usb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 0e5274c356..46af55f4b6 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -345,6 +345,9 @@ void upsdrv_reconnect(void) } /* USB functions */ +static void nutusb_open_error(const char *port) + __attribute__((noreturn)); + static void nutusb_open_error(const char *port) { printf("Unable to find POWERWARE UPS device on USB bus (%s)\n\n", port); From 0ff3265c5546cbeab0e2c56a328dba9eca3e995d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:48:28 +0100 Subject: [PATCH 23/48] drivers/nut-ipmipsu.c: annotate upsdrv_shutdown() with noreturn attr --- drivers/nut-ipmipsu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/nut-ipmipsu.c b/drivers/nut-ipmipsu.c index 4878c5a308..4eeefc3d1f 100644 --- a/drivers/nut-ipmipsu.c +++ b/drivers/nut-ipmipsu.c @@ -136,6 +136,9 @@ void upsdrv_updateinfo(void) */ } +void upsdrv_shutdown(void) + __attribute__((noreturn)); + void upsdrv_shutdown(void) { fatalx(EXIT_FAILURE, "shutdown not supported"); From 618fa4c8c0ecc5e73fc491f9a8c6957a655d1c75 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 17 Nov 2020 22:46:09 +0100 Subject: [PATCH 24/48] server/upsd.c: help(): do not shadow global varnames "progname" (from upsd.c and main.c) with func argument "progname" --- server/upsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/upsd.c b/server/upsd.c index a9343f5f8c..dc81c821a8 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -1074,10 +1074,10 @@ static void mainloop(void) } } -static void help(const char *progname) +static void help(const char *arg_progname) { printf("Network server for UPS data.\n\n"); - printf("usage: %s [OPTIONS]\n", progname); + printf("usage: %s [OPTIONS]\n", arg_progname); printf("\n"); printf(" -c send via signal to background process\n"); From f2aa96ca0e38d48dc35d53d60ed904929bee2233 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 16:51:59 +0100 Subject: [PATCH 25/48] server/upsd.c: annotate help() with noreturn attr --- server/upsd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/upsd.c b/server/upsd.c index dc81c821a8..14739e05ad 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -1074,6 +1074,9 @@ static void mainloop(void) } } +static void help(const char *arg_progname) + __attribute__((noreturn)); + static void help(const char *arg_progname) { printf("Network server for UPS data.\n\n"); From 2b9880faf54866c309f832334fa050fbb383b58b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 17:13:36 +0100 Subject: [PATCH 26/48] configure.ac: introduce AX_C___ATTRIBUTE__ from gnu.org --- configure.ac | 1 + m4/ax_c___attribute__.m4 | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 m4/ax_c___attribute__.m4 diff --git a/configure.ac b/configure.ac index 19595e3ea3..b3d6845e62 100644 --- a/configure.ac +++ b/configure.ac @@ -138,6 +138,7 @@ AC_C_BIGENDIAN AC_C_INLINE AC_C_FLEXIBLE_ARRAY_MEMBER AC_C_VARARRAYS +AX_C___ATTRIBUTE__ AC_CHECK_FUNCS(flock lockf fcvt fcvtl pow10 round abs_val abs) AC_CHECK_FUNCS(fabs, [], [], [#include ]) AC_CHECK_FUNCS(cfsetispeed tcsendbreak) diff --git a/m4/ax_c___attribute__.m4 b/m4/ax_c___attribute__.m4 new file mode 100644 index 0000000000..487323397a --- /dev/null +++ b/m4/ax_c___attribute__.m4 @@ -0,0 +1,70 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_c___attribute__.html +# +# Downloaded into NUT codebase from +# http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_c___attribute__.m4 +# as of 2020-11-20 +# =========================================================================== +# +# SYNOPSIS +# +# AX_C___ATTRIBUTE__ +# +# DESCRIPTION +# +# Provides a test for the compiler support of __attribute__ extensions. +# Defines HAVE___ATTRIBUTE__ if it is found. +# +# LICENSE +# +# Copyright (c) 2008 Stepan Kasal +# Copyright (c) 2008 Christian Haggstrom +# Copyright (c) 2008 Ryan McCabe +# +# 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 program 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 program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 9 + +AC_DEFUN([AX_C___ATTRIBUTE__], [ + AC_CACHE_CHECK([for __attribute__], [ax_cv___attribute__], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + static void foo(void) __attribute__ ((unused)); + static void + foo(void) { + exit(1); + } + ]], [])], + [ax_cv___attribute__=yes], + [ax_cv___attribute__=no] + ) + ]) + if test "$ax_cv___attribute__" = "yes"; then + AC_DEFINE([HAVE___ATTRIBUTE__], 1, [define if your compiler has __attribute__]) + fi +]) From b24e3a8dd5c1e9dab8d6756de8b870403eb1d4c1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 17:36:13 +0100 Subject: [PATCH 27/48] m4/ax_c___attribute__.m4: extend to declare support for certain __attribute__((...)) use-cases of interest to NUT --- m4/ax_c___attribute__.m4 | 74 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/m4/ax_c___attribute__.m4 b/m4/ax_c___attribute__.m4 index 487323397a..625a46c589 100644 --- a/m4/ax_c___attribute__.m4 +++ b/m4/ax_c___attribute__.m4 @@ -1,9 +1,9 @@ # =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_c___attribute__.html # -# Downloaded into NUT codebase from +# Downloaded into the Network UPS Tools (NUT) codebase from # http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_c___attribute__.m4 -# as of 2020-11-20 +# as of 2020-11-20 and adapted for attribute supports we needed # =========================================================================== # # SYNOPSIS @@ -14,12 +14,19 @@ # # Provides a test for the compiler support of __attribute__ extensions. # Defines HAVE___ATTRIBUTE__ if it is found. +# Also in particular defines +# HAVE___ATTRIBUTE__UNUSED_ARG +# HAVE___ATTRIBUTE__UNUSED_FUNC +# HAVE___ATTRIBUTE__NORETURN +# if support for respective values and use-cases of interest for NUT +# codebase is found. # # LICENSE # # Copyright (c) 2008 Stepan Kasal # Copyright (c) 2008 Christian Haggstrom # Copyright (c) 2008 Ryan McCabe +# Copyright (c) 2020 Jim Klimov # # 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 @@ -50,20 +57,75 @@ #serial 9 AC_DEFUN([AX_C___ATTRIBUTE__], [ - AC_CACHE_CHECK([for __attribute__], [ax_cv___attribute__], + AC_CACHE_CHECK([for __attribute__((unused)) for function arguments], [ax_cv___attribute__unused_arg], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + static void foo( int); + static void + foo(__attribute__ ((unused)) int i) { + return; + } + ]], [func(1);])], + [ax_cv___attribute__unused_arg=yes], + [ax_cv___attribute__unused_arg=no] + ) + ]) + + AC_CACHE_CHECK([for __attribute__((unused)) for functions], [ax_cv___attribute__unused_func], [AC_COMPILE_IFELSE( [AC_LANG_PROGRAM( [[#include static void foo(void) __attribute__ ((unused)); static void foo(void) { - exit(1); + return; } ]], [])], - [ax_cv___attribute__=yes], - [ax_cv___attribute__=no] + [ax_cv___attribute__unused_func=yes], + [ax_cv___attribute__unused_func=no] + ) + ]) + + AC_CACHE_CHECK([for __attribute__((noreturn))], [ax_cv___attribute__noreturn], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + static void foo(void) __attribute__ ((noreturn)); + static void + foo(void) { + exit(1); + } + ]], [foo();])], + [ax_cv___attribute__noreturn=yes], + [ax_cv___attribute__noreturn=no] ) ]) + + AC_CACHE_CHECK([for at least some __attribute__ support], [ax_cv___attribute__], + [if test "$ax_cv___attribute__unused_arg" = "yes" \ + || test "$ax_cv___attribute__unused_func" = "yes" \ + || test "$ax_cv___attribute__noreturn" = "yes" \ + ; then + dnl # Some values did not error, support for keyword itself exists + ax_cv___attribute__=yes + else + dnl # At least none of the options we are interested in work... + ax_cv___attribute__=no + fi + ]) + + if test "$ax_cv___attribute__unused_arg" = "yes"; then + AC_DEFINE([HAVE___ATTRIBUTE__UNUSED_ARG], 1, [define if your compiler has __attribute__((unused)) for function arguments]) + fi + + if test "$ax_cv___attribute__unused_func" = "yes"; then + AC_DEFINE([HAVE___ATTRIBUTE__UNUSED_FUNC], 1, [define if your compiler has __attribute__((unused)) for functions]) + fi + if test "$ax_cv___attribute__noreturn" = "yes"; then + AC_DEFINE([HAVE___ATTRIBUTE__NORETURN], 1, [define if your compiler has __attribute__((noreturn))]) + fi + if test "$ax_cv___attribute__" = "yes"; then AC_DEFINE([HAVE___ATTRIBUTE__], 1, [define if your compiler has __attribute__]) fi From 2ca8f0a83c8156c73a92c7f7572100c0615fc2f7 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:19:54 +0100 Subject: [PATCH 28/48] include/attribute.h: align with AX_C___ATTRIBUTE__ autoconf macro --- include/attribute.h | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/include/attribute.h b/include/attribute.h index a51632db49..f6ce29b4f4 100644 --- a/include/attribute.h +++ b/include/attribute.h @@ -22,10 +22,50 @@ #ifndef NUT_ATTRIBUTE_H_SEEN #define NUT_ATTRIBUTE_H_SEEN 1 -#ifndef __attribute__ +/* To complicate matters, compilers with native support + * for the keyword may expose or not expose it as a macro... + * but for those that perform such courtesy, or are known + * supporters, we can put up the flag. For others, someone + * with those compilers should check and file PRs to NUT. + */ +#if (!defined HAVE___ATTRIBUTE__) || (HAVE___ATTRIBUTE__ == 0) # if ( defined(__GNUC__) && ( __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) ) ) || ( defined(__STRICT_ANSI__) && __STRICT_ANSI__ ) -# define __attribute__(x) +# ifndef __attribute__ +# define __attribute__(x) +# endif +# ifndef HAVE___ATTRIBUTE__ +# define HAVE___ATTRIBUTE__ 0 +# endif +# else +# if defined(__clang__) || defined(__GNUC__) || defined(__SUNPRO_C) +# ifndef HAVE___ATTRIBUTE__ +# define HAVE___ATTRIBUTE__ 1 +# endif +# else +# ifndef HAVE___ATTRIBUTE__ +# define HAVE___ATTRIBUTE__ 0 +# endif +# endif # endif #endif +#if (!defined HAVE___ATTRIBUTE__) || (HAVE___ATTRIBUTE__ == 0) +# ifdef HAVE___ATTRIBUTE__UNUSED_ARG +# undef HAVE___ATTRIBUTE__UNUSED_ARG +# endif +# ifdef HAVE___ATTRIBUTE__UNUSED_FUNC +# undef HAVE___ATTRIBUTE__UNUSED_FUNC +# endif +# ifdef HAVE___ATTRIBUTE__NORETURN +# undef HAVE___ATTRIBUTE__NORETURN +# endif +# ifdef HAVE___ATTRIBUTE__ +# undef HAVE___ATTRIBUTE__ +# endif +#endif + +/* Other source files now can simply check for `ifdef HAVE___ATTRIBUTE__*` + * as usual, and not bother about 0/1 values of the macro as well. + */ + #endif /* NUT_ATTRIBUTE_H_SEEN */ From f38768c9c609bc33c87fd45e1a783418565497b3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:23:29 +0100 Subject: [PATCH 29/48] server/upsd.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- server/upsd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/upsd.c b/server/upsd.c index 14739e05ad..525e4e4304 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -1179,7 +1179,9 @@ int main(int argc, char **argv) fatalx(EXIT_FAILURE, "Specifying a listening addresses with '-i
' and '-p '\n" "is deprecated. Use 'LISTEN
[]' in 'upsd.conf' instead.\n" "See 'man 8 upsd.conf' for more information."); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case 'q': nut_log_level++; From 0a7bcf7b5eb8627d0068ad1a436eb38dfa6d6caf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:24:41 +0100 Subject: [PATCH 30/48] clients/upsc.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- clients/upsc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clients/upsc.c b/clients/upsc.c index beb49bdd54..835b34d9ee 100644 --- a/clients/upsc.c +++ b/clients/upsc.c @@ -229,7 +229,9 @@ int main(int argc, char **argv) case 'V': fatalx(EXIT_SUCCESS, "Network UPS Tools upscmd %s", UPS_VERSION); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_SUCCESS); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case 'h': default: From 1ee22746f200a2ed60e93e8f5b474328501b8156 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:25:24 +0100 Subject: [PATCH 31/48] clients/upscmd.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- clients/upscmd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clients/upscmd.c b/clients/upscmd.c index 9061983f16..ea6fa93675 100644 --- a/clients/upscmd.c +++ b/clients/upscmd.c @@ -257,7 +257,9 @@ int main(int argc, char **argv) case 'V': fatalx(EXIT_SUCCESS, "Network UPS Tools upscmd %s", UPS_VERSION); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_SUCCESS); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case 'h': default: From 1669b9575dc2ded7799d5e6240e757a8833fd31d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:29:15 +0100 Subject: [PATCH 32/48] clients/upslog.c: wrap unreachable switch()-break after help() with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid warnings --- clients/upslog.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clients/upslog.c b/clients/upslog.c index 653cf7a0e6..8401718378 100644 --- a/clients/upslog.c +++ b/clients/upslog.c @@ -406,7 +406,9 @@ int main(int argc, char **argv) switch(i) { case 'h': help(prog); +#ifndef HAVE___ATTRIBUTE__NORETURN break; +#endif case 's': monhost = optarg; From a9c4caa46e55b8d00753d172acaca55cd7eb70d5 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:29:25 +0100 Subject: [PATCH 33/48] clients/upsmon.c: wrap unreachable switch()-break after help() with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid warnings --- clients/upsmon.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clients/upsmon.c b/clients/upsmon.c index 703595ef14..7f73b85d6f 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -1942,7 +1942,9 @@ int main(int argc, char *argv[]) break; case 'h': help(argv[0]); +#ifndef HAVE___ATTRIBUTE__NORETURN break; +#endif case 'K': checking_flag = 1; break; @@ -1964,7 +1966,9 @@ int main(int argc, char *argv[]) break; default: help(argv[0]); +#ifndef HAVE___ATTRIBUTE__NORETURN break; +#endif } } From b66e17583d4334d9d5f4de21e50483af20ce7e76 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:29:35 +0100 Subject: [PATCH 34/48] clients/upsmon.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- clients/upsmon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clients/upsmon.c b/clients/upsmon.c index 7f73b85d6f..4d1d883afd 100644 --- a/clients/upsmon.c +++ b/clients/upsmon.c @@ -1756,7 +1756,9 @@ static void start_pipe(void) close(pipefd[1]); runparent(pipefd[0]); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* NOTREACHED */ +#endif } close(pipefd[0]); From 14465d82436dc2856caea1f6df2d14bd55c4700b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:31:34 +0100 Subject: [PATCH 35/48] GitIgnore temporary dirs made by configure script (remain around if it is aborted) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e4a206d60f..b9f50c3c40 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ Makefile.in /configure /conf_nut_report_feature /conf??????/ +/dir.??????/ /cscope.* /depcomp /INSTALL From f2815a8a4447e4480f27f3f4d455e719add31d4b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:32:55 +0100 Subject: [PATCH 36/48] drivers/dummy-ups.c: a switch() default needs no break, especially not after fatalx() --- drivers/dummy-ups.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dummy-ups.c b/drivers/dummy-ups.c index 4fba88ee71..67f6ed2a03 100644 --- a/drivers/dummy-ups.c +++ b/drivers/dummy-ups.c @@ -139,10 +139,9 @@ void upsdrv_initinfo(void) } /* FIXME: commands and settable variable! */ break; - default: case MODE_NONE: + default: fatalx(EXIT_FAILURE, "no suitable definition found!"); - break; } upsh.instcmd = instcmd; From de3857364b1f69afde573b025230a7194ef80274 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:33:41 +0100 Subject: [PATCH 37/48] drivers/metasys.c: a switch() default needs no break, especially not after fatalx() --- drivers/metasys.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/metasys.c b/drivers/metasys.c index 745644bd6c..9ea77e4d12 100644 --- a/drivers/metasys.c +++ b/drivers/metasys.c @@ -535,7 +535,6 @@ void upsdrv_initinfo(void) default: fatal_with_errno(EXIT_FAILURE, "Unknown UPS"); - break; } /* Get the serial number */ From 14d3b2517c953ee78e0be568674e6387ce4a90e1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:36:51 +0100 Subject: [PATCH 38/48] drivers/usbhid-ups.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- drivers/usbhid-ups.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usbhid-ups.c b/drivers/usbhid-ups.c index ee04423311..e3eabe20cc 100644 --- a/drivers/usbhid-ups.c +++ b/drivers/usbhid-ups.c @@ -935,10 +935,14 @@ void upsdrv_initups(void) break; case -1: fatal_with_errno(EXIT_FAILURE, "HIDNewRegexMatcher()"); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif default: fatalx(EXIT_FAILURE, "invalid regular expression: %s", regex_array[ret]); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif } /* link the matchers */ From 1003f8b76d53b62d4775a934e086cc370b7b06d0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:47:08 +0100 Subject: [PATCH 39/48] drivers/tripplite_usb.c: control_outlet(): do not warn about syntactic "break;" after returns in conditionals --- drivers/tripplite_usb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/tripplite_usb.c b/drivers/tripplite_usb.c index 622a64ba72..379ab664c4 100644 --- a/drivers/tripplite_usb.c +++ b/drivers/tripplite_usb.c @@ -735,7 +735,16 @@ static int control_outlet(int outlet_id, int state) } else { return 1; } +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunreachable-code-break" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif break; +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic pop +#endif + case TRIPP_LITE_SMART_3005: snprintf(k_cmd, sizeof(k_cmd)-1, "N%c", 5); ret = send_cmd((unsigned char *)k_cmd, strlen(k_cmd) + 1, (unsigned char *)buf, sizeof buf); @@ -748,7 +757,16 @@ static int control_outlet(int outlet_id, int state) } else { return 1; } +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunreachable-code-break" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif break; +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic pop +#endif + default: upslogx(LOG_ERR, "control_outlet unimplemented for protocol %04x", tl_model); } From 3f3957fab20e7235a163fce6c1795c1c65b44209 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:47:20 +0100 Subject: [PATCH 40/48] drivers/tripplite_usb.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- drivers/tripplite_usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/tripplite_usb.c b/drivers/tripplite_usb.c index 379ab664c4..6d0f02f0f2 100644 --- a/drivers/tripplite_usb.c +++ b/drivers/tripplite_usb.c @@ -506,7 +506,9 @@ void usb_comm_fail(int res, const char *msg) case -EBUSY: upslogx(LOG_WARNING, "%s: Device claimed by another process", msg); fatalx(EXIT_FAILURE, "Terminating: EBUSY"); +#ifndef HAVE___ATTRIBUTE__NORETURN break; +#endif default: upslogx(LOG_WARNING, "%s: Device detached? (error %d: %s)", msg, res, usb_strerror()); From 5b835cc26ad29e10d29e73d80dbd9b0b02398ad9 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:49:07 +0100 Subject: [PATCH 41/48] drivers/blazer_usb.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- drivers/blazer_usb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/blazer_usb.c b/drivers/blazer_usb.c index 33f5c2dec5..d7f24c7ae0 100644 --- a/drivers/blazer_usb.c +++ b/drivers/blazer_usb.c @@ -435,11 +435,15 @@ int blazer_command(const char *cmd, char *buf, size_t buflen) { case -EBUSY: /* Device or resource busy */ fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver"); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case -EPERM: /* Operation not permitted */ fatal_with_errno(EXIT_FAILURE, "Permissions problem"); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case -EPIPE: /* Broken pipe */ if (usb_clear_halt(udev, 0x81) == 0) { From d2ab8e168a197c506ad64dc809a9b285aa891ba1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:52:27 +0100 Subject: [PATCH 42/48] drivers/riello_usb.c: wrap unreachable exit() added due to earlier compiler warnings with "ifndef HAVE___ATTRIBUTE__NORETURN" to avoid opposite warnings now --- drivers/riello_usb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/riello_usb.c b/drivers/riello_usb.c index 2143c31ed1..ddbfb7de76 100644 --- a/drivers/riello_usb.c +++ b/drivers/riello_usb.c @@ -358,11 +358,15 @@ int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t buflen) { case -EBUSY: /* Device or resource busy */ fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver"); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case -EPERM: /* Operation not permitted */ fatal_with_errno(EXIT_FAILURE, "Permissions problem"); +#ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ +#endif case -EPIPE: /* Broken pipe */ if (usb_clear_halt(udev, 0x81) == 0) { From 2ac8d6a368511a1d9e5f39d01ca3891fa7a47111 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:53:19 +0100 Subject: [PATCH 43/48] drivers/upsdrvctl.c: a switch() default needs no break --- drivers/upsdrvctl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/upsdrvctl.c b/drivers/upsdrvctl.c index f96652a0b1..f9f2d5d294 100644 --- a/drivers/upsdrvctl.c +++ b/drivers/upsdrvctl.c @@ -495,7 +495,6 @@ int main(int argc, char **argv) case 'h': default: help(prog); - break; } } From 5a69161ee772badf40989d30661b3a3de273eee2 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:54:22 +0100 Subject: [PATCH 44/48] server/upsd.c: a switch() default needs no break --- server/upsd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/server/upsd.c b/server/upsd.c index 525e4e4304..6304635a9d 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -1224,7 +1224,6 @@ int main(int argc, char **argv) default: help(progname); - break; } } From 73045a5552ea280f7c055c488a6f35ad577915f3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:55:29 +0100 Subject: [PATCH 45/48] server/upsd.c: a move "help" switch() handling to default case --- server/upsd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/upsd.c b/server/upsd.c index 6304635a9d..8f96dabe39 100644 --- a/server/upsd.c +++ b/server/upsd.c @@ -1170,10 +1170,6 @@ int main(int argc, char **argv) while ((i = getopt(argc, argv, "+h46p:qr:i:fu:Vc:D")) != -1) { switch (i) { - case 'h': - help(progname); - break; - case 'p': case 'i': fatalx(EXIT_FAILURE, "Specifying a listening addresses with '-i
' and '-p '\n" @@ -1222,6 +1218,7 @@ int main(int argc, char **argv) opt_af = AF_INET6; break; + case 'h': default: help(progname); } From b4ab1358f55b1fed6fafdae36470bc94ddca39b6 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:59:06 +0100 Subject: [PATCH 46/48] drivers/libusb.c: do not warn about unreachable code where we handle a legacy off-chance that fatalx() might not exit the program --- drivers/libusb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/libusb.c b/drivers/libusb.c index 6284d4396e..d4aa5c54d7 100644 --- a/drivers/libusb.c +++ b/drivers/libusb.c @@ -251,7 +251,15 @@ static int libusb_open(usb_dev_handle **udevp, USBDevice_t *curDevice, USBDevice goto next_device; } else if (ret==-1) { fatal_with_errno(EXIT_FAILURE, "matcher"); +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunreachable-code-break" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif goto next_device; +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic pop +#endif } else if (ret==-2) { upsdebugx(2, "matcher: unspecified error"); goto next_device; From 441b7d1d6ad4597ae944aa929973092c845e2c0b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 18:59:46 +0100 Subject: [PATCH 47/48] drivers/richcomm_usb.c: do not warn about unreachable code where we handle a legacy off-chance that fatalx() might not exit the program --- drivers/richcomm_usb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/richcomm_usb.c b/drivers/richcomm_usb.c index 976d1c209e..79184fce61 100644 --- a/drivers/richcomm_usb.c +++ b/drivers/richcomm_usb.c @@ -312,7 +312,15 @@ static int usb_device_open(usb_dev_handle **handlep, USBDevice_t *device, USBDev goto next_device; case -1: fatal_with_errno(EXIT_FAILURE, "matcher"); +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunreachable-code-break" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif goto next_device; +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic pop +#endif case -2: upsdebugx(4, "matcher: unspecified error"); goto next_device; From 7ce0e1136a0bf6dff811604f65133422db24f005 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 20 Nov 2020 19:01:01 +0100 Subject: [PATCH 48/48] drivers/nutdrv_atcl_usb.c: do not warn about unreachable code where we handle a legacy off-chance that fatalx() might not exit the program --- drivers/nutdrv_atcl_usb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nutdrv_atcl_usb.c b/drivers/nutdrv_atcl_usb.c index 147b7d9d84..597b3e0110 100644 --- a/drivers/nutdrv_atcl_usb.c +++ b/drivers/nutdrv_atcl_usb.c @@ -320,7 +320,15 @@ static int usb_device_open(usb_dev_handle **handlep, USBDevice_t *device, USBDev goto next_device; case -1: fatal_with_errno(EXIT_FAILURE, "matcher"); +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunreachable-code-break" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif goto next_device; +#if defined (__GNUC__) || defined (__clang__) +#pragma GCC diagnostic pop +#endif case -2: upsdebugx(4, "matcher: unspecified error"); goto next_device;