mirror of
https://github.com/AuxXxilium/eudev.git
synced 2025-03-06 20:59:19 +07:00
unit: introduce ConditionPathIsMountPoint=
This commit is contained in:
parent
418112a296
commit
ab7f148f81
2
TODO
2
TODO
@ -13,6 +13,8 @@ Bugfixes:
|
||||
|
||||
Features:
|
||||
|
||||
* introduce sd_log_open() to create a connection to the syslog bridge via sd-daemon.h
|
||||
|
||||
* when a bus name of a service disappears from the bus make sure to queue further activation requests
|
||||
|
||||
* something like ConditionExec= or ExecStartPre= without failure state
|
||||
|
@ -665,6 +665,7 @@
|
||||
<term><varname>ConditionPathExists=</varname></term>
|
||||
<term><varname>ConditionPathExistsGlob=</varname></term>
|
||||
<term><varname>ConditionPathIsDirectory=</varname></term>
|
||||
<term><varname>ConditionPathIsMountPoint=</varname></term>
|
||||
<term><varname>ConditionDirectoryNotEmpty=</varname></term>
|
||||
<term><varname>ConditionFileIsExecutable=</varname></term>
|
||||
<term><varname>ConditionKernelCommandLine=</varname></term>
|
||||
@ -695,16 +696,24 @@
|
||||
works in a similar way, but checks for
|
||||
the existence of at least one file or
|
||||
directory matching the specified
|
||||
globbing pattern.
|
||||
<varname>ConditionPathIsDirectory=</varname>
|
||||
is similar to <varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path exists and
|
||||
is a directory. It does not follow symlinks.
|
||||
<varname>ConditionFileIsExecutable=</varname>
|
||||
is similar to <varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path exists,
|
||||
is a regular file and marked executable.
|
||||
It follows symlinks.
|
||||
globbing
|
||||
pattern. <varname>ConditionPathIsDirectory=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path
|
||||
exists and is a directory. It does not
|
||||
follow
|
||||
symlinks. <varname>ConditionPathIsMountPoint=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path
|
||||
exists and is a mount
|
||||
point. <varname>ConditionFileIsExecutable=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path
|
||||
exists, is a regular file and marked
|
||||
executable. It follows symlinks.
|
||||
<varname>ConditionDirectoryNotEmpty=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
|
@ -36,18 +36,21 @@ Condition* condition_new(ConditionType type, const char *parameter, bool trigger
|
||||
|
||||
assert(type < _CONDITION_TYPE_MAX);
|
||||
|
||||
if (!(c = new0(Condition, 1)))
|
||||
c = new0(Condition, 1);
|
||||
if (!c)
|
||||
return NULL;
|
||||
|
||||
c->type = type;
|
||||
c->trigger = trigger;
|
||||
c->negate = negate;
|
||||
|
||||
if (parameter)
|
||||
if (!(c->parameter = strdup(parameter))) {
|
||||
if (parameter) {
|
||||
c->parameter = strdup(parameter);
|
||||
if (!c->parameter) {
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
@ -78,7 +81,8 @@ static bool test_kernel_command_line(const char *parameter) {
|
||||
if (detect_container(NULL) > 0)
|
||||
return false;
|
||||
|
||||
if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
|
||||
r = read_one_line_file("/proc/cmdline", &line);
|
||||
if (r < 0) {
|
||||
log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
|
||||
return false;
|
||||
}
|
||||
@ -89,7 +93,8 @@ static bool test_kernel_command_line(const char *parameter) {
|
||||
FOREACH_WORD_QUOTED(w, l, line, state) {
|
||||
|
||||
free(word);
|
||||
if (!(word = strndup(w, l)))
|
||||
word = strndup(w, l);
|
||||
if (!word)
|
||||
break;
|
||||
|
||||
if (equal) {
|
||||
@ -118,7 +123,8 @@ static bool test_virtualization(const char *parameter) {
|
||||
|
||||
assert(parameter);
|
||||
|
||||
if ((r = detect_virtualization(&id)) < 0) {
|
||||
r = detect_virtualization(&id);
|
||||
if (r < 0) {
|
||||
log_warning("Failed to detect virtualization, ignoring: %s", strerror(-r));
|
||||
return false;
|
||||
}
|
||||
@ -161,6 +167,9 @@ bool condition_test(Condition *c) {
|
||||
return S_ISDIR(st.st_mode) == !c->negate;
|
||||
}
|
||||
|
||||
case CONDITION_PATH_IS_MOUNT_POINT:
|
||||
return (path_is_mount_point(c->parameter, true) > 0) == !c->negate;
|
||||
|
||||
case CONDITION_DIRECTORY_NOT_EMPTY: {
|
||||
int k;
|
||||
|
||||
@ -247,6 +256,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
|
||||
[CONDITION_PATH_EXISTS] = "ConditionPathExists",
|
||||
[CONDITION_PATH_EXISTS_GLOB] = "ConditionPathExistsGlob",
|
||||
[CONDITION_PATH_IS_DIRECTORY] = "ConditionPathIsDirectory",
|
||||
[CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
|
||||
[CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
|
||||
[CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",
|
||||
[CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
|
||||
|
@ -30,6 +30,7 @@ typedef enum ConditionType {
|
||||
CONDITION_PATH_EXISTS,
|
||||
CONDITION_PATH_EXISTS_GLOB,
|
||||
CONDITION_PATH_IS_DIRECTORY,
|
||||
CONDITION_PATH_IS_MOUNT_POINT,
|
||||
CONDITION_DIRECTORY_NOT_EMPTY,
|
||||
CONDITION_FILE_IS_EXECUTABLE,
|
||||
CONDITION_KERNEL_COMMAND_LINE,
|
||||
|
@ -112,6 +112,7 @@ Unit.JobTimeoutSec, config_parse_usec, 0,
|
||||
Unit.ConditionPathExists, config_parse_unit_condition_path, CONDITION_PATH_EXISTS, 0
|
||||
Unit.ConditionPathExistsGlob, config_parse_unit_condition_path, CONDITION_PATH_EXISTS_GLOB, 0
|
||||
Unit.ConditionPathIsDirectory, config_parse_unit_condition_path, CONDITION_PATH_IS_DIRECTORY, 0
|
||||
Unit.ConditionPathIsMountPoint, config_parse_unit_condition_path, CONDITION_PATH_IS_MOUNT_POINT, 0
|
||||
Unit.ConditionDirectoryNotEmpty, config_parse_unit_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, 0
|
||||
Unit.ConditionFileIsExecutable, config_parse_unit_condition_path, CONDITION_FILE_IS_EXECUTABLE, 0
|
||||
Unit.ConditionKernelCommandLine, config_parse_unit_condition_string, CONDITION_KERNEL_COMMAND_LINE, 0
|
||||
|
@ -1545,10 +1545,12 @@ int config_parse_unit_condition_path(
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if ((trigger = rvalue[0] == '|'))
|
||||
trigger = rvalue[0] == '|';
|
||||
if (trigger)
|
||||
rvalue++;
|
||||
|
||||
if ((negate = rvalue[0] == '!'))
|
||||
negate = rvalue[0] == '!';
|
||||
if (negate)
|
||||
rvalue++;
|
||||
|
||||
if (!path_is_absolute(rvalue)) {
|
||||
@ -1556,7 +1558,8 @@ int config_parse_unit_condition_path(
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(c = condition_new(cond, rvalue, trigger, negate)))
|
||||
c = condition_new(cond, rvalue, trigger, negate);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
|
||||
|
Loading…
Reference in New Issue
Block a user