summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/sd-bus.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-09 12:17:26 +0100
committerGitHub <noreply@github.com>2018-02-09 12:17:26 +0100
commitaf77d6f8da3994212b300f1dfd94d67366448f99 (patch)
treeeded5c385e279dec5b6edb9f81a5fb5a8dcd24e4 /src/libsystemd/sd-bus/sd-bus.c
parent8c2dbc8779025c7bd592708a0fc7ef0a29b80f90 (diff)
parent392cf1d05dbfa1395f6d99102e5ea41debb58fec (diff)
downloadsystemd-af77d6f8da3994212b300f1dfd94d67366448f99.tar.gz
Merge pull request #8083 from shawnl/close-ssh
sd-bus: cleanup ssh sessions (Closes: #8076)
Diffstat (limited to 'src/libsystemd/sd-bus/sd-bus.c')
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 5bc7ba6607..c69c596c59 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -22,8 +22,10 @@
#include <netdb.h>
#include <poll.h>
#include <pthread.h>
+#include <signal.h>
#include <stdlib.h>
#include <sys/mman.h>
+#include <sys/wait.h>
#include <unistd.h>
#include "sd-bus.h"
@@ -1095,6 +1097,13 @@ static int bus_parse_next_address(sd_bus *b) {
return 1;
}
+static void bus_kill_exec(sd_bus *bus) {
+ if (pid_is_valid(bus->busexec_pid) > 0) {
+ sigterm_wait(bus->busexec_pid);
+ bus->busexec_pid = 0;
+ }
+}
+
static int bus_start_address(sd_bus *b) {
int r;
@@ -1104,6 +1113,8 @@ static int bus_start_address(sd_bus *b) {
bus_close_io_fds(b);
bus_close_inotify_fd(b);
+ bus_kill_exec(b);
+
/* If you provide multiple different bus-addresses, we
* try all of them in order and use the first one that
* succeeds. */
@@ -1507,6 +1518,9 @@ _public_ void sd_bus_close(sd_bus *bus) {
if (bus_pid_changed(bus))
return;
+ /* Don't leave ssh hanging around */
+ bus_kill_exec(bus);
+
bus_set_state(bus, BUS_CLOSED);
sd_bus_detach_event(bus);
@@ -1524,6 +1538,9 @@ _public_ sd_bus* sd_bus_flush_close_unref(sd_bus *bus) {
if (!bus)
return NULL;
+ /* Have to do this before flush() to prevent hang */
+ bus_kill_exec(bus);
+
sd_bus_flush(bus);
sd_bus_close(bus);