From 84720c1f4c7b58ab274e3416d48fff23add8124a Mon Sep 17 00:00:00 2001 From: Nocturn9x Date: Mon, 31 Jan 2022 14:56:12 +0100 Subject: [PATCH] Added config reloading functionality and related subprogram --- src/core/mainloop.nim | 8 ++++++-- src/main.nim | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/core/mainloop.nim b/src/core/mainloop.nim index 381961b..d89b963 100644 --- a/src/core/mainloop.nim +++ b/src/core/mainloop.nim @@ -34,7 +34,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) = var opType: string try: logger.trace("Calling initControlSocket()") - var serverSocket = initControlSocket(logger) + var serverSocket = initControlSocket(logger, config.sock) serverSocket.listen(5) var clientSocket = newSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP) logger.switchToFile() @@ -62,7 +62,11 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) = logger.info("Received halt request") halt(logger) of "s": - discard # TODO + logger.info("Received service request") + # TODO: Operate on services + of "l": + logger.info("Received reload request") + mainLoop(logger, parseConfig(logger, "/etc/nimd/nimd.conf"), startServices=false) else: logger.warning(&"Received unknown operation type '{opType}' via control socket, ignoring it") discard diff --git a/src/main.nim b/src/main.nim index cdca173..8265bb8 100644 --- a/src/main.nim +++ b/src/main.nim @@ -25,21 +25,22 @@ proc addStuff = ## Adds stuff to test NimD. This is ## a temporary procedure + ## Note: Commented because the config file now does this work! # Adds symlinks - addSymlink(newSymlink(dest="/dev/fd", source="/proc/self/fd")) - addSymlink(newSymlink(dest="/dev/fd/0", source="/proc/self/fd/0")) - addSymlink(newSymlink(dest="/dev/fd/1", source="/proc/self/fd/1")) - addSymlink(newSymlink(dest="/dev/fd/2", source="/proc/self/fd/2")) - addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) - addSymlink(newSymlink(dest="/dev/std/out", source="/proc/self/fd/1")) - addSymlink(newSymlink(dest="/dev/std/err", source="/proc/self/fd/2")) - # Tests here. Check logging output (debug) to see if - # they work as intended - addSymlink(newSymlink(dest="/dev/std/err", source="/")) # Should say link already exists and points to /proc/self/fd/2 - addSymlink(newSymlink(dest="/dev/std/in", source="/does/not/exist")) # Should say destination does not exist - addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) # Should say link already exists - addDirectory(newDirectory("test", 764)) # Should create a directory - addDirectory(newDirectory("/dev/disk", 123)) # Should say directory already exists + # addSymlink(newSymlink(dest="/dev/fd", source="/proc/self/fd")) + # addSymlink(newSymlink(dest="/dev/fd/0", source="/proc/self/fd/0")) + # addSymlink(newSymlink(dest="/dev/fd/1", source="/proc/self/fd/1")) + # addSymlink(newSymlink(dest="/dev/fd/2", source="/proc/self/fd/2")) + # addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) + # addSymlink(newSymlink(dest="/dev/std/out", source="/proc/self/fd/1")) + # addSymlink(newSymlink(dest="/dev/std/err", source="/proc/self/fd/2")) + # # Tests here. Check logging output (debug) to see if + # # they work as intended + # addSymlink(newSymlink(dest="/dev/std/err", source="/")) # Should say link already exists and points to /proc/self/fd/2 + # addSymlink(newSymlink(dest="/dev/std/in", source="/does/not/exist")) # Should say destination does not exist + # addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) # Should say link already exists + # addDirectory(newDirectory("test", 764)) # Should create a directory + # addDirectory(newDirectory("/dev/disk", 123)) # Should say directory already exists # Adds test services var echoer = newService(name="echoer", description="prints owo", exec="/bin/echo owoooooooooo",