-
Notifications
You must be signed in to change notification settings - Fork 18
umask syscall implementation #1239
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
28a905a
8e0485e
e97d5fd
09358b2
223914a
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 |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| #include <unistd.h> | ||
| #include <fcntl.h> | ||
| #include <string.h> | ||
| #include <sys/stat.h> | ||
| #include <syscall-template.h> | ||
| #include <lind_syscall_num.h> | ||
|
|
||
| mode_t | ||
| umask (mode_t mask) | ||
| { | ||
| return -1; | ||
| } | ||
| return (mode_t) MAKE_LEGACY_SYSCALL ( | ||
| UMASK_SYSCALL, "syscall|umask", (uint64_t) mask, | ||
| NOTUSED, NOTUSED, NOTUSED, NOTUSED, NOTUSED, TRANSLATE_ERRNO_ON); | ||
| } | ||
|
Member
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. Add new line |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ use fdtables; | |
| use parking_lot::{Mutex, RwLock}; | ||
| use std::ffi::CString; | ||
| use std::path::PathBuf; | ||
| use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU64, Ordering::*}; | ||
| use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU32, AtomicU64, Ordering::*}; | ||
| use std::sync::Arc; | ||
| use sysdefs::constants::{ | ||
| EXIT_SUCCESS, FDKIND_KERNEL, INIT_CAGEID, MAIN_THREADID, RAWPOSIX_CAGEID, STDERR_FILENO, | ||
|
|
@@ -287,6 +287,7 @@ pub fn rawposix_start(verbosity: isize) { | |
| exit_group_initiated: AtomicBool::new(false), | ||
| is_dead: AtomicBool::new(false), | ||
| grate_inflight: AtomicU64::new(0), | ||
| umask: AtomicU32::new(0o022), | ||
|
Member
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 we have comments about default value here? |
||
| }; | ||
|
|
||
| // Add cage to cagetable | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Before running this test: | ||
| * 1. Ensure the test directory exists in $LIND_FS_ROOT. | ||
| * 2. No pre-existing files named "umask_test_file.txt" or "umask_test_dir". | ||
| */ | ||
|
|
||
|
|
||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
| #include <sys/stat.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main() { | ||
| mode_t old_mask; | ||
| int fd; | ||
| struct stat st; | ||
|
|
||
| /* Cleanup from any previous run */ | ||
| rmdir("testfiles/umask_test_dir"); | ||
| unlink("testfiles/umask_test_file.txt"); | ||
| unlink("testfiles/umask_test_file2.txt"); | ||
|
|
||
|
|
||
| /* Test 1: umask returns previous mask */ | ||
| old_mask = umask(0022); | ||
| if (old_mask != 0022) { | ||
| printf("FAIL: expected initial umask 0022, got %04o\n", old_mask); | ||
| return 1; | ||
| } | ||
| umask(old_mask); /* restore */ | ||
| printf("PASS: umask returns previous mask\n"); | ||
|
|
||
| /* Test 2: umask applied on open — file created with 0666 & ~0022 = 0644 */ | ||
| umask(0022); | ||
| fd = open("testfiles/umask_test_file.txt", O_CREAT | O_WRONLY, 0666); | ||
| if (fd == -1) { | ||
| perror("open failed"); | ||
| return 1; | ||
| } | ||
| close(fd); | ||
|
|
||
| if (stat("testfiles/umask_test_file.txt", &st) == -1) { | ||
| perror("stat failed"); | ||
| return 1; | ||
| } | ||
| if ((st.st_mode & 0777) != 0644) { | ||
| printf("FAIL: expected file perms 0644, got %04o\n", st.st_mode & 0777); | ||
| return 1; | ||
| } | ||
| printf("PASS: umask applied correctly on open (0644)\n"); | ||
|
|
||
| /* Test 3: umask applied on mkdir — dir created with 0777 & ~0022 = 0755 */ | ||
| umask(0022); | ||
| if (mkdir("testfiles/umask_test_dir", 0777) == -1) { | ||
| perror("mkdir failed"); | ||
| return 1; | ||
| } | ||
| if (stat("testfiles/umask_test_dir", &st) == -1) { | ||
| perror("stat on dir failed"); | ||
| return 1; | ||
| } | ||
| if ((st.st_mode & 0777) != 0755) { | ||
| printf("FAIL: expected dir perms 0755, got %04o\n", st.st_mode & 0777); | ||
| return 1; | ||
| } | ||
| printf("PASS: umask applied correctly on mkdir (0755)\n"); | ||
|
|
||
| /* Test 4: changing umask affects subsequent creates */ | ||
| umask(0077); | ||
| fd = open("testfiles/umask_test_file2.txt", O_CREAT | O_WRONLY, 0666); | ||
| if (fd == -1) { | ||
| perror("open failed"); | ||
| return 1; | ||
| } | ||
| close(fd); | ||
| if (stat("testfiles/umask_test_file2.txt", &st) == -1) { | ||
| perror("stat failed"); | ||
| return 1; | ||
| } | ||
| if ((st.st_mode & 0777) != 0600) { | ||
| printf("FAIL: expected file perms 0600, got %04o\n", st.st_mode & 0777); | ||
| return 1; | ||
| } | ||
| printf("PASS: umask 0077 applied correctly on open (0600)\n"); | ||
|
|
||
| printf("All umask tests passed.\n"); | ||
| return 0; | ||
| } | ||
|
Member
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. Add new line |
||
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.
Seems this file is not used. Should we remove?