summaryrefslogtreecommitdiff
path: root/usr/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/test')
-rw-r--r--usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg1
-rw-r--r--usr/src/test/libc-tests/tests/Makefile3
-rw-r--r--usr/src/test/libc-tests/tests/c11_threads.c4
-rw-r--r--usr/src/test/libc-tests/tests/call_once.c5
-rw-r--r--usr/src/test/libc-tests/tests/fnmatch.c2
-rw-r--r--usr/src/test/libc-tests/tests/memset_s.c24
-rw-r--r--usr/src/test/libc-tests/tests/printf-6961.c34
-rw-r--r--usr/src/test/libc-tests/tests/select/Makefile3
-rw-r--r--usr/src/test/libc-tests/tests/select/select_test.c18
-rw-r--r--usr/src/test/libc-tests/tests/set_constraint_handler_s.c4
-rw-r--r--usr/src/test/libc-tests/tests/symbols/Makefile3
-rw-r--r--usr/src/test/libc-tests/tests/symbols/symbols_test.c4
-rw-r--r--usr/src/test/os-tests/runfiles/default.run3
-rw-r--r--usr/src/test/os-tests/tests/Makefile14
-rw-r--r--usr/src/test/os-tests/tests/odirectory.c251
15 files changed, 313 insertions, 60 deletions
diff --git a/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg b/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg
index 92806885bc..0a359e92ce 100644
--- a/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg
+++ b/usr/src/test/libc-tests/cfg/symbols/fcntl_h.cfg
@@ -42,6 +42,7 @@ value | O_RDWR | int | fcntl.h | POSIX+ SUS+
value | O_RSYNC | int | fcntl.h | XPG3+ POSIX-1993+
value | O_SYNC | int | fcntl.h | XPG3+ POSIX-1993+
value | O_WRONLY | int | fcntl.h | POSIX+ SUS+
+value | O_DIRECTORY | int | fcntl.h | -ALL SUSv4+
#
# Functions
diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile
index 3342c04bc6..093f42ebc8 100644
--- a/usr/src/test/libc-tests/tests/Makefile
+++ b/usr/src/test/libc-tests/tests/Makefile
@@ -58,9 +58,6 @@ SCRIPTS = \
CPPFLAGS += -D_REENTRANT
-# needs work
-SMOFF += all_func_returns,snprintf_overflow,unreachable
-
PROGS32 = $(PROGS:%=%.32)
PROGS64 = \
$(PROGS:%=%.64) \
diff --git a/usr/src/test/libc-tests/tests/c11_threads.c b/usr/src/test/libc-tests/tests/c11_threads.c
index 4504a9c262..2c7185ce47 100644
--- a/usr/src/test/libc-tests/tests/c11_threads.c
+++ b/usr/src/test/libc-tests/tests/c11_threads.c
@@ -51,10 +51,10 @@ static int
cthr_test_sleep_thr(void *arg)
{
for (;;) {
- sleep(1000);
+ (void) sleep(1000);
}
- abort();
+ return (0);
}
static void
diff --git a/usr/src/test/libc-tests/tests/call_once.c b/usr/src/test/libc-tests/tests/call_once.c
index 8c10420bcd..17a7dcd98a 100644
--- a/usr/src/test/libc-tests/tests/call_once.c
+++ b/usr/src/test/libc-tests/tests/call_once.c
@@ -42,8 +42,9 @@ static int
co_thr(void *arg)
{
VERIFY3S(mtx_lock(&co_mtx), ==, thrd_success);
- while (co_go == B_FALSE)
- cnd_wait(&co_cnd, &co_mtx);
+ while (co_go == B_FALSE) {
+ (void) cnd_wait(&co_cnd, &co_mtx);
+ }
VERIFY3S(mtx_unlock(&co_mtx), ==, thrd_success);
call_once(&co_once, co_once_func);
return (0);
diff --git a/usr/src/test/libc-tests/tests/fnmatch.c b/usr/src/test/libc-tests/tests/fnmatch.c
index ca42d9e904..503ae78d32 100644
--- a/usr/src/test/libc-tests/tests/fnmatch.c
+++ b/usr/src/test/libc-tests/tests/fnmatch.c
@@ -208,7 +208,7 @@ flags_to_string(int flags)
if (p == result)
memcpy(p, "0", 2);
else if (flags != 0)
- sprintf(p, "%d", flags);
+ (void) sprintf(p, "%d", flags);
else
*p = '\0';
return (result);
diff --git a/usr/src/test/libc-tests/tests/memset_s.c b/usr/src/test/libc-tests/tests/memset_s.c
index eb44230d60..e02fef20b2 100644
--- a/usr/src/test/libc-tests/tests/memset_s.c
+++ b/usr/src/test/libc-tests/tests/memset_s.c
@@ -46,33 +46,33 @@ main(void)
char b[3];
/* null ptr */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(memset_s(0, 1, 1, 1) != 0);
/* smax > rmax */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(memset_s(&b, RSIZE_MAX + 1, 1, 1) != 0);
/* smax < 0 */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(memset_s(&a, -1, 1, 1) != 0);
/* normal */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
a = 3;
assert(memset_s(&a, 1, 5, 1) == 0);
assert(a == 5);
/* n > rmax */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(memset_s(&a, 1, 1, RSIZE_MAX + 1) != 0);
/* n < 0 */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(memset_s(&a, 1, 1, -1) != 0);
/* n < smax */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
b[0] = 1; b[1] = 2; b[2] = 3;
assert(memset_s(&b[0], 3, 9, 1) == 0);
assert(b[0] == 9);
@@ -80,7 +80,7 @@ main(void)
assert(b[2] == 3);
/* n > smax, handler */
- set_constraint_handler_s(h);
+ (void) set_constraint_handler_s(h);
e = 0;
m = NULL;
b[0] = 1; b[1] = 2; b[2] = 3;
@@ -92,7 +92,7 @@ main(void)
assert(b[2] == 3);
/* smax > rmax, handler */
- set_constraint_handler_s(h);
+ (void) set_constraint_handler_s(h);
e = 0;
m = NULL;
assert(memset_s(&a, RSIZE_MAX + 1, 1, 1) != 0);
@@ -100,7 +100,7 @@ main(void)
assert(strcmp(m, "memset_s: smax > RSIZE_MAX") == 0);
/* smax < 0, handler */
- set_constraint_handler_s(h);
+ (void) set_constraint_handler_s(h);
e = 0;
m = NULL;
assert(memset_s(&a, -1, 1, 1) != 0);
@@ -108,7 +108,7 @@ main(void)
assert(strcmp(m, "memset_s: smax > RSIZE_MAX") == 0);
/* n > rmax, handler */
- set_constraint_handler_s(h);
+ (void) set_constraint_handler_s(h);
e = 0;
m = NULL;
assert(memset_s(&a, 1, 1, RSIZE_MAX + 1) != 0);
@@ -116,7 +116,7 @@ main(void)
assert(strcmp(m, "memset_s: n > RSIZE_MAX") == 0);
/* n < 0, handler */
- set_constraint_handler_s(h);
+ (void) set_constraint_handler_s(h);
e = 0;
m = NULL;
assert(memset_s(&a, 1, 1, -1) != 0);
diff --git a/usr/src/test/libc-tests/tests/printf-6961.c b/usr/src/test/libc-tests/tests/printf-6961.c
index 5c60b96425..c98c2b6a79 100644
--- a/usr/src/test/libc-tests/tests/printf-6961.c
+++ b/usr/src/test/libc-tests/tests/printf-6961.c
@@ -41,71 +41,71 @@ main(void)
char buf[32];
/* ~0L in octal */
- char octal0[] = { 'r', 'r', 'r', 'r', '1', '7', '7', '7', '7', '7', '7',
+ char octal0[32] = { 'r', 'r', 'r', 'r', '1', '7', '7', '7', '7', '7',
'7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
- '7', '7', '\0', 'r', 'r', 'r', 'r', 'r', 'r' };
+ '7', '7', '7', '\0', 'r', 'r', 'r', 'r', 'r' };
- char decimal0[] = { 'r', 'r', 'r', 'r', '-', '1', '\0', 'r', 'r', 'r',
+ char decimal0[32] = { 'r', 'r', 'r', 'r', '-', '1', '\0', 'r', 'r', 'r',
'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
- 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
+ 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
- char hex0[] = { 'r', 'r', 'r', 'r', 'f', 'f', 'f', 'f', 'f', 'f',
+ char hex0[32] = { 'r', 'r', 'r', 'r', 'f', 'f', 'f', 'f', 'f', 'f',
'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', 'f', '\0', 'r', 'r',
- 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
+ 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
/* 42 in octal */
- char octal1[] = { 'r', 'r', 'r', 'r', '5', '2', '\0', 'r', 'r', 'r',
+ char octal1[32] = { 'r', 'r', 'r', 'r', '5', '2', '\0', 'r', 'r', 'r',
'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
- 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
+ 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
/* 42 in decimal */
- char decimal1[] = { 'r', 'r', 'r', 'r', '4', '2', '\0', 'r', 'r', 'r',
+ char decimal1[32] = { 'r', 'r', 'r', 'r', '4', '2', '\0', 'r', 'r', 'r',
'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
- 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
+ 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
/* 42 in hex */
- char hex1[] = { 'r', 'r', 'r', 'r', '2', 'a', '\0', 'r', 'r', 'r', 'r',
+ char hex1[32] = { 'r', 'r', 'r', 'r', '2', 'a', '\0', 'r', 'r', 'r',
'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r',
'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r' };
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%lo", ~0L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%lo", ~0L);
if (bcmp(octal0, buf, sizeof (buf)) != 0) {
print_diff("~0 in Octal", octal0, buf);
ret++;
}
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%lo", 42L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%lo", 42L);
if (bcmp(octal1, buf, sizeof (buf)) != 0) {
print_diff("42 in Octal", octal1, buf);
ret++;
}
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%ld", ~0L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%ld", ~0L);
if (bcmp(decimal0, buf, sizeof (buf)) != 0) {
print_diff("~0 in Decimal", decimal0, buf);
ret++;
}
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%ld", 42L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%ld", 42L);
if (bcmp(decimal1, buf, sizeof (buf)) != 0) {
print_diff("42 in Decimal", decimal1, buf);
ret++;
}
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%lx", ~0L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%lx", ~0L);
if (bcmp(hex0, buf, sizeof (buf)) != 0) {
print_diff("~0 in Hex", hex0, buf);
ret++;
}
(void) memset(buf, 'r', sizeof (buf));
- (void) snprintf(buf + 4, sizeof (buf), "%lx", 42L);
+ (void) snprintf(buf + 4, sizeof (buf) - 4, "%lx", 42L);
if (bcmp(hex1, buf, sizeof (buf)) != 0) {
print_diff("42 in Hex", hex1, buf);
ret++;
diff --git a/usr/src/test/libc-tests/tests/select/Makefile b/usr/src/test/libc-tests/tests/select/Makefile
index 2b0d80c6d6..ce019e281a 100644
--- a/usr/src/test/libc-tests/tests/select/Makefile
+++ b/usr/src/test/libc-tests/tests/select/Makefile
@@ -25,9 +25,6 @@ PROGS= select_test
CSTD= $(CSTD_GNU99)
-# needs work
-SMOFF += all_func_returns
-
select_test: select_test.c
$(LINK64.c) -o $@ select_test.c $(LDLIBS64)
$(POST_PROCESS)
diff --git a/usr/src/test/libc-tests/tests/select/select_test.c b/usr/src/test/libc-tests/tests/select/select_test.c
index f6af3718cb..2b30df4f5c 100644
--- a/usr/src/test/libc-tests/tests/select/select_test.c
+++ b/usr/src/test/libc-tests/tests/select/select_test.c
@@ -39,12 +39,12 @@ print_set(fd_set *a, size_t size)
{
for (int i = 0; i < size; i++) {
if (FD_ISSET(i, a))
- putc('1', stdout);
+ (void) putc('1', stdout);
else
- putc('0', stdout);
+ (void) putc('0', stdout);
}
- putc('\n', stdout);
+ (void) putc('\n', stdout);
}
int
@@ -85,8 +85,10 @@ main(int argc, char **argv)
if ((null = open("/dev/null", O_RDONLY)) == -1)
err(1, "couldn't open /dev/null");
- read(null, &buf, 1);
- read(null, &buf, 1);
+ if (read(null, &buf, 1) < 0)
+ err(1, "failed to read fd");
+ if (read(null, &buf, 1) < 0)
+ err(1, "failed to read fd");
if ((zero = open("/dev/zero", O_RDWR)) == -1)
err(1, "couldn't open /dev/zero");
@@ -103,11 +105,11 @@ main(int argc, char **argv)
}
if (swrite != NULL)
- puts("write");
+ (void) puts("write");
else if (sread != NULL)
- puts("read");
+ (void) puts("read");
else if (serr != NULL)
- puts("err");
+ (void) puts("err");
print_set(&proto, 80);
diff --git a/usr/src/test/libc-tests/tests/set_constraint_handler_s.c b/usr/src/test/libc-tests/tests/set_constraint_handler_s.c
index 770d5d46a4..1f9d6fe6df 100644
--- a/usr/src/test/libc-tests/tests/set_constraint_handler_s.c
+++ b/usr/src/test/libc-tests/tests/set_constraint_handler_s.c
@@ -33,11 +33,11 @@ main(void)
assert(set_constraint_handler_s(abort_handler_s) == NULL);
/* abort handler */
- set_constraint_handler_s(abort_handler_s);
+ (void) set_constraint_handler_s(abort_handler_s);
assert(set_constraint_handler_s(ignore_handler_s) == abort_handler_s);
/* ignore handler */
- set_constraint_handler_s(ignore_handler_s);
+ (void) set_constraint_handler_s(ignore_handler_s);
assert(set_constraint_handler_s(abort_handler_s) == ignore_handler_s);
return (0);
diff --git a/usr/src/test/libc-tests/tests/symbols/Makefile b/usr/src/test/libc-tests/tests/symbols/Makefile
index ac2ede1092..a5eef8a3a8 100644
--- a/usr/src/test/libc-tests/tests/symbols/Makefile
+++ b/usr/src/test/libc-tests/tests/symbols/Makefile
@@ -50,9 +50,6 @@ EXTRAPROG += $(SYMTESTS)
include ../Makefile.com
-# needs work
-SMOFF += testing_index_after_use
-
LDLIBS += -lcustr
LDLIBS64 += -lcustr
diff --git a/usr/src/test/libc-tests/tests/symbols/symbols_test.c b/usr/src/test/libc-tests/tests/symbols/symbols_test.c
index ac92feb2b6..ca714eb9f2 100644
--- a/usr/src/test/libc-tests/tests/symbols/symbols_test.c
+++ b/usr/src/test/libc-tests/tests/symbols/symbols_test.c
@@ -372,7 +372,7 @@ mkprog(struct sym_test *st)
case SYM_FUNC:
addprogstr("\ntest_func(");
- for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) {
+ for (int i = 0; i < MAXARG && st->st_atypes[i] != NULL; i++) {
int didname = 0;
if (i > 0) {
addprogstr(", ");
@@ -422,7 +422,7 @@ mkprog(struct sym_test *st)
/* add the function call */
addprogfmt("%s(", st->st_name);
- for (int i = 0; st->st_atypes[i] != NULL && i < MAXARG; i++) {
+ for (int i = 0; i < MAXARG && st->st_atypes[i] != NULL; i++) {
if (strcmp(st->st_atypes[i], "") != 0 &&
strcmp(st->st_atypes[i], "void") != 0) {
addprogfmt("%sa%d", i > 0 ? ", " : "", i);
diff --git a/usr/src/test/os-tests/runfiles/default.run b/usr/src/test/os-tests/runfiles/default.run
index 940b9bf97a..795f559c50 100644
--- a/usr/src/test/os-tests/runfiles/default.run
+++ b/usr/src/test/os-tests/runfiles/default.run
@@ -26,6 +26,9 @@ outputdir = /var/tmp/test_results
user = root
tests = ['poll_test', 'epoll_test']
+[/opt/os-tests/tests/odirectory.32]
+[/opt/os-tests/tests/odirectory.64]
+
[/opt/os-tests/tests/secflags]
user = root
tests = ['secflags_aslr',
diff --git a/usr/src/test/os-tests/tests/Makefile b/usr/src/test/os-tests/tests/Makefile
index 3107af540c..a0a5592ef1 100644
--- a/usr/src/test/os-tests/tests/Makefile
+++ b/usr/src/test/os-tests/tests/Makefile
@@ -33,26 +33,30 @@ SUBDIRS = \
$(SUBDIRS_$(MACH))
PROGS = \
+ odirectory \
OS-6097
+CPPFLAGS += -D_REENTRANT
PROGS32 = $(PROGS:%=%.32)
PROGS64 = $(PROGS:%=%.64)
-OS-6097.32 := LDLIBS += -ldlpi
-OS-6097.64 := LDLIBS64 += -ldlpi
-
ROOTOPTDIR = $(ROOT)/opt/os-tests/tests
ROOTOPTPROGS = $(PROGS32:%=$(ROOTOPTDIR)/%) \
$(PROGS64:%=$(ROOTOPTDIR)/%) \
$(SCRIPTS:%=$(ROOTOPTDIR)/%)
+odirectory.32 := LDLIBS += -lsocket
+odirectory.64 := LDLIBS64 += -lsocket
+
+OS-6097.32 := LDLIBS += -ldlpi
+OS-6097.64 := LDLIBS64 += -ldlpi
+
include $(SRC)/cmd/Makefile.cmd
all := TARGET = all
install := TARGET = install
clean := TARGET = clean
clobber := TARGET = clobber
-lint := TARGET = lint
.KEEP_STATE:
@@ -60,7 +64,7 @@ install: $(SUBDIRS) $(ROOTOPTPROGS)
all: $(SUBDIRS) $(PROGS32) $(PROGS64)
-clean lint: $(SUBDIRS)
+clean: $(SUBDIRS)
$(ROOTOPTPROGS): $(PROGS32) $(PROGS64) $(ROOTOPTDIR)
diff --git a/usr/src/test/os-tests/tests/odirectory.c b/usr/src/test/os-tests/tests/odirectory.c
new file mode 100644
index 0000000000..e994126227
--- /dev/null
+++ b/usr/src/test/os-tests/tests/odirectory.c
@@ -0,0 +1,251 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2020 Robert Mustacchi
+ */
+
+/*
+ * Test different O_DIRECTORY open cases.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <err.h>
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <door.h>
+#include <stropts.h>
+#include <sys/socket.h>
+
+static uint_t odir_failures;
+static char odir_fpath[PATH_MAX];
+static char odir_dpath[PATH_MAX];
+static char odir_doorpath[PATH_MAX];
+static char odir_enoent[PATH_MAX];
+static char odir_udspath[PATH_MAX];
+static int odir_did = -1;
+static int odir_uds = -1;
+
+static void
+odir_test_one(const char *test, const char *path, int flags, int err)
+{
+ int fd = open(path, flags | O_DIRECTORY | O_RDONLY, 0644);
+ if (fd >= 0) {
+ (void) close(fd);
+ if (err != 0) {
+ odir_failures++;
+ warnx("TEST FAILED: %s: opened %s, but expected error: "
+ "%d", test, path, err);
+ }
+ } else {
+ if (err == 0) {
+ odir_failures++;
+ warnx("TEST FAILED: %s: failed to open %s, error: %d",
+ test, path, err);
+ } else if (err != errno) {
+ odir_failures++;
+ warnx("TEST FAILED: %s: wrong error for path %s, "
+ "found %d, expected %d", test, path, errno, err);
+ }
+ }
+}
+
+static void
+odir_door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp,
+ uint_t ndesc)
+{
+ (void) door_return(NULL, 0, NULL, 0);
+}
+
+static boolean_t
+odir_setup(void)
+{
+ int fd;
+ struct stat st;
+ struct sockaddr_un un;
+ pid_t pid = getpid();
+
+ (void) snprintf(odir_fpath, sizeof (odir_fpath),
+ "/tmp/odir.%d.file", pid);
+ if ((fd = creat(odir_fpath, 0644)) < 0) {
+ warn("failed to create temp file %s", odir_fpath);
+ odir_fpath[0] = '\0';
+ return (B_FALSE);
+ }
+ (void) close(fd);
+
+ (void) snprintf(odir_dpath, sizeof (odir_dpath),
+ "/tmp/odir.%d.dir", pid);
+ if (mkdir(odir_dpath, 0755) != 0) {
+ warn("failed to create temp directory %s", odir_dpath);
+ odir_dpath[0] = '\0';
+ return (B_FALSE);
+ }
+
+ odir_did = door_create(odir_door_server, NULL, 0);
+ if (odir_did == -1) {
+ warnx("failed to create door");
+ return (B_FALSE);
+ }
+ (void) snprintf(odir_doorpath, sizeof (odir_doorpath),
+ "/tmp/odir.%d.door", pid);
+ if ((fd = creat(odir_doorpath, 0644)) < 0) {
+ warn("failed to create %s", odir_doorpath);
+ odir_doorpath[0] = '\0';
+ return (B_FALSE);
+ }
+ (void) close(fd);
+ if (fattach(odir_did, odir_doorpath) != 0) {
+ warn("failed to attach door to %s", odir_doorpath);
+ (void) unlink(odir_doorpath);
+ odir_doorpath[0] = '\0';
+ return (B_FALSE);
+ }
+
+ (void) snprintf(odir_enoent, sizeof (odir_enoent),
+ "/tmp/odir.%d.enoent", pid);
+ if (stat(odir_enoent, &st) == 0) {
+ warnx("somehow random file %s exists!", odir_enoent);
+ }
+
+ odir_uds = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (odir_uds == -1) {
+ warn("failed to create UDS");
+ return (B_FALSE);
+ }
+ (void) snprintf(odir_udspath, sizeof (odir_udspath),
+ "/tmp/odir.%d.uds", pid);
+ (void) memset(&un, '\0', sizeof (un));
+ un.sun_family = AF_UNIX;
+ if (strlcpy(un.sun_path, odir_udspath, sizeof (un.sun_path)) >=
+ sizeof (un.sun_path)) {
+ warnx("%s overflows AF_UNIX path", odir_udspath);
+ odir_udspath[0] = '\0';
+ return (B_FALSE);
+ }
+
+ if (bind(odir_uds, (struct sockaddr *)&un, SUN_LEN(&un)) != 0) {
+ warn("failed to bind %s", odir_udspath);
+ odir_udspath[0] = '\0';
+ return (B_FALSE);
+ }
+
+ if (listen(odir_uds, 1) != 0) {
+ warn("failed to listen on %s", odir_udspath);
+ return (B_FALSE);
+ }
+
+ return (B_TRUE);
+}
+
+static void
+odir_verify_enoent(void)
+{
+ struct stat st;
+
+ if (stat(odir_enoent, &st) == 0) {
+ warnx("TEST FAILED: %s was created", odir_enoent);
+ odir_failures++;
+ } else if (errno != ENOENT) {
+ warn("TEST FAILED: stat on %s failed", odir_enoent);
+ odir_failures++;
+ }
+}
+
+static void
+odir_cleanup(void)
+{
+ if (odir_udspath[0] != '\0') {
+ if (unlink(odir_udspath) != 0) {
+ warn("failed to unlink %s", odir_udspath);
+ }
+ }
+
+ if (odir_uds != -1) {
+ if (close(odir_uds) != 0) {
+ warn("failed to close UDS");
+ }
+ }
+
+ if (odir_doorpath[0] != '\0') {
+ if (fdetach(odir_doorpath) != 0) {
+ warn("failed to detach door %s", odir_doorpath);
+ }
+
+ if (unlink(odir_doorpath) != 0) {
+ warn("failed to unlink %s", odir_doorpath);
+ }
+ }
+
+ if (odir_did != -1) {
+ if (door_revoke(odir_did) != 0) {
+ warn("failed to revoke door");
+ }
+ }
+
+ if (odir_dpath[0] != '\0') {
+ if (rmdir(odir_dpath) != 0) {
+ warn("failed to clean up %s", odir_dpath);
+ }
+ }
+
+ if (odir_fpath[0] != '\0') {
+ if (unlink(odir_fpath) != 0) {
+ warn("failed to clean up %s", odir_fpath);
+ }
+ }
+}
+
+int
+main(void)
+{
+ if (!odir_setup()) {
+ odir_cleanup();
+ return (EXIT_FAILURE);
+ }
+
+ odir_test_one("regular file", odir_fpath, 0, ENOTDIR);
+ odir_test_one("directory", odir_dpath, 0, 0);
+ odir_test_one("character device", "/dev/null", 0, ENOTDIR);
+ odir_test_one("door server", odir_doorpath, 0, ENOTDIR);
+ odir_test_one("missing file", odir_enoent, 0, ENOENT);
+ odir_test_one("UDS", odir_udspath, 0, ENOTDIR);
+
+ odir_test_one("O_CREAT | O_DIRECTORY on a regular file", odir_fpath,
+ O_CREAT, ENOTDIR);
+ odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a regular file",
+ odir_fpath, O_CREAT | O_EXCL, EINVAL);
+
+ odir_test_one("O_CREAT | O_DIRECTORY on a directory", odir_dpath,
+ O_CREAT, 0);
+ odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a directory",
+ odir_dpath, O_CREAT | O_EXCL, EINVAL);
+
+ odir_test_one("O_CREAT | O_DIRECTORY on a missing file", odir_enoent,
+ O_CREAT, ENOENT);
+ odir_verify_enoent();
+ odir_test_one("O_CREAT | O_DIRECTORY | O_EXCL on a missing file",
+ odir_enoent, O_CREAT | O_EXCL, EINVAL);
+ odir_verify_enoent();
+
+ odir_cleanup();
+ if (odir_failures > 0) {
+ warnx("%u tests failed", odir_failures);
+ }
+
+ return (odir_failures > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
+}