Re: munmap & cp [patch enclosed]

2003-11-12 Thread Wiktor Niesiobedzki
On Wed, Nov 12, 2003 at 08:18:05PM +0100, Dimitry Andric wrote:
> On 2003-11-11 at 15:31:15 Wiktor Niesiobedzki wrote:
> 
> > $ mkdir foo
> > $ cd foo
> > $ touch foo
> > $ cp foo foo2
> > cp: foo: Invalid argument
> Anyway, cp (and possibly other tools which use munmap) will need to be
> fixed. For now, I simply disabled the VM_AND_BUFFER_CACHE_SYNCHRONIZED
> flag in the Makefile for cp, which simply disables the whole mmap'ing
> stuff. I don't notice any difference without it...
I would still propose my one-line solution, to use mmap only when the file
size is greater than 0. As far as I looked into source tree, most usages of
munmap are in unsafe way - i.e. without checking the return value. 
 
Is there someone willing to commit this trival change? For now, some number of
ports will refuse tu build/install.

Cheers,

Wiktor Niesiobedzki

PS. The acctual patch attached.

--- utils.c 2003/06/22 07:02:17 1.41
+++ utils.c 2003/11/11 14:32:17 
@@ -133,7 +133,7 @@
 * wins some CPU back.
 */
 #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
+   if (S_ISREG(fs->st_mode) && fs->st_size <= 8 * 1048576 && fs->st_size > 0) {
-   if (S_ISREG(fs->st_mode) && fs->st_size <= 8 * 1048576) {
if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) {
warn("%s", entp->fts_path);
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: munmap & cp

2003-11-12 Thread Dimitry Andric
On 2003-11-11 at 15:31:15 Wiktor Niesiobedzki wrote:

> $ mkdir foo
> $ cd foo
> $ touch foo
> $ cp foo foo2
> cp: foo: Invalid argument

Yes, I've just run into this problem too, because a large number of
ports failed to install because of it. This is because they cp -r a
number of directories to be installed, and these obviously contain 0
byte files... :(

Since the cp source doesn't seem to have been touched for 4 months, it
turns out that the semantics of the munmap call changed suddenly, due
to "Open Group Base Specifications Issue 6", see:

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/vm/vm_map.c

I wonder why mmap of 0 bytes is allowed to succeed, and munmap of the
same amount is not, but then again, it's obviously following a
standard, which doesn't have to abide to any rules of logic. ;)

Anyway, cp (and possibly other tools which use munmap) will need to be
fixed. For now, I simply disabled the VM_AND_BUFFER_CACHE_SYNCHRONIZED
flag in the Makefile for cp, which simply disables the whole mmap'ing
stuff. I don't notice any difference without it...


pgp0.pgp
Description: PGP signature


munmap & cp

2003-11-11 Thread Wiktor Niesiobedzki
Hi,

The simple scenario:
$ mkdir foo
$ cd foo
$ touch foo
$ cp foo foo2
cp: foo: Invalid argument

The problem lies in:
src/bin/cp/utils.c:163
if (munmap(p, fs->st_size) < 0) {
warn("%s", entp->fts_path);
rval = 1;
}

For the size 0, the munmap will return EINVAL. Returning now error leads us,
to think, that no file was copied.

My quick hack is to change the line 136:
if (S_ISREG(fs->st_mode) && fs->st_size <= 8 * 1048576) {
into:
if (S_ISREG(fs->st_mode) && fs->st_size <= 8 * 1048576 && fs->st_size > 0) {


Anyone feels like to look into it?

Cheers,

Wiktor NiesiobÄdzki

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[EMAIL PROTECTED]"