delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/02/02/22:15:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <4201966F.7070508@byu.net>
Date: Wed, 02 Feb 2005 20:11:43 -0700
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: snapshot bug - pathchk still broken
X-IsSubscribed: yes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

With the 20050131 snapshot and new CYGWIN=traverse option, trying to stat
elements in an inaccessible directory now fails, but with with an
unexpected errno (ENOENT=2 instead of EACCES=13).  When CYGWIN=notraverse,
the elements within the inaccessible directory are still reachable.  What
is odd about this all is that the strace noted that the windows error
translated to EACCES when trying to resolve the path name as a symlink,
but discarded that information and returned ENOENT anyways.  As a result,
coreutils pathchk now silently accepts 'inaccessible/x' where it used to
fail in 5.2.1, because it assumes that ENOENT means the file doesn't exist
but can be created.  However, the snapshot DID fix pathchk's ability to
reject 'file/x' with ENOTDIR since file is not a directory.

Additionally, I noticed that chmod("dir", 0) succeeded, but changed errno
to ENOTDIR.  I think that POSIX allows this behavior (it said something to
the effect that programs should, but not shall, only read errno when the
return value indicated that it is valid; and that syscalls only need to
preserve errno if explicitly called out for that function), but it would
be nicer if errno were untouched like it is for mkdir.

$ cat foo.c
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>

static void
error(const char* str, int status)
{
   perror(str);
   /* Cleanup, ignoring errors if we encounter them */
   chmod("d", S_IRWXU) && puts("cleanup chmod failed");
   rmdir("d/d1") && puts("deep rmdir failed");
   rmdir("d") && puts("shallow rmdir failed");
   exit(status);
}

int
main()
{
   struct stat st;
   int err;
   if (mkdir("d", S_IRWXU))
      error("failed to create d", 1);
   if (mkdir("d/d1", S_IRWXU))
      error("failed to create d/d1", 1);
   if (chmod("d", 0))
      error("failed to restrict d", 1);
   errno = 0;
   write(1, "~~~Start\n", 9);
   err = stat("d/d1", &st);
   write(1, "~~~End\n", 7);
   if (-1 != err)
      error("shouldn't be able to see d/d1", 2);
   if (errno != EACCES)
      error("unexpected error from stat", 2);
   if (chmod("d", S_IRWXU))
      error("failed to unrestrict d", 3);
   if (rmdir("d/d1"))
      error("failed to remove d/d1", 3);
   if (rmdir("d"))
      error("failed to remove d", 3);
   puts("Passed!");
   return 0;
}
$ strace foo 2>&1 |sed -n '/^~~~Start/,/^~~~End/p'
~~~Start
  297   80811 [main] foo 12672 stat64: entering
   66   80877 [main] foo 12672 normalize_posix_path: src d/d1
   62   80939 [main] foo 12672 cwdstuff::get: posix /tmp/cp.test
   61   81000 [main] foo 12672 cwdstuff::get: (/tmp/cp.test) = cwdstuff::get
(0x22EC30, 260, 1, 0), errno 0
   62   81062 [main] foo 12672 normalize_posix_path: /tmp/cp.test/d/d1 =
normalize_posix_path (d/d1)
   62   81124 [main] foo 12672 mount_info::conv_to_win32_path:
conv_to_win32_path (/tmp/cp.test/d/d1)
  384   81508 [main] foo 12672 set_flags: flags: binary (0x2)
   76   81584 [main] foo 12672 mount_info::conv_to_win32_path: src_path
/tmp/cp.test/d/d1, dst C:\cygwin\tmp\cp.test\d\d1, flags 0xA, rc 0
  267   81851 [main] foo 12672 symlink_info::check: GetFileAttributes
(C:\cygwin\tmp\cp.test\d\d1) failed
   87   81938 [main] foo 12672 geterrno_from_win_error: windows error 5 ==
errno 13
  265   82203 [main] foo 12672 symlink_info::check: GetFileAttributes
(C:\cygwin\tmp\cp.test\d\d1.exe) failed
   85   82288 [main] foo 12672 geterrno_from_win_error: windows error 5 ==
errno 13
  161   82449 [main] foo 12672 symlink_info::check: GetFileAttributes
(C:\cygwin\tmp\cp.test\d\d1.exe.lnk) failed
   77   82526 [main] foo 12672 geterrno_from_win_error: windows error 5 ==
errno 13
  414   82940 [main] foo 12672 symlink_info::check: GetFileAttributes
(C:\cygwin\tmp\cp.test\d\d1.lnk) failed
   86   83026 [main] foo 12672 geterrno_from_win_error: windows error 5 ==
errno 13
   62   83088 [main] foo 12672 symlink_info::check: 0 = symlink.check
(C:\cygwin\tmp\cp.test\d\d1, 0x22E8F0) (0xA)
   64   83152 [main] foo 12672 mount_info::conv_to_win32_path:
conv_to_win32_path (/tmp/cp.test/d)
   64   83216 [main] foo 12672 set_flags: flags: binary (0x2)
   62   83278 [main] foo 12672 mount_info::conv_to_win32_path: src_path
/tmp/cp.test/d, dst C:\cygwin\tmp\cp.test\d, flags 0xA, rc 0
  197   83475 [main] foo 12672 symlink_info::check: not a symlink
   78   83553 [main] foo 12672 symlink_info::check: 0 = symlink.check
(C:\cygwin\tmp\cp.test\d, 0x22E8F0) (0xA)
   65   83618 [main] foo 12672 path_conv::check:
this->path(C:\cygwin\tmp\cp.test\d\d1), has_acls(1)
   67   83685 [main] foo 12672 build_fh_pc: fh 0x617E1410
   73   83758 [main] foo 12672 stat_worker: -1 = (d/d1, 0x22EF50)
  475   84233 [main] foo 12672 fhandler_base::write: binary write
~~~End

- --
Life is short - so eat dessert first!

Eric Blake             ebb9 AT byu DOT net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCAZZv84KuGfSFAYARAjrCAKCgQog5SgztrQpzz3vKkDaPjOUsIQCgnjei
krfL80WBAxhQ8zcaKtsKcDM=
=NjRL
-----END PGP SIGNATURE-----

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019