diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-12 11:06:46 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-12 16:01:40 +0100 |
commit | 52f05ef21d7790f37bc3cd6e54fb9a4bcb16efa5 (patch) | |
tree | 52a9ead4db8ae30d8b4cf69b0e19e39c9fbc37c4 | |
parent | b0c4b2824693fe6a27ea9439ec7a6328a0e23704 (diff) | |
download | systemd-52f05ef21d7790f37bc3cd6e54fb9a4bcb16efa5.tar.gz |
umask-util: add helper that resets umask until end of current code block
-rw-r--r-- | src/basic/umask-util.h | 3 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 9 | ||||
-rw-r--r-- | src/shared/dev-setup.c | 3 | ||||
-rw-r--r-- | src/test/test-fs-util.c | 3 |
4 files changed, 9 insertions, 9 deletions
diff --git a/src/basic/umask-util.h b/src/basic/umask-util.h index bd7c2bdb8c..90d18f70ba 100644 --- a/src/basic/umask-util.h +++ b/src/basic/umask-util.h @@ -24,3 +24,6 @@ assert_cc((S_IFMT & 0777) == 0); for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \ FLAGS_SET(_saved_umask_, S_IFMT); \ _saved_umask_ &= 0777) + +#define BLOCK_WITH_UMASK(mask) \ + _unused_ _cleanup_umask_ mode_t _saved_umask_ = umask(mask); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 66daeb4f64..b85b8c3d43 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2216,13 +2216,12 @@ static int copy_devnodes(const char *dest) { "tty\0" "net/tun\0"; - _unused_ _cleanup_umask_ mode_t u; const char *d; int r = 0; assert(dest); - u = umask(0000); + BLOCK_WITH_UMASK(0000); /* Create /dev/net, so that we can create /dev/net/tun in it */ if (userns_mkdir(dest, "/dev/net", 0755, 0, 0) < 0) @@ -2299,11 +2298,10 @@ static int copy_devnodes(const char *dest) { } static int make_extra_nodes(const char *dest) { - _unused_ _cleanup_umask_ mode_t u; size_t i; int r; - u = umask(0000); + BLOCK_WITH_UMASK(0000); for (i = 0; i < arg_n_extra_nodes; i++) { _cleanup_free_ char *path = NULL; @@ -2500,12 +2498,11 @@ static int setup_kmsg(int kmsg_socket) { _cleanup_(unlink_and_freep) char *from = NULL; _cleanup_free_ char *fifo = NULL; _cleanup_close_ int fd = -1; - _unused_ _cleanup_umask_ mode_t u; int r; assert(kmsg_socket >= 0); - u = umask(0000); + BLOCK_WITH_UMASK(0000); /* We create the kmsg FIFO as as temporary file in /run, but immediately delete it after bind mounting it to * /proc/kmsg. While FIFOs on the reading side behave very similar to /proc/kmsg, their writing side behaves diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index c3e717ae11..0390abbfdc 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -81,13 +81,12 @@ int make_inaccessible_nodes( { "inaccessible/blk", S_IFBLK | 0000 }, }; - _unused_ _cleanup_umask_ mode_t u; int r; if (!parent_dir) parent_dir = "/run/systemd"; - u = umask(0000); + BLOCK_WITH_UMASK(0000); /* Set up inaccessible (and empty) file nodes of all types. This are used to as mount sources for over-mounting * ("masking") file nodes that shall become inaccessible and empty for specific containers or services. We try diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 41ddec4783..d8273bc846 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -765,7 +765,6 @@ static void test_rename_noreplace(void) { static void test_chmod_and_chown(void) { _cleanup_(rm_rf_physical_and_freep) char *d = NULL; - _unused_ _cleanup_umask_ mode_t u = umask(0000); struct stat st; const char *p; @@ -774,6 +773,8 @@ static void test_chmod_and_chown(void) { log_info("/* %s */", __func__); + BLOCK_WITH_UMASK(0000); + assert_se(mkdtemp_malloc(NULL, &d) >= 0); p = strjoina(d, "/reg"); |