bug in chown()

Eric Blake ebb9@byu.net
Thu Jan 13 14:14:00 GMT 2005


In trying to get the newly released coreutils 5.3.0 tarball working on
cygwin, I discovered that cygwin chown() has a bug.  Background:
http://lists.gnu.org/archive/html/bug-coreutils/2005-01/msg00064.html

POSIX requires that "chown() shall mark for update the st_ctime field of
the file" if successful and at least one of owner or group was not -1.
http://www.opengroup.org/onlinepubs/009695399/functions/chown.html

However, in cygwin, chown() appears to have no effect whatsoever on the
change time.  (gid_t)0 is the 'root' group.  I tested this on a WinXP
machine, since it appears that cygwin does not support multiple groups on
my Win98 box.  The printouts in the test program allow me to narrow in on
the relevant section of the strace.

$ cd /tmp
$ cat chowntest.c
#include <unistd.h>
int main()
{
  int ret = 0;
  write(1, "~~~Start\n", 9);
  if (chown("f", (uid_t)-1, (gid_t)0))
    {
      perror("failed to chown\n");
      ret = 1;
    }
  write(1, "~~~End\n", 7);
  return ret;
}
$ touch f
$ stat f
  File: `f'
  Size: 0               Blocks: 0          IO Block: 1024   regular empty file
Device: d47c93feh/-730033154d   Inode: 61328       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1007/  eblake)   Gid: (  513/    None)
Access: 2005-01-13 06:21:53.936500000 -0700
Modify: 2005-01-13 06:21:53.936500000 -0700
Change: 2005-01-13 06:21:53.920875000 -0700
$ chowntest.exe f
~~~Start
~~~End
$ stat f
  File: `f'
  Size: 0               Blocks: 0          IO Block: 1024   regular empty file
Device: d47c93feh/-730033154d   Inode: 61328       Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1007/  eblake)   Gid: (    0/    root)
Access: 2005-01-13 06:21:53.936500000 -0700
Modify: 2005-01-13 06:21:53.936500000 -0700
Change: 2005-01-13 06:21:53.920875000 -0700
$ cygcheck -c cygwin
Cygwin Package Information
Package              Version        Status
cygwin               1.5.12-1       OK
$ uname -a
CYGWIN_NT-5.1 EBLAKE 1.5.12(0.116/4/2) 2004-11-10 08:34 i686 unknown
unknown Cygwin
$ strace chowntest 2>&1 | sed -e '/^~~~Start/,/^~~~End/!d' > chowntest.trace

-- 
Life is short - so eat dessert first!

Eric Blake             ebb9@byu.net
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: chowntest.trace
URL: <http://cygwin.com/pipermail/cygwin/attachments/20050113/72c59adb/attachment.ksh>
-------------- next part --------------
--
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/


More information about the Cygwin mailing list