changeset 10141:69c854126601

Portability fixes for MacOS X, Solaris, HP-UX, IRIX.
author Bruno Haible <bruno@clisp.org>
date Sun, 01 Jun 2008 22:41:49 +0200
parents 879d77289ca0
children dc740b83408a
files ChangeLog tests/test-copy-file.sh tests/test-sameacls.c
diffstat 3 files changed, 146 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jun 01 18:43:55 2008 +0200
+++ b/ChangeLog	Sun Jun 01 22:41:49 2008 +0200
@@ -1,3 +1,10 @@
+2008-06-01  Bruno Haible  <bruno@clisp.org>
+
+	* tests/test-copy-file.sh: Portability fixes for Solaris, HP-UX, IRIX.
+	* tests/test-sameacls.c: Include progname.h.
+	(main): Invoke set_program_name. Portability fixes for MacOS X,
+	Solaris, HP-UX.
+
 2008-06-01  Bruno Haible  <bruno@clisp.org>
 
 	* lib/freadahead.c (freadahead) [__DragonFly__]: Use the __sreadahead
--- a/tests/test-copy-file.sh	Sun Jun 01 18:43:55 2008 +0200
+++ b/tests/test-copy-file.sh	Sun Jun 01 22:41:49 2008 +0200
@@ -79,7 +79,7 @@
       fi
     fi
   else
-    if (lsacl tmpfile0 >/dev/null) 2>/dev/null; then
+    if (lsacl / >/dev/null) 2>/dev/null; then
       # Platforms with the lsacl and chacl programs.
       # HP-UX, sometimes also IRIX.
       acl_flavor=hpux
@@ -221,7 +221,7 @@
 
         # Remove the ACL for other.
         case $acl_flavor in
-          linux)   ;; # impossible
+          linux | solaris) ;; # impossible
           freebsd) setfacl -x other::4 tmpfile0 ;;
           *)       setfacl -d other:4 tmpfile0 ;;
         esac
@@ -447,32 +447,27 @@
       irix)
 
         # Set an ACL for a user.
-        /sbin/chacl user:$auid:--x tmpfile0
+        /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x tmpfile0
 
         func_test_copy tmpfile0 tmpfile2
 
         # Set an ACL for a group.
-        /sbin/chacl user:$auid:--x,group:$agid:r-- tmpfile0
+        /sbin/chacl user::rw-,group::---,other::---,user:$auid:--x,group:$agid:r-- tmpfile0
 
         func_test_copy tmpfile0 tmpfile3
 
         # Set an ACL for other.
-        /sbin/chacl user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
+        /sbin/chacl user::rw-,group::---,user:$auid:--x,group:$agid:r--,other::r-- tmpfile0
 
         func_test_copy tmpfile0 tmpfile4
 
         # Remove the ACL for the user.
-        /sbin/chacl group:$agid:r--,other::r-- tmpfile0
+        /sbin/chacl user::rw-,group::---,group:$agid:r--,other::r-- tmpfile0
 
         func_test_copy tmpfile0 tmpfile5
 
-        # Remove the ACL for other.
-        /sbin/chacl group:$agid:r-- tmpfile0
-
-        func_test_copy tmpfile0 tmpfile6
-
         # Remove the ACL for the group.
-        /sbin/chacl , tmpfile0
+        /sbin/chacl user::rw-,group::---,other::r-- tmpfile0
 
         func_test_copy tmpfile0 tmpfile7
 
--- a/tests/test-sameacls.c	Sun Jun 01 18:43:55 2008 +0200
+++ b/tests/test-sameacls.c	Sun Jun 01 22:41:49 2008 +0200
@@ -29,6 +29,7 @@
 # include <sys/acl.h>
 #endif
 
+#include "progname.h"
 #include "read-file.h"
 #include "xalloc.h"
 
@@ -50,6 +51,8 @@
   const char *file1;
   const char *file2;
 
+  set_program_name (argv[0]);
+
   ASSERT (argc == 3);
 
   file1 = argv[1];
@@ -120,97 +123,110 @@
   }
   {
 #if HAVE_ACL_GET_FILE /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
-    acl_t acl1;
-    char *text1;
-    int errno1;
-    acl_t acl2;
-    char *text2;
-    int errno2;
-
-    acl1 = acl_get_file (file1, ACL_TYPE_ACCESS);
-    if (acl1 == (acl_t)NULL)
+    static const int types[] =
       {
-	text1 = NULL;
-	errno1 = errno;
-      }
-    else
-      {
-	text1 = acl_to_text (acl1, NULL);
-	if (text1 == NULL)
-	  errno1 = errno;
-	else
-	  errno1 = 0;
-      }
-    acl2 = acl_get_file (file2, ACL_TYPE_ACCESS);
-    if (acl2 == (acl_t)NULL)
+	ACL_TYPE_ACCESS
+# if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
+	, ACL_TYPE_EXTENDED
+# endif
+      };
+    int t;
+
+    for (t = 0; t < sizeof (types) / sizeof (types[0]); t++)
       {
-	text2 = NULL;
-	errno2 = errno;
-      }
-    else
-      {
-	text2 = acl_to_text (acl2, NULL);
-	if (text2 == NULL)
-	  errno2 = errno;
-	else
-	  errno2 = 0;
-      }
+	int type = types[t];
+	acl_t acl1;
+	char *text1;
+	int errno1;
+	acl_t acl2;
+	char *text2;
+	int errno2;
 
