can't create file in c++ with rwx for ugo (777)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > can't create file in c++ with rwx for ugo (777)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    can't create file in c++ with rwx for ugo (777)  
nass


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:26 PM

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






[ Post a follow-up to this message ]



    Re: can't create file in c++ with rwx for ugo (777)  
Bin Chen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:26 PM

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.






[ Post a follow-up to this message ]



    Re: can't create file in c++ with rwx for ugo (777)  
nass


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:26 PM

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 ever
yone, 
> 
> 
>
> 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






[ Post a follow-up to this message ]



    Re: can't create file in c++ with rwx for ugo (777)  
Rainer Temme


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:26 PM

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





[ Post a follow-up to this message ]



    Re: can't create file in c++ with rwx for ugo (777)  
Kenny McCormack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-07 12:20 AM

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.






[ Post a follow-up to this message ]



    Re: can't create file in c++ with rwx for ugo (777)  
Lew Pitcher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-07 06: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:11 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register