From 7864b16b27cf7039c92492c4699fb8476618b7d0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 19 Jun 2019 09:09:58 +0900 Subject: [PATCH] ethtool-util: make ethtool_connect() warn on failure --- src/shared/ethtool-util.c | 29 +++++++++++++++-------------- src/shared/ethtool-util.h | 2 -- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index d953639..3fba238 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -115,14 +115,15 @@ assert_cc((ELEMENTSOF(ethtool_link_mode_bit_table)-1) / 32 < N_ADVERTISE); DEFINE_STRING_TABLE_LOOKUP(ethtool_link_mode_bit, enum ethtool_link_mode_bit_indices); -int ethtool_connect(int *ret) { +static int ethtool_connect_or_warn(int *ret, bool warn) { int fd; assert_return(ret, -EINVAL); fd = socket_ioctl_fd(); if (fd < 0) - return fd; + return log_full_errno(warn ? LOG_WARNING: LOG_DEBUG, fd, + "ethtool: could not create control socket: %m"); *ret = fd; @@ -140,9 +141,9 @@ int ethtool_get_driver(int *fd, const char *ifname, char **ret) { int r; if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); @@ -173,9 +174,9 @@ int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex return 0; if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); @@ -231,9 +232,9 @@ int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol) { return 0; if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); @@ -368,9 +369,9 @@ int ethtool_set_features(int *fd, const char *ifname, int *features) { struct ifreq ifr = {}; if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); @@ -599,9 +600,9 @@ int ethtool_set_glinksettings( } if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); @@ -654,9 +655,9 @@ int ethtool_set_channels(int *fd, const char *ifname, netdev_channels *channels) int r; if (*fd < 0) { - r = ethtool_connect(fd); + r = ethtool_connect_or_warn(fd, true); if (r < 0) - return log_warning_errno(r, "ethtool: could not connect to ethtool: %m"); + return r; } strscpy(ifr.ifr_name, IFNAMSIZ, ifname); diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h index 5e26989..cbbe041 100644 --- a/src/shared/ethtool-util.h +++ b/src/shared/ethtool-util.h @@ -79,8 +79,6 @@ typedef struct netdev_channels { bool combined_count_set; } netdev_channels; -int ethtool_connect(int *ret); - int ethtool_get_driver(int *fd, const char *ifname, char **ret); int ethtool_set_speed(int *fd, const char *ifname, unsigned speed, Duplex duplex); int ethtool_set_wol(int *fd, const char *ifname, WakeOnLan wol); -- 2.7.4