Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Creating file with 777 permission

by Smaug (Pilgrim)
on Nov 21, 2006 at 09:25 UTC ( [id://585224] : note . print w/replies, xml ) Need Help??


in reply to Creating file with 777 permission

Hi,

Can you give a little more information? I'm not sure why you want world to be able to execute or write to a file that is still being written?

Thanks,
Smaug.
Update:
Try:
sysopen(FILEHANDLE, $filename, permissions, CHMOD);

Just another update:
Based on reasonablekeith comments I decided to try some tests. I ran the following code:
#!/usr/bin/perl use strict; use Fcntl; my $var = 1; while ($var) { sysopen (FILE, '/home/smaug/testing/file.txt', O_RDWR|O_EXCL|O_CRE +AT, 0777); printf FILE "A value of n\n"; } close (FILE);


This, of course, opens the file and keeps it open for reading, writing and executing...... or so it would seem. However an "ls -l" shows the following:
-rwxr-xr-x 1 root root 13 2006-11-21 11:55 file.txt

In short, sysopen calls the underlying operating system's open function. On my OS (Ubuntu Linux) the OS prevents writing to files that are already open for writing, so it seems that although it is still executable (why oh why!!) it is not writable.
(The same is shown by trying to open the same file twice using "vi".)
Again, looks can be deceiving... Trying to run the file while it is written shows:
bash: ./file.txt: Text file busy
Perhaps there are other OS's out there that allow this, but for now - I'm going with the "Cannot be done" answer.
Thanks for pricking my curiosity reasonablekeith.

Replies are listed 'Best First'.
Re^2: Creating file with 777 permission
by reasonablekeith (Deacon) on Nov 21, 2006 at 09:31 UTC
    That's still going to be affected by umask, and is unlikely to reliably give 777 as the permission mode of the file.

    You're probably best off creating the file first with your specific requirements, then opening it.

    ---
    my name's not Keith, and I'm not reasonable.
      Agreed, but you're also unlikely to want a file that is open for writing to be executed.
Re^2: Creating file with 777 permission
by Anonymous Monk on Nov 21, 2006 at 10:49 UTC

    On my OS (Ubuntu Linux) the OS prevents writing to files that are already open for writing,

    That's a very odd Unix. One I've never encountered before.

    Now, there are some OSses that won't allow you to write to pages binaries currently being executed by some process (giving you a 'text busy' message), but that's something else entirely.

    (The same is shown by trying to open the same file twice using "vi".)

    Ah, yes, that editor. The one that tries to be vi but isn't. I'm a vi-lover and have been using vi and vi-clones for 25+ years. But I loathe environments where 'vi file' starts up an editor that isn't quite 'vi'. By all means, if you call it 'vi', then have it act like 'vi'. If it acts otherwise, call it otherwise.

    As for that editor, that editor creates another file in the same directory, and if that file exists, it thinks the file is already edited and starts complaining. That has nothing to do with the OS - that's just a behavioural thing of the editor that isn't quite vi. Using another program, I can happily modify the same file.

      Thanks for that, although it really did not help me.
      Thanks johngg.