1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

Fix several issues found by Coverity (#36726)

This commit is contained in:
Yu Watanabe 2025-03-13 07:54:06 +09:00 committed by GitHub
commit fdab24bf6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 301 additions and 301 deletions

View File

@ -2548,7 +2548,7 @@ static int create_or_register_from_credentials(void) {
const char *e;
if ((e = startswith(de->d_name, "home.create.")))
op = OPERATION_CREATE;
if ((e = startswith(de->d_name, "home.register.")))
else if ((e = startswith(de->d_name, "home.register.")))
op = OPERATION_REGISTER;
else
continue;

View File

@ -993,7 +993,7 @@ static int method_add_signing_key(sd_bus_message *message, void *userdata, sd_bu
return log_error_errno(r, "Failed to convert public key to PEM: %m");
_cleanup_free_ char *fn_copy = strdup(fn);
if (!fn)
if (!fn_copy)
return log_oom();
_cleanup_free_ char *p = path_join("/var/lib/systemd/home/", fn);

View File

@ -376,13 +376,13 @@ TEST(sd_device_monitor_receive) {
ASSERT_OK(device_monitor_send(monitor_server, &sa, device));
ASSERT_OK(fd = sd_device_monitor_get_fd(monitor_client));
ASSERT_OK((fd = sd_device_monitor_get_fd(monitor_client)));
for (;;) {
usec_t timeout;
int events;
ASSERT_OK(events = sd_device_monitor_get_events(monitor_client));
ASSERT_OK((events = sd_device_monitor_get_events(monitor_client)));
ASSERT_EQ(events, (int) EPOLLIN);
ASSERT_OK(sd_device_monitor_get_timeout(monitor_client, &timeout));
ASSERT_EQ(timeout, USEC_INFINITY);

View File

@ -572,7 +572,7 @@ TEST(pidfd) {
assert_se(pid > 1);
ASSERT_OK(pidfd = pidfd_open(pid, 0));
ASSERT_OK((pidfd = pidfd_open(pid, 0)));
pid2 = fork();
if (pid2 == 0)

View File

@ -28,7 +28,7 @@ static JournalFile* test_open_internal(const char *name, JournalFileFlags flags)
_cleanup_(mmap_cache_unrefp) MMapCache *m = NULL;
JournalFile *f;
ASSERT_NOT_NULL(m = mmap_cache_new());
ASSERT_NOT_NULL((m = mmap_cache_new()));
ASSERT_OK(journal_file_open(-EBADF, name, O_RDWR|O_CREAT, flags, 0644, UINT64_MAX, NULL, m, NULL, &f));
return f;
}
@ -80,11 +80,11 @@ static void append_number(JournalFile *f, unsigned n, const sd_id128_t *boot_id,
ASSERT_OK(asprintf(&p, "NUMBER=%u", n));
iovec[n_iov++] = IOVEC_MAKE_STRING(p);
ASSERT_NOT_NULL(s = strjoin("LESS_THAN_FIVE=", yes_no(n < 5)));
ASSERT_NOT_NULL((s = strjoin("LESS_THAN_FIVE=", yes_no(n < 5))));
iovec[n_iov++] = IOVEC_MAKE_STRING(s);
if (boot_id) {
ASSERT_NOT_NULL(q = strjoin("_BOOT_ID=", SD_ID128_TO_STRING(*boot_id)));
ASSERT_NOT_NULL((q = strjoin("_BOOT_ID=", SD_ID128_TO_STRING(*boot_id))));
iovec[n_iov++] = IOVEC_MAKE_STRING(q);
}
@ -101,7 +101,7 @@ static void append_unreferenced_data(JournalFile *f, const sd_id128_t *boot_id)
ts.monotonic = usec_sub_unsigned(previous_ts.monotonic, 10);
ts.realtime = usec_sub_unsigned(previous_ts.realtime, 10);
ASSERT_NOT_NULL(q = strjoin("_BOOT_ID=", SD_ID128_TO_STRING(*boot_id)));
ASSERT_NOT_NULL((q = strjoin("_BOOT_ID=", SD_ID128_TO_STRING(*boot_id))));
iovec = IOVEC_MAKE_STRING(q);
ASSERT_ERROR(journal_file_append_entry(f, &ts, boot_id, &iovec, 1, NULL, NULL, NULL, NULL), EREMCHG);
@ -116,7 +116,7 @@ static void test_check_number(sd_journal *j, unsigned expected) {
ASSERT_OK(sd_journal_get_data(j, "NUMBER", &d, &l));
_cleanup_free_ char *k = NULL;
ASSERT_NOT_NULL(k = strndup(d, l));
ASSERT_NOT_NULL((k = strndup(d, l)));
printf("%s %s (expected=%u)\n", SD_ID128_TO_STRING(boot_id), k, expected);
unsigned x;
@ -236,7 +236,7 @@ static void test_cursor(sd_journal *j) {
ASSERT_OK(sd_journal_seek_head(j));
for (;;) {
ASSERT_OK(r = sd_journal_next(j));
ASSERT_OK((r = sd_journal_next(j)));
if (r == 0)
break;
@ -508,7 +508,7 @@ static void test_sequence_numbers_one(void) {
uint64_t seqnum = 0;
sd_id128_t seqnum_id;
ASSERT_NOT_NULL(m = mmap_cache_new());
ASSERT_NOT_NULL((m = mmap_cache_new()));
mkdtemp_chdir_chattr("/var/tmp/journal-seq-XXXXXX", &t);
@ -831,15 +831,15 @@ static void test_generic_array_bisect_one(size_t n, size_t num_corrupted) {
log_info("/* %s(%zu, %zu) */", __func__, n, num_corrupted);
ASSERT_NOT_NULL(m = mmap_cache_new());
ASSERT_NOT_NULL((m = mmap_cache_new()));
mkdtemp_chdir_chattr("/var/tmp/journal-seq-XXXXXX", &t);
ASSERT_OK(journal_file_open(-EBADF, "test.journal", O_RDWR|O_CREAT, JOURNAL_COMPRESS, 0644,
UINT64_MAX, NULL, m, NULL, &f));
ASSERT_NOT_NULL(seqnum = new0(uint64_t, n));
ASSERT_NOT_NULL(offset = new0(uint64_t, n));
ASSERT_NOT_NULL((seqnum = new0(uint64_t, n)));
ASSERT_NOT_NULL((offset = new0(uint64_t, n)));
for (size_t i = 0; i < n; i++) {
append_number(f, i, NULL, seqnum + i, offset + i);
@ -847,7 +847,7 @@ static void test_generic_array_bisect_one(size_t n, size_t num_corrupted) {
ASSERT_GT(offset[i], i == 0 ? 0 : offset[i-1]);
}
ASSERT_NOT_NULL(offset_candidates = newdup(uint64_t, offset, n));
ASSERT_NOT_NULL((offset_candidates = newdup(uint64_t, offset, n)));
verify(f, seqnum, offset_candidates, offset, n);
@ -1003,7 +1003,7 @@ static void verify_entry(sd_journal *j, const TestEntry *entry) {
ASSERT_EQ(t, entry->ts.realtime);
ASSERT_OK(sd_journal_get_data(j, "NUMBER", &d, &l));
ASSERT_NOT_NULL(s = strndup(d, l));
ASSERT_NOT_NULL((s = strndup(d, l)));
ASSERT_OK(asprintf(&e, "NUMBER=%u", entry->number));
ASSERT_STREQ(s, e);
@ -1011,7 +1011,7 @@ static void verify_entry(sd_journal *j, const TestEntry *entry) {
e = mfree(e);
ASSERT_OK(sd_journal_get_data(j, "DATA", &d, &l));
ASSERT_NOT_NULL(s = strndup(d, l));
ASSERT_NOT_NULL((s = strndup(d, l)));
ASSERT_OK(asprintf(&e, "DATA=%u", entry->data));
ASSERT_STREQ(s, e);
}
@ -1188,7 +1188,7 @@ TEST(seek_time) {
mkdtemp_chdir_chattr("/var/tmp/journal-seek-time-XXXXXX", &t);
ASSERT_NOT_NULL(m = mmap_cache_new());
ASSERT_NOT_NULL((m = mmap_cache_new()));
ASSERT_OK(journal_file_open(
-EBADF,

View File

@ -94,11 +94,11 @@ TEST(message_address) {
const char *label;
int r;
ASSERT_OK(sd_netlink_open(&rtnl) >= 0);
ASSERT_OK(sd_netlink_open(&rtnl));
ifindex = (int) if_nametoindex("lo");
ASSERT_OK(sd_rtnl_message_new_addr(rtnl, &message, RTM_GETADDR, ifindex, AF_INET) >= 0);
ASSERT_OK(sd_netlink_message_set_request_dump(message, true) >= 0);
ASSERT_OK(sd_rtnl_message_new_addr(rtnl, &message, RTM_GETADDR, ifindex, AF_INET));
ASSERT_OK(sd_netlink_message_set_request_dump(message, true));
ASSERT_OK((r = sd_netlink_call(rtnl, message, 0, &reply)));
@ -117,21 +117,21 @@ TEST(message_route) {
struct in_addr addr, addr_data;
uint32_t index = 2, u32_data;
ASSERT_OK(sd_netlink_open(&rtnl) >= 0);
ASSERT_OK(sd_netlink_open(&rtnl));
ASSERT_OK(sd_rtnl_message_new_route(rtnl, &req, RTM_NEWROUTE, AF_INET, RTPROT_STATIC) >= 0);
ASSERT_OK(sd_rtnl_message_new_route(rtnl, &req, RTM_NEWROUTE, AF_INET, RTPROT_STATIC));
addr.s_addr = htobe32(INADDR_LOOPBACK);
ASSERT_OK(sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr) >= 0);
ASSERT_OK(sd_netlink_message_append_u32(req, RTA_OIF, index) >= 0);
ASSERT_OK(sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr));
ASSERT_OK(sd_netlink_message_append_u32(req, RTA_OIF, index));
ASSERT_OK(sd_netlink_message_rewind(req, rtnl) >= 0);
ASSERT_OK(sd_netlink_message_rewind(req, rtnl));
ASSERT_OK(sd_netlink_message_read_in_addr(req, RTA_GATEWAY, &addr_data) >= 0);
ASSERT_OK(sd_netlink_message_read_in_addr(req, RTA_GATEWAY, &addr_data));
ASSERT_EQ(addr_data.s_addr, addr.s_addr);
ASSERT_OK(sd_netlink_message_read_u32(req, RTA_OIF, &u32_data) >= 0);
ASSERT_OK(sd_netlink_message_read_u32(req, RTA_OIF, &u32_data));
ASSERT_EQ(u32_data, index);
ASSERT_NULL((req = sd_netlink_message_unref(req)));

View File

@ -13,7 +13,7 @@ static void test_network_one(const char *ifname, const char *key, const char *va
log_debug("/* %s(%s=%s) */", __func__, key, value);
ASSERT_OK(parse_cmdline_item(key, value, &context));
ASSERT_NOT_NULL(network = network_get(&context, ifname));
ASSERT_NOT_NULL((network = network_get(&context, ifname)));
ASSERT_OK(network_format(network, &output));
ASSERT_STREQ(output, expected);
}
@ -31,7 +31,7 @@ static void test_network_two(const char *ifname,
ASSERT_OK(parse_cmdline_item(key1, value1, &context));
ASSERT_OK(parse_cmdline_item(key2, value2, &context));
ASSERT_OK(context_merge_networks(&context));
ASSERT_NOT_NULL(network = network_get(&context, ifname));
ASSERT_NOT_NULL((network = network_get(&context, ifname)));
ASSERT_OK(network_format(network, &output));
ASSERT_STREQ(output, expected);
}
@ -44,7 +44,7 @@ static void test_netdev_one(const char *ifname, const char *key, const char *val
log_debug("/* %s(%s=%s) */", __func__, key, value);
ASSERT_OK(parse_cmdline_item(key, value, &context));
ASSERT_NOT_NULL(netdev = netdev_get(&context, ifname));
ASSERT_NOT_NULL((netdev = netdev_get(&context, ifname)));
ASSERT_OK(netdev_format(netdev, &output));
ASSERT_STREQ(output, expected);
}
@ -57,7 +57,7 @@ static void test_link_one(const char *filename, const char *key, const char *val
log_debug("/* %s(%s=%s) */", __func__, key, value);
ASSERT_OK(parse_cmdline_item(key, value, &context));
ASSERT_NOT_NULL(link = link_get(&context, filename));
ASSERT_NOT_NULL((link = link_get(&context, filename)));
ASSERT_OK(link_format(link, &output));
ASSERT_STREQ(output, expected);
}

View File

@ -66,7 +66,7 @@ static void test_config_parse_ether_addrs_one(const char *rvalue, const struct e
for (size_t m = 0; m < n; m++) {
_cleanup_free_ struct ether_addr *q = NULL;
ASSERT_NOT_NULL(q = set_remove(s, &list[m]));
ASSERT_NOT_NULL((q = set_remove(s, &list[m])));
}
ASSERT_TRUE(set_isempty(s));

View File

@ -19,7 +19,7 @@ static void test_mount_points_list_one(const char *fname) {
if (fname) {
_cleanup_free_ char *testdata_fname = NULL;
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
ASSERT_NOT_NULL(f = fopen(testdata_fname, "re"));
ASSERT_NOT_NULL((f = fopen(testdata_fname, "re")));
}
LIST_HEAD_INIT(mp_list_head);

View File

@ -29,7 +29,7 @@ TEST_RET(add_acls_for_user) {
return log_tests_skipped_errno(r, "Could not find %s binary: %m", s);
}
ASSERT_OK(fd = mkostemp_safe(fn));
ASSERT_OK((fd = mkostemp_safe(fn)));
/* Use the mode that user journal files use */
ASSERT_OK_ZERO_ERRNO(fchmod(fd, 0640));
@ -86,7 +86,7 @@ TEST_RET(fd_acl_make_read_only) {
return log_tests_skipped_errno(r, "Could not find %s binary: %m", s);
}
ASSERT_OK(fd = mkostemp_safe(fn));
ASSERT_OK((fd = mkostemp_safe(fn)));
/* make it more exciting */
(void) fd_add_uid_acl_permission(fd, 1, ACL_READ|ACL_WRITE|ACL_EXECUTE);

View File

@ -18,9 +18,9 @@ static int test_restrict_filesystems(Manager *m, const char *unit_name, const ch
ExecContext *ec = NULL;
int cld_code, r;
ASSERT_NOT_NULL(u = unit_new(m, sizeof(Service)));
ASSERT_NOT_NULL((u = unit_new(m, sizeof(Service))));
ASSERT_OK_ZERO(unit_add_name(u, unit_name));
ASSERT_NOT_NULL(ec = unit_get_exec_context(u));
ASSERT_NOT_NULL((ec = unit_get_exec_context(u)));
STRV_FOREACH(allow_filesystem, allowed_filesystems) {
r = config_parse_restrict_filesystems(
@ -30,7 +30,7 @@ static int test_restrict_filesystems(Manager *m, const char *unit_name, const ch
return log_unit_error_errno(u, r, "Failed to parse RestrictFileSystems: %m");
}
ASSERT_NOT_NULL(exec_start = strjoin("cat ", file_path));
ASSERT_NOT_NULL((exec_start = strjoin("cat ", file_path)));
r = config_parse_exec(u->id, "filename", 1, "Service", 1, "ExecStart",
SERVICE_EXEC_START, exec_start, SERVICE(u)->exec_command, u);
if (r < 0)
@ -84,7 +84,7 @@ int main(int argc, char *argv[]) {
ASSERT_OK(get_testdata_dir("units", &unit_dir));
ASSERT_OK(setenv_unit_path(unit_dir));
ASSERT_NOT_NULL(runtime_dir = setup_fake_runtime_dir());
ASSERT_NOT_NULL((runtime_dir = setup_fake_runtime_dir()));
ASSERT_OK(manager_new(RUNTIME_SCOPE_SYSTEM, MANAGER_TEST_RUN_BASIC, &m));
ASSERT_OK(manager_startup(m, NULL, NULL, NULL));

View File

@ -520,7 +520,7 @@ TEST(chaseat) {
/* Test that absolute path or not are the same when resolving relative to a directory file
* descriptor and that we always get a relative path back. */
ASSERT_OK(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700));
ASSERT_OK((fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700)));
fd = safe_close(fd);
ASSERT_OK(symlinkat("/def", tfd, "qed"));
ASSERT_OK(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));

File diff suppressed because it is too large Load Diff

View File

@ -409,7 +409,7 @@ TEST(config_parse_standard_file_with_dropins_full) {
_cleanup_close_ int rfd = -EBADF;
int r;
ASSERT_OK(rfd = mkdtemp_open("/tmp/test-config-parse-XXXXXX", 0, &root));
ASSERT_OK((rfd = mkdtemp_open("/tmp/test-config-parse-XXXXXX", 0, &root)));
assert_se(mkdir_p_root(root, "/etc/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
assert_se(mkdir_p_root(root, "/run/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));
assert_se(mkdir_p_root(root, "/usr/lib/kernel/install.conf.d", UID_INVALID, GID_INVALID, 0755));

View File

@ -20,7 +20,7 @@ TEST(read_credential_strings) {
const char *e = getenv("CREDENTIALS_DIRECTORY");
if (e)
ASSERT_NOT_NULL(saved = strdup(e));
ASSERT_NOT_NULL((saved = strdup(e)));
ASSERT_OK_ZERO(read_credential_strings_many("foo", &x, "bar", &y));
ASSERT_NULL(x);
@ -34,7 +34,7 @@ TEST(read_credential_strings) {
ASSERT_NULL(x);
ASSERT_NULL(y);
ASSERT_NOT_NULL(p = path_join(tmp, "bar"));
ASSERT_NOT_NULL((p = path_join(tmp, "bar")));
ASSERT_OK(write_string_file(p, "piff", WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_AVOID_NEWLINE));
ASSERT_OK_ZERO(read_credential_strings_many("foo", &x, "bar", &y));
@ -48,7 +48,7 @@ TEST(read_credential_strings) {
ASSERT_STREQ(y, "paff");
p = mfree(p);
ASSERT_NOT_NULL(p = path_join(tmp, "foo"));
ASSERT_NOT_NULL((p = path_join(tmp, "foo")));
ASSERT_OK(write_string_file(p, "knurz", WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_AVOID_NEWLINE));
ASSERT_OK(read_credential_strings_many("foo", &x, "bar", &y));
@ -56,8 +56,8 @@ TEST(read_credential_strings) {
ASSERT_STREQ(y, "paff");
p = mfree(p);
ASSERT_NOT_NULL(p = path_join(tmp, "bazz"));
ASSERT_NOT_NULL(f = fopen(p, "w"));
ASSERT_NOT_NULL((p = path_join(tmp, "bazz")));
ASSERT_NOT_NULL((f = fopen(p, "w")));
ASSERT_EQ(fwrite("x\0y", 1, 3, f), 3UL); /* embedded NUL byte should result in EBADMSG when reading back with read_credential_strings_many() */
f = safe_fclose(f);
@ -211,7 +211,7 @@ TEST(credential_encrypt_decrypt) {
_cleanup_free_ char *ec = NULL;
if (e)
ASSERT_NOT_NULL(ec = strdup(e));
ASSERT_NOT_NULL((ec = strdup(e)));
ASSERT_OK_ERRNO(setenv("SYSTEMD_CREDENTIAL_SECRET", j, true));

View File

@ -788,13 +788,13 @@ static void test_exec_mount_apivfs(Manager *m) {
ASSERT_OK(strv_extend_strv(&libraries, libraries_test, true));
ASSERT_NOT_NULL(strextend(&data, "[Service]\n"));
ASSERT_NOT_NULL(strextend(&data, "ExecStart=", fullpath_touch, " /aaa\n"));
ASSERT_NOT_NULL(strextend(&data, "ExecStart=", fullpath_test, " -f /aaa\n"));
ASSERT_NOT_NULL(strextend(&data, "BindReadOnlyPaths=", fullpath_touch, "\n"));
ASSERT_NOT_NULL(strextend(&data, "BindReadOnlyPaths=", fullpath_test, "\n"));
ASSERT_NOT_NULL((strextend(&data, "ExecStart=", fullpath_touch, " /aaa\n")));
ASSERT_NOT_NULL((strextend(&data, "ExecStart=", fullpath_test, " -f /aaa\n")));
ASSERT_NOT_NULL((strextend(&data, "BindReadOnlyPaths=", fullpath_touch, "\n")));
ASSERT_NOT_NULL((strextend(&data, "BindReadOnlyPaths=", fullpath_test, "\n")));
STRV_FOREACH(p, libraries)
ASSERT_NOT_NULL(strextend(&data, "BindReadOnlyPaths=", *p, "\n"));
ASSERT_NOT_NULL((strextend(&data, "BindReadOnlyPaths=", *p, "\n")));
ASSERT_OK(write_drop_in(user_runtime_unit_dir, "exec-mount-apivfs-no.service", 10, "bind-mount", data));
@ -981,7 +981,7 @@ static char* private_directory_bad(Manager *m) {
_cleanup_free_ char *p = NULL;
struct stat st;
ASSERT_NOT_NULL(p = path_join(m->prefix[dt], "private"));
ASSERT_NOT_NULL((p = path_join(m->prefix[dt], "private")));
if (stat(p, &st) >= 0 &&
(st.st_mode & (S_IRWXG|S_IRWXO)))
@ -1393,9 +1393,9 @@ static void run_tests(RuntimeScope scope, char **patterns) {
ASSERT_OK_ERRNO(unsetenv("VAR4"));
ASSERT_OK_ERRNO(unsetenv("VAR5"));
ASSERT_NOT_NULL(runtime_dir = setup_fake_runtime_dir());
ASSERT_NOT_NULL(user_runtime_unit_dir = path_join(runtime_dir, "systemd/user"));
ASSERT_NOT_NULL(unit_paths = strjoin(PRIVATE_UNIT_DIR, ":", user_runtime_unit_dir));
ASSERT_NOT_NULL((runtime_dir = setup_fake_runtime_dir()));
ASSERT_NOT_NULL((user_runtime_unit_dir = path_join(runtime_dir, "systemd/user")));
ASSERT_NOT_NULL((unit_paths = strjoin(PRIVATE_UNIT_DIR, ":", user_runtime_unit_dir)));
ASSERT_OK(setenv_unit_path(unit_paths));
/* Write credential for test-execute-load-credential to the fake runtime dir, too */
@ -1481,7 +1481,7 @@ static int prepare_ns(const char *process_name) {
* 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_OK_ERRNO(access(build_dir, F_OK));
ASSERT_NOT_NULL(build_dir_mount = path_join(PRIVATE_UNIT_DIR, "build_dir"));
ASSERT_NOT_NULL((build_dir_mount = path_join(PRIVATE_UNIT_DIR, "build_dir")));
ASSERT_OK(mkdir_p(build_dir_mount, 0755));
ASSERT_OK(mount_nofollow_verbose(LOG_DEBUG, build_dir, build_dir_mount, NULL, MS_BIND, NULL));
}
@ -1521,7 +1521,7 @@ TEST(run_tests_root) {
return (void) log_tests_skipped("unshare() is disabled");
/* safe_fork() clears saved_argv in the child process. Let's copy it. */
ASSERT_NOT_NULL(filters = strv_copy(strv_skip(saved_argv, 1)));
ASSERT_NOT_NULL((filters = strv_copy(strv_skip(saved_argv, 1))));
if (prepare_ns("(test-execute-root)") == 0) {
can_unshare = true;
@ -1547,7 +1547,7 @@ TEST(run_tests_without_unshare) {
return (void) log_tests_skipped("Seccomp not available, cannot run unshare() filtered tests");
/* safe_fork() clears saved_argv in the child process. Let's copy it. */
ASSERT_NOT_NULL(filters = strv_copy(strv_skip(saved_argv, 1)));
ASSERT_NOT_NULL((filters = strv_copy(strv_skip(saved_argv, 1))));
if (prepare_ns("(test-execute-without-unshare)") == 0) {
_cleanup_hashmap_free_ Hashmap *s = NULL;
@ -1576,7 +1576,7 @@ TEST(run_tests_unprivileged) {
return (void) log_tests_skipped("unshare() is disabled");
/* safe_fork() clears saved_argv in the child process. Let's copy it. */
ASSERT_NOT_NULL(filters = strv_copy(strv_skip(saved_argv, 1)));
ASSERT_NOT_NULL((filters = strv_copy(strv_skip(saved_argv, 1))));
if (prepare_ns("(test-execute-unprivileged)") == 0) {
ASSERT_OK(capability_bounding_set_drop(0, /* right_now = */ true));

View File

@ -15,7 +15,7 @@ TEST(issue_9549) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(table = table_new("name", "type", "ro", "usage", "created", "modified"));
ASSERT_NOT_NULL((table = table_new("name", "type", "ro", "usage", "created", "modified")));
ASSERT_OK(table_set_align_percent(table, TABLE_HEADER_CELL(3), 100));
ASSERT_OK(table_add_many(table,
TABLE_STRING, "foooo",
@ -38,7 +38,7 @@ TEST(multiline) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(table = table_new("foo", "bar"));
ASSERT_NOT_NULL((table = table_new("foo", "bar")));
ASSERT_OK(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100));
@ -150,7 +150,7 @@ TEST(strv) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(table = table_new("foo", "bar"));
ASSERT_NOT_NULL((table = table_new("foo", "bar")));
ASSERT_OK(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100));
@ -262,7 +262,7 @@ TEST(strv_wrapped) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(table = table_new("foo", "bar"));
ASSERT_NOT_NULL((table = table_new("foo", "bar")));
ASSERT_OK(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100));
@ -364,7 +364,7 @@ TEST(json) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL, *w = NULL;
_cleanup_(table_unrefp) Table *t = NULL;
ASSERT_NOT_NULL(t = table_new_raw(4));
ASSERT_NOT_NULL((t = table_new_raw(4)));
ASSERT_OK(table_add_many(t,
TABLE_HEADER, "foo bar",
@ -432,7 +432,7 @@ TEST(json_mangling) {
FOREACH_ELEMENT(i, cases) {
_cleanup_free_ char *ret = NULL;
ASSERT_NOT_NULL(ret = table_mangle_to_json_field_name(i->arg));
ASSERT_NOT_NULL((ret = table_mangle_to_json_field_name(i->arg)));
printf("\"%s\" -> \"%s\"\n", i->arg, ret);
ASSERT_STREQ(ret, i->exp);
}
@ -442,7 +442,7 @@ TEST(table) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new("one", "two", "three", "four"));
ASSERT_NOT_NULL((t = table_new("one", "two", "three", "four")));
ASSERT_OK(table_set_align_percent(t, TABLE_HEADER_CELL(3), 100));
@ -584,7 +584,7 @@ TEST(signed_integers) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new("int", "int8", "int16", "int32", "int64"));
ASSERT_NOT_NULL((t = table_new("int", "int8", "int16", "int32", "int64")));
table_set_width(t, 0);
ASSERT_OK(table_add_many(t,
@ -649,7 +649,7 @@ TEST(unsigned_integers) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new("uint", "uint8", "uint16", "uint32", "uhex32", "uint64", "uhex64"));
ASSERT_NOT_NULL((t = table_new("uint", "uint8", "uint16", "uint32", "uhex32", "uint64", "uhex64")));
table_set_width(t, 0);
ASSERT_OK(table_add_many(t,
@ -709,7 +709,7 @@ TEST(vertical) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new_vertical());
ASSERT_NOT_NULL((t = table_new_vertical()));
ASSERT_OK(table_add_many(t,
TABLE_FIELD, "pfft aa", TABLE_STRING, "foo",
@ -745,7 +745,7 @@ TEST(path_basename) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new("x"));
ASSERT_NOT_NULL((t = table_new("x")));
table_set_header(t, false);
@ -763,7 +763,7 @@ TEST(dup_cell) {
_cleanup_(table_unrefp) Table *t = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(t = table_new("foo", "bar", "x", "baz", ".", "%", "!", "~", "+"));
ASSERT_NOT_NULL((t = table_new("foo", "bar", "x", "baz", ".", "%", "!", "~", "+")));
table_set_width(t, 75);
ASSERT_OK(table_add_many(t,
@ -806,7 +806,7 @@ TEST(table_bps) {
_cleanup_(table_unrefp) Table *table = NULL;
_cleanup_free_ char *formatted = NULL;
ASSERT_NOT_NULL(table = table_new("uint64", "size", "bps"));
ASSERT_NOT_NULL((table = table_new("uint64", "size", "bps")));
uint64_t v;
FOREACH_ARGUMENT(v,
2500,

View File

@ -76,14 +76,14 @@ TEST(hashmap_ensure_replace) {
TEST(hashmap_copy) {
_cleanup_hashmap_free_ Hashmap *m = NULL, *copy = NULL;
ASSERT_NOT_NULL(m = hashmap_new(&string_hash_ops));
ASSERT_NOT_NULL((m = hashmap_new(&string_hash_ops)));
ASSERT_OK_POSITIVE(hashmap_put(m, "key 1", (void*) "val1"));
ASSERT_OK_POSITIVE(hashmap_put(m, "key 2", (void*) "val2"));
ASSERT_OK_POSITIVE(hashmap_put(m, "key 3", (void*) "val3"));
ASSERT_OK_POSITIVE(hashmap_put(m, "key 4", (void*) "val4"));
ASSERT_NOT_NULL(copy = hashmap_copy(m));
ASSERT_NOT_NULL((copy = hashmap_copy(m)));
ASSERT_STREQ(hashmap_get(copy, "key 1"), "val1");
ASSERT_STREQ(hashmap_get(copy, "key 2"), "val2");
@ -975,14 +975,14 @@ TEST(string_strv_hashmap) {
assert_se(strv_equal(s, STRV_MAKE("bar", "BAR")));
string_strv_hashmap_remove(m, "foo", "bar");
ASSERT_NOT_NULL(s = hashmap_get(m, "foo"));
ASSERT_NOT_NULL((s = hashmap_get(m, "foo")));
ASSERT_TRUE(strv_equal(s, STRV_MAKE("BAR")));
string_strv_hashmap_remove(m, "foo", "BAR");
ASSERT_NULL(hashmap_get(m, "foo"));
string_strv_hashmap_remove(m, "xxx", "BAR");
ASSERT_NOT_NULL(s = hashmap_get(m, "xxx"));
ASSERT_NOT_NULL((s = hashmap_get(m, "xxx")));
ASSERT_TRUE(strv_equal(s, STRV_MAKE("bar")));
string_strv_hashmap_remove(m, "xxx", "bar");

View File

@ -307,28 +307,28 @@ TEST(id128_at) {
ASSERT_EQ_ID128(id, i);
/* id128_read() */
ASSERT_NOT_NULL(p = path_join(t, "/etc/machine-id"));
ASSERT_NOT_NULL((p = path_join(t, "/etc/machine-id")));
i = SD_ID128_NULL;
ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
ASSERT_EQ_ID128(id, i);
free(p);
ASSERT_NOT_NULL(p = path_join(t, "/etc2/machine-id"));
ASSERT_NOT_NULL((p = path_join(t, "/etc2/machine-id")));
i = SD_ID128_NULL;
ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
ASSERT_EQ_ID128(id, i);
free(p);
ASSERT_NOT_NULL(p = path_join(t, "/etc/hoge-id"));
ASSERT_NOT_NULL((p = path_join(t, "/etc/hoge-id")));
i = SD_ID128_NULL;
ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));
ASSERT_EQ_ID128(id, i);
free(p);
ASSERT_NOT_NULL(p = path_join(t, "/etc2/hoge-id"));
ASSERT_NOT_NULL((p = path_join(t, "/etc2/hoge-id")));
i = SD_ID128_NULL;
ASSERT_OK(id128_read(p, ID128_FORMAT_PLAIN, &i));

View File

@ -1366,7 +1366,7 @@ TEST(fd_info) {
fd = safe_close(fd);
/* regular file */
ASSERT_OK(fd = open_tmpfile_unlinkable(NULL, O_RDWR));
ASSERT_OK((fd = open_tmpfile_unlinkable(NULL, O_RDWR)));
ASSERT_OK(json_variant_new_fd_info(&v, fd));
ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL));
v = sd_json_variant_unref(v);

View File

@ -145,7 +145,7 @@ TEST(mkdir_p_root_full) {
ASSERT_OK(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp));
ASSERT_NOT_NULL(p = path_join(tmp, "foo"));
ASSERT_NOT_NULL((p = path_join(tmp, "foo")));
ASSERT_OK(mkdir_p_root_full(tmp, "/foo", UID_INVALID, GID_INVALID, 0755, 2 * USEC_PER_SEC, NULL));
ASSERT_GT(is_dir(p, false), 0);
ASSERT_GT(is_dir(p, true), 0);
@ -154,12 +154,12 @@ TEST(mkdir_p_root_full) {
ASSERT_EQ(st.st_atim.tv_sec, 2);
p = mfree(p);
ASSERT_NOT_NULL(p = path_join(tmp, "dir-not-exists/foo"));
ASSERT_NOT_NULL((p = path_join(tmp, "dir-not-exists/foo")));
ASSERT_OK(mkdir_p_root_full(NULL, p, UID_INVALID, GID_INVALID, 0755, 90 * USEC_PER_HOUR, NULL));
ASSERT_GT(is_dir(p, false), 0);
ASSERT_GT(is_dir(p, true), 0);
p = mfree(p);
ASSERT_NOT_NULL(p = path_join(tmp, "dir-not-exists"));
ASSERT_NOT_NULL((p = path_join(tmp, "dir-not-exists")));
ASSERT_OK_ERRNO(stat(p, &st));
ASSERT_EQ(st.st_mtim.tv_sec, 90 * 60 * 60);
ASSERT_EQ(st.st_atim.tv_sec, 90 * 60 * 60);

View File

@ -540,7 +540,7 @@ TEST(path_is_network_fs_harder) {
_cleanup_close_ int dir_fd = -EBADF;
int r;
ASSERT_OK(dir_fd = open("/", O_PATH | O_CLOEXEC));
ASSERT_OK((dir_fd = open("/", O_PATH | O_CLOEXEC)));
FOREACH_STRING(s,
"/", "/dev/", "/proc/", "/run/", "/sys/", "/tmp/", "/usr/", "/var/tmp/",
"", ".", "../../../", "/this/path/should/not/exist/for/test-mount-util/") {

View File

@ -184,11 +184,11 @@ TEST(fd_is_namespace) {
ASSERT_OK_ZERO(fd_is_namespace(fd, NAMESPACE_NET));
fd = safe_close(fd);
ASSERT_OK(fd = namespace_open_by_type(NAMESPACE_IPC));
ASSERT_OK((fd = namespace_open_by_type(NAMESPACE_IPC)));
ASSERT_OK_POSITIVE(fd_is_namespace(fd, NAMESPACE_IPC));
fd = safe_close(fd);
ASSERT_OK(fd = namespace_open_by_type(NAMESPACE_NET));
ASSERT_OK((fd = namespace_open_by_type(NAMESPACE_NET)));
ASSERT_OK_POSITIVE(fd_is_namespace(fd, NAMESPACE_NET));
}

View File

@ -143,14 +143,14 @@ static void test_pid_get_cmdline_one(pid_t pid) {
r = pid_get_cmdline_strv(pid, 0, &strv_a);
if (r >= 0)
ASSERT_NOT_NULL(joined = strv_join(strv_a, "\", \""));
ASSERT_NOT_NULL((joined = strv_join(strv_a, "\", \"")));
log_info(" \"%s\"", r >= 0 ? joined : errno_to_name(r));
joined = mfree(joined);
r = pid_get_cmdline_strv(pid, PROCESS_CMDLINE_COMM_FALLBACK, &strv_b);
if (r >= 0)
ASSERT_NOT_NULL(joined = strv_join(strv_b, "\", \""));
ASSERT_NOT_NULL((joined = strv_join(strv_b, "\", \"")));
log_info(" \"%s\"", r >= 0 ? joined : errno_to_name(r));
}

View File

@ -551,41 +551,41 @@ TEST(strv_sort_uniq) {
ASSERT_NULL(strv_sort_uniq(a));
ASSERT_NOT_NULL(a = strv_new(NULL));
ASSERT_NOT_NULL((a = strv_new(NULL)));
assert_se(strv_sort_uniq(a) == a);
ASSERT_NULL(a[0]);
a = strv_free(a);
ASSERT_NOT_NULL(a = strv_new("a", "a", "a", "a", "a"));
ASSERT_NOT_NULL((a = strv_new("a", "a", "a", "a", "a")));
assert_se(strv_sort_uniq(a) == a);
ASSERT_STREQ(a[0], "a");
ASSERT_NULL(a[1]);
a = strv_free(a);
ASSERT_NOT_NULL(a = strv_new("a", "a", "a", "a", "b"));
ASSERT_NOT_NULL((a = strv_new("a", "a", "a", "a", "b")));
assert_se(strv_sort_uniq(a) == a);
ASSERT_STREQ(a[0], "a");
ASSERT_STREQ(a[1], "b");
ASSERT_NULL(a[2]);
a = strv_free(a);
ASSERT_NOT_NULL(a = strv_new("b", "a", "a", "a", "a"));
ASSERT_NOT_NULL((a = strv_new("b", "a", "a", "a", "a")));
assert_se(strv_sort_uniq(a) == a);
ASSERT_STREQ(a[0], "a");
ASSERT_STREQ(a[1], "b");
ASSERT_NULL(a[2]);
a = strv_free(a);
ASSERT_NOT_NULL(a = strv_new("a", "a", "b", "a", "b"));
ASSERT_NOT_NULL((a = strv_new("a", "a", "b", "a", "b")));
assert_se(strv_sort_uniq(a) == a);
ASSERT_STREQ(a[0], "a");
ASSERT_STREQ(a[1], "b");
ASSERT_NULL(a[2]);
a = strv_free(a);
ASSERT_NOT_NULL(a = strv_copy((char**) input_table));
ASSERT_NOT_NULL(b = strv_copy((char**) input_table));
ASSERT_NOT_NULL(c = strv_copy((char**) input_table));
ASSERT_NOT_NULL((a = strv_copy((char**) input_table)));
ASSERT_NOT_NULL((b = strv_copy((char**) input_table)));
ASSERT_NOT_NULL((c = strv_copy((char**) input_table)));
assert_se(strv_sort_uniq(a) == a);
assert_se(strv_sort(strv_uniq(b)) == b);
@ -664,8 +664,8 @@ TEST(strv_extend_strv_consume) {
_cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **n = NULL;
const char *s1, *s2, *s3;
ASSERT_NOT_NULL(a = strv_new("abc", "def", "ghi"));
ASSERT_NOT_NULL(b = strv_new("jkl", "mno", "abc", "pqr"));
ASSERT_NOT_NULL((a = strv_new("abc", "def", "ghi")));
ASSERT_NOT_NULL((b = strv_new("jkl", "mno", "abc", "pqr")));
s1 = b[0];
s2 = b[1];
@ -685,7 +685,7 @@ TEST(strv_extend_strv_consume) {
ASSERT_STREQ(a[5], "pqr");
ASSERT_EQ(strv_length(a), (size_t) 6);
ASSERT_NOT_NULL(c = strv_new("jkl", "mno"));
ASSERT_NOT_NULL((c = strv_new("jkl", "mno")));
s1 = c[0];
s2 = c[1];

View File

@ -319,8 +319,8 @@ TEST(terminal_new_session) {
_cleanup_close_ int pty_fd = -EBADF, peer_fd = -EBADF;
int r;
ASSERT_OK(pty_fd = openpt_allocate(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK, NULL));
ASSERT_OK(peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC));
ASSERT_OK((pty_fd = openpt_allocate(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK, NULL)));
ASSERT_OK((peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC)));
r = safe_fork_full("test-term-session",
(int[]) { peer_fd, peer_fd, peer_fd },

View File

@ -966,7 +966,7 @@ static void test_parse_timestamp_impl(const char *tz) {
if (tz) {
_cleanup_free_ char *s = NULL;
ASSERT_NOT_NULL(s = strjoin("Fri 2012-11-23 23:02:15 ", tz));
ASSERT_NOT_NULL((s = strjoin("Fri 2012-11-23 23:02:15 ", tz)));
ASSERT_OK(parse_timestamp(s, NULL));
}

View File

@ -122,7 +122,7 @@ static bool test_unit_file_remove_from_name_map_trail(const LookupPaths *lp, siz
ASSERT_OK_ERRNO(unlink(path));
ASSERT_OK(r = unit_file_remove_from_name_map(lp, &cache_timestamp_hash, &unit_ids, &unit_names, &path_cache, path));
ASSERT_OK((r = unit_file_remove_from_name_map(lp, &cache_timestamp_hash, &unit_ids, &unit_names, &path_cache, path)));
if (r > 0)
return false; /* someone touches unit files. Retrying. */
@ -158,7 +158,7 @@ TEST(unit_file_remove_from_name_map) {
_cleanup_(lookup_paths_done) LookupPaths lp = {};
ASSERT_OK(lookup_paths_init(&lp, RUNTIME_SCOPE_SYSTEM, LOOKUP_PATHS_TEMPORARY_GENERATED, NULL));
ASSERT_NOT_NULL(d = strdup(lp.temporary_dir));
ASSERT_NOT_NULL((d = strdup(lp.temporary_dir)));
for (size_t i = 0; i < 10; i++)
if (test_unit_file_remove_from_name_map_trail(&lp, i))

View File

@ -444,7 +444,7 @@ TEST(gid_lists_ops) {
assert_se(nresult >= 0);
assert_se(memcmp_nn(result2, ELEMENTSOF(result2), res4, nresult) == 0);
ASSERT_OK(nresult = getgroups_alloc(&gids));
ASSERT_OK((nresult = getgroups_alloc(&gids)));
assert_se(gids || nresult == 0);
}

View File

@ -102,7 +102,7 @@ static void xattr_symlink_test_one(int fd, const char *path) {
r = listxattr_at_malloc(fd, path, 0, &list);
ASSERT_OK(r);
ASSERT_GE(r, (int) sizeof("trusted.test\0trusted.bar"));
ASSERT_NOT_NULL(list_split = strv_parse_nulstr(list, r));
ASSERT_NOT_NULL((list_split = strv_parse_nulstr(list, r)));
ASSERT_TRUE(strv_contains(list_split, "trusted.bar"));
ASSERT_TRUE(strv_contains(list_split, "trusted.test"));

View File

@ -17,7 +17,7 @@ static void test_event_spawn_core(bool with_pidfd, const char *cmd, char *result
ASSERT_OK_ERRNO(setenv("SYSTEMD_PIDFD", yes_no(with_pidfd), 1));
ASSERT_OK(sd_device_new_from_syspath(&dev, "/sys/class/net/lo"));
ASSERT_NOT_NULL(event = udev_event_new(dev, NULL, EVENT_TEST_SPAWN));
ASSERT_NOT_NULL((event = udev_event_new(dev, NULL, EVENT_TEST_SPAWN)));
ASSERT_OK_ZERO(udev_event_spawn(event, false, cmd, result_buf, buf_size, NULL));
ASSERT_OK_ERRNO(unsetenv("SYSTEMD_PIDFD"));
@ -36,7 +36,7 @@ static void test_event_spawn_cat(bool with_pidfd, size_t buf_size) {
test_event_spawn_core(with_pidfd, cmd, result_buf,
buf_size >= BUF_SIZE ? BUF_SIZE : buf_size);
ASSERT_NOT_NULL(lines = strv_split_newlines(result_buf));
ASSERT_NOT_NULL((lines = strv_split_newlines(result_buf)));
strv_print(lines);
if (buf_size >= BUF_SIZE) {
@ -53,11 +53,11 @@ static void test_event_spawn_self(const char *self, const char *arg, bool with_p
log_debug("/* %s(%s, %s) */", __func__, arg, yes_no(with_pidfd));
/* 'self' may contain spaces, hence needs to be quoted. */
ASSERT_NOT_NULL(cmd = strjoin("'", self, "' ", arg));
ASSERT_NOT_NULL((cmd = strjoin("'", self, "' ", arg)));
test_event_spawn_core(with_pidfd, cmd, result_buf, BUF_SIZE);
ASSERT_NOT_NULL(lines = strv_split_newlines(result_buf));
ASSERT_NOT_NULL((lines = strv_split_newlines(result_buf)));
strv_print(lines);
ASSERT_TRUE(strv_contains(lines, "aaa"));