-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change default umask
from 777
to 027
#22589
base: main
Are you sure you want to change the base?
Changes from all commits
b7d046d
a42e9e0
b0d7dcf
1ff58dd
3d69a91
48487f1
75827a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2024 The Emscripten Authors. All rights reserved. | ||
* Emscripten is available under two separate licenses, the MIT license and the | ||
* University of Illinois/NCSA Open Source License. Both these licenses can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
|
||
mode_t get_umask() { | ||
mode_t current = umask(0); // Set umask to 0 and get the old value | ||
umask(current); // Immediately set it back | ||
return current; | ||
} | ||
|
||
void create_file(const char *path, const char *buffer) { | ||
mode_t mode = 0777 - get_umask(); | ||
int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); | ||
assert(fd >= 0); | ||
|
||
int err = write(fd, buffer, sizeof(char) * strlen(buffer)); | ||
assert(err == (sizeof(char) * strlen(buffer))); | ||
|
||
close(fd); | ||
} | ||
|
||
void cleanup() { | ||
unlink("umask_test_file"); | ||
} | ||
|
||
void test() { | ||
// Get the default umask | ||
mode_t default_umask = get_umask(); | ||
printf("default umask: %o\n", default_umask); | ||
assert(default_umask == 027); | ||
|
||
// Create a new file with default umask | ||
create_file("umask_test_file", "abcdef"); | ||
struct stat st; | ||
stat("umask_test_file", &st); | ||
printf("default_umask - stat: %o\n", st.st_mode); | ||
assert((st.st_mode & 0666) == 0640); | ||
unlink("umask_test_file"); | ||
|
||
// Set new umask | ||
mode_t new_umask = 022; | ||
mode_t old_umask = umask(new_umask); | ||
|
||
// Create a new file with new umask | ||
create_file("umask_test_file", "abcdef"); | ||
stat("umask_test_file", &st); | ||
printf("new_umask - stat: %o\n", st.st_mode); | ||
assert((st.st_mode & 0666) == 0644); | ||
|
||
// Restore the old umask | ||
umask(old_umask); | ||
|
||
puts("success"); | ||
} | ||
|
||
int main() { | ||
signal(SIGABRT, cleanup); | ||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove this line, along with the cleanup function? |
||
test(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I guess you might as well inline the test into |
||
return EXIT_SUCCESS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7673,6 +7673,12 @@ def test_umask_0(self): | |
self.run_process([EMCC, 'src.c']) | ||
self.assertContained('hello, world!', self.run_js('a.out.js')) | ||
|
||
@crossplatform | ||
@also_with_wasmfs | ||
def test_umask(self): | ||
self.set_setting("FORCE_FILESYSTEM") | ||
self.do_runf('stat/test_umask.c', 'success') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this test into |
||
|
||
def test_no_missing_symbols(self): | ||
# simple hello world should not show any missing symbols | ||
self.run_process([EMCC, test_file('hello_world.c')]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making the default 022 makes sense yes.