3c14dc61f7
Don't assume that 4MB can be allocated from stack since there could be smaller DefaultLimitSTACK= in force, so let's use malloc(). NUL terminate the huge strings by hand, also ensure termination in test_lz4_decompress_partial() and optimize the memset() for the string. Some items in /proc and /etc may not be accessible to poor unprivileged users due to e.g. SELinux, BOFH or both, so check for EACCES and EPERM. /var/tmp may be a symlink to /tmp and then path_compare() will always fail, so let's stick to /tmp like elsewhere. /tmp may be mounted with noexec option and then trying to execute scripts from there would fail. Detect and warn if seccomp is already in use, which could make seccomp test fail if the syscalls are already blocked. Unset $TMPDIR so it will not break specifier tests where %T is assumed to be /tmp and %V /var/tmp.
75 lines
2.5 KiB
C
75 lines
2.5 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
|
#include "alloc-util.h"
|
|
#include "errno-util.h"
|
|
#include "log.h"
|
|
#include "path-util.h"
|
|
#include "string-util.h"
|
|
#include "tests.h"
|
|
#include "umount.h"
|
|
#include "util.h"
|
|
|
|
static void test_mount_points_list(const char *fname) {
|
|
_cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
|
|
_cleanup_free_ char *testdata_fname = NULL;
|
|
MountPoint *m;
|
|
|
|
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
|
|
|
|
if (fname) {
|
|
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
|
|
fname = testdata_fname;
|
|
}
|
|
|
|
LIST_HEAD_INIT(mp_list_head);
|
|
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
|
|
|
|
LIST_FOREACH(mount_point, m, mp_list_head)
|
|
log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
|
|
m->path,
|
|
strempty(m->remount_options),
|
|
m->remount_flags,
|
|
yes_no(m->try_remount_ro),
|
|
major(m->devnum), minor(m->devnum));
|
|
}
|
|
|
|
static void test_swap_list(const char *fname) {
|
|
_cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
|
|
_cleanup_free_ char *testdata_fname = NULL;
|
|
MountPoint *m;
|
|
int r;
|
|
|
|
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
|
|
|
|
if (fname) {
|
|
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
|
|
fname = testdata_fname;
|
|
}
|
|
|
|
LIST_HEAD_INIT(mp_list_head);
|
|
r = swap_list_get(fname, &mp_list_head);
|
|
if (ERRNO_IS_PRIVILEGE(r))
|
|
return;
|
|
assert_se(r >= 0);
|
|
|
|
LIST_FOREACH(mount_point, m, mp_list_head)
|
|
log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
|
|
m->path,
|
|
strempty(m->remount_options),
|
|
m->remount_flags,
|
|
yes_no(m->try_remount_ro),
|
|
major(m->devnum), minor(m->devnum));
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
test_setup_logging(LOG_DEBUG);
|
|
|
|
test_mount_points_list(NULL);
|
|
test_mount_points_list("/test-umount/empty.mountinfo");
|
|
test_mount_points_list("/test-umount/garbled.mountinfo");
|
|
test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
|
|
|
|
test_swap_list(NULL);
|
|
test_swap_list("/test-umount/example.swaps");
|
|
}
|