Subject: lib/5858: regress testing of posix rename
To: None <gnats-bugs@gnats.netbsd.org>
From: Arne H Juul <arnej@math.ntnu.no>
List: netbsd-bugs
Date: 07/27/1998 00:01:11
>Number: 5858
>Category: lib
>Synopsis: regress testing of posix rename
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Jul 26 15:05:00 1998
>Last-Modified:
>Originator: Arne H. Juul
>Organization:
Norwegian Univerisity of Technology and Science
>Release: NetBSD-current as of today
>Environment:
System: NetBSD leon.math.ntnu.no 1.3F NetBSD 1.3F (LEON) #0: Tue Jul 7 23:38:33 CEST 1998 root@leon.math.ntnu.no:/usr/src/sys/arch/i386/compile/LEON i386
>Description:
There was a small error in the cerror() implementation in
the mips part of NetBSD. cerror() is the common error return
from system calls, and therefore is normally only called from
inside libc, and didn't initialise it's GOT pointer. But the
posix library actually has system calls in it as well, so
programs using those crashed with SEGV, but only if they got
the error return! This was pretty hard to find, and can
potentially bite other ports with shared libraries as well.
On request from Jonathan Stone I hereby submit a small
addition to the regress test suite. In addition to testing
the error return from the rename() in the posix library, it
also tests whether posix rename() differs from BSD rename()
in the expected way, so it's a bit more worth the bother of
adding it, at the cost of some extra directories and Makefiles.
>How-To-Repeat:
Run the regress tests on NetBSD/pmax before the bug was fixed :-)
>Fix:
Apply the following patch (no copyright, this is hereby assigned
to the public domain).
diff -ruN src/regress/lib/Makefile ahj/src/regress/lib/Makefile
--- src/regress/lib/Makefile Sun Oct 12 13:44:03 1997
+++ ahj/src/regress/lib/Makefile Sun Jul 26 21:47:37 1998
@@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.4 1997/10/11 22:57:55 mycroft Exp $
-SUBDIR+= libc
+SUBDIR+= libc libposix
.include <bsd.subdir.mk>
diff -ruN src/regress/lib/libposix/Makefile ahj/src/regress/lib/libposix/Makefile
--- src/regress/lib/libposix/Makefile Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/Makefile Sun Jul 26 23:44:18 1998
@@ -0,0 +1,5 @@
+# $NetBSD$
+
+SUBDIR= prn1 prn2 nrn
+
+.include <bsd.subdir.mk>
diff -ruN src/regress/lib/libposix/Makefile.inc ahj/src/regress/lib/libposix/Makefile.inc
--- src/regress/lib/libposix/Makefile.inc Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/Makefile.inc Sun Jul 26 23:45:37 1998
@@ -0,0 +1,4 @@
+# $NetBSD: Makefile.inc,v 1.2 1998/01/09 08:03:46 perry Exp $
+#
+# do not install regression test programs
+proginstall::
diff -ruN src/regress/lib/libposix/nrn/Makefile ahj/src/regress/lib/libposix/nrn/Makefile
--- src/regress/lib/libposix/nrn/Makefile Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/nrn/Makefile Sun Jul 26 23:43:41 1998
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+PROG= prn
+NOMAN= t
+CLEANFILES+= t1 t2
+
+.PATH: ${.CURDIR}/..
+
+CPPFLAGS+= -DBSD_RENAME
+
+regress:
+ @echo Testing BSD rename
+ ./prn
+
+.include <bsd.prog.mk>
diff -ruN src/regress/lib/libposix/prn.c ahj/src/regress/lib/libposix/prn.c
--- src/regress/lib/libposix/prn.c Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/prn.c Sun Jul 26 23:40:54 1998
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int main(void)
+{
+ int errors = 0;
+ struct stat sb;
+
+ (void)unlink("t1");
+ (void)unlink("t2");
+ if (creat("t1", 0600) < 0) {
+ perror("create t1");
+ exit(1);
+ }
+
+ if (link("t1", "t2")) {
+ perror("link t1 t2");
+ exit(1);
+ }
+
+ /* Check if rename to same name works as expected */
+ if (rename("t1", "t1")) {
+ perror("rename t1 t1");
+ errors++;
+ }
+ if (stat("t1", &sb)) {
+ perror("rename removed file? stat t1");
+ exit(1);
+ }
+
+ if (rename("t1", "t2")) {
+ perror("rename t1 t2");
+ errors++;
+ }
+#if BSD_RENAME
+ /* check if rename of hardlinked file works the BSD way */
+ if (stat("t1", &sb)) {
+ if (errno != ENOENT) {
+ perror("BSD rename should remove file! stat t1");
+ errors++;
+ }
+ } else {
+ fprintf(stderr, "BSD rename should remove file!");
+ errors++;
+ }
+#else
+ /* check if rename of hardlinked file works as the standard says */
+ if (stat("t1", &sb)) {
+ perror("Posix rename should not remove file! stat t1");
+ errors++;
+ }
+#endif
+
+ /* check if we get the expected error */
+ /* this also exercises icky shared libraries goo */
+ if (rename("no/such/file/or/dir", "no/such/file/or/dir")) {
+ if (errno != ENOENT) {
+ perror("rename no/such/file/or/dir");
+ errors++;
+ }
+ } else {
+ fprintf(stderr, "No error renaming no/such/file/or/dir\n");
+ errors++;
+ }
+
+ exit(errors ? 1 : 0);
+}
diff -ruN src/regress/lib/libposix/prn1/Makefile ahj/src/regress/lib/libposix/prn1/Makefile
--- src/regress/lib/libposix/prn1/Makefile Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/prn1/Makefile Sun Jul 26 23:41:56 1998
@@ -0,0 +1,16 @@
+# $NetBSD$
+
+PROG= prn
+NOMAN= t
+CLEANFILES+= t1 t2
+
+.PATH: ${.CURDIR}/..
+
+DPADD+= ${LIBPOSIX}
+LDADD+= -lposix
+
+regress:
+ @echo Testing posix rename with -lposix
+ ./prn
+
+.include <bsd.prog.mk>
diff -ruN src/regress/lib/libposix/prn2/Makefile ahj/src/regress/lib/libposix/prn2/Makefile
--- src/regress/lib/libposix/prn2/Makefile Thu Jan 1 01:00:00 1970
+++ ahj/src/regress/lib/libposix/prn2/Makefile Sun Jul 26 23:42:54 1998
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+PROG= prn
+NOMAN= t
+CLEANFILES+= t1 t2
+
+.PATH: ${.CURDIR}/..
+
+CPPFLAGS+= -D_POSIX_SOURCE
+
+regress:
+ @echo Testing posix rename with -D_POSIX_SOURCE
+ ./prn
+
+.include <bsd.prog.mk>
>Audit-Trail:
>Unformatted: