From 1a682f27306d19c29476f262e00de86409609895 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 29 Jun 2019 13:41:38 +1000 Subject: [PATCH] Re-create control socket file node if it disappears. In case something is mounted over /dev (or wherever the control socket lives) it will become inaccessible. When a starts-rwfs service starts, check the socket node still exists and if not, close the socket and re-open. Cherry-picked from development branch. --- src/dinit.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dinit.cc b/src/dinit.cc index 93809df..1bff5dc 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -660,6 +660,17 @@ void rootfs_is_rw() noexcept // once the socket has been successfully opened, further calls have no effect. static void open_control_socket(bool report_ro_failure) noexcept { + if (control_socket_open) { + struct stat stat_buf; + if (stat(control_socket_path, &stat_buf) != 0 && errno == ENOENT) { + // Looks like our control socket has disappeared from the filesystem. Close our control + // socket and re-create it: + control_socket_io.deregister(event_loop); + close(control_socket_io.get_watched_fd()); + control_socket_open = false; // now re-open below + } + } + if (! control_socket_open) { const char * saddrname = control_socket_path; size_t saddrname_len = strlen(saddrname); -- 2.25.1