diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-06-12 14:37:36 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-06-12 14:37:36 +0200 |
commit | a936783e1728c28d9cb690a750792d0e08c6a422 (patch) | |
tree | 56c6428357e86536fe298821d1e6f8f55b13129e /ioops.c | |
parent | dfb45a7ac75d17c3a8421bfb53840d6db271a121 (diff) |
ioops: mark failure path as unlikely
Just tell GCC that those paths are unexpected.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'ioops.c')
-rw-r--r-- | ioops.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -17,16 +17,15 @@ int open_or_die(const char *file, int flags) { int ret = open(file, flags); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot open file %s! %s.\n", file, strerror(errno)); - return ret; } int open_or_die_m(const char *file, int flags, mode_t mode) { int ret = open(file, flags, mode); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot open or create file %s! %s.", file, strerror(errno)); return ret; } @@ -55,7 +54,7 @@ void create_or_die(const char *file, mode_t mode) void pipe_or_die(int pipefd[2], int flags) { int ret = pipe2(pipefd, flags); - if (ret < 0) + if (unlikely(ret < 0)) panic("Cannot create pipe2 event fd! %s.\n", strerror(errno)); } @@ -65,7 +64,7 @@ int tun_open_or_die(char *name, int type) short flags; struct ifreq ifr; - if (!name) + if (unlikely(!name)) panic("No name provided for tundev!\n"); fd = open_or_die("/dev/net/tun", O_RDWR); @@ -75,11 +74,11 @@ int tun_open_or_die(char *name, int type) strlcpy(ifr.ifr_name, name, IFNAMSIZ); ret = ioctl(fd, TUNSETIFF, &ifr); - if (ret < 0) + if (unlikely(ret < 0)) panic("ioctl screwed up! %s.\n", strerror(errno)); ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); - if (ret < 0) + if (unlikely(ret < 0)) panic("fctnl screwed up! %s.\n", strerror(errno)); flags = device_get_flags(name); @@ -92,7 +91,7 @@ int tun_open_or_die(char *name, int type) ssize_t read_or_die(int fd, void *buf, size_t len) { ssize_t ret = read(fd, buf, len); - if (ret < 0) { + if (unlikely(ret < 0)) { if (errno == EPIPE) die(); panic("Cannot read from descriptor! %s.\n", strerror(errno)); @@ -104,7 +103,7 @@ ssize_t read_or_die(int fd, void *buf, size_t len) ssize_t write_or_die(int fd, const void *buf, size_t len) { ssize_t ret = write(fd, buf, len); - if (ret < 0) { + if (unlikely(ret < 0)) { if (errno == EPIPE) die(); panic("Cannot write to descriptor! %s.", strerror(errno)); |