<div dir="ltr">Hey, I think this is because the process's umask is changing the mode. In fs/namei.c in the function lookup_open() there's this bit:<div><br></div><div>....</div><div> if (!IS_POSIXACL(dir->d_inode))</div><div> mode &= ~current_umask();<br>....</div><div><br></div><div>the open(2) and umask(2) manpages will explain how to deal with it</div><div><br></div><div>-Marcelo</div><div><br></div></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Oct 31, 2020 at 11:06 AM Nicky Chorley <<a href="mailto:ndchorley@gmail.com">ndchorley@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi folks,<br>
<br>
I hope it's OK to ask this question here. I'm reading The Linux<br>
Programming Interface and am beginning to get to grips with the file<br>
oriented system calls.<br>
<br>
I have a program that calls open to create a file, specifying the mode<br>
flags for owner, group, other read and write. The file is created<br>
sucessfully, but when I look at its permissions, I only see the read<br>
perms set for group and others:<br>
<br>
> ./create_file foo<br>
> ls -l foo<br>
-rw-r--r-- 1 nick users 0 Oct 31 14:52 foo<br>
<br>
Why would that be? The entirety of my program is<br>
<br>
#include <fcntl.h><br>
#include <unistd.h><br>
<br>
int main(int argc, char *argv[]) {<br>
int open_flags = O_CREAT | O_WRONLY | O_TRUNC;<br>
mode_t file_perms =<br>
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;<br>
<br>
int output_fd = open(argv[1], open_flags, file_perms);<br>
<br>
close(output_fd);<br>
}<br>
<br>
I also ran the program with strace and the perms in the openat call are<br>
as I would expect:<br>
<br>
openat(AT_FDCWD, "foo", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3<br>
<br>
I don't understand why the group and other write flags aren't being<br>
set. Could someone help shed some light on this please?<br>
<br>
I'm not sure what factors influence this, but I'm running openSUSE Leap<br>
15.2, with kernel 5.3.18-lp152.47-default, gcc 7.5.0 and glibc 2.26.<br>
<br>
Thanks,<br>
<br>
Nicky<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div>