diff --git a/clients/upssched.c b/clients/upssched.c index 32e5b060be..eb822f0cd2 100644 --- a/clients/upssched.c +++ b/clients/upssched.c @@ -692,8 +692,8 @@ static int sock_read(conn_t *conn) ret = read(conn->fd, &ch, 1); if (ret > 0) - upsdebugx(6, "read() from fd %d returned %" PRIiSIZE " (bytes): '%c'; errno=%d: %s", - conn->fd, ret, ch, errno, strerror(errno)); + upsdebug_with_errno(6, "read() from fd %d returned %" PRIiSIZE " (bytes): '%c'", + conn->fd, ret, ch); if (ret < 1) { @@ -723,15 +723,13 @@ static int sock_read(conn_t *conn) || (poll(&pfd, 1, 0) <= 0) || errno ) { - upsdebugx(4, "read() from fd %d returned 0; errno=%d: %s", - conn->fd, errno, strerror(errno)); + upsdebug_with_errno(4, "read() from fd %d returned 0", conn->fd); return -1; /* connection closed, probably */ } if (i == (US_MAX_READ - 1)) { - upsdebugx(4, "read() from fd %d returned 0 " + upsdebug_with_errno(4, "read() from fd %d returned 0 " "too many times in a row, aborting " - "sock_read(); errno=%d: %s", - conn->fd, errno, strerror(errno)); + "sock_read()", conn->fd); return -1; /* connection closed, probably */ } continue; @@ -783,10 +781,8 @@ static int sock_read(conn_t *conn) return 1; /* we did some work */ } - upsdebugx(6, "sock_read() from fd %d returned nothing " - "(maybe still collecting the command line); " - "errno=%d: %s", - conn->fd, errno, strerror(errno)); + upsdebug_with_errno(6, "sock_read() from fd %d returned nothing " + "(maybe still collecting the command line); ", conn->fd); return 0; /* fell out without parsing anything */ } @@ -1241,7 +1237,7 @@ static void sendcmd(const char *cmd, const char *arg1, const char *arg2) switch(ret_s) { /* select error */ case -1: - upslogx(LOG_DEBUG, "parent select error: %s", strerror(errno)); + upslog_with_errno(LOG_DEBUG, "parent select error"); break; /* nothing to read */ diff --git a/drivers/adelsystem_cbi.c b/drivers/adelsystem_cbi.c index 6c4d7df174..2247b6e6a2 100644 --- a/drivers/adelsystem_cbi.c +++ b/drivers/adelsystem_cbi.c @@ -473,7 +473,7 @@ void upsdrv_shutdown(void) while ((rval = upscmd("load.off", NULL)) != STAT_INSTCMD_HANDLED && cnt > 0) { rval = gettimeofday(&start, NULL); if (rval < 0) { - upslogx(LOG_ERR, "upscmd: gettimeofday: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "upscmd: gettimeofday"); } /* wait for an increasing time interval before sending shutdown command */ @@ -792,7 +792,7 @@ long time_elapsed(struct timeval *start) rval = gettimeofday(&end, NULL); if (rval < 0) { - upslogx(LOG_ERR, "time_elapsed: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "time_elapsed"); } if (start->tv_usec < end.tv_usec) { suseconds_t nsec = (end.tv_usec - start->tv_usec) / 1000000 + 1; diff --git a/drivers/al175.c b/drivers/al175.c index fe01763492..8438882144 100644 --- a/drivers/al175.c +++ b/drivers/al175.c @@ -713,7 +713,7 @@ static int tx(const char *dmsg, /*const*/ raw_data_t frame) err = ser_send_buf(upsfd, frame.begin, frame_len ); if (err==-1) { - upslogx(LOG_ERR, "failed to send frame to PRS: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "failed to send frame to PRS"); return -1; } diff --git a/drivers/dstate.c b/drivers/dstate.c index f6edaf616a..2b36688291 100644 --- a/drivers/dstate.c +++ b/drivers/dstate.c @@ -301,13 +301,13 @@ static void send_to_all(const char *fmt, ...) if ((ret < 1) || (ret != (ssize_t)buflen)) { #ifndef WIN32 - upsdebugx(0, "WARNING: %s: write %" PRIiSIZE " bytes to " - "socket %d failed (ret=%" PRIiSIZE "), disconnecting: %s", - __func__, buflen, (int)conn->fd, ret, strerror(errno)); + upsdebug_with_errno(0, "WARNING: %s: write %" PRIiSIZE " bytes to " + "socket %d failed (ret=%" PRIiSIZE "), disconnecting.", + __func__, buflen, (int)conn->fd, ret); #else - upsdebugx(0, "WARNING: %s: write %" PRIiSIZE " bytes to " - "handle %p failed (ret=%" PRIiSIZE "), disconnecting: %s", - __func__, buflen, conn->fd, ret, strerror(errno)); + upsdebug_with_errno(0, "WARNING: %s: write %" PRIiSIZE " bytes to " + "handle %p failed (ret=%" PRIiSIZE "), disconnecting.", + __func__, buflen, conn->fd, ret); #endif upsdebugx(6, "%s: failed write: %s", __func__, buf); @@ -394,19 +394,13 @@ static int send_to_one(conn_t *conn, const char *fmt, ...) if (ret < 0) { /* Hacky bugfix: throttle down for upsd to read that */ #ifndef WIN32 - upsdebugx(1, "%s: had to throttle down to retry " - "writing %" PRIiSIZE " bytes to socket %d " - "(ret=%" PRIiSIZE ", errno=%d, strerror=%s): %s", - __func__, buflen, (int)conn->fd, - ret, errno, strerror(errno), - buf); + upsdebug_with_errno(1, "%s: had to throttle down to retry " + "writing %" PRIiSIZE " bytes to socket %d (ret=%" PRIiSIZE ") : %s", + __func__, buflen, (int)conn->fd, ret, buf); #else - upsdebugx(1, "%s: had to throttle down to retry " - "writing %" PRIiSIZE " bytes to handle %p " - "(ret=%" PRIiSIZE ", errno=%d, strerror=%s): %s", - __func__, buflen, conn->fd, - ret, errno, strerror(errno), - buf); + upsdebug_with_errno(1, "%s: had to throttle down to retry " + "writing %" PRIiSIZE " bytes to handle %p (ret=%" PRIiSIZE ") : %s", + __func__, buflen, conn->fd, ret, buf); #endif usleep(200); #ifndef WIN32 @@ -427,13 +421,13 @@ static int send_to_one(conn_t *conn, const char *fmt, ...) if ((ret < 1) || (ret != (ssize_t)buflen)) { #ifndef WIN32 - upsdebugx(0, "WARNING: %s: write %" PRIiSIZE " bytes to " - "socket %d failed (ret=%" PRIiSIZE "), disconnecting: %s", - __func__, buflen, (int)conn->fd, ret, strerror(errno)); + upsdebug_with_errno(0, "WARNING: %s: write %" PRIiSIZE " bytes to " + "socket %d failed (ret=%" PRIiSIZE "), disconnecting.", + __func__, buflen, (int)conn->fd, ret); #else - upsdebugx(0, "WARNING: %s: write %" PRIiSIZE " bytes to " - "handle %p failed (ret=%" PRIiSIZE "), disconnecting: %s", - __func__, buflen, conn->fd, ret, strerror(errno)); + upsdebug_with_errno(0, "WARNING: %s: write %" PRIiSIZE " bytes to " + "handle %p failed (ret=%" PRIiSIZE "), disconnecting.", + __func__, buflen, conn->fd, ret); #endif upsdebugx(6, "%s: failed write: %s", __func__, buf); sock_disconnect(conn); diff --git a/drivers/generic_modbus.c b/drivers/generic_modbus.c index c5a9fd5090..4aa87f17e7 100644 --- a/drivers/generic_modbus.c +++ b/drivers/generic_modbus.c @@ -325,7 +325,7 @@ void upsdrv_shutdown(void) while ((rval = upscmd("load.off", NULL)) != STAT_INSTCMD_HANDLED && cnt > 0) { rval = gettimeofday(&start, NULL); if (rval < 0) { - upslogx(LOG_ERR, "upscmd: gettimeofday: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "upscmd: gettimeofday"); } /* wait for an increasing time interval before sending shutdown command */ @@ -548,7 +548,7 @@ long time_elapsed(struct timeval *start) rval = gettimeofday(&end, NULL); if (rval < 0) { - upslogx(LOG_ERR, "time_elapsed: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "time_elapsed"); } if (start->tv_usec < end.tv_usec) { suseconds_t nsec = (end.tv_usec - start->tv_usec) / 1000000 + 1; @@ -597,7 +597,7 @@ int upscmd(const char *cmd, const char *arg) if (FSD_pulse_duration != NOTUSED && rval == STAT_INSTCMD_HANDLED) { rval = gettimeofday(&start, NULL); if (rval < 0) { - upslogx(LOG_ERR, "upscmd: gettimeofday: %s", strerror(errno)); + upslog_with_errno(LOG_ERR, "upscmd: gettimeofday"); } /* wait for FSD_pulse_duration ms */ diff --git a/drivers/main.c b/drivers/main.c index d31ebb4eaa..52443b1c5a 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -2058,7 +2058,7 @@ int main(int argc, char **argv) NULL, 0, &tv); if (cmdret < 0) { - upsdebugx(1, "Socket dialog with the other driver instance: %s", strerror(errno)); + upsdebug_with_errno(1, "Socket dialog with the other driver instance"); } else { upslogx(LOG_INFO, "Request to killpower via running driver returned code %" PRIiSIZE, cmdret); if (cmdret == 0) @@ -2353,17 +2353,15 @@ int main(int argc, char **argv) int sigret; if ((sigret = stat(pidfnbuf, &st)) != 0) { - upsdebugx(1, "PID file %s not found; stat() returned %d (errno=%d): %s", - pidfnbuf, sigret, errno, strerror(errno)); + upsdebug_with_errno(1, "PID file %s not found; stat() returned %d", pidfnbuf, sigret); break; } upslogx(LOG_WARNING, "Duplicate driver instance detected (PID file %s exists)! Terminating other driver!", pidfnbuf); if ((sigret = sendsignalfn(pidfnbuf, SIGTERM, progname, 1) != 0)) { - upsdebugx(1, "Can't send signal to PID, assume invalid PID file %s; " - "sendsignalfn() returned %d (errno=%d): %s", - pidfnbuf, sigret, errno, strerror(errno)); + upsdebug_with_errno(1, "Can't send signal to PID, assume invalid PID file %s; " + "sendsignalfn() returned %d", pidfnbuf, sigret); break; } @@ -2546,10 +2544,7 @@ int main(int argc, char **argv) user, group, sockname); if (grp == NULL) { - upsdebugx(1, "WARNING: could not resolve " - "group name '%s' (%i): %s", - group, errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: could not resolve group name '%s'", group); allOk = 0; goto sockname_ownership_finished; } else { @@ -2557,19 +2552,15 @@ int main(int argc, char **argv) mode_t mode; if (INVALID_FD((fd = open(sockname, O_RDWR | O_APPEND)))) { - upsdebugx(1, "WARNING: opening socket file for stat/chown failed " - "(%i), which is rather typical for Unix socket handling: %s", - errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: opening socket file for stat/chown failed," + " which is rather typical for Unix socket handling"); allOk = 0; } if ((VALID_FD(fd) && fstat(fd, &statbuf)) || (INVALID_FD(fd) && stat(sockname, &statbuf)) ) { - upsdebugx(1, "WARNING: stat for chown of socket file failed (%i): %s", - errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: stat for chown of socket file failed"); allOk = 0; if (INVALID_FD(fd)) { /* Can not proceed with ops below */ @@ -2582,9 +2573,7 @@ int main(int argc, char **argv) if ((VALID_FD(fd) && fchown(fd, statbuf.st_uid, grp->gr_gid)) || (INVALID_FD(fd) && chown(sockname, statbuf.st_uid, grp->gr_gid)) ) { - upsdebugx(1, "WARNING: chown of socket file failed (%i): %s", - errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: chown of socket file failed"); allOk = 0; } } @@ -2595,9 +2584,7 @@ int main(int argc, char **argv) ) { /* Logically we'd fail chown above if file * does not exist or is not accessible */ - upsdebugx(1, "WARNING: stat for chmod of socket file failed (%i): %s", - errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: stat for chmod of socket file failed"); allOk = 0; } else { /* chmod g+rw sockname */ @@ -2607,9 +2594,7 @@ int main(int argc, char **argv) if ((VALID_FD(fd) && fchmod(fd, mode)) || (INVALID_FD(fd) && chmod(sockname, mode)) ) { - upsdebugx(1, "WARNING: chmod of socket file failed (%i): %s", - errno, strerror(errno) - ); + upsdebug_with_errno(1, "WARNING: chmod of socket file failed"); allOk = 0; } } diff --git a/drivers/riello_usb.c b/drivers/riello_usb.c index fdc7de8246..cde20fbae9 100644 --- a/drivers/riello_usb.c +++ b/drivers/riello_usb.c @@ -143,7 +143,7 @@ static int Send_USB_Packet(uint8_t *send_str, uint16_t numbytes) err = usb_bulk_write(udev, 0x2, (usb_ctrl_charbuf) USB_buff_pom, 8, 1000); if (err < 0) { - upsdebugx(3, "USB: Send_USB_Packet: send_usb_packet, err = %d %s ", err, strerror(errno)); + upsdebug_with_errno(3, "USB: Send_USB_Packet: send_usb_packet, err = %d %s ", err, nut_usb_strerror(err)); return err; } ussleep(USB_WRITE_DELAY); @@ -173,7 +173,7 @@ static int Send_USB_Packet(uint8_t *send_str, uint16_t numbytes) err = usb_bulk_write(udev, 0x2, (usb_ctrl_charbuf) USB_buff_pom, 8, 1000); if (err < 0) { - upsdebugx(3, "USB: Send_USB_Packet: send_usb_packet, err = %d %s ", err, strerror(errno)); + upsdebug_with_errno(3, "USB: Send_USB_Packet: send_usb_packet, err = %d %s ", err, nut_usb_strerror(err)); return err; } ussleep(USB_WRITE_DELAY); @@ -201,7 +201,7 @@ static int Get_USB_Packet(uint8_t *buffer) upsdebugx(3, "read: %02X %02X %02X %02X %02X %02X %02X %02X", inBuf[0], inBuf[1], inBuf[2], inBuf[3], inBuf[4], inBuf[5], inBuf[6], inBuf[7]); if (err < 0){ - upsdebugx(3, "USB: Get_USB_Packet: send_usb_packet, err = %d %s ", err, strerror(errno)); + upsdebug_with_errno(3, "USB: Get_USB_Packet: send_usb_packet, err = %d %s ", err, nut_usb_strerror(err)); return err; }