mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
unit: introduce ConditionFileIsExecutable= and use it where we check for a binary we'll spawn
This commit is contained in:
parent
3611581ebd
commit
82e487c56d
2
TODO
2
TODO
@ -26,8 +26,6 @@ Features:
|
||||
|
||||
* possibly apply systemd-sysctl per network device subtrees on hotplug
|
||||
|
||||
* add conditions for file executability
|
||||
|
||||
* implement Register= switch in .socket units to enable registration
|
||||
in Avahi, RPC and other socket registration services.
|
||||
|
||||
|
@ -610,6 +610,7 @@
|
||||
<term><varname>ConditionPathExistsGlob=</varname></term>
|
||||
<term><varname>ConditionPathIsDirectory=</varname></term>
|
||||
<term><varname>ConditionDirectoryNotEmpty=</varname></term>
|
||||
<term><varname>ConditionFileIsExecutable=</varname></term>
|
||||
<term><varname>ConditionKernelCommandLine=</varname></term>
|
||||
<term><varname>ConditionVirtualization=</varname></term>
|
||||
<term><varname>ConditionSecurity=</varname></term>
|
||||
@ -642,7 +643,13 @@
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path
|
||||
exists and is a directory.
|
||||
exists and is a
|
||||
directory. <varname>ConditionFileIsExecutable=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
but verifies whether a certain path
|
||||
exists, is a regular file and marked
|
||||
executable.
|
||||
<varname>ConditionDirectoryNotEmpty=</varname>
|
||||
is similar to
|
||||
<varname>ConditionPathExists=</varname>
|
||||
|
@ -168,6 +168,15 @@ bool condition_test(Condition *c) {
|
||||
return !(k == -ENOENT || k > 0) == !c->negate;
|
||||
}
|
||||
|
||||
case CONDITION_FILE_IS_EXECUTABLE: {
|
||||
struct stat st;
|
||||
|
||||
if (lstat(c->parameter, &st) < 0)
|
||||
return !c->negate;
|
||||
|
||||
return (S_ISREG(st.st_mode) && (st.st_mode & 0111)) == !c->negate;
|
||||
}
|
||||
|
||||
case CONDITION_KERNEL_COMMAND_LINE:
|
||||
return test_kernel_command_line(c->parameter) == !c->negate;
|
||||
|
||||
|
@ -31,6 +31,7 @@ typedef enum ConditionType {
|
||||
CONDITION_PATH_EXISTS_GLOB,
|
||||
CONDITION_PATH_IS_DIRECTORY,
|
||||
CONDITION_DIRECTORY_NOT_EMPTY,
|
||||
CONDITION_FILE_IS_EXECUTABLE,
|
||||
CONDITION_KERNEL_COMMAND_LINE,
|
||||
CONDITION_VIRTUALIZATION,
|
||||
CONDITION_SECURITY,
|
||||
|
@ -2003,6 +2003,7 @@ static int load_from_path(Unit *u, const char *path) {
|
||||
{ "ConditionPathExistsGlob", config_parse_condition_path, CONDITION_PATH_EXISTS_GLOB, u, "Unit" },
|
||||
{ "ConditionPathIsDirectory", config_parse_condition_path, CONDITION_PATH_IS_DIRECTORY, u, "Unit" },
|
||||
{ "ConditionDirectoryNotEmpty", config_parse_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, u, "Unit" },
|
||||
{ "ConditionFileIsExecutable", config_parse_condition_path, CONDITION_FILE_IS_EXECUTABLE, u, "Unit" },
|
||||
{ "ConditionKernelCommandLine", config_parse_condition_string, CONDITION_KERNEL_COMMAND_LINE, u, "Unit" },
|
||||
{ "ConditionVirtualization", config_parse_condition_string, CONDITION_VIRTUALIZATION, u, "Unit" },
|
||||
{ "ConditionSecurity", config_parse_condition_string, CONDITION_SECURITY, u, "Unit" },
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
[Unit]
|
||||
Description=/sbin/halt.local Compatibility
|
||||
ConditionPathExists=/sbin/halt.local
|
||||
ConditionFileIsExecutable=/sbin/halt.local
|
||||
DefaultDependencies=no
|
||||
After=shutdown.target
|
||||
Before=final.target
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
[Unit]
|
||||
Description=/etc/rc.local Compatibility
|
||||
ConditionPathExists=/etc/rc.d/rc.local
|
||||
ConditionFileIsExecutable=/etc/rc.d/rc.local
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
[Unit]
|
||||
Description=/etc/init.d/halt.local Compatibility
|
||||
ConditionPathExists=/etc/init.d/halt.local
|
||||
ConditionFileIsExecutable=/etc/init.d/halt.local
|
||||
DefaultDependencies=no
|
||||
After=shutdown.target
|
||||
Before=final.target
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
[Unit]
|
||||
Description=/etc/init.d/boot.local Compatibility
|
||||
ConditionPathExists=/etc/init.d/boot.local
|
||||
ConditionFileIsExecutable=/etc/init.d/boot.local
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
|
Loading…
Reference in New Issue
Block a user