#define HUGE_SIZE (4096*1024)
assert_se(huge = malloc(HUGE_SIZE));
- memset(huge, 'x', HUGE_SIZE);
- memcpy(huge, "HUGE=", 5);
+ memcpy(huge, "HUGE=", STRLEN("HUGE="));
+ memset(&huge[STRLEN("HUGE=")], 'x', HUGE_SIZE - STRLEN("HUGE=") - 1);
+ huge[HUGE_SIZE - 1] = '\0';
r = LZ4_compress_default(huge, buf, HUGE_SIZE, buf_size);
assert_se(r >= 0);
char data[512] = "random\0";
- char huge[4096*1024];
- memset(huge, 'x', sizeof(huge));
- memcpy(huge, "HUGE=", 5);
- char_array_0(huge);
+ _cleanup_free_ char *huge = NULL;
+
+ assert_se(huge = malloc(HUGE_SIZE));
+ memcpy(huge, "HUGE=", STRLEN("HUGE="));
+ memset(&huge[STRLEN("HUGE=")], 'x', HUGE_SIZE - STRLEN("HUGE=") - 1);
+ huge[HUGE_SIZE - 1] = '\0';
test_setup_logging(LOG_DEBUG);
data, sizeof(data), true);
test_decompress_startswith(OBJECT_COMPRESSED_XZ,
compress_blob_xz, decompress_startswith_xz,
- huge, sizeof(huge), true);
+ huge, HUGE_SIZE, true);
test_compress_stream(OBJECT_COMPRESSED_XZ, "xzcat",
compress_stream_xz, decompress_stream_xz, srcfile);
data, sizeof(data), true);
test_decompress_startswith(OBJECT_COMPRESSED_LZ4,
compress_blob_lz4, decompress_startswith_lz4,
- huge, sizeof(huge), true);
+ huge, HUGE_SIZE, true);
test_compress_stream(OBJECT_COMPRESSED_LZ4, "lz4cat",
compress_stream_lz4, decompress_stream_lz4, srcfile);
#include "sd-journal.h"
#include "macro.h"
+#include "memory-util.h"
int main(int argc, char *argv[]) {
- char huge[4096*1024];
+ _cleanup_free_ char *huge = NULL;
+
+#define HUGE_SIZE (4096*1024)
+ assert_se(huge = malloc(HUGE_SIZE));
/* utf-8 and non-utf-8, message-less and message-ful iovecs */
struct iovec graph1[] = {
assert_se(sd_journal_perror("") == 0);
- memset(huge, 'x', sizeof(huge));
- memcpy(huge, "HUGE=", 5);
- char_array_0(huge);
+ memcpy(huge, "HUGE=", STRLEN("HUGE="));
+ memset(&huge[STRLEN("HUGE=")], 'x', HUGE_SIZE - STRLEN("HUGE=") - 1);
+ huge[HUGE_SIZE - 1] = '\0';
assert_se(sd_journal_send("MESSAGE=Huge field attached",
huge,
#include "alloc-util.h"
#include "capability-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "macro.h"
int r;
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
+ return;
assert_se(r >= 0);
r = safe_atolu(content, &val);
int r;
r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content);
- if (r == -ENOENT) /* kernel pre 3.2 */
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) /* kernel pre 3.2 or no access */
return;
assert_se(r >= 0);
/* SPDX-License-Identifier: LGPL-2.1+ */
+#include <unistd.h>
+
#include "alloc-util.h"
#include "build.h"
#include "cgroup-setup.h"
+#include "errno-util.h"
#include "log.h"
#include "proc-cmdline.h"
#include "string-util.h"
int main(void) {
test_setup_logging(LOG_DEBUG);
+ if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return log_tests_skipped("can't read /proc/cmdline");
+
test_is_wanted_print(true);
test_is_wanted_print(false); /* run twice to test caching */
test_is_wanted();
#include "build.h"
#include "cgroup-util.h"
#include "dirent-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "parse-util.h"
int i, r;
r = cg_get_keyed_attribute("cpu", "/init.scope", "no_such_file", STRV_MAKE("no_such_attr"), &val);
- if (r == -ENOMEDIUM) {
+ if (r == -ENOMEDIUM || ERRNO_IS_PRIVILEGE(r)) {
log_info_errno(r, "Skipping most of %s, /sys/fs/cgroup not accessible: %m", __func__);
return;
}
int r;
r = clock_is_localtime(NULL);
- if (access("/etc/adjtime", F_OK) == 0) {
- log_info("/etc/adjtime exists, clock_is_localtime() == %i", r);
+ if (access("/etc/adjtime", R_OK) == 0) {
+ log_info("/etc/adjtime is readable, clock_is_localtime() == %i", r);
/* if /etc/adjtime exists we expect some answer, no error or
* crash */
assert_se(IN_SET(r, 0, 1));
} else
/* default is UTC if there is no /etc/adjtime */
- assert_se(r == 0);
+ assert_se(r == 0 || ERRNO_IS_PRIVILEGE(r));
}
int main(int argc, char *argv[]) {
#include "condition.h"
#include "cpu-set-util.h"
#include "efi-loader.h"
+#include "errno-util.h"
#include "hostname-util.h"
#include "id128-util.h"
#include "ima-util.h"
static void test_condition_test_kernel_command_line(void) {
Condition *condition;
+ int r;
condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false);
assert_se(condition);
- assert_se(condition_test(condition) == 0);
+ r = condition_test(condition);
+ if (ERRNO_IS_PRIVILEGE(r))
+ return;
+ assert_se(r == 0);
condition_free(condition);
condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false);
condition = condition_new(CONDITION_VIRTUALIZATION, "garbage oifdsjfoidsjoj", false, false);
assert_se(condition);
r = condition_test(condition);
+ if (ERRNO_IS_PRIVILEGE(r))
+ return;
log_info("ConditionVirtualization=garbage → %i", r);
assert_se(r == 0);
condition_free(condition);
}
static void test_copy_tree(void) {
- char original_dir[] = "/var/tmp/test-copy_tree/";
- char copy_dir[] = "/var/tmp/test-copy_tree-copy/";
+ char original_dir[] = "/tmp/test-copy_tree/";
+ char copy_dir[] = "/tmp/test-copy_tree-copy/";
char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file");
char **links = STRV_MAKE("link", "file",
"link2", "dir1/file");
q = strjoina(p, "/fstab");
r = copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REFLINK);
- if (r == -ENOENT)
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
return;
assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REFLINK) == -EEXIST);
assert_se(chmod(masked2e, 0755) == 0);
assert_se(chmod(mask2e, 0755) == 0);
+ if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return;
+
if (gather_stdout)
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
else
assert_se(chmod(override, 0755) == 0);
assert_se(chmod(masked, 0755) == 0);
+ if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return;
+
execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
assert_se(read_full_file(output, &contents, NULL) >= 0);
assert_se(chmod(name2, 0755) == 0);
assert_se(chmod(name3, 0755) == 0);
+ if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return;
+
r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_stdout, args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
assert_se(r >= 0);
r = setenv("PATH", "no-sh-built-in-path", 1);
assert_se(r >= 0);
+ if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return;
+
r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
assert_se(r >= 0);
assert_se(chmod(name2, 0755) == 0);
assert_se(chmod(name3, 0755) == 0);
+ if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return;
+
r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, NULL, NULL, EXEC_DIR_NONE);
/* we should exit with the error code of the first script that failed */
(void) unsetenv("LOGNAME");
(void) unsetenv("SHELL");
(void) unsetenv("HOME");
+ (void) unsetenv("TMPDIR");
can_unshare = have_namespaces();
_cleanup_free_ char *buf = NULL, *buf2 = NULL;
int r;
- assert_se(read_one_line_file("/proc/version", &buf) >= 0);
+ r = read_one_line_file("/proc/version", &buf);
+ if (ERRNO_IS_PRIVILEGE(r))
+ return;
+ assert_se(r >= 0);
assert_se(buf2 = strjoin(buf, "\n"));
r = write_string_file("/proc/version", buf, 0);
#include "alloc-util.h"
#include "env-util.h"
+#include "errno-util.h"
#include "log.h"
#include "macro.h"
#include "proc-cmdline.h"
int main(void) {
test_setup_logging(LOG_INFO);
+ if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
+ return log_tests_skipped("can't read /proc/cmdline");
+
test_proc_cmdline_parse();
test_proc_cmdline_override();
test_proc_cmdline_given(false);
#include <errno.h>
+#include "errno-util.h"
#include "format-util.h"
#include "log.h"
#include "procfs-util.h"
+#include "tests.h"
int main(int argc, char *argv[]) {
char buf[CONST_MAX(FORMAT_TIMESPAN_MAX, FORMAT_BYTES_MAX)];
assert_se(procfs_tasks_get_current(&v) >= 0);
log_info("Current number of tasks: %" PRIu64, v);
- assert_se(procfs_tasks_get_limit(&v) >= 0);
+ r = procfs_tasks_get_limit(&v);
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
+ return log_tests_skipped("can't read /proc/sys/kernel/pid_max");
+
+ assert_se(r >= 0);
log_info("Limit of tasks: %" PRIu64, v);
assert_se(v > 0);
assert_se(procfs_tasks_set_limit(v) >= 0);
#include "sd-hwdb.h"
#include "alloc-util.h"
+#include "errno-util.h"
#include "errno.h"
#include "tests.h"
log_info("/* %s */", __func__);
r = sd_hwdb_new(&hwdb);
- if (r == -ENOENT)
+ if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
return r;
assert_se(r == 0);
#include "alloc-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "macro.h"
#include "memory-util.h"
#include "missing_sched.h"
static void test_protect_sysctl(void) {
pid_t pid;
+ _cleanup_free_ char *seccomp = NULL;
log_info("/* %s */", __func__);
return;
}
+ assert_se(get_proc_field("/proc/self/status", "Seccomp", WHITESPACE, &seccomp) == 0);
+ if (!streq(seccomp, "0"))
+ log_warning("Warning: seccomp filter detected, results may be unreliable for %s", __func__);
+
pid = fork();
assert_se(pid >= 0);
/* 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"
_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");
}
LIST_HEAD_INIT(mp_list_head);
- assert_se(swap_list_get(fname, &mp_list_head) >= 0);
+ 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",