summaryrefslogtreecommitdiff
path: root/regress/sys/kern
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-06 04:43:02 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-06 04:43:02 +0000
commit40495568bbb0751160a1e89710b8fe17aace1357 (patch)
tree5859d2be17b3381daee2454cd5969724c04214db /regress/sys/kern
parent48f0c4d99fa1f45a0662bbfdca2eaabab685d4f3 (diff)
Add regress for errno returns of failed fchdir()s
Diffstat (limited to 'regress/sys/kern')
-rw-r--r--regress/sys/kern/Makefile3
-rw-r--r--regress/sys/kern/fchdir/Makefile5
-rw-r--r--regress/sys/kern/fchdir/fchdir.c53
3 files changed, 60 insertions, 1 deletions
diff --git a/regress/sys/kern/Makefile b/regress/sys/kern/Makefile
index 7953d87ca37..1998e693260 100644
--- a/regress/sys/kern/Makefile
+++ b/regress/sys/kern/Makefile
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile,v 1.55 2011/07/05 23:14:19 claudio Exp $
+# $OpenBSD: Makefile,v 1.56 2011/07/06 04:43:01 guenther Exp $
SUBDIR+= __syscall accept dup2 dup2_self exec_self execve exit extent
+SUBDIR+= fchdir
SUBDIR+= fcntl_dup
SUBDIR+= flock
SUBDIR+= getpeereid getrusage gettimeofday itimer
diff --git a/regress/sys/kern/fchdir/Makefile b/regress/sys/kern/fchdir/Makefile
new file mode 100644
index 00000000000..9c2cf3d3c1c
--- /dev/null
+++ b/regress/sys/kern/fchdir/Makefile
@@ -0,0 +1,5 @@
+# $OpenBSD: Makefile,v 1.1 2011/07/06 04:43:01 guenther Exp $
+
+PROG= fchdir
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/fchdir/fchdir.c b/regress/sys/kern/fchdir/fchdir.c
new file mode 100644
index 00000000000..311bf57cbe6
--- /dev/null
+++ b/regress/sys/kern/fchdir/fchdir.c
@@ -0,0 +1,53 @@
+/* $OpenBSD: fchdir.c,v 1.1 2011/07/06 04:43:01 guenther Exp $
+/*
+ * Written by Philip Guenther <guenther@openbsd.org> 2011 Public Domain.
+ *
+ * Verify errno returns from fchdir()
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+ int fds[2];
+ int fd;
+
+ if ((fd = open("/etc/passwd", O_RDONLY)) == -1)
+ err(1, "open");
+ if (fchdir(fd) == 0)
+ errx(1, "fchdir file succeeded");
+ if (errno != ENOTDIR)
+ err(1, "fchdir file: wrong errno");
+ close(fd);
+
+ if (pipe(fds))
+ err(1, "pipe");
+ if (fchdir(fds[0]) == 0)
+ errx(1, "fchdir pipe succeeded");
+ if (errno != ENOTDIR)
+ err(1, "fchdir pipe: wrong errno");
+ close(fds[0]);
+ close(fds[1]);
+
+ if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+ err(1, "socket");
+ if (fchdir(fd) == 0)
+ errx(1, "fchdir socket succeeded");
+ if (errno != ENOTDIR)
+ err(1, "fchdir socket: wrong errno");
+ close(fd);
+
+ if (fchdir(fd) == 0)
+ errx(1, "fchdir bad fd succeeded");
+ if (errno != EBADF)
+ err(1, "fchdir bad fd: wrong errno");
+
+ return 0;
+}