diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-05-26 16:22:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-05-27 15:01:07 +0200 |
commit | 2b5f708985a0d175f86a57d4e8e2c8eccfb73bd6 (patch) | |
tree | b65bc644fa06dbf6e739242eea976aa335107750 /src/run | |
parent | 518a9bd689fe83f29cb97e00be184f1417d2c291 (diff) | |
download | systemd-2b5f708985a0d175f86a57d4e8e2c8eccfb73bd6.tar.gz |
run: when waiting for unit, also check if no job is pending anymore
This is a fix-up for a7c71d214c37797d82de2f66cfe0a0a79c3a5c92: since we
now don't wait for the job to finish anymore right after enqueuing it,
we should not exit our ptyfwd logic before the unit is back to inactive
*and* no job pending anymore.
Diffstat (limited to 'src/run')
-rw-r--r-- | src/run/run.c | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/run/run.c b/src/run/run.c index 8761dc5d07..70a27924b5 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -978,8 +978,11 @@ typedef struct RunContext { PTYForward *forward; sd_bus_slot *match; - /* The exit data of the unit */ + /* Current state of the unit */ char *active_state; + bool has_job; + + /* The exit data of the unit */ uint64_t inactive_exit_usec; uint64_t inactive_enter_usec; char *result; @@ -1010,7 +1013,7 @@ static void run_context_check_done(RunContext *c) { assert(c); if (c->match) - done = STRPTR_IN_SET(c->active_state, "inactive", "failed"); + done = STRPTR_IN_SET(c->active_state, "inactive", "failed") && !c->has_job; else done = true; @@ -1021,20 +1024,35 @@ static void run_context_check_done(RunContext *c) { sd_event_exit(c->event, EXIT_SUCCESS); } +static int map_job(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) { + bool *b = userdata; + const char *job; + uint32_t id; + int r; + + r = sd_bus_message_read(m, "(uo)", &id, &job); + if (r < 0) + return r; + + *b = id != 0 || !streq(job, "/"); + return 0; +} + static int run_context_update(RunContext *c, const char *path) { static const struct bus_properties_map map[] = { - { "ActiveState", "s", NULL, offsetof(RunContext, active_state) }, - { "InactiveExitTimestampMonotonic", "t", NULL, offsetof(RunContext, inactive_exit_usec) }, - { "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(RunContext, inactive_enter_usec) }, - { "Result", "s", NULL, offsetof(RunContext, result) }, - { "ExecMainCode", "i", NULL, offsetof(RunContext, exit_code) }, - { "ExecMainStatus", "i", NULL, offsetof(RunContext, exit_status) }, - { "CPUUsageNSec", "t", NULL, offsetof(RunContext, cpu_usage_nsec) }, - { "IPIngressBytes", "t", NULL, offsetof(RunContext, ip_ingress_bytes) }, - { "IPEgressBytes", "t", NULL, offsetof(RunContext, ip_egress_bytes) }, - { "IOReadBytes", "t", NULL, offsetof(RunContext, io_read_bytes) }, - { "IOWriteBytes", "t", NULL, offsetof(RunContext, io_write_bytes) }, + { "ActiveState", "s", NULL, offsetof(RunContext, active_state) }, + { "InactiveExitTimestampMonotonic", "t", NULL, offsetof(RunContext, inactive_exit_usec) }, + { "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(RunContext, inactive_enter_usec) }, + { "Result", "s", NULL, offsetof(RunContext, result) }, + { "ExecMainCode", "i", NULL, offsetof(RunContext, exit_code) }, + { "ExecMainStatus", "i", NULL, offsetof(RunContext, exit_status) }, + { "CPUUsageNSec", "t", NULL, offsetof(RunContext, cpu_usage_nsec) }, + { "IPIngressBytes", "t", NULL, offsetof(RunContext, ip_ingress_bytes) }, + { "IPEgressBytes", "t", NULL, offsetof(RunContext, ip_egress_bytes) }, + { "IOReadBytes", "t", NULL, offsetof(RunContext, io_read_bytes) }, + { "IOWriteBytes", "t", NULL, offsetof(RunContext, io_write_bytes) }, + { "Job", "(uo)", map_job, offsetof(RunContext, has_job) }, {} }; |