Skip to content

Commit 52f05ef

Browse files
committed
umask-util: add helper that resets umask until end of current code block
1 parent b0c4b28 commit 52f05ef

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/basic/umask-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ assert_cc((S_IFMT & 0777) == 0);
2424
for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
2525
FLAGS_SET(_saved_umask_, S_IFMT); \
2626
_saved_umask_ &= 0777)
27+
28+
#define BLOCK_WITH_UMASK(mask) \
29+
_unused_ _cleanup_umask_ mode_t _saved_umask_ = umask(mask);

src/nspawn/nspawn.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,13 +2216,12 @@ static int copy_devnodes(const char *dest) {
22162216
"tty\0"
22172217
"net/tun\0";
22182218

2219-
_unused_ _cleanup_umask_ mode_t u;
22202219
const char *d;
22212220
int r = 0;
22222221

22232222
assert(dest);
22242223

2225-
u = umask(0000);
2224+
BLOCK_WITH_UMASK(0000);
22262225

22272226
/* Create /dev/net, so that we can create /dev/net/tun in it */
22282227
if (userns_mkdir(dest, "/dev/net", 0755, 0, 0) < 0)
@@ -2299,11 +2298,10 @@ static int copy_devnodes(const char *dest) {
22992298
}
23002299

23012300
static int make_extra_nodes(const char *dest) {
2302-
_unused_ _cleanup_umask_ mode_t u;
23032301
size_t i;
23042302
int r;
23052303

2306-
u = umask(0000);
2304+
BLOCK_WITH_UMASK(0000);
23072305

23082306
for (i = 0; i < arg_n_extra_nodes; i++) {
23092307
_cleanup_free_ char *path = NULL;
@@ -2500,12 +2498,11 @@ static int setup_kmsg(int kmsg_socket) {
25002498
_cleanup_(unlink_and_freep) char *from = NULL;
25012499
_cleanup_free_ char *fifo = NULL;
25022500
_cleanup_close_ int fd = -1;
2503-
_unused_ _cleanup_umask_ mode_t u;
25042501
int r;
25052502

25062503
assert(kmsg_socket >= 0);
25072504

2508-
u = umask(0000);
2505+
BLOCK_WITH_UMASK(0000);
25092506

25102507
/* We create the kmsg FIFO as as temporary file in /run, but immediately delete it after bind mounting it to
25112508
* /proc/kmsg. While FIFOs on the reading side behave very similar to /proc/kmsg, their writing side behaves

src/shared/dev-setup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,12 @@ int make_inaccessible_nodes(
8181
{ "inaccessible/blk", S_IFBLK | 0000 },
8282
};
8383

84-
_unused_ _cleanup_umask_ mode_t u;
8584
int r;
8685

8786
if (!parent_dir)
8887
parent_dir = "/run/systemd";
8988

90-
u = umask(0000);
89+
BLOCK_WITH_UMASK(0000);
9190

9291
/* Set up inaccessible (and empty) file nodes of all types. This are used to as mount sources for over-mounting
9392
* ("masking") file nodes that shall become inaccessible and empty for specific containers or services. We try

src/test/test-fs-util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ static void test_rename_noreplace(void) {
765765

766766
static void test_chmod_and_chown(void) {
767767
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
768-
_unused_ _cleanup_umask_ mode_t u = umask(0000);
769768
struct stat st;
770769
const char *p;
771770

@@ -774,6 +773,8 @@ static void test_chmod_and_chown(void) {
774773

775774
log_info("/* %s */", __func__);
776775

776+
BLOCK_WITH_UMASK(0000);
777+
777778
assert_se(mkdtemp_malloc(NULL, &d) >= 0);
778779

779780
p = strjoina(d, "/reg");

0 commit comments

Comments
 (0)