Skip to content

Commit 898fc00

Browse files
anitazhamrc0mmand
authored andcommitted
core: add ExecXYZEx= bus hook ups to all exec command properties
The "Ex" variant was originally only added for ExecStartXYZ= but it makes sense to have feature parity for the rest of the exec command properties as well (e.g. ExecReload=, ExecStop=, etc).
1 parent 8813a8c commit 898fc00

File tree

7 files changed

+114
-2
lines changed

7 files changed

+114
-2
lines changed

src/core/dbus-service.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,19 @@ const sd_bus_vtable bus_service_vtable[] = {
130130

131131
BUS_EXEC_STATUS_VTABLE("ExecMain", offsetof(Service, main_exec_status), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
132132
BUS_EXEC_COMMAND_LIST_VTABLE("ExecCondition", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
133+
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecConditionEx", offsetof(Service, exec_command[SERVICE_EXEC_CONDITION]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
133134
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
134135
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPreEx", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
135136
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
136137
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartEx", offsetof(Service, exec_command[SERVICE_EXEC_START]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
137138
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
138139
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStartPostEx", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
139140
BUS_EXEC_COMMAND_LIST_VTABLE("ExecReload", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
141+
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecReloadEx", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
140142
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStop", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
143+
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
141144
BUS_EXEC_COMMAND_LIST_VTABLE("ExecStopPost", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
145+
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopPostEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
142146

143147
/* The following four are obsolete, and thus marked hidden here. They moved into the Unit interface */
144148
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),

src/core/service.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,9 +4329,13 @@ static const char* const service_exec_command_table[_SERVICE_EXEC_COMMAND_MAX] =
43294329
DEFINE_STRING_TABLE_LOOKUP(service_exec_command, ServiceExecCommand);
43304330

43314331
static const char* const service_exec_ex_command_table[_SERVICE_EXEC_COMMAND_MAX] = {
4332+
[SERVICE_EXEC_CONDITION] = "ExecConditionEx",
43324333
[SERVICE_EXEC_START_PRE] = "ExecStartPreEx",
43334334
[SERVICE_EXEC_START] = "ExecStartEx",
43344335
[SERVICE_EXEC_START_POST] = "ExecStartPostEx",
4336+
[SERVICE_EXEC_RELOAD] = "ExecReloadEx",
4337+
[SERVICE_EXEC_STOP] = "ExecStopEx",
4338+
[SERVICE_EXEC_STOP_POST] = "ExecStopPostEx",
43354339
};
43364340

43374341
DEFINE_STRING_TABLE_LOOKUP(service_exec_ex_command, ServiceExecCommand);

src/shared/bus-unit-util.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,9 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con
14341434

14351435
if (STR_IN_SET(field,
14361436
"ExecCondition", "ExecStartPre", "ExecStart", "ExecStartPost",
1437-
"ExecStartPreEx", "ExecStartEx", "ExecStartPostEx",
1438-
"ExecReload", "ExecStop", "ExecStopPost"))
1437+
"ExecConditionEx", "ExecStartPreEx", "ExecStartEx", "ExecStartPostEx",
1438+
"ExecReload", "ExecStop", "ExecStopPost",
1439+
"ExecReloadEx", "ExecStopEx", "ExecStopPostEx"))
14391440
return bus_append_exec_command(m, field, eq);
14401441

14411442
if (STR_IN_SET(field, "RestartPreventExitStatus", "RestartForceExitStatus", "SuccessExitStatus")) {

src/systemctl/systemctl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5534,16 +5534,21 @@ static int show_one(
55345534
{ "IPEgressBytes", "t", NULL, offsetof(UnitStatusInfo, ip_egress_bytes) },
55355535
{ "IOReadBytes", "t", NULL, offsetof(UnitStatusInfo, io_read_bytes) },
55365536
{ "IOWriteBytes", "t", NULL, offsetof(UnitStatusInfo, io_write_bytes) },
5537+
{ "ExecCondition", "a(sasbttttuii)", map_exec, 0 },
5538+
{ "ExecConditionEx", "a(sasasttttuii)", map_exec, 0 },
55375539
{ "ExecStartPre", "a(sasbttttuii)", map_exec, 0 },
55385540
{ "ExecStartPreEx", "a(sasasttttuii)", map_exec, 0 },
55395541
{ "ExecStart", "a(sasbttttuii)", map_exec, 0 },
55405542
{ "ExecStartEx", "a(sasasttttuii)", map_exec, 0 },
55415543
{ "ExecStartPost", "a(sasbttttuii)", map_exec, 0 },
55425544
{ "ExecStartPostEx", "a(sasasttttuii)", map_exec, 0 },
55435545
{ "ExecReload", "a(sasbttttuii)", map_exec, 0 },
5546+
{ "ExecReloadEx", "a(sasasttttuii)", map_exec, 0 },
55445547
{ "ExecStopPre", "a(sasbttttuii)", map_exec, 0 },
55455548
{ "ExecStop", "a(sasbttttuii)", map_exec, 0 },
5549+
{ "ExecStopEx", "a(sasasttttuii)", map_exec, 0 },
55465550
{ "ExecStopPost", "a(sasbttttuii)", map_exec, 0 },
5551+
{ "ExecStopPostEx", "a(sasasttttuii)", map_exec, 0 },
55475552
{}
55485553
};
55495554

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BUILD_DIR=$(shell ../../tools/find-build-dir.sh)
2+
3+
all setup run:
4+
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@
5+
6+
clean clean-again:
7+
@basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --clean
8+
9+
.PHONY: all setup run clean clean-again
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -e
3+
TEST_DESCRIPTION="test ExecXYZEx= service unit dbus hookups"
4+
5+
. $TEST_BASE_DIR/test-functions
6+
7+
test_setup() {
8+
create_empty_image_rootdir
9+
10+
(
11+
LOG_LEVEL=5
12+
eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
13+
14+
setup_basic_environment
15+
16+
# mask some services that we do not want to run in these tests
17+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
18+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
19+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service
20+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
21+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service
22+
ln -fs /dev/null $initdir/etc/systemd/system/systemd-machined.service
23+
24+
# setup the testsuite service
25+
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
26+
[Unit]
27+
Description=Testsuite service
28+
29+
[Service]
30+
ExecStart=/testsuite.sh
31+
Type=oneshot
32+
StandardOutput=tty
33+
StandardError=tty
34+
NotifyAccess=all
35+
EOF
36+
cp testsuite.sh $initdir/
37+
38+
setup_testsuite
39+
)
40+
setup_nspawn_root
41+
}
42+
43+
do_test "$@"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -ex
3+
set -o pipefail
4+
5+
systemd-analyze log-level debug
6+
systemd-analyze log-target console
7+
8+
declare -A property
9+
10+
property[1_one]=ExecCondition
11+
property[2_two]=ExecStartPre
12+
property[3_three]=ExecStart
13+
property[4_four]=ExecStartPost
14+
property[5_five]=ExecReload
15+
property[6_six]=ExecStop
16+
property[7_seven]=ExecStopPost
17+
18+
# These should all get upgraded to the corresponding Ex property as the non-Ex variant
19+
# does not support the ":" prefix (no-env-expand).
20+
for c in "${!property[@]}"; do
21+
systemd-run --unit="$c" -r -p "Type=oneshot" -p "${property[$c]}=:/bin/echo \${$c}" /bin/true
22+
systemctl show -p "${property[$c]}" "$c" | grep -F "path=/bin/echo ; argv[]=/bin/echo \${$c} ; ignore_errors=no"
23+
systemctl show -p "${property[$c]}Ex" "$c" | grep -F "path=/bin/echo ; argv[]=/bin/echo \${$c} ; flags=no-env-expand"
24+
done
25+
26+
declare -A property_ex
27+
28+
property_ex[1_one_ex]=ExecConditionEx
29+
property_ex[2_two_ex]=ExecStartPreEx
30+
property_ex[3_three_ex]=ExecStartEx
31+
property_ex[4_four_ex]=ExecStartPostEx
32+
property_ex[5_five_ex]=ExecReloadEx
33+
property_ex[6_six_ex]=ExecStopEx
34+
property_ex[7_seven_ex]=ExecStopPostEx
35+
36+
for c in "${!property_ex[@]}"; do
37+
systemd-run --unit="$c" -r -p "Type=oneshot" -p "${property_ex[$c]}=:/bin/echo \${$c}" /bin/true
38+
systemctl show -p "${property_ex[$c]%??}" "$c" | grep -F "path=/bin/echo ; argv[]=/bin/echo \${$c} ; ignore_errors=no"
39+
systemctl show -p "${property_ex[$c]}" "$c" | grep -F "path=/bin/echo ; argv[]=/bin/echo \${$c} ; flags=no-env-expand"
40+
done
41+
42+
systemd-analyze log-level info
43+
44+
echo OK > /testok
45+
46+
exit 0

0 commit comments

Comments
 (0)