[cs631apue] File permission Control use oflag and mode

hao wu hwu9 at stevens.edu
Sat Sep 14 11:24:53 EDT 2013


When doing the HW, my function's option is open(dst, O_WRONLY | O_CREAT |
O_TRUNC, src_st.st_mode), it works fine when I copy a executable shell
script.

But when I chmod 777 to the source script and use program to copy, the
target file's permission remains "-rwxr-xr-x". This is where this problem
from.


if the file already exist, /bin/cp will keep its original permissions,

According the specification of open(2):

the third parameter is used to mode specifies the permissions to use in
case a *new* file is created.


-Hao


On Sat, Sep 14, 2013 at 12:33 AM, Hongyi Shen <hshen4 at stevens.edu> wrote:

>   In open() function:
>
> int open(const char *pathname, int oflag, ... /* mode_t mode */ );
>
>
> Both *oflag* and *mode could *control the file's permission. So both of
> them call stat() inside?
>
> *Question: What if they are conflict with each other? (like O_RDONLY and
> mode 0777 together)*
>
>
> When doing the HW, my function's option is open(dst, O_WRONLY | O_CREAT |
> O_TRUNC, src_st.st_mode), it works fine when I copy a executable shell
> script.
>
> But when I chmod 777 to the source script and use program to copy, the
> target file's permission remains "-rwxr-xr-x". This is where this problem
> from.
>
>
>
>
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20130914/2b9d03de/attachment.html>


More information about the cs631apue mailing list