From: Amitay Isaacs Date: Tue, 10 Jul 2018 07:38:42 +0000 (+1000) Subject: ctdb-tests: Add errno matching utility X-Git-Tag: ldb-1.5.0~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af8c31ead80d6c74b0e9d057cb47dff6552178a9;p=thirdparty%2Fsamba.git ctdb-tests: Add errno matching utility BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- diff --git a/ctdb/tests/src/errcode.c b/ctdb/tests/src/errcode.c new file mode 100644 index 00000000000..90853624add --- /dev/null +++ b/ctdb/tests/src/errcode.c @@ -0,0 +1,189 @@ +/* + Portability layer for error codes + + Copyright (C) Amitay Isaacs 2018 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +/* + * These errors are as listed in POSIX standard + * IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) + * + * Error codes marked obsolete are removed (ENODATA, ENOSR, ENOSTR, ETIME) + */ + +#include "replace.h" + +struct { + const char *label; + int code; +} err_codes[] = { + { "E2BIG", E2BIG }, + + { "EACCES", EACCES }, + { "EADDRINUSE", EADDRINUSE }, + { "EADDRNOTAVAIL", EADDRNOTAVAIL }, + { "EAFNOSUPPORT", EAFNOSUPPORT }, + { "EAGAIN", EAGAIN }, + { "EALREADY", EALREADY }, + + { "EBADF", EBADF }, + { "EBADMSG", EBADMSG }, + { "EBUSY", EBUSY }, + + { "ECANCELED", ECANCELED }, + { "ECHILD", ECHILD }, + { "ECONNABORTED", ECONNABORTED }, + { "ECONNREFUSED", ECONNREFUSED }, + { "ECONNRESET", ECONNRESET }, + + { "EDEADLK", EDEADLK }, + { "EDESTADDRREQ", EDESTADDRREQ }, + { "EDOM", EDOM }, + { "EDQUOT", EDQUOT }, + + { "EEXIST", EEXIST }, + + { "EFAULT", EFAULT }, + { "EFBIG", EFBIG }, + + { "EHOSTUNREACH", EHOSTUNREACH }, + + { "EIDRM", EIDRM }, + { "EILSEQ", EILSEQ }, + { "EINPROGRESS", EINPROGRESS }, + { "EINTR", EINTR }, + { "EINVAL", EINVAL }, + { "EIO", EIO }, + { "EISCONN", EISCONN }, + { "EISDIR", EISDIR }, + + { "ELOOP", ELOOP }, + + { "EMFILE", EMFILE }, + { "EMLINK", EMLINK }, + { "EMSGSIZE", EMSGSIZE }, + { "EMULTIHOP", EMULTIHOP }, + + { "ENAMETOOLONG", ENAMETOOLONG }, + { "ENETDOWN", ENETDOWN }, + { "ENETRESET", ENETRESET }, + { "ENETUNREACH", ENETUNREACH }, + { "ENFILE", ENFILE }, + { "ENOBUFS", ENOBUFS }, + { "ENODEV", ENODEV }, + { "ENOENT", ENOENT }, + { "ENOEXEC", ENOEXEC }, + { "ENOLCK", ENOLCK }, + { "ENOLINK", ENOLINK }, + { "ENOMEM", ENOMEM }, + { "ENOMSG", ENOMSG }, + { "ENOPROTOOPT", ENOPROTOOPT }, + { "ENOSPC", ENOSPC }, + { "ENOSYS", ENOSYS }, + { "ENOTCONN", ENOTCONN }, + { "ENOTDIR", ENOTDIR }, + { "ENOTEMPTY", ENOTEMPTY }, + { "ENOTSOCK", ENOTSOCK }, + { "ENOTSUP", ENOTSUP }, + { "ENOTTY", ENOTTY }, + { "ENXIO", ENXIO }, + + { "EOPNOTSUPP", EOPNOTSUPP }, + { "EOVERFLOW", EOVERFLOW }, + + { "EPERM", EPERM }, + { "EPIPE", EPIPE }, + { "EPROTO", EPROTO }, + { "EPROTONOSUPPORT", EPROTONOSUPPORT }, + { "EPROTOTYPE", EPROTOTYPE }, + + { "ERANGE", ERANGE }, + { "EROFS", EROFS }, + + { "ESPIPE", ESPIPE }, + { "ESRCH", ESRCH }, + { "ESTALE", ESTALE }, + + { "ETIMEDOUT", ETIMEDOUT }, + { "ETXTBSY", ETXTBSY }, + + { "EWOULDBLOCK", EWOULDBLOCK }, + + { "EXDEV", EXDEV }, +}; + +static void dump(void) +{ + int i; + + for (i=0; i\n", argv[0]); + exit(1); + } + + if (strcmp(argv[1], "dump") == 0) { + dump(); + } else { + code = strtol(argv[1], &endptr, 0); + if (*endptr == '\0') { + match_code(code); + } else { + match_label(argv[1]); + } + } + + exit(0); +} diff --git a/ctdb/wscript b/ctdb/wscript index 73fd5bd3d00..08c8016dd39 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -842,6 +842,11 @@ def build(bld): for d in ['volatile', 'persistent', 'state']: bld.install_dir(os.path.join(bld.env.CTDB_VARDIR, d)) + bld.SAMBA_BINARY('errcode', + source='tests/src/errcode.c', + deps='replace', + install_path='${CTDB_TEST_LIBEXECDIR}') + # Unit tests ctdb_unit_tests = [ 'db_hash_test',