mirror of
https://github.com/systemd/systemd.git
synced 2026-08-11 01:25:28 +00:00
core: Introduce ConditionPathIsSocket= (#40791)
This commit is contained in:
@@ -1797,6 +1797,17 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>ConditionPathIsSocket=</varname></term>
|
||||
|
||||
<listitem><para><varname>ConditionPathIsSocket=</varname> is similar to
|
||||
<varname>ConditionPathExists=</varname> but verifies that a certain path exists and is a
|
||||
socket.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v260"/>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>ConditionDirectoryNotEmpty=</varname></term>
|
||||
|
||||
@@ -2052,6 +2063,7 @@
|
||||
<term><varname>AssertPathIsMountPoint=</varname></term>
|
||||
<term><varname>AssertPathIsReadWrite=</varname></term>
|
||||
<term><varname>AssertPathIsEncrypted=</varname></term>
|
||||
<term><varname>AssertPathIsSocket=</varname></term>
|
||||
<term><varname>AssertDirectoryNotEmpty=</varname></term>
|
||||
<term><varname>AssertFileNotEmpty=</varname></term>
|
||||
<term><varname>AssertFileIsExecutable=</varname></term>
|
||||
|
||||
@@ -366,6 +366,7 @@ Unit.ConditionPathIsSymbolicLink, config_parse_unit_condition_path,
|
||||
Unit.ConditionPathIsMountPoint, config_parse_unit_condition_path, CONDITION_PATH_IS_MOUNT_POINT, offsetof(Unit, conditions)
|
||||
Unit.ConditionPathIsReadWrite, config_parse_unit_condition_path, CONDITION_PATH_IS_READ_WRITE, offsetof(Unit, conditions)
|
||||
Unit.ConditionPathIsEncrypted, config_parse_unit_condition_path, CONDITION_PATH_IS_ENCRYPTED, offsetof(Unit, conditions)
|
||||
Unit.ConditionPathIsSocket, config_parse_unit_condition_path, CONDITION_PATH_IS_SOCKET, offsetof(Unit, conditions)
|
||||
Unit.ConditionDirectoryNotEmpty, config_parse_unit_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, offsetof(Unit, conditions)
|
||||
Unit.ConditionFileNotEmpty, config_parse_unit_condition_path, CONDITION_FILE_NOT_EMPTY, offsetof(Unit, conditions)
|
||||
Unit.ConditionFileIsExecutable, config_parse_unit_condition_path, CONDITION_FILE_IS_EXECUTABLE, offsetof(Unit, conditions)
|
||||
@@ -401,6 +402,7 @@ Unit.AssertPathIsSymbolicLink, config_parse_unit_condition_path,
|
||||
Unit.AssertPathIsMountPoint, config_parse_unit_condition_path, CONDITION_PATH_IS_MOUNT_POINT, offsetof(Unit, asserts)
|
||||
Unit.AssertPathIsReadWrite, config_parse_unit_condition_path, CONDITION_PATH_IS_READ_WRITE, offsetof(Unit, asserts)
|
||||
Unit.AssertPathIsEncrypted, config_parse_unit_condition_path, CONDITION_PATH_IS_ENCRYPTED, offsetof(Unit, asserts)
|
||||
Unit.AssertPathIsSocket, config_parse_unit_condition_path, CONDITION_PATH_IS_SOCKET, offsetof(Unit, asserts)
|
||||
Unit.AssertDirectoryNotEmpty, config_parse_unit_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, offsetof(Unit, asserts)
|
||||
Unit.AssertFileNotEmpty, config_parse_unit_condition_path, CONDITION_FILE_NOT_EMPTY, offsetof(Unit, asserts)
|
||||
Unit.AssertFileIsExecutable, config_parse_unit_condition_path, CONDITION_FILE_IS_EXECUTABLE, offsetof(Unit, asserts)
|
||||
|
||||
@@ -992,6 +992,14 @@ static int condition_test_path_is_encrypted(Condition *c, char **env) {
|
||||
return r > 0;
|
||||
}
|
||||
|
||||
static int condition_test_path_is_socket(Condition *c, char **env) {
|
||||
assert(c);
|
||||
assert(c->parameter);
|
||||
assert(c->type == CONDITION_PATH_IS_SOCKET);
|
||||
|
||||
return is_socket(c->parameter) > 0;
|
||||
}
|
||||
|
||||
static int condition_test_directory_not_empty(Condition *c, char **env) {
|
||||
int r;
|
||||
|
||||
@@ -1233,6 +1241,7 @@ int condition_test(Condition *c, char **env) {
|
||||
[CONDITION_PATH_IS_MOUNT_POINT] = condition_test_path_is_mount_point,
|
||||
[CONDITION_PATH_IS_READ_WRITE] = condition_test_path_is_read_write,
|
||||
[CONDITION_PATH_IS_ENCRYPTED] = condition_test_path_is_encrypted,
|
||||
[CONDITION_PATH_IS_SOCKET] = condition_test_path_is_socket,
|
||||
[CONDITION_DIRECTORY_NOT_EMPTY] = condition_test_directory_not_empty,
|
||||
[CONDITION_FILE_NOT_EMPTY] = condition_test_file_not_empty,
|
||||
[CONDITION_FILE_IS_EXECUTABLE] = condition_test_file_is_executable,
|
||||
@@ -1370,6 +1379,7 @@ static const char* const _condition_type_table[_CONDITION_TYPE_MAX] = {
|
||||
[CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
|
||||
[CONDITION_PATH_IS_READ_WRITE] = "ConditionPathIsReadWrite",
|
||||
[CONDITION_PATH_IS_ENCRYPTED] = "ConditionPathIsEncrypted",
|
||||
[CONDITION_PATH_IS_SOCKET] = "ConditionPathIsSocket",
|
||||
[CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
|
||||
[CONDITION_FILE_NOT_EMPTY] = "ConditionFileNotEmpty",
|
||||
[CONDITION_FILE_IS_EXECUTABLE] = "ConditionFileIsExecutable",
|
||||
@@ -1425,6 +1435,7 @@ static const char* const _assert_type_table[_CONDITION_TYPE_MAX] = {
|
||||
[CONDITION_PATH_IS_MOUNT_POINT] = "AssertPathIsMountPoint",
|
||||
[CONDITION_PATH_IS_READ_WRITE] = "AssertPathIsReadWrite",
|
||||
[CONDITION_PATH_IS_ENCRYPTED] = "AssertPathIsEncrypted",
|
||||
[CONDITION_PATH_IS_SOCKET] = "AssertPathIsSocket",
|
||||
[CONDITION_DIRECTORY_NOT_EMPTY] = "AssertDirectoryNotEmpty",
|
||||
[CONDITION_FILE_NOT_EMPTY] = "AssertFileNotEmpty",
|
||||
[CONDITION_FILE_IS_EXECUTABLE] = "AssertFileIsExecutable",
|
||||
|
||||
@@ -34,6 +34,7 @@ typedef enum ConditionType {
|
||||
CONDITION_PATH_IS_MOUNT_POINT,
|
||||
CONDITION_PATH_IS_READ_WRITE,
|
||||
CONDITION_PATH_IS_ENCRYPTED,
|
||||
CONDITION_PATH_IS_SOCKET,
|
||||
CONDITION_DIRECTORY_NOT_EMPTY,
|
||||
CONDITION_FILE_NOT_EMPTY,
|
||||
CONDITION_FILE_IS_EXECUTABLE,
|
||||
@@ -104,6 +105,7 @@ static inline bool condition_takes_path(ConditionType t) {
|
||||
CONDITION_PATH_IS_MOUNT_POINT,
|
||||
CONDITION_PATH_IS_READ_WRITE,
|
||||
CONDITION_PATH_IS_ENCRYPTED,
|
||||
CONDITION_PATH_IS_SOCKET,
|
||||
CONDITION_DIRECTORY_NOT_EMPTY,
|
||||
CONDITION_FILE_NOT_EMPTY,
|
||||
CONDITION_FILE_IS_EXECUTABLE,
|
||||
|
||||
@@ -274,6 +274,29 @@ _noreturn_ void log_test_failed_internal(const char *file, int line, const char
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifdef __COVERITY__
|
||||
# define ASSERT_OK_NE(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
__coverity_check__(_expr1 != _expr2); \
|
||||
_expr1; \
|
||||
})
|
||||
#else
|
||||
# define ASSERT_OK_NE(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (_expr1 < 0) \
|
||||
log_test_failed("Expected \"%s\" to succeed, but got error: %"PRIiMAX"/%s", \
|
||||
#expr1, (intmax_t) _expr1, ERRNO_NAME(_expr1)); \
|
||||
if (_expr1 == _expr2) \
|
||||
log_test_failed("Expected \"%s != %s\", got %"PRIiMAX" != %"PRIiMAX, \
|
||||
#expr1, #expr2, (intmax_t) _expr1, (intmax_t) _expr2); \
|
||||
_expr1; \
|
||||
})
|
||||
#endif
|
||||
|
||||
/* For functions that return a boolean on success and set errno on failure. */
|
||||
#ifdef __COVERITY__
|
||||
# define ASSERT_OK_ERRNO(expr) \
|
||||
|
||||
@@ -1105,6 +1105,7 @@ TEST(unit_properties) {
|
||||
"ConditionPathIsMountPoint=|foo",
|
||||
"ConditionPathIsReadWrite=|foo",
|
||||
"ConditionPathIsEncrypted=|foo",
|
||||
"ConditionPathIsSocket=|foo",
|
||||
"ConditionDirectoryNotEmpty=|foo",
|
||||
"ConditionFileNotEmpty=|foo",
|
||||
"ConditionFileIsExecutable=|foo",
|
||||
@@ -1139,6 +1140,7 @@ TEST(unit_properties) {
|
||||
"AssertPathIsMountPoint=|foo",
|
||||
"AssertPathIsReadWrite=|foo",
|
||||
"AssertPathIsEncrypted=|foo",
|
||||
"AssertPathIsSocket=|foo",
|
||||
"AssertDirectoryNotEmpty=|foo",
|
||||
"AssertFileNotEmpty=|foo",
|
||||
"AssertFileIsExecutable=|foo",
|
||||
|
||||
@@ -110,6 +110,16 @@ TEST(condition_test_path) {
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
if (access("/run/dbus/system_bus_socket", F_OK) >= 0) {
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_PATH_IS_SOCKET, "/run/dbus/system_bus_socket", false, false)));
|
||||
ASSERT_OK_POSITIVE(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_PATH_IS_SOCKET, "/sys", false, false)));
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_PATH_IS_SYMBOLIC_LINK, "/dev/stdout", false, false)));
|
||||
ASSERT_OK_POSITIVE(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
@@ -187,15 +197,15 @@ TEST(condition_test_ac_power) {
|
||||
Condition *condition;
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_AC_POWER, "true", false, false)));
|
||||
assert_se(condition_test(condition, environ) == on_ac_power());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), on_ac_power());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_AC_POWER, "false", false, false)));
|
||||
assert_se(condition_test(condition, environ) != on_ac_power());
|
||||
ASSERT_OK_NE(condition_test(condition, environ), on_ac_power());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_AC_POWER, "false", false, true)));
|
||||
assert_se(condition_test(condition, environ) == on_ac_power());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), on_ac_power());
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
@@ -714,8 +724,8 @@ TEST(condition_test_credential) {
|
||||
_cleanup_free_ char *d1 = NULL, *d2 = NULL, *j = NULL;
|
||||
Condition *condition;
|
||||
|
||||
assert_se(free_and_strdup(&d1, getenv("CREDENTIALS_DIRECTORY")) >= 0);
|
||||
assert_se(free_and_strdup(&d2, getenv("ENCRYPTED_CREDENTIALS_DIRECTORY")) >= 0);
|
||||
ASSERT_OK(free_and_strdup(&d1, getenv("CREDENTIALS_DIRECTORY")));
|
||||
ASSERT_OK(free_and_strdup(&d2, getenv("ENCRYPTED_CREDENTIALS_DIRECTORY")));
|
||||
|
||||
ASSERT_OK_ERRNO(unsetenv("CREDENTIALS_DIRECTORY"));
|
||||
ASSERT_OK_ERRNO(unsetenv("ENCRYPTED_CREDENTIALS_DIRECTORY"));
|
||||
@@ -729,8 +739,8 @@ TEST(condition_test_credential) {
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
assert_se(mkdtemp_malloc(NULL, &n1) >= 0);
|
||||
assert_se(mkdtemp_malloc(NULL, &n2) >= 0);
|
||||
ASSERT_OK(mkdtemp_malloc(NULL, &n1));
|
||||
ASSERT_OK(mkdtemp_malloc(NULL, &n2));
|
||||
|
||||
ASSERT_OK_ERRNO(setenv("CREDENTIALS_DIRECTORY", n1, /* overwrite= */ true));
|
||||
ASSERT_OK_ERRNO(setenv("ENCRYPTED_CREDENTIALS_DIRECTORY", n2, /* overwrite= */ true));
|
||||
@@ -740,20 +750,20 @@ TEST(condition_test_credential) {
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((j = path_join(n1, "existing")));
|
||||
assert_se(touch(j) >= 0);
|
||||
ASSERT_OK(touch(j));
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_CREDENTIAL, "existing", /* trigger= */ false, /* negate= */ false)));
|
||||
ASSERT_OK_POSITIVE(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
free(j);
|
||||
|
||||
ASSERT_NOT_NULL((j = path_join(n2, "existing-encrypted")));
|
||||
assert_se(touch(j) >= 0);
|
||||
ASSERT_OK(touch(j));
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_CREDENTIAL, "existing-encrypted", /* trigger= */ false, /* negate= */ false)));
|
||||
ASSERT_OK_POSITIVE(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
assert_se(set_unset_env("CREDENTIALS_DIRECTORY", d1, /* overwrite= */ true) >= 0);
|
||||
assert_se(set_unset_env("ENCRYPTED_CREDENTIALS_DIRECTORY", d2, /* overwrite= */ true) >= 0);
|
||||
ASSERT_OK(set_unset_env("CREDENTIALS_DIRECTORY", d1, /* overwrite= */ true));
|
||||
ASSERT_OK(set_unset_env("ENCRYPTED_CREDENTIALS_DIRECTORY", d2, /* overwrite= */ true));
|
||||
}
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
@@ -782,36 +792,36 @@ TEST(condition_test_security) {
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "selinux", false, true)));
|
||||
assert_se(condition_test(condition, environ) != mac_selinux_use());
|
||||
ASSERT_OK_NE(condition_test(condition, environ), mac_selinux_use());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "apparmor", false, false)));
|
||||
assert_se(condition_test(condition, environ) == mac_apparmor_use());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), mac_apparmor_use());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "tomoyo", false, false)));
|
||||
assert_se(condition_test(condition, environ) == mac_tomoyo_use());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), mac_tomoyo_use());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "ima", false, false)));
|
||||
assert_se(condition_test(condition, environ) == use_ima());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), use_ima());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "smack", false, false)));
|
||||
assert_se(condition_test(condition, environ) == mac_smack_use());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), mac_smack_use());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "audit", false, false)));
|
||||
assert_se(condition_test(condition, environ) == use_audit());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), use_audit());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "uefi-secureboot", false, false)));
|
||||
assert_se(condition_test(condition, environ) == is_efi_secure_boot());
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), is_efi_secure_boot());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_SECURITY, "cvm", false, false)));
|
||||
assert_se(condition_test(condition, environ) ==
|
||||
(detect_confidential_virtualization() != CONFIDENTIAL_VIRTUALIZATION_NONE));
|
||||
ASSERT_OK_EQ(condition_test(condition, environ),
|
||||
(detect_confidential_virtualization() != CONFIDENTIAL_VIRTUALIZATION_NONE));
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
@@ -844,19 +854,19 @@ TEST(condition_test_virtualization) {
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_VIRTUALIZATION, "container", false, false)));
|
||||
r = condition_test(condition, environ);
|
||||
log_info("ConditionVirtualization=container → %i", r);
|
||||
assert_se(r == !!detect_container());
|
||||
ASSERT_OK_EQ(r, !!detect_container());
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_VIRTUALIZATION, "vm", false, false)));
|
||||
r = condition_test(condition, environ);
|
||||
log_info("ConditionVirtualization=vm → %i", r);
|
||||
assert_se(r == (detect_vm() && !detect_container()));
|
||||
ASSERT_OK_EQ(r, (detect_vm() && !detect_container()));
|
||||
condition_free(condition);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_VIRTUALIZATION, "private-users", false, false)));
|
||||
r = condition_test(condition, environ);
|
||||
log_info("ConditionVirtualization=private-users → %i", r);
|
||||
assert_se(r == !!running_in_userns());
|
||||
ASSERT_OK_EQ(r, !!running_in_userns());
|
||||
condition_free(condition);
|
||||
|
||||
NULSTR_FOREACH(virt,
|
||||
@@ -963,13 +973,12 @@ TEST(condition_test_group) {
|
||||
ASSERT_OK_POSITIVE(r);
|
||||
condition_free(condition);
|
||||
|
||||
ngroups_max = sysconf(_SC_NGROUPS_MAX);
|
||||
assert_se(ngroups_max > 0);
|
||||
ngroups_max = ASSERT_OK_ERRNO(sysconf(_SC_NGROUPS_MAX));
|
||||
ASSERT_GT(ngroups_max, 0);
|
||||
|
||||
gids = newa(gid_t, ngroups_max);
|
||||
|
||||
ngroups = getgroups(ngroups_max, gids);
|
||||
assert_se(ngroups >= 0);
|
||||
ngroups = ASSERT_OK_ERRNO(getgroups(ngroups_max, gids));
|
||||
|
||||
max_gid = getgid();
|
||||
for (i = 0; i < ngroups; i++) {
|
||||
@@ -1019,15 +1028,12 @@ TEST(condition_test_group) {
|
||||
|
||||
static void test_condition_test_cpus_one(const char *s, bool result) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
log_debug("%s=%s", condition_type_to_string(CONDITION_CPUS), s);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_CPUS, s, false, false)));
|
||||
|
||||
r = condition_test(condition, environ);
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == result);
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), result);
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
@@ -1035,8 +1041,7 @@ TEST(condition_test_cpus) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
int cpus;
|
||||
|
||||
cpus = cpus_in_affinity_mask();
|
||||
assert_se(cpus >= 0);
|
||||
cpus = ASSERT_OK(cpus_in_affinity_mask());
|
||||
|
||||
test_condition_test_cpus_one("> 0", true);
|
||||
test_condition_test_cpus_one(">= 0", true);
|
||||
@@ -1052,42 +1057,39 @@ TEST(condition_test_cpus) {
|
||||
test_condition_test_cpus_one("!= 100000", true);
|
||||
test_condition_test_cpus_one("<= 100000", true);
|
||||
|
||||
assert_se(asprintf(&t, "= %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "= %i", cpus));
|
||||
test_condition_test_cpus_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "<= %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "<= %i", cpus));
|
||||
test_condition_test_cpus_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, ">= %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, ">= %i", cpus));
|
||||
test_condition_test_cpus_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "!= %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "!= %i", cpus));
|
||||
test_condition_test_cpus_one(t, false);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "< %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "< %i", cpus));
|
||||
test_condition_test_cpus_one(t, false);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "> %i", cpus) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "> %i", cpus));
|
||||
test_condition_test_cpus_one(t, false);
|
||||
t = mfree(t);
|
||||
}
|
||||
|
||||
static void test_condition_test_memory_one(const char *s, bool result) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
log_debug("%s=%s", condition_type_to_string(CONDITION_MEMORY), s);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_MEMORY, s, false, false)));
|
||||
|
||||
r = condition_test(condition, environ);
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == result);
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), result);
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
@@ -1132,42 +1134,39 @@ TEST(condition_test_memory) {
|
||||
test_condition_test_memory_one("!= 100 T 1 G", true);
|
||||
test_condition_test_memory_one("<= 100 T 1 G", true);
|
||||
|
||||
assert_se(asprintf(&t, "= %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "= %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "<= %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "<= %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, ">= %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, ">= %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, true);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "!= %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "!= %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, false);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "< %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "< %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, false);
|
||||
t = mfree(t);
|
||||
|
||||
assert_se(asprintf(&t, "> %" PRIu64, memory) >= 0);
|
||||
ASSERT_OK(asprintf(&t, "> %" PRIu64, memory));
|
||||
test_condition_test_memory_one(t, false);
|
||||
t = mfree(t);
|
||||
}
|
||||
|
||||
static void test_condition_test_environment_one(const char *s, bool result) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
log_debug("%s=%s", condition_type_to_string(CONDITION_ENVIRONMENT), s);
|
||||
|
||||
ASSERT_NOT_NULL((condition = condition_new(CONDITION_ENVIRONMENT, s, false, false)));
|
||||
|
||||
r = condition_test(condition, environ);
|
||||
assert_se(r >= 0);
|
||||
assert_se(r == result);
|
||||
ASSERT_OK_EQ(condition_test(condition, environ), result);
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
@@ -1463,13 +1462,11 @@ TEST(condition_test_kernel_module_loaded) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
condition = condition_new(CONDITION_KERNEL_MODULE_LOADED, "", /* trigger= */ false, /* negate= */ false);
|
||||
assert_se(condition);
|
||||
condition = ASSERT_NOT_NULL(condition_new(CONDITION_KERNEL_MODULE_LOADED, "", /* trigger= */ false, /* negate= */ false));
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
condition = condition_new(CONDITION_KERNEL_MODULE_LOADED, "..", /* trigger= */ false, /* negate= */ false);
|
||||
assert_se(condition);
|
||||
condition = ASSERT_NOT_NULL(condition_new(CONDITION_KERNEL_MODULE_LOADED, "..", /* trigger= */ false, /* negate= */ false));
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
|
||||
@@ -1477,8 +1474,7 @@ TEST(condition_test_kernel_module_loaded) {
|
||||
return (void) log_tests_skipped("/sys/module not available, skipping.");
|
||||
|
||||
FOREACH_STRING(m, "random", "vfat", "fat", "cec", "binfmt_misc", "binfmt-misc") {
|
||||
condition = condition_new(CONDITION_KERNEL_MODULE_LOADED, m, /* trigger= */ false, /* negate= */ false);
|
||||
assert_se(condition);
|
||||
condition = ASSERT_NOT_NULL(condition_new(CONDITION_KERNEL_MODULE_LOADED, m, /* trigger= */ false, /* negate= */ false));
|
||||
r = condition_test(condition, environ);
|
||||
ASSERT_OK(r);
|
||||
condition_free(condition);
|
||||
@@ -1486,8 +1482,7 @@ TEST(condition_test_kernel_module_loaded) {
|
||||
log_notice("kmod %s is loaded: %s", m, yes_no(r));
|
||||
}
|
||||
|
||||
condition = condition_new(CONDITION_KERNEL_MODULE_LOADED, "idefinitelydontexist", /* trigger= */ false, /* negate= */ false);
|
||||
assert_se(condition);
|
||||
condition = ASSERT_NOT_NULL(condition_new(CONDITION_KERNEL_MODULE_LOADED, "idefinitelydontexist", /* trigger= */ false, /* negate= */ false));
|
||||
ASSERT_OK_ZERO(condition_test(condition, environ));
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user