Merge pull request #32123 from mrc0mmand/assorted-tweaks
A couple of assorted tweaks
This commit is contained in:
+1
-1
@@ -32,7 +32,7 @@ typedef enum LogTarget{
|
||||
} LogTarget;
|
||||
|
||||
/* This log level disables logging completely. It can only be passed to log_set_max_level() and cannot be
|
||||
* used a regular log level. */
|
||||
* used as a regular log level. */
|
||||
#define LOG_NULL (LOG_EMERG - 1)
|
||||
|
||||
/* Note to readers: << and >> have lower precedence (are evaluated earlier) than & and | */
|
||||
|
||||
@@ -120,13 +120,13 @@ static const BaseFilesystem table[] = {
|
||||
# else
|
||||
# error "Unknown RISC-V ABI"
|
||||
# endif
|
||||
#elif defined(__s390__)
|
||||
/* s390-linux-gnu */
|
||||
#elif defined(__s390x__)
|
||||
{ "lib64", 0, "usr/lib/"LIB_ARCH_TUPLE"\0"
|
||||
"usr/lib64\0"
|
||||
"usr/lib\0", "ld-lsb-s390x.so.3" },
|
||||
# define KNOW_LIB64_DIRS 1
|
||||
#elif defined(__s390__)
|
||||
/* s390-linux-gnu */
|
||||
#elif defined(__sparc__)
|
||||
#endif
|
||||
/* gcc doesn't allow pragma to be used within constructs, hence log about this separately below */
|
||||
|
||||
+30
-1
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "build-path.h"
|
||||
#include "capability-util.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "copy.h"
|
||||
@@ -1428,7 +1429,8 @@ static int prepare_ns(const char *process_name) {
|
||||
NULL);
|
||||
assert_se(r >= 0);
|
||||
if (r == 0) {
|
||||
_cleanup_free_ char *unit_dir = NULL;
|
||||
_cleanup_free_ char *unit_dir = NULL, *build_dir = NULL, *build_dir_mount = NULL;
|
||||
int ret;
|
||||
|
||||
/* Make "/" read-only. */
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, NULL, "/", NULL, MS_BIND|MS_REMOUNT|MS_RDONLY, NULL) >= 0);
|
||||
@@ -1440,15 +1442,42 @@ static int prepare_ns(const char *process_name) {
|
||||
|
||||
assert_se(mkdir_p(PRIVATE_UNIT_DIR, 0755) >= 0);
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, "tmpfs", PRIVATE_UNIT_DIR, "tmpfs", MS_NOSUID|MS_NODEV, NULL) >= 0);
|
||||
/* Mark our test "playground" as MS_SLAVE, so we can MS_MOVE mounts underneath it. */
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, NULL, PRIVATE_UNIT_DIR, NULL, MS_SLAVE, NULL) >= 0);
|
||||
|
||||
/* Copy unit files to make them accessible even when unprivileged. */
|
||||
assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0);
|
||||
assert_se(copy_directory_at(AT_FDCWD, unit_dir, AT_FDCWD, PRIVATE_UNIT_DIR, COPY_MERGE_EMPTY) >= 0);
|
||||
|
||||
/* Mount tmpfs on the following directories to make not StateDirectory= or friends disturb the host. */
|
||||
ret = get_build_exec_dir(&build_dir);
|
||||
assert_se(ret >= 0 || ret == -ENOEXEC);
|
||||
|
||||
if (build_dir) {
|
||||
/* Account for a build directory being in one of the soon-to-be-tmpfs directories. If we
|
||||
* overmount it with an empty tmpfs, manager_new() will pin the wrong systemd-executor binary,
|
||||
* which can then lead to unexpected (and painful to debug) test fails. */
|
||||
assert_se(access(build_dir, F_OK) >= 0);
|
||||
assert_se(build_dir_mount = path_join(PRIVATE_UNIT_DIR, "build_dir"));
|
||||
assert_se(mkdir_p(build_dir_mount, 0755) >= 0);
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, build_dir, build_dir_mount, NULL, MS_BIND, NULL) >= 0);
|
||||
}
|
||||
|
||||
FOREACH_STRING(p, "/dev/shm", "/root", "/tmp", "/var/tmp", "/var/lib")
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, "tmpfs", p, "tmpfs", MS_NOSUID|MS_NODEV, NULL) >= 0);
|
||||
|
||||
if (build_dir_mount) {
|
||||
ret = RET_NERRNO(access(build_dir, F_OK));
|
||||
assert_se(ret >= 0 || ret == -ENOENT);
|
||||
|
||||
if (ret == -ENOENT) {
|
||||
/* The build directory got overmounted by tmpfs, so let's use the "backup" bind mount to
|
||||
* bring it back. */
|
||||
assert_se(mkdir_p(build_dir, 0755) >= 0);
|
||||
assert_se(mount_nofollow_verbose(LOG_DEBUG, build_dir_mount, build_dir, NULL, MS_MOVE, NULL) >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare credstore like tmpfiles.d/credstore.conf for LoadCredential= tests. */
|
||||
FOREACH_STRING(p, "/run/credstore", "/run/credstore.encrypted") {
|
||||
assert_se(mkdir_p(p, 0) >= 0);
|
||||
|
||||
+13
-9
@@ -138,6 +138,7 @@ TEST(rearrange_stdio) {
|
||||
|
||||
if (r == 0) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
int pipe_read_fd, pair[2];
|
||||
char buffer[10];
|
||||
|
||||
/* Child */
|
||||
@@ -145,6 +146,10 @@ TEST(rearrange_stdio) {
|
||||
safe_close(STDERR_FILENO); /* Let's close an fd < 2, to make it more interesting */
|
||||
|
||||
assert_se(rearrange_stdio(-EBADF, -EBADF, -EBADF) >= 0);
|
||||
/* Reconfigure logging after rearranging stdout/stderr, so we still log to somewhere if the
|
||||
* following tests fail, making it slightly less annoying to debug */
|
||||
log_set_target(LOG_TARGET_KMSG);
|
||||
log_open();
|
||||
|
||||
assert_se(fd_get_path(STDIN_FILENO, &path) >= 0);
|
||||
assert_se(path_equal(path, "/dev/null"));
|
||||
@@ -162,13 +167,12 @@ TEST(rearrange_stdio) {
|
||||
safe_close(STDOUT_FILENO);
|
||||
safe_close(STDERR_FILENO);
|
||||
|
||||
{
|
||||
int pair[2];
|
||||
assert_se(pipe(pair) >= 0);
|
||||
assert_se(pair[0] == 0);
|
||||
assert_se(pair[1] == 1);
|
||||
assert_se(fd_move_above_stdio(0) == 3);
|
||||
}
|
||||
assert_se(pipe(pair) >= 0);
|
||||
assert_se(pair[0] == 0);
|
||||
assert_se(pair[1] == 1);
|
||||
pipe_read_fd = fd_move_above_stdio(0);
|
||||
assert_se(pipe_read_fd >= 3);
|
||||
|
||||
assert_se(open("/dev/full", O_WRONLY|O_CLOEXEC) == 0);
|
||||
assert_se(acquire_data_fd("foobar") == 2);
|
||||
|
||||
@@ -176,7 +180,7 @@ TEST(rearrange_stdio) {
|
||||
|
||||
assert_se(write(1, "x", 1) < 0 && errno == ENOSPC);
|
||||
assert_se(write(2, "z", 1) == 1);
|
||||
assert_se(read(3, buffer, sizeof(buffer)) == 1);
|
||||
assert_se(read(pipe_read_fd, buffer, sizeof(buffer)) == 1);
|
||||
assert_se(buffer[0] == 'z');
|
||||
assert_se(read(0, buffer, sizeof(buffer)) == 6);
|
||||
assert_se(memcmp(buffer, "foobar", 6) == 0);
|
||||
@@ -184,7 +188,7 @@ TEST(rearrange_stdio) {
|
||||
assert_se(rearrange_stdio(-EBADF, 1, 2) >= 0);
|
||||
assert_se(write(1, "a", 1) < 0 && errno == ENOSPC);
|
||||
assert_se(write(2, "y", 1) == 1);
|
||||
assert_se(read(3, buffer, sizeof(buffer)) == 1);
|
||||
assert_se(read(pipe_read_fd, buffer, sizeof(buffer)) == 1);
|
||||
assert_se(buffer[0] == 'y');
|
||||
|
||||
assert_se(fd_get_path(0, &path) >= 0);
|
||||
|
||||
Reference in New Issue
Block a user