|
Home > Archive > Unix Programming > March 2007 > can't create file in c++ with rwx for ugo (777)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
can't create file in c++ with rwx for ugo (777)
|
|
|
| hello everyone,
im using the function open() to get a file descriptor for some binary
and some text files. i would like these to be globally read/write/
execute by everyone so i run open() as following:
fdLog = open ( logCurDate.c_str() , O_WRONLY | O_APPEND | O_CREAT ,
S_IRWXU | S_IRWXG | S_IRWXO );
the problem is that when i check the created files they have 755
attirbutes...
i checked the global umask in /etc/profile it was 022 and thought that
perhaps it had to do with this. so i changed the umask to 000 but
still the generated files have 755 attributes...
what am i missing?
nass
| |
| Bin Chen 2007-03-14, 7:26 am |
| On Mar 14, 6:20 pm, "nass" <athanasios.si...@gmail.com> wrote:
> hello everyone,
> im using the function open() to get a file descriptor for some binary
> and some text files. i would like these to be globally read/write/
> execute by everyone so i run open() as following:
>
> fdLog = open ( logCurDate.c_str() , O_WRONLY | O_APPEND | O_CREAT ,
> S_IRWXU | S_IRWXG | S_IRWXO );
>
> the problem is that when i check the created files they have 755
> attirbutes...
> i checked the global umask in /etc/profile it was 022 and thought that
> perhaps it had to do with this. so i changed the umask to 000 but
> still the generated files have 755 attributes...
> what am i missing?
> nass
Have you deleted the file you create in the first time? You open is OK
and if you type 'umask 000' in your shell and then invoke you program,
the mode will be 777.
| |
|
| On Mar 14, 1:46 pm, "Bin Chen" <binary.c...@gmail.com> wrote:
> On Mar 14, 6:20 pm, "nass" <athanasios.si...@gmail.com> wrote:> hello everyone,
>
>
>
> Have you deleted the file you create in the first time? You open is OK
> and if you type 'umask 000' in your shell and then invoke you program,
> the mode will be 777.
its always a different file created, thing of it like logging. as for
the umask in the shell, isn't it sufficient i've changed the global
umask from /etc/profile?
thank you for your help
nass
| |
| Rainer Temme 2007-03-14, 7:26 am |
| nass wrote:
> its always a different file created, thing of it like logging. as for
> the umask in the shell, isn't it sufficient i've changed the global
> umask from /etc/profile?
Changes in /etc/profile don't mean anything, if you haven't logged out
and logged in since the change.
Also, a umask of 0 applied in /etc/profile can be overwritten later
in a group- or private profile.
So, check with the umask command on shell-level to see if
umask is really set to 000 for you.
Rainer
| |
| Kenny McCormack 2007-03-14, 7:20 pm |
| In article <et8pj0$7pa$1@daniel-new.mch.sbs.de>,
Rainer Temme <Rainer_Temme@nospam.hotmail_dot_com> wrote:
>nass wrote:
>
>Changes in /etc/profile don't mean anything, if you haven't logged out
>and logged in since the change.
>Also, a umask of 0 applied in /etc/profile can be overwritten later
>in a group- or private profile.
>
>So, check with the umask command on shell-level to see if
>umask is really set to 000 for you.
>
>Rainer
Really, the best way to solve this problem is to assume nothing about
umask and the associated apparatus. Instead, create the file, then use
chmod() to change it to what you want it to be.
| |
| Lew Pitcher 2007-03-15, 1:25 am |
| On Mar 14, 3:20 pm, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <et8pj0$7p...@daniel-new.mch.sbs.de>,
> Rainer Temme <Rainer_Te...@nospam.hotmail_dot_com> wrote:
>
>
>
>
>
> Really, the best way to solve this problem is to assume nothing about
> umask and the associated apparatus. Instead, create the file, then use
> chmod() to change it to what you want it to be.
Alternately, before open()ing the file, make an explicit call to
umask(2) to override the inherited umask with a umask of 0.
I.e.
mode_t old_umask;
old_umask = umask(0);
fdLog = open (logCurDate. c_str(),O_WRONLY|O_APPEND|O_CREAT,S_IRWX
U|
S_IRWXG|S_IRWXO);
HTH
--
Lew
|
|
|
|
|