Also, implement the negation check inside of condition_test() instead of
individually in each test function.
src/udev/udevd.c
systemd_udevd_LDADD = \
src/udev/udevd.c
systemd_udevd_LDADD = \
+ libudev-core.la \
+ libsystemd-capability.la
udevadm_SOURCES = \
src/udev/udevadm.c \
udevadm_SOURCES = \
src/udev/udevadm.c \
src/udev/udevadm-test-builtin.c
udevadm_LDADD = \
src/udev/udevadm-test-builtin.c
udevadm_LDADD = \
+ libudev-core.la \
+ libsystemd-capability.la
# Update hwdb on installation. Do not bother if installing
# in DESTDIR, since this is likely for packaging purposes.
# Update hwdb on installation. Do not bother if installing
# in DESTDIR, since this is likely for packaging purposes.
src/test/test-udev.c
test_udev_LDADD = \
src/test/test-udev.c
test_udev_LDADD = \
+ libudev-core.la \
+ libsystemd-capability.la \
$(BLKID_LIBS) \
$(KMOD_LIBS) \
$(SELINUX_LIBS)
$(BLKID_LIBS) \
$(KMOD_LIBS) \
$(SELINUX_LIBS)
test_network_SOURCES = \
src/network/test-network.c
test_network_SOURCES = \
src/network/test-network.c
-test_network_CFLAGS = \
- $(AM_CFLAGS)
-
- libsystemd-networkd-core.la
+ libsystemd-networkd-core.la \
+ libsystemd-capability.la
test_network_tables_SOURCES = \
src/network/test-network-tables.c \
test_network_tables_SOURCES = \
src/network/test-network-tables.c \
const char *dev_type,
const char *dev_name) {
const char *dev_type,
const char *dev_name) {
- if (match_host && !condition_test_host(match_host))
+ if (match_host && !condition_test(match_host))
- if (match_virt && !condition_test_virtualization(match_virt))
+ if (match_virt && !condition_test(match_virt))
- if (match_kernel && !condition_test_kernel_command_line(match_kernel))
+ if (match_kernel && !condition_test(match_kernel))
- if (match_arch && !condition_test_architecture(match_arch))
+ if (match_arch && !condition_test(match_arch))
return 0;
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
return 0;
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
-int condition_test_kernel_command_line(Condition *c) {
+static int condition_test_kernel_command_line(Condition *c) {
_cleanup_free_ char *line = NULL;
const char *p;
bool equal;
_cleanup_free_ char *line = NULL;
const char *p;
bool equal;
if (r < 0)
return r;
if (r == 0)
if (r < 0)
return r;
if (r == 0)
equal = !!strchr(c->parameter, '=');
p = line;
equal = !!strchr(c->parameter, '=');
p = line;
if (r < 0)
return r;
if (r == 0)
if (r < 0)
return r;
if (r == 0)
if (equal)
found = streq(word, c->parameter);
if (equal)
found = streq(word, c->parameter);
-int condition_test_virtualization(Condition *c) {
+static int condition_test_virtualization(Condition *c) {
int b, v;
const char *id;
int b, v;
const char *id;
b = parse_boolean(c->parameter);
if (v > 0 && b > 0)
b = parse_boolean(c->parameter);
if (v > 0 && b > 0)
/* Then, compare categorization */
if (v == VIRTUALIZATION_VM && streq(c->parameter, "vm"))
/* Then, compare categorization */
if (v == VIRTUALIZATION_VM && streq(c->parameter, "vm"))
if (v == VIRTUALIZATION_CONTAINER && streq(c->parameter, "container"))
if (v == VIRTUALIZATION_CONTAINER && streq(c->parameter, "container"))
- return (v > 0 && streq(c->parameter, id)) == !c->negate;
+ return v > 0 && streq(c->parameter, id);
-int condition_test_architecture(Condition *c) {
+static int condition_test_architecture(Condition *c) {
- return (a == b) == !c->negate;
-int condition_test_host(Condition *c) {
+static int condition_test_host(Condition *c) {
_cleanup_free_ char *h = NULL;
sd_id128_t x, y;
int r;
_cleanup_free_ char *h = NULL;
sd_id128_t x, y;
int r;
- return sd_id128_equal(x, y) == !c->negate;
+ return sd_id128_equal(x, y);
}
h = gethostname_malloc();
if (!h)
return -ENOMEM;
}
h = gethostname_malloc();
if (!h)
return -ENOMEM;
- return (fnmatch(c->parameter, h, FNM_CASEFOLD) == 0) == !c->negate;
+ return fnmatch(c->parameter, h, FNM_CASEFOLD) == 0;
-int condition_test_ac_power(Condition *c) {
+static int condition_test_ac_power(Condition *c) {
- return ((on_ac_power() != 0) == !!r) == !c->negate;
+ return (on_ac_power() != 0) == !!r;
}
static int condition_test_security(Condition *c) {
}
static int condition_test_security(Condition *c) {
assert(c->type == CONDITION_SECURITY);
if (streq(c->parameter, "selinux"))
assert(c->type == CONDITION_SECURITY);
if (streq(c->parameter, "selinux"))
- return mac_selinux_use() == !c->negate;
+ return mac_selinux_use();
if (streq(c->parameter, "smack"))
if (streq(c->parameter, "smack"))
- return mac_smack_use() == !c->negate;
+ return mac_smack_use();
if (streq(c->parameter, "apparmor"))
if (streq(c->parameter, "apparmor"))
- return mac_apparmor_use() == !c->negate;
+ return mac_apparmor_use();
if (streq(c->parameter, "audit"))
if (streq(c->parameter, "audit"))
- return use_audit() == !c->negate;
if (streq(c->parameter, "ima"))
if (streq(c->parameter, "ima"))
- return use_ima() == !c->negate;
}
static int condition_test_capability(Condition *c) {
}
static int condition_test_capability(Condition *c) {
- return !!(capabilities & (1ULL << value)) == !c->negate;
+ return !!(capabilities & (1ULL << value));
}
static int condition_test_needs_update(Condition *c) {
}
static int condition_test_needs_update(Condition *c) {
/* If the file system is read-only we shouldn't suggest an update */
if (path_is_read_only_fs(c->parameter) > 0)
/* If the file system is read-only we shouldn't suggest an update */
if (path_is_read_only_fs(c->parameter) > 0)
/* Any other failure means we should allow the condition to be true,
* so that we rather invoke too many update tools then too
* few. */
if (!path_is_absolute(c->parameter))
/* Any other failure means we should allow the condition to be true,
* so that we rather invoke too many update tools then too
* few. */
if (!path_is_absolute(c->parameter))
p = strappenda(c->parameter, "/.updated");
if (lstat(p, &other) < 0)
p = strappenda(c->parameter, "/.updated");
if (lstat(p, &other) < 0)
if (lstat("/usr/", &usr) < 0)
if (lstat("/usr/", &usr) < 0)
- return (usr.st_mtim.tv_sec > other.st_mtim.tv_sec ||
- (usr.st_mtim.tv_sec == other.st_mtim.tv_sec && usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec)) == !c->negate;
+ return usr.st_mtim.tv_sec > other.st_mtim.tv_sec ||
+ (usr.st_mtim.tv_sec == other.st_mtim.tv_sec && usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec);
}
static int condition_test_first_boot(Condition *c) {
}
static int condition_test_first_boot(Condition *c) {
- return ((access("/run/systemd/first-boot", F_OK) >= 0) == !!r) == !c->negate;
+ return (access("/run/systemd/first-boot", F_OK) >= 0) == !!r;
}
static int condition_test_path_exists(Condition *c) {
}
static int condition_test_path_exists(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_EXISTS);
assert(c->parameter);
assert(c->type == CONDITION_PATH_EXISTS);
- return (access(c->parameter, F_OK) >= 0) == !c->negate;
+ return access(c->parameter, F_OK) >= 0;
}
static int condition_test_path_exists_glob(Condition *c) {
}
static int condition_test_path_exists_glob(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_EXISTS_GLOB);
assert(c->parameter);
assert(c->type == CONDITION_PATH_EXISTS_GLOB);
- return (glob_exists(c->parameter) > 0) == !c->negate;
+ return glob_exists(c->parameter) > 0;
}
static int condition_test_path_is_directory(Condition *c) {
}
static int condition_test_path_is_directory(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_DIRECTORY);
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_DIRECTORY);
- return (is_dir(c->parameter, true) > 0) == !c->negate;
+ return is_dir(c->parameter, true) > 0;
}
static int condition_test_path_is_symbolic_link(Condition *c) {
}
static int condition_test_path_is_symbolic_link(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_SYMBOLIC_LINK);
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_SYMBOLIC_LINK);
- return (is_symlink(c->parameter) > 0) == !c->negate;
+ return is_symlink(c->parameter) > 0;
}
static int condition_test_path_is_mount_point(Condition *c) {
}
static int condition_test_path_is_mount_point(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
- return (path_is_mount_point(c->parameter, true) > 0) == !c->negate;
+ return path_is_mount_point(c->parameter, true) > 0;
}
static int condition_test_path_is_read_write(Condition *c) {
}
static int condition_test_path_is_read_write(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_READ_WRITE);
assert(c->parameter);
assert(c->type == CONDITION_PATH_IS_READ_WRITE);
- return (path_is_read_only_fs(c->parameter) > 0) == c->negate;
+ return path_is_read_only_fs(c->parameter) <= 0;
}
static int condition_test_directory_not_empty(Condition *c) {
}
static int condition_test_directory_not_empty(Condition *c) {
assert(c->type == CONDITION_DIRECTORY_NOT_EMPTY);
r = dir_is_empty(c->parameter);
assert(c->type == CONDITION_DIRECTORY_NOT_EMPTY);
r = dir_is_empty(c->parameter);
- return !(r == -ENOENT || r > 0) == !c->negate;
+ return r <= 0 && r != -ENOENT;
}
static int condition_test_file_not_empty(Condition *c) {
}
static int condition_test_file_not_empty(Condition *c) {
return (stat(c->parameter, &st) >= 0 &&
S_ISREG(st.st_mode) &&
return (stat(c->parameter, &st) >= 0 &&
S_ISREG(st.st_mode) &&
- st.st_size > 0) == !c->negate;
}
static int condition_test_file_is_executable(Condition *c) {
}
static int condition_test_file_is_executable(Condition *c) {
return (stat(c->parameter, &st) >= 0 &&
S_ISREG(st.st_mode) &&
return (stat(c->parameter, &st) >= 0 &&
S_ISREG(st.st_mode) &&
- (st.st_mode & 0111)) == !c->negate;
}
static int condition_test_null(Condition *c) {
}
static int condition_test_null(Condition *c) {
/* Note that during parsing we already evaluate the string and
* store it in c->negate */
/* Note that during parsing we already evaluate the string and
* store it in c->negate */
}
int condition_test(Condition *c) {
}
int condition_test(Condition *c) {
[CONDITION_FIRST_BOOT] = condition_test_first_boot,
[CONDITION_NULL] = condition_test_null,
};
[CONDITION_FIRST_BOOT] = condition_test_first_boot,
[CONDITION_NULL] = condition_test_null,
};
assert(c);
assert(c->type >= 0);
assert(c->type < _CONDITION_TYPE_MAX);
assert(c);
assert(c->type >= 0);
assert(c->type < _CONDITION_TYPE_MAX);
- return condition_tests[c->type](c);
+ r = condition_tests[c->type](c);
+ if (r < 0)
+ return r;
+
+ return (r > 0) == !c->negate;
}
void condition_dump(Condition *c, FILE *f, const char *prefix) {
}
void condition_dump(Condition *c, FILE *f, const char *prefix) {
void condition_free(Condition *c);
void condition_free_list(Condition *c);
void condition_free(Condition *c);
void condition_free_list(Condition *c);
-int condition_test_kernel_command_line(Condition *c);
-int condition_test_virtualization(Condition *c);
-int condition_test_architecture(Condition *c);
-int condition_test_host(Condition *c);
-int condition_test_ac_power(Condition *c);
-
int condition_test(Condition *c);
void condition_dump(Condition *c, FILE *f, const char *prefix);
int condition_test(Condition *c);
void condition_dump(Condition *c, FILE *f, const char *prefix);