delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2002/05/21/15:57:16

Mailing-List: contact cygwin-developers-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT cygwin DOT com>
List-Help: <mailto:cygwin-developers-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-developers-owner AT cygwin DOT com
Delivered-To: mailing list cygwin-developers AT cygwin DOT com
Date: Tue, 21 May 2002 16:03:09 -0400
From: Jason Tishler <jason AT tishler DOT net>
Subject: path_conv::check() gets confused by recently opened files
To: Cygwin-Developers <cygwin-developers AT cygwin DOT com>
Mail-followup-to: Cygwin-Developers <cygwin-developers AT cygwin DOT com>
Message-id: <20020521200309.GA2392@tishler.net>
MIME-version: 1.0
User-Agent: Mutt/1.3.24i

--Boundary_(ID_OIrY0BZNPAvOmVMnuwa/kA)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: inline

I stumbled across a problem with path_conv::check() when scp-ing a
read-only file.  I can reproduce the problem with the attached simple
test case, tchmod.cc.  For example:

    $ ls -l -d foo foo/readonly 
    ls: foo/readonly: No such file or directory
    drwxr-xr-x    2 jt       Domain U        0 May 21 15:13 foo
    $ tchmod foo/readonly
    $ ls -l -d foo foo/readonly
    dr--r--r--    2 jt       Domain U        0 May 21 15:13 foo
    -rw-r--r--    1 jt       Domain U        0 May 21 15:13 foo/readonly

Note that foo's permissions should not have changed and foo/readonly
should be read-only instead of read-write.

The expected results which can be forced by supplying a second argument
is:

    $ ls -l -d foo foo/readonly
    ls: foo/readonly: No such file or directory
    drwxr-xr-x    2 jt       Domain U        0 May 21 15:23 foo
    $ tchmod foo/readonly 1
    $ ls -l -d foo foo/readonly
    drwxr-xr-x    2 jt       Domain U        0 May 21 15:23 foo
    -r--r--r--    1 jt       Domain U        0 May 21 15:23 foo/readonly

Unfortunately, I haven't figured out how to teach path_conv::check()
to deal with recently opened files.  I'm also a little leery to perturb
this code.  Any hints or help would be greatly appreciated.

Thanks,
Jason

--Boundary_(ID_OIrY0BZNPAvOmVMnuwa/kA)
Content-type: text/plain; charset=us-ascii; NAME=tchmod.cc
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=tchmod.cc

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int
main(int argc, char* argv[])
{
	char* path = argv[1];
	int fd = open(path, O_WRONLY|O_CREAT, 0644);
	if (fd == -1)
	{
		printf("open failed\n");
		return 1;
	}

	if (argc > 2)
	{
		close(fd);
		fd = open(path, O_WRONLY|O_CREAT, 0644);
	}

	int status = fchmod(fd, 0444);
	if (status == -1)
	{
		printf("chmod failed\n");
		return 2;
	}

	return 0;
}

--Boundary_(ID_OIrY0BZNPAvOmVMnuwa/kA)--

- Raw text -


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