From 818d1a3aa98121ec2d5339d11dece7bc2f5aa6af Mon Sep 17 00:00:00 2001 From: Gerrit Renker Date: Thu, 25 Feb 2010 17:05:45 +0100 Subject: [PATCH] 09_fix-errno-usage.diff This fixes a bug in the use of errno which corresponds to the 'common mistake' in the use of errno(3): to not save it before making new system calls. Thanks. --- net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net.c b/net.c index d9b3a9de..aeeca20e 100644 --- a/net.c +++ b/net.c @@ -457,10 +457,11 @@ get_next_src: flowopt_cleanup(fo); if (src == NULL && dst == NULL) { + rc = errno; PARA_ERROR_LOG("can not create %s socket %s#%s.\n", layer4_name(l4type), host? host : (passive? "[loopback]" : "[localhost]"), port); - return -ERRNO_TO_PARA_ERROR(errno); + return -ERRNO_TO_PARA_ERROR(rc); } return sockfd; } @@ -491,8 +492,9 @@ int para_listen(unsigned l4type, uint16_t port, struct flowopts *fo) if (fd > 0) { ret = listen(fd, BACKLOG); if (ret < 0) { + ret = errno; close(fd); - return -ERRNO_TO_PARA_ERROR(errno); + return -ERRNO_TO_PARA_ERROR(ret); } PARA_INFO_LOG("listening on %s port %u, fd %d\n", layer4_name(l4type), port, fd); -- 2.39.2