static void sigint_reboot_cb(EventLoop_t *eloop) noexcept;
static void sigquit_cb(EventLoop_t *eloop) noexcept;
static void sigterm_cb(EventLoop_t *eloop) noexcept;
-static void open_control_socket(EventLoop_t *loop) noexcept;
-static void close_control_socket(EventLoop_t *loop) noexcept;
+static void close_control_socket() noexcept;
static void control_socket_cb(EventLoop_t *loop, int fd);
+void open_control_socket() noexcept;
+void setup_external_log() noexcept;
+
+
class ControlSocketWatcher : public EventLoop_t::FdWatcher
{
Rearm fdEvent(EventLoop_t &loop, int fd, int flags) override
sigterm_watcher.addWatch(eventLoop, SIGTERM);
// Try to open control socket (may fail due to readonly filesystem)
- open_control_socket(&eventLoop);
+ open_control_socket();
#ifdef __linux__
if (am_system_init) {
eventLoop.run();
}
- close_control_socket(&eventLoop);
+ close_control_socket();
if (am_system_init) {
if (shutdown_type == ShutdownType::CONTINUE) {
}
}
-static void open_control_socket(EventLoop_t *loop) noexcept
+void open_control_socket() noexcept
{
if (! control_socket_open) {
const char * saddrname = control_socket_path;
return;
}
- control_socket_open = true;
- control_socket_io.addWatch(eventLoop, sockfd, IN_EVENTS);
+ try {
+ control_socket_io.addWatch(eventLoop, sockfd, IN_EVENTS);
+ control_socket_open = true;
+ }
+ catch (std::exception &e)
+ {
+ log(LogLevel::ERROR, "Could not setup I/O on control socket: ", e.what());
+ close(sockfd);
+ }
}
}
-static void close_control_socket(EventLoop_t *loop) noexcept
+static void close_control_socket() noexcept
{
if (control_socket_open) {
int fd = control_socket_io.fd;
- control_socket_io.deregister(*loop);
+ control_socket_io.deregister(eventLoop);
close(fd);
// Unlink the socket:
}
}
-static void setup_external_log() noexcept
+void setup_external_log() noexcept
{
if (! external_log_open) {
}
}
-// Called from service when the system is "rw ready" (filesystem mounted r/w etc).
-// May be called more than once.
-void system_rw_ready() noexcept
-{
- open_control_socket(&eventLoop);
- setup_external_log();
-}
-
/* handle SIGINT signal (generated by kernel when ctrl+alt+del pressed) */
static void sigint_reboot_cb(EventLoop_t *eloop) noexcept
{
// This allows remounting the filesystem read-only if the dinit binary has been
// unlinked. In that case the kernel holds the binary open, so that it can't be
// properly removed.
- close_control_socket(eloop);
+ close_control_socket();
execl("/sbin/shutdown", "/sbin/shutdown", (char *) 0);
log(LogLevel::ERROR, "Error executing /sbin/shutdown: ", strerror(errno));
}
*/
// from dinit.cc:
-void system_rw_ready() noexcept;
+void open_control_socket() noexcept;
+void setup_external_log() noexcept;
extern EventLoop_t eventLoop;
// Find the requested service by name
{
if (service_type != ServiceType::SCRIPTED && service_type != ServiceType::BGPROCESS && onstart_flags.runs_on_console) {
tcsetpgrp(0, getpgrp());
+ discard_console_log_buffer();
releaseConsole();
}
notifyListeners(ServiceEvent::STARTED);
if (onstart_flags.rw_ready) {
- system_rw_ready();
+ open_control_socket();
+ }
+ if (onstart_flags.log_ready) {
+ setup_external_log();
}
if (force_stop || desired_state == ServiceState::STOPPED) {