// 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)
/* 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)
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);
/* 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)
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
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");
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");
(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);
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);
goto finish;
}
- RUN_WITH_UMASK(0022)
+ WITH_UMASK(0022)
(void) execute_directories(
(const char* const*) paths,
DEFAULT_TIMEOUT_USEC,
if (errno != ENOENT)
return -errno;
- RUN_WITH_UMASK(000)
+ WITH_UMASK(000)
r = mkdir_parents(prefix, 0755);
if (r < 0)
return r;
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;
if (!y)
return -ENOMEM;
- RUN_WITH_UMASK(0000)
+ WITH_UMASK(0000)
if (mkdir(y, 0777 | S_ISVTX) < 0)
return -errno;
/* 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;
/* 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;
switch (user_record_storage(h)) {
case USER_SUBVOLUME:
- RUN_WITH_UMASK(0077)
+ WITH_UMASK(0077)
r = btrfs_subvol_make(d);
if (r >= 0) {
return r;
sa_len = r;
- RUN_WITH_UMASK(0177)
+ WITH_UMASK(0177)
if (bind(fd, &sa.sa, sa_len) < 0)
return -errno;
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,
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)
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
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);
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)
(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 */
(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;
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);
u = umask(0111);
n = 0;
- RUN_WITH_UMASK(0123) {
+ WITH_UMASK(0123) {
assert_se(umask(000) == 0123);
n++;
}
assert_se(n == 1);
assert_se(umask(u) == 0111);
- RUN_WITH_UMASK(0135) {
+ WITH_UMASK(0135) {
assert_se(umask(000) == 0135);
n++;
}
assert_se(n == 2);
assert_se(umask(0111) == u);
- RUN_WITH_UMASK(0315) {
+ WITH_UMASK(0315) {
assert_se(umask(000) == 0315);
n++;
break;
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();
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();
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;
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();
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();
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();
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();
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;
if (r < 0 && r != -ENOENT)
return r;
} else
- RUN_WITH_UMASK(0000)
+ WITH_UMASK(0000)
(void) mkdir_parents_label(i->path, 0755);
return 0;
(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");