diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2015-06-14 13:16:47 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@googlemail.com> | 2015-06-14 13:16:47 +0200 |
commit | 485e590a6119bdef0d73449ffa406e7a702cec08 (patch) | |
tree | 243194b5ad7de1234ef88d0eb03a0211af6890fb | |
parent | f3a8f45b2128d0b396f000e8a55943857884ac29 (diff) | |
parent | ce67afb04320c5b94435dd171af68629b54bb7b5 (diff) |
Merge pull request #183 from ssahani/net
Improve tun/tap logging by using the new log_*errno*() functions that set 'errno' explicitly. Also fix a bunch of incorrect errno/r confusions.
-rw-r--r-- | src/network/networkd-netdev-tuntap.c | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/src/network/networkd-netdev-tuntap.c b/src/network/networkd-netdev-tuntap.c index 4e974927cb..378312f091 100644 --- a/src/network/networkd-netdev-tuntap.c +++ b/src/network/networkd-netdev-tuntap.c @@ -69,18 +69,12 @@ static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) { assert(ifr); fd = open(TUN_DEV, O_RDWR); - if (fd < 0) { - log_netdev_error(netdev, "Failed to open tun dev: %m"); - return -errno; - } + if (fd < 0) + return log_netdev_error_errno(netdev, -errno, "Failed to open tun dev: %m"); r = ioctl(fd, TUNSETIFF, ifr); - if (r < 0) { - log_netdev_error(netdev, - "TUNSETIFF failed on tun dev: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, -errno, "TUNSETIFF failed on tun dev: %m"); if (netdev->kind == NETDEV_KIND_TAP) t = TAP(netdev); @@ -94,18 +88,12 @@ static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) { user = t->user_name; r = get_user_creds(&user, &uid, NULL, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Cannot resolve user name %s: %m", - t->user_name); - return 0; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Cannot resolve user name %s: %m", t->user_name); r = ioctl(fd, TUNSETOWNER, uid); - if ( r < 0) { - log_netdev_error(netdev, - "TUNSETOWNER failed on tun dev: %s", - strerror(-r)); - } + if (r < 0) + return log_netdev_error_errno(netdev, -errno, "TUNSETOWNER failed on tun dev: %m"); } if (t->group_name) { @@ -113,29 +101,18 @@ static int netdev_tuntap_add(NetDev *netdev, struct ifreq *ifr) { group = t->group_name; r = get_group_creds(&group, &gid); - if (r < 0) { - log_error_errno(r, "Cannot resolve group name %s: %m", - t->group_name); - return 0; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Cannot resolve group name %s: %m", t->group_name); r = ioctl(fd, TUNSETGROUP, gid); - if( r < 0) { - log_netdev_error(netdev, - "TUNSETGROUP failed on tun dev: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, -errno, "TUNSETGROUP failed on tun dev: %m"); } r = ioctl(fd, TUNSETPERSIST, 1); - if (r < 0) { - log_netdev_error(netdev, - "TUNSETPERSIST failed on tun dev: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, -errno, "TUNSETPERSIST failed on tun dev: %m"); return 0; } |