]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
treewide: drop "RUN_" from "RUN_WITH_UMASK"
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Dec 2022 11:11:29 +0000 (12:11 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 13 Dec 2022 13:39:30 +0000 (14:39 +0100)
RUN_WITH_UMASK was initially conceived for spawning externals progs with the
umask set. But nowadays we use it various syscalls and stuff that doesn't "run"
anything, so the "RUN_" prefix has outlived its usefulness.

20 files changed:
coccinelle/macros.h
src/basic/umask-util.h
src/boot/bootctl.c
src/core/dbus.c
src/core/main.c
src/core/manager.c
src/core/namespace.c
src/core/unit.c
src/home/homework-directory.c
src/shared/ask-password-api.c
src/shared/base-filesystem.c
src/shared/copy.c
src/shared/machine-id-setup.c
src/shared/reboot-util.c
src/shared/socket-label.c
src/shared/varlink.c
src/test/test-install-file.c
src/test/test-umask-util.c
src/tmpfiles/tmpfiles.c
src/userdb/userdbd-manager.c

index f44b3f2d26f48746e0533d2e7e6902d77510a509..adfea5fbec47bedbf0e0ff4210931ad37e9e2398 100644 (file)
@@ -43,7 +43,7 @@
 
 // src/basic/umask-util.h
 #define _cleanup_umask_
-#define RUN_WITH_UMASK(mask)                                            \
+#define WITH_UMASK(mask)                                            \
         for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
              FLAGS_SET(_saved_umask_, S_IFMT);                          \
              _saved_umask_ &= 0777)
index 90d18f70ba441d5085aa17b31f34a1f562a55400..6f0e1cc2b24a88328da71b89a9d2f74b11e4801e 100644 (file)
@@ -15,12 +15,12 @@ static inline void umaskp(mode_t *u) {
 
 /* We make use of the fact here that the umask() concept is using only the lower 9 bits of mode_t, although
  * mode_t has space for the file type in the bits further up. We simply OR in the file type mask S_IFMT to
- * distinguish the first and the second iteration of the RUN_WITH_UMASK() loop, so that we can run the first
- * one, and exit on the second. */
+ * distinguish the first and the second iteration of the WITH_UMASK() loop, so that we can run the first one,
+ * and exit on the second. */
 
 assert_cc((S_IFMT & 0777) == 0);
 
-#define RUN_WITH_UMASK(mask)                                            \
+#define WITH_UMASK(mask)                                            \
         for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
              FLAGS_SET(_saved_umask_, S_IFMT);                          \
              _saved_umask_ &= 0777)
