From 742a862bb803641b78a40f6b498486397a321294 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 11 Sep 2012 01:29:46 +0200 Subject: condition: add ConditionFileNotEmpty= https://bugs.freedesktop.org/show_bug.cgi?id=54448 --- man/systemd.unit.xml | 22 +++++++++++++++------- src/core/condition.c | 10 ++++++++++ src/core/condition.h | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index bf22ca9bd0..00f6066717 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -755,6 +755,7 @@ ConditionPathIsMountPoint= ConditionPathIsReadWrite= ConditionDirectoryNotEmpty= + ConditionFileNotEmpty= ConditionFileIsExecutable= ConditionKernelCommandLine= ConditionVirtualization= @@ -825,21 +826,28 @@ (i.e. not mounted read-only). - ConditionFileIsExecutable= + ConditionDirectoryNotEmpty= is similar to ConditionPathExists= but verifies whether a certain path - exists, is a regular file and marked - executable. + exists and is a non-empty + directory. - ConditionDirectoryNotEmpty= + ConditionFileNotEmpty= is similar to ConditionPathExists= but verifies whether a certain path - exists and is a non-empty - directory. + exists and refers to a regular file + with a non-zero size. + + ConditionFileIsExecutable= + is similar to + ConditionPathExists= + but verifies whether a certain path + exists, is a regular file and marked + executable. - Similarly, + Similar, ConditionKernelCommandLine= may be used to check whether a specific kernel command line option is diff --git a/src/core/condition.c b/src/core/condition.c index e5cda21c37..32a37ccad6 100644 --- a/src/core/condition.c +++ b/src/core/condition.c @@ -261,6 +261,15 @@ bool condition_test(Condition *c) { return !(k == -ENOENT || k > 0) == !c->negate; } + case CONDITION_FILE_NOT_EMPTY: { + struct stat st; + + if (stat(c->parameter, &st) < 0) + return c->negate; + + return (S_ISREG(st.st_mode) && st.st_size > 0) == !c->negate; + } + case CONDITION_FILE_IS_EXECUTABLE: { struct stat st; @@ -350,6 +359,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = { [CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint", [CONDITION_PATH_IS_READ_WRITE] = "ConditionPathIsReadWrite", [CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty", + [CONDITION_FILE_NOT_EMPTY] = "ConditionFileNotEmpty", [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine", [CONDITION_VIRTUALIZATION] = "ConditionVirtualization", [CONDITION_SECURITY] = "ConditionSecurity", diff --git a/src/core/condition.h b/src/core/condition.h index 55b331edd7..03954e40b3 100644 --- a/src/core/condition.h +++ b/src/core/condition.h @@ -33,6 +33,7 @@ typedef enum ConditionType { CONDITION_PATH_IS_MOUNT_POINT, CONDITION_PATH_IS_READ_WRITE, CONDITION_DIRECTORY_NOT_EMPTY, + CONDITION_FILE_NOT_EMPTY, CONDITION_FILE_IS_EXECUTABLE, CONDITION_KERNEL_COMMAND_LINE, CONDITION_VIRTUALIZATION, -- cgit v1.2.3-54-g00ecf