From 325e5ac8ddf2cb100a47e39185bc9f134d3b2f98 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Wed, 22 Jan 2020 15:05:34 -0800 Subject: core: Make style of debug messages with errno consistent across library Signed-off-by: Chris Dickens --- libusb/io.c | 7 +++---- libusb/os/linux_netlink.c | 16 ++++++++-------- libusb/os/linux_udev.c | 8 ++++---- libusb/os/linux_usbfs.c | 25 ++++++++++++------------- libusb/os/poll_posix.c | 14 +++++++------- libusb/os/sunos_usb.c | 35 ++++++++++++++++++----------------- libusb/version_nano.h | 2 +- 7 files changed, 53 insertions(+), 54 deletions(-) diff --git a/libusb/io.c b/libusb/io.c index f274a41..0c7ef6c 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -1156,8 +1156,7 @@ int usbi_io_init(struct libusb_context *ctx) if (r < 0) goto err_close_timerfd; } else { - usbi_dbg("timerfd not available (code %d error %d)", ctx->timerfd, errno); - ctx->timerfd = -1; + usbi_dbg("timerfd not available, errno=%d", errno); } #endif @@ -1435,7 +1434,7 @@ out: USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout); r = timerfd_settime(ctx->timerfd, TFD_TIMER_ABSTIME, &it, NULL); if (r < 0) { - usbi_warn(ctx, "failed to arm first timerfd (errno %d)", errno); + usbi_warn(ctx, "failed to arm first timerfd, errno=%d", errno); r = LIBUSB_ERROR_OTHER; } } @@ -2188,7 +2187,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv) r = LIBUSB_ERROR_INTERRUPTED; goto done; } else if (r < 0) { - usbi_err(ctx, "poll failed %d err=%d", r, errno); + usbi_err(ctx, "poll failed, errno=%d", errno); r = LIBUSB_ERROR_IO; goto done; } diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c index c1ad1ec..0ceb951 100644 --- a/libusb/os/linux_netlink.c +++ b/libusb/os/linux_netlink.c @@ -68,12 +68,12 @@ static int set_fd_cloexec_nb(int fd, int socktype) if (!(socktype & SOCK_CLOEXEC)) { flags = fcntl(fd, F_GETFD); if (flags == -1) { - usbi_err(NULL, "failed to get netlink fd flags (%d)", errno); + usbi_err(NULL, "failed to get netlink fd flags, errno=%d", errno); return -1; } if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) { - usbi_err(NULL, "failed to set netlink fd flags (%d)", errno); + usbi_err(NULL, "failed to set netlink fd flags, errno=%d", errno); return -1; } } @@ -83,12 +83,12 @@ static int set_fd_cloexec_nb(int fd, int socktype) if (!(socktype & SOCK_NONBLOCK)) { flags = fcntl(fd, F_GETFL); if (flags == -1) { - usbi_err(NULL, "failed to get netlink fd status flags (%d)", errno); + usbi_err(NULL, "failed to get netlink fd status flags, errno=%d", errno); return -1; } if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - usbi_err(NULL, "failed to set netlink fd status flags (%d)", errno); + usbi_err(NULL, "failed to set netlink fd status flags, errno=%d", errno); return -1; } } @@ -111,7 +111,7 @@ int linux_netlink_start_event_monitor(void) } if (linux_netlink_socket == -1) { - usbi_err(NULL, "failed to create netlink socket (%d)", errno); + usbi_err(NULL, "failed to create netlink socket, errno=%d", errno); goto err; } @@ -121,13 +121,13 @@ int linux_netlink_start_event_monitor(void) ret = bind(linux_netlink_socket, (struct sockaddr *)&sa_nl, sizeof(sa_nl)); if (ret == -1) { - usbi_err(NULL, "failed to bind netlink socket (%d)", errno); + usbi_err(NULL, "failed to bind netlink socket, errno=%d", errno); goto err_close_socket; } ret = setsockopt(linux_netlink_socket, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt)); if (ret == -1) { - usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option (%d)", errno); + usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option, errno=%d", errno); goto err_close_socket; } @@ -314,7 +314,7 @@ static int linux_netlink_read_message(void) len = recvmsg(linux_netlink_socket, &msg, 0); if (len == -1) { if (errno != EAGAIN && errno != EINTR) - usbi_err(NULL, "error receiving message from netlink (%d)", errno); + usbi_err(NULL, "error receiving message from netlink, errno=%d", errno); return -1; } diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c index b09d299..8cf19d5 100644 --- a/libusb/os/linux_udev.c +++ b/libusb/os/linux_udev.c @@ -86,12 +86,12 @@ int linux_udev_start_event_monitor(void) /* Make sure the udev file descriptor is marked as CLOEXEC */ r = fcntl(udev_monitor_fd, F_GETFD); if (r == -1) { - usbi_err(NULL, "geting udev monitor fd flags (%d)", errno); + usbi_err(NULL, "failed to get udev monitor fd flags, errno=%d", errno); goto err_free_monitor; } if (!(r & FD_CLOEXEC)) { if (fcntl(udev_monitor_fd, F_SETFD, r | FD_CLOEXEC) == -1) { - usbi_err(NULL, "setting udev monitor fd flags (%d)", errno); + usbi_err(NULL, "failed to set udev monitor fd flags, errno=%d", errno); goto err_free_monitor; } } @@ -101,12 +101,12 @@ int linux_udev_start_event_monitor(void) * so make sure this is set */ r = fcntl(udev_monitor_fd, F_GETFL); if (r == -1) { - usbi_err(NULL, "getting udev monitor fd status flags (%d)", errno); + usbi_err(NULL, "failed to get udev monitor fd status flags, errno=%d", errno); goto err_free_monitor; } if (!(r & O_NONBLOCK)) { if (fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK) == -1) { - usbi_err(NULL, "setting udev monitor fd status flags (%d)", errno); + usbi_err(NULL, "failed to set udev monitor fd status flags, errno=%d", errno); goto err_free_monitor; } } diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index bccafad..f16907b 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -368,7 +368,7 @@ static clockid_t find_monotonic_clock(void) r = clock_gettime(CLOCK_MONOTONIC, &ts); if (r == 0) return CLOCK_MONOTONIC; - usbi_dbg("monotonic clock doesn't work, errno %d", errno); + usbi_dbg("monotonic clock doesn't work, errno=%d", errno); #endif return CLOCK_REALTIME; @@ -381,7 +381,7 @@ static int get_kernel_version(struct libusb_context *ctx, int atoms; if (uname(&uts) < 0) { - usbi_err(ctx, "uname failed, errno %d", errno); + usbi_err(ctx, "uname failed, errno=%d", errno); return -1; } @@ -589,7 +589,7 @@ static int _open_sysfs_attr(struct libusb_device *dev, const char *attr) fd = _open(filename, O_RDONLY); if (fd < 0) { usbi_err(DEVICE_CTX(dev), - "open %s failed ret=%d errno=%d", filename, fd, errno); + "open %s failed, errno=%d", filename, errno); return LIBUSB_ERROR_IO; } @@ -613,13 +613,13 @@ static int __read_sysfs_attr(struct libusb_context *ctx, disconnected (see trac ticket #70). */ return LIBUSB_ERROR_NO_DEVICE; } - usbi_err(ctx, "open %s failed errno=%d", filename, errno); + usbi_err(ctx, "open %s failed, errno=%d", filename, errno); return LIBUSB_ERROR_IO; } f = fdopen(fd, "r"); if (f == NULL) { - usbi_err(ctx, "fdopen %s failed errno=%d", filename, errno); + usbi_err(ctx, "fdopen %s failed, errno=%d", filename, errno); close(fd); return LIBUSB_ERROR_OTHER; } @@ -666,7 +666,7 @@ static int sysfs_get_active_config(struct libusb_device *dev, int *config) close(fd); if (r < 0) { usbi_err(DEVICE_CTX(dev), - "read bConfigurationValue failed ret=%zd errno=%d", r, errno); + "read bConfigurationValue failed, errno=%d", errno); return LIBUSB_ERROR_IO; } else if (r == 0) { usbi_dbg("device unconfigured"); @@ -1006,7 +1006,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum, fd = wrapped_fd; r = lseek(fd, 0, SEEK_SET); if (r < 0) { - usbi_err(ctx, "seek failed ret=%zd errno=%d", r, errno); + usbi_err(ctx, "lseek failed, errno=%d", errno); return LIBUSB_ERROR_IO; } } @@ -1030,8 +1030,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum, r = read(fd, priv->descriptors + priv->descriptors_len, descriptors_size - priv->descriptors_len); if (r < 0) { - usbi_err(ctx, "read descriptor failed ret=%d errno=%d", - fd, errno); + usbi_err(ctx, "read descriptor failed, errno=%d", errno); if (fd != wrapped_fd) close(fd); return LIBUSB_ERROR_IO; @@ -1280,7 +1279,7 @@ static int usbfs_get_device_list(struct libusb_context *ctx) int r = 0; if (!buses) { - usbi_err(ctx, "opendir buses failed errno=%d", errno); + usbi_err(ctx, "opendir buses failed, errno=%d", errno); return LIBUSB_ERROR_IO; } @@ -1342,7 +1341,7 @@ static int sysfs_get_device_list(struct libusb_context *ctx) int num_enumerated = 0; if (!devices) { - usbi_err(ctx, "opendir devices failed errno=%d", errno); + usbi_err(ctx, "opendir devices failed, errno=%d", errno); return LIBUSB_ERROR_IO; } @@ -1736,7 +1735,7 @@ static unsigned char *op_dev_mem_alloc(struct libusb_device_handle *handle, unsigned char *buffer = (unsigned char *)mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, hpriv->fd, 0); if (buffer == MAP_FAILED) { - usbi_err(HANDLE_CTX(handle), "alloc dev mem failed errno %d", + usbi_err(HANDLE_CTX(handle), "alloc dev mem failed, errno=%d", errno); return NULL; } @@ -1747,7 +1746,7 @@ static int op_dev_mem_free(struct libusb_device_handle *handle, unsigned char *buffer, size_t len) { if (munmap(buffer, len) != 0) { - usbi_err(HANDLE_CTX(handle), "free dev mem failed errno %d", + usbi_err(HANDLE_CTX(handle), "free dev mem failed, errno=%d", errno); return LIBUSB_ERROR_OTHER; } else { diff --git a/libusb/os/poll_posix.c b/libusb/os/poll_posix.c index 337714a..a2ad157 100644 --- a/libusb/os/poll_posix.c +++ b/libusb/os/poll_posix.c @@ -36,42 +36,42 @@ int usbi_pipe(int pipefd[2]) #endif if (ret != 0) { - usbi_err(NULL, "failed to create pipe (%d)", errno); + usbi_err(NULL, "failed to create pipe, errno=%d", errno); return ret; } #if !defined(HAVE_PIPE2) && defined(FD_CLOEXEC) ret = fcntl(pipefd[0], F_GETFD); if (ret == -1) { - usbi_err(NULL, "failed to get pipe fd flags (%d)", errno); + usbi_err(NULL, "failed to get pipe fd flags, errno=%d", errno); goto err_close_pipe; } ret = fcntl(pipefd[0], F_SETFD, ret | FD_CLOEXEC); if (ret == -1) { - usbi_err(NULL, "failed to set pipe fd flags (%d)", errno); + usbi_err(NULL, "failed to set pipe fd flags, errno=%d", errno); goto err_close_pipe; } ret = fcntl(pipefd[1], F_GETFD); if (ret == -1) { - usbi_err(NULL, "failed to get pipe fd flags (%d)", errno); + usbi_err(NULL, "failed to get pipe fd flags, errno=%d", errno); goto err_close_pipe; } ret = fcntl(pipefd[1], F_SETFD, ret | FD_CLOEXEC); if (ret == -1) { - usbi_err(NULL, "failed to set pipe fd flags (%d)", errno); + usbi_err(NULL, "failed to set pipe fd flags, errno=%d", errno); goto err_close_pipe; } #endif ret = fcntl(pipefd[1], F_GETFL); if (ret == -1) { - usbi_err(NULL, "failed to get pipe fd status flags (%d)", errno); + usbi_err(NULL, "failed to get pipe fd status flags, errno=%d", errno); goto err_close_pipe; } ret = fcntl(pipefd[1], F_SETFL, ret | O_NONBLOCK); if (ret == -1) { - usbi_err(NULL, "failed to set pipe fd status flags (%d)", errno); + usbi_err(NULL, "failed to set pipe fd status flags, errno=%d", errno); goto err_close_pipe; } diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c index 4bc9187..6960033 100644 --- a/libusb/os/sunos_usb.c +++ b/libusb/os/sunos_usb.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -186,7 +185,7 @@ sunos_usb_ioctl(struct libusb_device *dev, int cmd) fd = open(path_arg, O_RDONLY); if (fd < 0) { - usbi_err(DEVICE_CTX(dev), "open failed: %d (%s)", errno, strerror(errno)); + usbi_err(DEVICE_CTX(dev), "open failed: errno %d (%s)", errno, strerror(errno)); nvlist_free(nvlist); free(hubpath); return (-1); @@ -710,13 +709,13 @@ sunos_get_device_list(struct libusb_context * ctx, args.discdevs = discdevs; args.last_ugenpath = NULL; if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) { - usbi_dbg("di_int() failed: %s", strerror(errno)); + usbi_dbg("di_int() failed: errno %d (%s)", errno, strerror(errno)); return (LIBUSB_ERROR_IO); } if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) { di_fini(root_node); - usbi_dbg("di_devlink_init() failed: %s", strerror(errno)); + usbi_dbg("di_devlink_init() failed: errno %d (%s)", errno, strerror(errno)); return (LIBUSB_ERROR_IO); } @@ -725,7 +724,7 @@ sunos_get_device_list(struct libusb_context * ctx, /* walk each node to find USB devices */ if (di_walk_node(root_node, DI_WALK_SIBFIRST, &args, sunos_walk_minor_node_link) == -1) { - usbi_dbg("di_walk_node() failed: %s", strerror(errno)); + usbi_dbg("di_walk_node() failed: errno %d (%s)", errno, strerror(errno)); di_fini(root_node); return (LIBUSB_ERROR_IO); @@ -917,7 +916,7 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, } /* Open the xfer endpoint first */ if ((fd = open(filename, mode)) == -1) { - usbi_dbg("can't open %s: %d(%s)", filename, errno, + usbi_dbg("can't open %s: errno %d (%s)", filename, errno, strerror(errno)); return (errno); @@ -938,16 +937,16 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, /* Open the status endpoint with RDWR */ if ((fdstat = open(statfilename, O_RDWR)) == -1) { - usbi_dbg("can't open %s RDWR: %d", - statfilename, errno); + usbi_dbg("can't open %s RDWR: errno %d (%s)", + statfilename, errno, strerror(errno)); return (errno); } else { count = write(fdstat, &control, sizeof (control)); if (count != 1) { /* this should have worked */ - usbi_dbg("can't write to %s: %d", - statfilename, errno); + usbi_dbg("can't write to %s: errno %d (%s)", + statfilename, errno, strerror(errno)); (void) close(fdstat); return (errno); @@ -955,7 +954,8 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, } } else { if ((fdstat = open(statfilename, O_RDONLY)) == -1) { - usbi_dbg("can't open %s: %d", statfilename, errno); + usbi_dbg("can't open %s: errno %d (%s)", statfilename, errno, + strerror(errno)); return (errno); } @@ -963,8 +963,8 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl, /* Re-open the xfer endpoint */ if ((fd = open(filename, mode)) == -1) { - usbi_dbg("can't open %s: %d(%s)", filename, errno, - strerror(errno)); + usbi_dbg("can't open %s: errno %d (%s)", filename, errno, + strerror(errno)); (void) close(fdstat); return (errno); @@ -1059,7 +1059,8 @@ sunos_get_active_config_descriptor(struct libusb_device *dev, * has ever been changed through setCfg. */ if ((node = di_init(dpriv->phypath, DINFOCPYALL)) == DI_NODE_NIL) { - usbi_dbg("di_int() failed: %s", strerror(errno)); + usbi_dbg("di_int() failed: errno %d (%s)", errno, + strerror(errno)); return (LIBUSB_ERROR_IO); } proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node, @@ -1301,12 +1302,12 @@ usb_do_io(int fd, int stat_fd, char *data, size_t size, int flag, int *status) if (ret < 0) { int save_errno = errno; - usbi_dbg("TID=%x io %s errno=%d(%s) ret=%d", pthread_self(), - flag?"WRITE":"READ", errno, strerror(errno), ret); + usbi_dbg("TID=%x io %s errno %d (%s)", pthread_self(), + flag?"WRITE":"READ", errno, strerror(errno)); /* sunos_usb_get_status will do a read and overwrite errno */ error = sunos_usb_get_status(stat_fd); - usbi_dbg("io status=%d errno=%d(%s)", error, + usbi_dbg("io status=%d errno %d (%s)", error, save_errno, strerror(save_errno)); if (status) { diff --git a/libusb/version_nano.h b/libusb/version_nano.h index d7c69b6..6cb8510 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11439 +#define LIBUSB_NANO 11440 -- cgit v1.2.1