index 44a5a371b905f26491d94b4f8324e9bf3bfd06ae..7721c3d2e38ed16c2baf96a263ecc9e2409be9e1 100644 (file)
@@ -828,7 +828,7 @@ static int copy_file_with_version_check(const char *from, const char *to, bool f
         if (r < 0)
                 return log_oom();
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 fd_to = open(t, O_WRONLY|O_CREAT|O_CLOEXEC|O_EXCL|O_NOFOLLOW, 0644);
                 if (fd_to < 0)
                         return log_error_errno(errno, "Failed to open \"%s\" for writing: %m", t);
@@ -2073,7 +2073,7 @@ static int install_random_seed(const char *esp) {
         /* Let's write this variable with an umask in effect, so that unprivileged users can't see the token
          * and possibly get identification information or too much insight into the kernel's entropy pool
          * state. */
-        RUN_WITH_UMASK(0077) {
+        WITH_UMASK(0077) {
                 r = efi_set_variable(EFI_LOADER_VARIABLE(LoaderSystemToken), buffer, sizeof(buffer));
                 if (r < 0) {
                         if (!arg_graceful)
@@ -2147,7 +2147,7 @@ static int verb_install(int argc, char *argv[], void *userdata) {
 
         const char *arch = arg_arch_all ? "" : get_efi_arch();
 
-        RUN_WITH_UMASK(0002) {
+        WITH_UMASK(0002) {
                 if (install) {
                         /* Don't create any of these directories when we are just updating. When we update
                          * we'll drop-in our files (unless there are newer ones already), but we won't create
index 0bf2391b03946db7f9f437feb677e9ae1c581f41..c6024a061ebcf2b731b5f5e9cce32ccb1a341219 100644 (file)
@@ -941,7 +941,7 @@ int bus_init_private(Manager *m) {
         if (fd < 0)
                 return log_error_errno(errno, "Failed to allocate private socket: %m");
 
-        RUN_WITH_UMASK(0077)
+        WITH_UMASK(0077)
                 r = bind(fd, &sa.sa, sa_len);
         if (r < 0)
                 return log_error_errno(errno, "Failed to bind private socket: %m");
index 9c1de3624cb94d719a3564e9624de5107a1ea2e9..25a558b6cf4d1a123c6eae1f6ae1ec61de151635 100644 (file)
@@ -1376,7 +1376,7 @@ static int write_container_id(void) {
         if (isempty(c))
                 return 0;
 
-        RUN_WITH_UMASK(0022)
+        WITH_UMASK(0022)
                 r = write_string_file("/run/systemd/container", c, WRITE_STRING_FILE_CREATE);
         if (r < 0)
                 return log_warning_errno(r, "Failed to write /run/systemd/container, ignoring: %m");
index 598604d69453d3e3cecb2077f1ccf7cefff12e7d..e9b7b26160f237edd9ea88a1c2c5e07b326d35f3 100644 (file)
@@ -1103,7 +1103,7 @@ static int manager_setup_cgroups_agent(Manager *m) {
                 (void) sockaddr_un_unlink(&sa.un);
 
                 /* Only allow root to connect to this socket */
-                RUN_WITH_UMASK(0077)
+                WITH_UMASK(0077)
                         r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
                 if (r < 0)
                         return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
@@ -3674,7 +3674,7 @@ static int manager_run_environment_generators(Manager *m) {
         if (!generator_path_any((const char* const*) paths))
                 return 0;
 
-        RUN_WITH_UMASK(0022)
+        WITH_UMASK(0022)
                 r = execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, gather_environment,
                                         args, NULL, m->transient_environment,
                                         EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID);
@@ -3776,7 +3776,7 @@ static int manager_run_generators(Manager *m) {
                 goto finish;
         }
 
-        RUN_WITH_UMASK(0022)
+        WITH_UMASK(0022)
                 (void) execute_directories(
                                 (const char* const*) paths,
                                 DEFAULT_TIMEOUT_USEC,
index 4920716f3487536271996a955e961f205f0abe49..7082cd19d89ab3e14a3a319da422abed6d3e0aac 100644 (file)
@@ -2708,7 +2708,7 @@ static int make_tmp_prefix(const char *prefix) {
         if (errno != ENOENT)
                 return -errno;
 
-        RUN_WITH_UMASK(000)
+        WITH_UMASK(000)
                 r = mkdir_parents(prefix, 0755);
         if (r < 0)
                 return r;
@@ -2765,7 +2765,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, ch
         if (r < 0)
                 return r;
 
-        RUN_WITH_UMASK(0077)
+        WITH_UMASK(0077)
                 if (!mkdtemp(x)) {
                         if (errno == EROFS || ERRNO_IS_DISK_SPACE(errno))
                                 rw = false;
@@ -2778,7 +2778,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, ch
                 if (!y)
                         return -ENOMEM;
 
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         if (mkdir(y, 0777 | S_ISVTX) < 0)
                                     return -errno;
 
@@ -2792,7 +2792,7 @@ static int setup_one_tmp_dir(const char *id, const char *prefix, char **path, ch
                 /* Trouble: we failed to create the directory. Instead of failing, let's simulate /tmp being
                  * read-only. This way the service will get the EROFS result as if it was writing to the real
                  * file system. */
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         r = mkdir_p(RUN_SYSTEMD_EMPTY, 0500);
                 if (r < 0)
                         return r;
index b052402cfb356a2b53390345cb72f705be57512c..b7cca3e2871a8ac6d2e4b49773ff2764af7c0380 100644 (file)
@@ -4469,7 +4469,7 @@ int unit_make_transient(Unit *u) {
         /* Let's open the file we'll write the transient settings into. This file is kept open as long as we are
          * creating the transient, and is closed in unit_load(), as soon as we start loading the file. */
 
-        RUN_WITH_UMASK(0022) {
+        WITH_UMASK(0022) {
                 f = fopen(path, "we");
                 if (!f)
                         return -errno;
index 6dc3df55a85acf980f385990a214a72e9f76c1fc..d3bc54742981d417e0ac4ceaa65c7b51ae25af9d 100644 (file)
@@ -130,7 +130,7 @@ int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserReco
         switch (user_record_storage(h)) {
 
         case USER_SUBVOLUME:
-                RUN_WITH_UMASK(0077)
+                WITH_UMASK(0077)
                         r = btrfs_subvol_make(d);
 
                 if (r >= 0) {
index 1ad5ddd50327c81593519c9374f234a5d5a500f2..0b1b9c6861b13f14a7c3aef75a075a0203ca3b5a 100644 (file)
@@ -687,7 +687,7 @@ static int create_socket(char **ret) {
                 return r;
         sa_len = r;
 
-        RUN_WITH_UMASK(0177)
+        WITH_UMASK(0177)
                 if (bind(fd, &sa.sa, sa_len) < 0)
                         return -errno;
 
index c2902d35082e40b9d26a69269a64e634885ae518..9b7270ae535b9bac4b83a160389e319ea7498deb 100644 (file)
@@ -178,7 +178,7 @@ int base_filesystem_create(const char *root, uid_t uid, gid_t gid) {
                         continue;
                 }
 
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         r = mkdirat(fd, table[i].dir, table[i].mode);
                 if (r < 0) {
                         log_full_errno(IN_SET(errno, EEXIST, EROFS) || table[i].ignore_failure ? LOG_DEBUG : LOG_ERR, errno,
index e6265e2c9663f6ce7502483dc1d321629e89c21c..e2ce4b29074bfc2ad8a209f5944f3bd92793ab68 100644 (file)
@@ -1357,7 +1357,7 @@ int copy_file_full(
         if (r < 0)
                 return r;
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 if (copy_flags & COPY_MAC_CREATE) {
                         r = mac_selinux_create_file_prepare(to, S_IFREG);
                         if (r < 0)
index 2e33a23cb92176f31342c8e2bbfa3831e5c17c6c..0bdaba00e64d2c6e0648e2e05d6073072abd1c4b 100644 (file)
@@ -89,7 +89,7 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_
 
         etc_machine_id = prefix_roota(root, "/etc/machine-id");
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 /* We create this 0444, to indicate that this isn't really
                  * something you should ever modify. Of course, since the file
                  * will be owned by root it doesn't matter much, but maybe
@@ -166,7 +166,7 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_
 
         run_machine_id = prefix_roota(root, "/run/machine-id");
 
-        RUN_WITH_UMASK(0022)
+        WITH_UMASK(0022)
                 r = id128_write(run_machine_id, ID128_FORMAT_PLAIN, machine_id);
         if (r < 0) {
                 (void) unlink(run_machine_id);
index 7fa3ff98b69deedc97e4951ac0709afb430054ed..b11040556830574a4df15f094cb512aba842964d 100644 (file)
@@ -42,7 +42,7 @@ int update_reboot_parameter_and_warn(const char *parameter, bool keep) {
                 return 0;
         }
 
-        RUN_WITH_UMASK(0022) {
+        WITH_UMASK(0022) {
                 r = write_string_file("/run/systemd/reboot-param", parameter,
                                       WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
                 if (r < 0)
index 8094ad764345f2da96019617f37689f7eca92b94..5195ca410c99c37d419b584c78569b3d2e185c59 100644 (file)
@@ -101,7 +101,7 @@ int socket_address_listen(
                 (void) mkdir_parents_label(p, directory_mode);
 
                 /* Enforce the right access mode for the socket */
-                RUN_WITH_UMASK(~socket_mode) {
+                WITH_UMASK(~socket_mode) {
                         r = mac_selinux_bind(fd, &a->sockaddr.sa, a->size);
                         if (r == -EADDRINUSE) {
                                 /* Unlink and try again */
index 4d2cfee4918aa9377debad71d59b381d01d1456a..7ff81973e1c1d3b55387991f193751ec1d393626 100644 (file)
@@ -2326,7 +2326,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t
 
         (void) sockaddr_un_unlink(&sockaddr.un);
 
-        RUN_WITH_UMASK(~m & 0777) {
+        WITH_UMASK(~m & 0777) {
                 r = mac_selinux_bind(fd, &sockaddr.sa, sockaddr_len);
                 if (r < 0)
                         return r;
index 711277550747d4bd794dcd848500ad1a669aa6aa..8206eb01a2f46a15d5997fb8df16ea166eb0f72d 100644 (file)
@@ -17,7 +17,7 @@ TEST(install_file) {
         assert_se(a = path_join(p, "foo"));
         assert_se(b = path_join(p, "bar"));
 
-        RUN_WITH_UMASK(0077)
+        WITH_UMASK(0077)
                 assert_se(write_string_file(a, "wups", WRITE_STRING_FILE_CREATE) >= 0);
 
         assert_se(lstat(a, &stat1) >= 0);
index df3ae98f5050238f5bf0c58e08d3c9db29d85a5b..bd5bc9cb437029d2571323bf2a9f2979d2ddb020 100644 (file)
@@ -12,7 +12,7 @@ int main(int argc, char *argv[]) {
         u = umask(0111);
 
         n = 0;
-        RUN_WITH_UMASK(0123) {
+        WITH_UMASK(0123) {
                 assert_se(umask(000) == 0123);
                 n++;
         }
@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) {
         assert_se(n == 1);
         assert_se(umask(u) == 0111);
 
-        RUN_WITH_UMASK(0135) {
+        WITH_UMASK(0135) {
                 assert_se(umask(000) == 0135);
                 n++;
         }
@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
         assert_se(n == 2);
         assert_se(umask(0111) == u);
 
-        RUN_WITH_UMASK(0315) {
+        WITH_UMASK(0315) {
                 assert_se(umask(000) == 0315);
                 n++;
                 break;
index f156d90073dc27557648ce4e5b6868303614207c..efe0e107b1467cdf381e375624b3281014f630bf 100644 (file)
@@ -1499,7 +1499,7 @@ static int create_file(Item *i, const char *path) {
         if (dir_fd < 0)
                 return dir_fd;
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 mac_selinux_create_file_prepare(path, S_IFREG);
                 fd = RET_NERRNO(openat(dir_fd, bn, O_CREAT|O_EXCL|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC|O_WRONLY|O_NOCTTY, i->mode));
                 mac_selinux_create_file_clear();
@@ -1572,7 +1572,7 @@ static int truncate_file(Item *i, const char *path) {
         if (fd == -ENOENT) {
                 creation = CREATION_NORMAL; /* Didn't work without O_CREATE, try again with */
 
-                RUN_WITH_UMASK(0000) {
+                WITH_UMASK(0000) {
                         mac_selinux_create_file_prepare(path, S_IFREG);
                         fd = RET_NERRNO(openat(dir_fd, bn, O_CREAT|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC|O_WRONLY|O_NOCTTY, i->mode));
                         mac_selinux_create_file_clear();
@@ -1716,14 +1716,14 @@ static int create_directory_or_subvolume(
 
                         subvol = false;
                 else {
-                        RUN_WITH_UMASK((~mode) & 0777)
+                        WITH_UMASK((~mode) & 0777)
                                 r = btrfs_subvol_make_fd(pfd, bn);
                 }
         } else
                 r = 0;
 
         if (!subvol || ERRNO_IS_NOT_SUPPORTED(r))
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         r = mkdirat_label(pfd, bn, mode);
 
         creation = r >= 0 ? CREATION_NORMAL : CREATION_EXISTING;
@@ -1869,7 +1869,7 @@ static int create_device(Item *i, mode_t file_type) {
         if (dfd < 0)
                 return dfd;
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 mac_selinux_create_file_prepare(i->path, file_type);
                 r = RET_NERRNO(mknodat(dfd, bn, i->mode | file_type, i->major_minor));
                 mac_selinux_create_file_clear();
@@ -1900,7 +1900,7 @@ static int create_device(Item *i, mode_t file_type) {
                 if (i->append_or_force) {
                         fd = safe_close(fd);
 
-                        RUN_WITH_UMASK(0000) {
+                        WITH_UMASK(0000) {
                                 mac_selinux_create_file_prepare(i->path, file_type);
                                 r = mknodat_atomic(dfd, bn, i->mode | file_type, i->major_minor);
                                 mac_selinux_create_file_clear();
@@ -1971,7 +1971,7 @@ static int create_fifo(Item *i) {
         if (pfd < 0)
                 return pfd;
 
-        RUN_WITH_UMASK(0000) {
+        WITH_UMASK(0000) {
                 mac_selinux_create_file_prepare(i->path, S_IFIFO);
                 r = RET_NERRNO(mkfifoat(pfd, bn, i->mode));
                 mac_selinux_create_file_clear();
@@ -1996,7 +1996,7 @@ static int create_fifo(Item *i) {
                 if (i->append_or_force) {
                         fd = safe_close(fd);
 
-                        RUN_WITH_UMASK(0000) {
+                        WITH_UMASK(0000) {
                                 mac_selinux_create_file_prepare(i->path, S_IFIFO);
                                 r = mkfifoat_atomic(pfd, bn, i->mode);
                                 mac_selinux_create_file_clear();
@@ -2378,7 +2378,7 @@ static int mkdir_parents_rm_if_wrong_type(mode_t child_mode, const char *path) {
                 if (r == -ENOENT)
                         r = rm_if_wrong_type_safe(S_IFDIR, parent_fd, &parent_st, t, AT_SYMLINK_NOFOLLOW);
                 if (r == -ENOENT) {
-                        RUN_WITH_UMASK(0000)
+                        WITH_UMASK(0000)
                                 r = mkdirat_label(parent_fd, t, 0755);
                         if (r < 0) {
                                 _cleanup_free_ char *parent_name = NULL;
@@ -2416,7 +2416,7 @@ static int mkdir_parents_item(Item *i, mode_t child_mode) {
                 if (r < 0 && r != -ENOENT)
                         return r;
         } else
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         (void) mkdir_parents_label(i->path, 0755);
 
         return 0;
index ff2607f8fe24724b1d115c8e96f5a007f429a433..81d3f6407c9d5f61e2d960a8840f1a8eb8e9ad5e 100644 (file)
@@ -277,7 +277,7 @@ int manager_startup(Manager *m) {
 
                 (void) sockaddr_un_unlink(&sockaddr.un);
 
-                RUN_WITH_UMASK(0000)
+                WITH_UMASK(0000)
                         if (bind(m->listen_fd, &sockaddr.sa, SOCKADDR_UN_LEN(sockaddr.un)) < 0)
                                 return log_error_errno(errno, "Failed to bind socket: %m");