[v9_9] isc_errno_toresult()

4445.	[cleanup]	isc_errno_toresult() can now be used to call the
			formerly private function isc__errno2result().
			[RT #43050]

(cherry picked from commit ddef16e1d9)
This commit is contained in:
Evan Hunt 2016-08-17 11:31:57 -07:00
parent 69d239f1c9
commit 65e144e0de
19 changed files with 261 additions and 32 deletions

View file

@ -1,3 +1,7 @@
4445. [cleanup] isc_errno_toresult() can now be used to call the
formerly private function isc__errno2result().
[RT #43050]
4443. [func] Set TCP_MAXSEG in addition to IPV6_USE_MIN_MTU on
TCP sockets. [RT #42864]

View file

@ -131,3 +131,12 @@ key "mykey" {
algorithm "hmac-md5";
secret "qwertyuiopasdfgh";
};
dyndb "name" "library.so" {
this;
\};
is a {
"test" { \{ of; the; };
} bracketed;
"text \"";
system;
};

View file

@ -31,7 +31,7 @@ CWARNINGS =
# Alphabetically
UNIXOBJS = @ISC_ISCIPV6_O@ \
unix/app.@O@ unix/dir.@O@ unix/entropy.@O@ \
unix/app.@O@ unix/dir.@O@ unix/entropy.@O@ unix/errno.@O@ \
unix/errno2result.@O@ unix/file.@O@ unix/fsaccess.@O@ \
unix/interfaceiter.@O@ unix/keyboard.@O@ unix/net.@O@ \
unix/os.@O@ unix/resource.@O@ unix/socket.@O@ unix/stdio.@O@ \
@ -43,8 +43,9 @@ THREADOPTOBJS = @ISC_THREAD_DIR@/condition.@O@ @ISC_THREAD_DIR@/mutex.@O@
THREADOBJS = @THREADOPTOBJS@ @ISC_THREAD_DIR@/thread.@O@
WIN32OBJS = win32/condition.@O@ win32/dir.@O@ win32/file.@O@ \
win32/fsaccess.@O@ win32/once.@O@ win32/stdtime.@O@ \
WIN32OBJS = win32/condition.@O@ win32/dir.@O@ win32/errno.@O@ \
win32/file.@O@ win32/fsaccess.@O@ \
win32/once.@O@ win32/stdtime.@O@ \
win32/thread.@O@ win32/time.@O@
# Alphabetically

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef ISC_ERRNO_H
#define ISC_ERRNO_H 1
/*! \file isc/file.h */
#include <isc/types.h>
ISC_LANG_BEGINDECLS
isc_result_t
isc_errno_toresult(int err);
/*!<
* \brief Convert a POSIX errno value to an ISC result code.
*/
ISC_LANG_ENDDECLS
#endif /* ISC_ERRNO_H */

View file

@ -39,7 +39,7 @@ SRCS = isctest.c taskpool_test.c socket_test.c hash_test.c \
lex_test.c radix_test.c \
sockaddr_test.c symtab_test.c task_test.c queue_test.c \
parse_test.c pool_test.c print_test.c regex_test.c \
safe_test.c time_test.c counter_test.c
safe_test.c time_test.c counter_test.c errno_test.c
SUBDIRS =
TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
@ -47,7 +47,8 @@ TARGETS = taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
sockaddr_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
print_test@EXEEXT@ regex_test@EXEEXT@ socket_test@EXEEXT@ \
safe_test@EXEEXT@ time_test@EXEEXT@ counter_test@EXEEXT@
safe_test@EXEEXT@ time_test@EXEEXT@ counter_test@EXEEXT@ \
errno_test@EXEEXT@
@BIND9_MAKE_RULES@
@ -116,6 +117,10 @@ counter_test@EXEEXT@: counter_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
counter_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
errno_test@EXEEXT@: errno_test.@O@ ${ISCDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
errno_test.@O@ ${ISCLIBS} ${LIBS}
unit::
sh ${top_srcdir}/unit/unittest.sh

100
lib/isc/tests/errno_test.c Normal file
View file

@ -0,0 +1,100 @@
/*
* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config.h>
#include <stdio.h>
#include <sys/errno.h>
#include <atf-c.h>
#include <isc/errno.h>
#include <isc/result.h>
typedef struct {
int err;
isc_result_t result;
} testpair_t;
testpair_t testpair[] = {
{ EPERM, ISC_R_NOPERM },
{ ENOENT, ISC_R_FILENOTFOUND },
{ EIO, ISC_R_IOERROR },
{ EBADF, ISC_R_INVALIDFILE },
{ ENOMEM, ISC_R_NOMEMORY },
{ EACCES, ISC_R_NOPERM },
{ EEXIST, ISC_R_FILEEXISTS },
{ ENOTDIR, ISC_R_INVALIDFILE },
{ EINVAL, ISC_R_INVALIDFILE },
{ ENFILE, ISC_R_TOOMANYOPENFILES },
{ EMFILE, ISC_R_TOOMANYOPENFILES },
{ EPIPE, ISC_R_CONNECTIONRESET },
{ ENAMETOOLONG, ISC_R_INVALIDFILE },
{ ELOOP, ISC_R_INVALIDFILE },
#ifdef EAFNOSUPPORT
{ EAFNOSUPPORT, ISC_R_FAMILYNOSUPPORT },
#endif
#ifdef EADDRINUSE
{ EADDRINUSE, ISC_R_ADDRINUSE },
#endif
{ EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL },
#ifdef ENETDOWN
{ ENETDOWN, ISC_R_NETDOWN },
#endif
#ifdef ENETUNREACH
{ ENETUNREACH, ISC_R_NETUNREACH },
#endif
#ifdef ECONNABORTED
{ ECONNABORTED, ISC_R_CONNECTIONRESET },
#endif
#ifdef ECONNRESET
{ ECONNRESET, ISC_R_CONNECTIONRESET },
#endif
#ifdef ENOBUFS
{ ENOBUFS, ISC_R_NORESOURCES },
#endif
#ifdef ENOTCONN
{ ENOTCONN, ISC_R_NOTCONNECTED },
#endif
#ifdef ETIMEDOUT
{ ETIMEDOUT, ISC_R_TIMEDOUT },
#endif
{ ECONNREFUSED, ISC_R_CONNREFUSED },
#ifdef EHOSTDOWN
{ EHOSTDOWN, ISC_R_HOSTDOWN },
#endif
#ifdef EHOSTUNREACH
{ EHOSTUNREACH, ISC_R_HOSTUNREACH },
#endif
{ 0, ISC_R_UNEXPECTED }
};
ATF_TC(isc_errno_toresult);
ATF_TC_HEAD(isc_errno_toresult, tc) {
atf_tc_set_md_var(tc, "descr", "convert errno to ISC result");
}
ATF_TC_BODY(isc_errno_toresult, tc) {
isc_result_t result, expect;
size_t i;
for (i = 0; i < sizeof(testpair)/sizeof(testpair[0]); i++) {
result = isc_errno_toresult(testpair[i].err);
expect = testpair[i].result;
ATF_CHECK(result == expect);
}
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_errno_toresult);
return (atf_no_error());
}

View file

@ -13,8 +13,6 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id: Makefile.in,v 1.44 2009/12/05 23:31:41 each Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@ -30,14 +28,15 @@ CWARNINGS =
# Alphabetically
OBJS = @ISC_IPV6_O@ \
app.@O@ dir.@O@ entropy.@O@ errno2result.@O@ file.@O@ \
fsaccess.@O@ interfaceiter.@O@ keyboard.@O@ net.@O@ \
app.@O@ dir.@O@ entropy.@O@ errno.@O@ errno2result.@O@ \
file.@O@ fsaccess.@O@ interfaceiter.@O@ \
keyboard.@O@ net.@O@ \
os.@O@ resource.@O@ socket.@O@ stdio.@O@ stdtime.@O@ \
strerror.@O@ syslog.@O@ time.@O@
# Alphabetically
SRCS = @ISC_IPV6_C@ \
app.c dir.c entropy.c errno2result.c file.c \
app.c dir.c entropy.c errno.c errno2result.c file.c \
fsaccess.c interfaceiter.c keyboard.c net.c \
os.c resource.c socket.c stdio.c stdtime.c \
strerror.c syslog.c time.c

21
lib/isc/unix/errno.c Normal file
View file

@ -0,0 +1,21 @@
/*
* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include <isc/errno.h>
#include <isc/util.h>
#include "errno2result.h"
isc_result_t
isc_errno_toresult(int err) {
return (isc___errno2result(err, ISC_FALSE, 0, 0));
}

View file

@ -34,7 +34,9 @@
* not already there.
*/
isc_result_t
isc___errno2result(int posixerrno, const char *file, unsigned int line) {
isc___errno2result(int posixerrno, isc_boolean_t dolog,
const char *file, unsigned int line)
{
char strbuf[ISC_STRERRORSIZE];
switch (posixerrno) {
@ -107,10 +109,12 @@ isc___errno2result(int posixerrno, const char *file, unsigned int line) {
case ECONNREFUSED:
return (ISC_R_CONNREFUSED);
default:
isc__strerror(posixerrno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(file, line, "unable to convert errno "
"to isc_result: %d: %s",
posixerrno, strbuf);
if (dolog) {
isc__strerror(posixerrno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(file, line, "unable to convert errno "
"to isc_result: %d: %s",
posixerrno, strbuf);
}
/*
* XXXDCL would be nice if perhaps this function could
* return the system's error string, so the caller

View file

@ -15,8 +15,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id$ */
#ifndef UNIX_ERRNO2RESULT_H
#define UNIX_ERRNO2RESULT_H 1
@ -31,10 +29,11 @@
ISC_LANG_BEGINDECLS
#define isc__errno2result(x) isc___errno2result(x, __FILE__, __LINE__)
#define isc__errno2result(x) isc___errno2result(x, ISC_TRUE, __FILE__, __LINE__)
isc_result_t
isc___errno2result(int posixerrno, const char *file, unsigned int line);
isc___errno2result(int posixerrno, isc_boolean_t dolog,
const char *file, unsigned int line);
ISC_LANG_ENDDECLS

View file

@ -13,8 +13,6 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id: Makefile.in,v 1.14 2009/12/05 23:31:41 each Exp $
srcdir = @srcdir@
VPATH = @srcdir@
top_srcdir = @top_srcdir@
@ -27,11 +25,11 @@ CDEFINES =
CWARNINGS =
# Alphabetically
OBJS = condition.@O@ dir.@O@ file.@O@ fsaccess.@O@ once.@O@ \
stdtime.@O@ thread.@O@ time.@O@
OBJS = condition.@O@ dir.@O@ errno.@O@ file.@O@ fsaccess.@O@ \
once.@O@ stdtime.@O@ thread.@O@ time.@O@
# Alphabetically
SRCS = condition.c dir.c file.c once.c fsaccess.c \
SRCS = condition.c dir.c errno.c file.c once.c fsaccess.c \
stdtime.c thread.c time.c
SUBDIRS = include

18
lib/isc/win32/errno.c Normal file
View file

@ -0,0 +1,18 @@
/*
* Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \file */
#include <config.h>
#include "errno2result.h"
isc_result_t
isc_errno_toresult(int err) {
return (isc__errno2resultx(err, ISC_FALSE, 0, 0));
}

View file

@ -32,7 +32,9 @@
* not already there.
*/
isc_result_t
isc__errno2resultx(int posixerrno, const char *file, int line) {
isc__errno2resultx(int posixerrno, isc_boolean_t dolog,
const char *file, int line)
{
char strbuf[ISC_STRERRORSIZE];
switch (posixerrno) {
@ -99,9 +101,13 @@ isc__errno2resultx(int posixerrno, const char *file, int line) {
case WSAENOBUFS:
return (ISC_R_NORESOURCES);
default:
isc__strerror(posixerrno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(file, line, "unable to convert errno "
"to isc_result: %d: %s", posixerrno, strbuf);
if (dolog) {
isc__strerror(posixerrno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(file, line,
"unable to convert errno "
"to isc_result: %d: %s",
posixerrno, strbuf);
}
/*
* XXXDCL would be nice if perhaps this function could
* return the system's error string, so the caller

View file

@ -30,10 +30,11 @@
ISC_LANG_BEGINDECLS
#define isc__errno2result(posixerrno) \
isc__errno2resultx(posixerrno, __FILE__, __LINE__)
isc__errno2resultx(posixerrno, ISC_TRUE, __FILE__, __LINE__)
isc_result_t
isc__errno2resultx(int posixerrno, const char *file, int line);
isc__errno2resultx(int posixerrno, isc_boolean_t dolog,
const char *file, int line);
ISC_LANG_ENDDECLS

View file

@ -113,6 +113,10 @@ SOURCE=.\entropy.c
# End Source File
# Begin Source File
SOURCE=.\errno.c
# End Source File
# Begin Source File
SOURCE=.\errno2result.c
# End Source File
# Begin Source File
@ -269,6 +273,10 @@ SOURCE=..\include\isc\entropy.h
# End Source File
# Begin Source File
SOURCE=..\include\isc\errno.h
# End Source File
# Begin Source File
SOURCE=.\errno2result.h
# End Source File
# Begin Source File

View file

@ -129,6 +129,7 @@ CLEAN :
-@erase "$(INTDIR)\dir.obj"
-@erase "$(INTDIR)\DLLMain.obj"
-@erase "$(INTDIR)\entropy.obj"
-@erase "$(INTDIR)\errno.obj"
-@erase "$(INTDIR)\errno2result.obj"
-@erase "$(INTDIR)\error.obj"
-@erase "$(INTDIR)\event.obj"
@ -221,6 +222,7 @@ LINK32_OBJS= \
"$(INTDIR)\dir.obj" \
"$(INTDIR)\DLLMain.obj" \
"$(INTDIR)\entropy.obj" \
"$(INTDIR)\errno.obj" \
"$(INTDIR)\errno2result.obj" \
"$(INTDIR)\file.obj" \
"$(INTDIR)\fsaccess.obj" \
@ -347,6 +349,8 @@ CLEAN :
-@erase "$(INTDIR)\DLLMain.sbr"
-@erase "$(INTDIR)\entropy.obj"
-@erase "$(INTDIR)\entropy.sbr"
-@erase "$(INTDIR)\errno.obj"
-@erase "$(INTDIR)\errno.sbr"
-@erase "$(INTDIR)\errno2result.obj"
-@erase "$(INTDIR)\errno2result.sbr"
-@erase "$(INTDIR)\error.obj"
@ -505,6 +509,7 @@ BSC32_SBRS= \
"$(INTDIR)\dir.sbr" \
"$(INTDIR)\DLLMain.sbr" \
"$(INTDIR)\entropy.sbr" \
"$(INTDIR)\errno.sbr" \
"$(INTDIR)\errno2result.sbr" \
"$(INTDIR)\file.sbr" \
"$(INTDIR)\fsaccess.sbr" \
@ -598,6 +603,7 @@ LINK32_OBJS= \
"$(INTDIR)\dir.obj" \
"$(INTDIR)\DLLMain.obj" \
"$(INTDIR)\entropy.obj" \
"$(INTDIR)\errno.obj" \
"$(INTDIR)\errno2result.obj" \
"$(INTDIR)\file.obj" \
"$(INTDIR)\fsaccess.obj" \
@ -805,6 +811,23 @@ SOURCE=.\entropy.c
!ENDIF
SOURCE=.\errno.c
!IF "$(CFG)" == "libisc - @PLATFORM@ Release"
"$(INTDIR)\errno.obj" : $(SOURCE) "$(INTDIR)"
!ELSEIF "$(CFG)" == "libisc - @PLATFORM@ Debug"
"$(INTDIR)\errno.obj" "$(INTDIR)\errno.sbr" : $(SOURCE) "$(INTDIR)"
!ENDIF
SOURCE=.\errno2result.c
!IF "$(CFG)" == "libisc - @PLATFORM@ Release"

View file

@ -65,6 +65,9 @@
<ClInclude Include="..\include\isc\entropy.h">
<Filter>Library Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\isc\errno.h">
<Filter>Library Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\isc\error.h">
<Filter>Library Header Files</Filter>
</ClInclude>
@ -371,6 +374,9 @@
<ClCompile Include="entropy.c">
<Filter>Win32 Source Files</Filter>
</ClCompile>
<ClCompile Include="errno.c">
<Filter>Win32 Source Files</Filter>
</ClCompile>
<ClCompile Include="errno2result.c">
<Filter>Win32 Source Files</Filter>
</ClCompile>

View file

@ -281,6 +281,7 @@ copy InstallFiles ..\Build\Release\
<ClInclude Include="..\include\isc\commandline.h" />
<ClInclude Include="..\include\isc\counter.h" />
<ClInclude Include="..\include\isc\entropy.h" />
<ClInclude Include="..\include\isc\errno.h" />
<ClInclude Include="..\include\isc\error.h" />
<ClInclude Include="..\include\isc\event.h" />
<ClInclude Include="..\include\isc\eventclass.h" />
@ -443,6 +444,7 @@ copy InstallFiles ..\Build\Release\
<ClCompile Include="dir.c" />
<ClCompile Include="DLLMain.c" />
<ClCompile Include="entropy.c" />
<ClCompile Include="errno.c" />
<ClCompile Include="errno2result.c" />
<ClCompile Include="file.c" />
<ClCompile Include="fsaccess.c" />

View file

@ -2473,7 +2473,7 @@ SocketIoThread(LPVOID ThreadContext) {
* Did the I/O operation complete?
*/
errstatus = GetLastError();
isc_result = isc__errno2resultx(errstatus, __FILE__, __LINE__);
isc_result = isc__errno2result(errstatus);
LOCK(&sock->lock);
CONSISTENT(sock);
@ -2525,7 +2525,7 @@ SocketIoThread(LPVOID ThreadContext) {
goto wait_again;
} else {
errstatus = GetLastError();
isc_result = isc__errno2resultx(errstatus, __FILE__, __LINE__);
isc_result = isc__errno2result(errstatus);
socket_log(__LINE__, sock, NULL, EVENT, NULL, 0, 0,
"restart_accept() failed: errstatus=%d isc_result=%d",
errstatus, isc_result);