-    if (acl1 != (acl_t)NULL)
-      {
-	if (acl2 != (acl_t)NULL)
+	acl1 = acl_get_file (file1, type);
+	if (acl1 == (acl_t)NULL)
+	  {
+	    text1 = NULL;
+	    errno1 = errno;
+	  }
+	else
 	  {
-	    if (text1 != NULL)
+	    text1 = acl_to_text (acl1, NULL);
+	    if (text1 == NULL)
+	      errno1 = errno;
+	    else
+	      errno1 = 0;
+	  }
+	acl2 = acl_get_file (file2, type);
+	if (acl2 == (acl_t)NULL)
+	  {
+	    text2 = NULL;
+	    errno2 = errno;
+	  }
+	else
+	  {
+	    text2 = acl_to_text (acl2, NULL);
+	    if (text2 == NULL)
+	      errno2 = errno;
+	    else
+	      errno2 = 0;
+	  }
+
+	if (acl1 != (acl_t)NULL)
+	  {
+	    if (acl2 != (acl_t)NULL)
 	      {
-		if (text2 != NULL)
+		if (text1 != NULL)
 		  {
-		    if (strcmp (text1, text2) != 0)
+		    if (text2 != NULL)
 		      {
-			fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n",
-				 file1, file2, text1, text2);
+			if (strcmp (text1, text2) != 0)
+			  {
+			    fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n",
+				     file1, file2, text1, text2);
+			    return 1;
+			  }
+		      }
+		    else
+		      {
+			fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n",
+				 file1, file2);
 			return 1;
 		      }
 		  }
 		else
 		  {
-		    fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n",
-			     file1, file2);
-		    return 1;
+		    if (text2 != NULL)
+		      {
+			fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n",
+				 file1, file2);
+			return 1;
+		      }
+		    else
+		      {
+			if (errno1 != errno2)
+			  {
+			    fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n",
+				     file1, file2, errno1, errno2);
+			    return 1;
+			  }
+		      }
 		  }
 	      }
 	    else
 	      {
-		if (text2 != NULL)
-		  {
-		    fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n",
-			     file1, file2);
-		    return 1;
-		  }
-		else
-		  {
-		    if (errno1 != errno2)
-		      {
-			fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n",
-				 file1, file2, errno1, errno2);
-			return 1;
-		      }
-		  }
+		fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n",
+			 file1, file2);
+		return 1;
 	      }
 	  }
 	else
 	  {
-	    fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n",
-		     file1, file2);
-	    return 1;
-	  }
-      }
-    else
-      {
-	if (acl2 != (acl_t)NULL)
-	  {
-	    fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n",
-		     file1, file2);
-	    return 1;
+	    if (acl2 != (acl_t)NULL)
+	      {
+		fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n",
+			 file1, file2);
+		return 1;
+	      }
 	  }
       }
 #elif HAVE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
@@ -220,20 +236,20 @@
   count1 = acl (file1, GETACLCNT, 0, NULL);
   count2 = acl (file2, GETACLCNT, 0, NULL);
 
+  if (count1 < 0)
+    {
+      fprintf (stderr, "error accessing the ACLs of file %s\n", file1);
+      fflush (stderr);
+      abort ();
+    }
+  if (count2 < 0)
+    {
+      fprintf (stderr, "error accessing the ACLs of file %s\n", file2);
+      fflush (stderr);
+      abort ();
+    }
   if (count1 != count2)
     {
-      if (count1 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACLs of file %s\n", file1);
-	  fflush (stderr);
-	  abort ();
-	}
-      if (count2 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACLs of file %s\n", file2);
-	  fflush (stderr);
-	  abort ();
-	}
       fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n",
 	       file1, file2, count1, count2);
       return 1;
@@ -280,21 +296,25 @@
     }
 # ifdef ACE_GETACL
   count1 = acl (file1, ACE_GETACLCNT, 0, NULL);
+  if (count1 < 0 && errno == EINVAL)
+    count1 = 0;
   count2 = acl (file2, ACE_GETACLCNT, 0, NULL);
+  if (count2 < 0 && errno == EINVAL)
+    count2 = 0;
+  if (count1 < 0)
+    {
+      fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file1);
+      fflush (stderr);
+      abort ();
+    }
+  if (count2 < 0)
+    {
+      fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file2);
+      fflush (stderr);
+      abort ();
+    }
   if (count1 != count2)
     {
-      if (count1 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file1);
-	  fflush (stderr);
-	  abort ();
-	}
-      if (count2 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file2);
-	  fflush (stderr);
-	  abort ();
-	}
       fprintf (stderr, "files %s and %s have different number of ACE-ACLs: %d and %d\n",
 	       file1, file2, count1, count2);
       return 1;
@@ -351,27 +371,31 @@
   int count2;
 
   count1 = getacl (file1, 0, NULL);
+  if (count1 < 0 && (errno == ENOSYS || errno == EOPNOTSUPP))
+    count1 = 0;
   count2 = getacl (file2, 0, NULL);
+  if (count2 < 0 && (errno == ENOSYS || errno == EOPNOTSUPP))
+    count2 = 0;
 
+  if (count1 < 0)
+    {
+      fprintf (stderr, "error accessing the ACLs of file %s\n", file1);
+      fflush (stderr);
+      abort ();
+    }
+  if (count2 < 0)
+    {
+      fprintf (stderr, "error accessing the ACLs of file %s\n", file2);
+      fflush (stderr);
+      abort ();
+    }
   if (count1 != count2)
     {
-      if (count1 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACLs of file %s\n", file1);
-	  fflush (stderr);
-	  abort ();
-	}
-      if (count2 < 0)
-	{
-	  fprintf (stderr, "error accessing the ACLs of file %s\n", file2);
-	  fflush (stderr);
-	  abort ();
-	}
       fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n",
 	       file1, file2, count1, count2);
       return 1;
     }
-  else
+  else if (count1 > 0)
     {
       struct acl_entry *entries1 = XNMALLOC (count1, struct acl_entry);
       struct acl_entry *entries2 = XNMALLOC (count2, struct acl_entry);