Browse Source

Integrated sd_notify to get status messages in systemd (#28)

* Integrated sd_notify to get status messages in systemd
* reset color attributes after use in string
OlliC 7 years ago
parent
commit
6b71edf740
4 changed files with 11 additions and 0 deletions
  1. 2 0
      daemon/dbus_messaging.c
  2. 5 0
      daemon/gamemode.c
  3. 3 0
      daemon/main.c
  4. 1 0
      data/gamemoded.service.in

+ 2 - 0
daemon/dbus_messaging.c

@@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <stdlib.h>
 
 #include <systemd/sd-bus.h>
+#include <systemd/sd-daemon.h>
 
 /* systemd dbus components */
 static sd_bus *bus = NULL;
@@ -144,6 +145,7 @@ void game_mode_context_loop(GameModeContext *context)
 	}
 
 	LOG_MSG("Successfully initialised bus with name [%s]...\n", "com.feralinteractive.GameMode");
+	sd_notifyf(0,"STATUS=%sGameMode is ready to be activated.%s\n", "\x1B[1;36m", "\x1B[0m");
 
 	/* Now loop, waiting for callbacks */
 	for (;;) {

+ 5 - 0
daemon/gamemode.c

@@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "governors.h"
 #include "logging.h"
 
+#include <systemd/sd-daemon.h>
 #include <linux/limits.h>
 #include <pthread.h>
 #include <signal.h>
@@ -161,6 +162,8 @@ void game_mode_context_destroy(GameModeContext *self)
 static void game_mode_context_enter(GameModeContext *self)
 {
 	LOG_MSG("Entering Game Mode...\n");
+	sd_notifyf(0,"STATUS=%sGameMode is now active.%s\n", "\x1B[1;32m", "\x1B[0m");
+
 	if (!self->performance_mode && set_governors("performance")) {
 		self->performance_mode = true;
 	}
@@ -175,6 +178,8 @@ static void game_mode_context_enter(GameModeContext *self)
 static void game_mode_context_leave(GameModeContext *self)
 {
 	LOG_MSG("Leaving Game Mode...\n");
+	sd_notifyf(0,"STATUS=%sGameMode is currently deactivated.%s\n", "\x1B[1;36m", "\x1B[0m");
+	
 	if (self->performance_mode && set_governors(NULL)) {
 		self->performance_mode = false;
 	}

+ 3 - 0
daemon/main.c

@@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "gamemode.h"
 #include "logging.h"
 
+#include <systemd/sd-daemon.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
@@ -74,6 +75,7 @@ POSSIBILITY OF SUCH DAMAGE.
 static void sigint_handler(__attribute__((unused)) int signo)
 {
 	LOG_MSG("Quitting by request...\n");
+	sd_notify(0,"STATUS=GameMode is quitting by request...\n");
 
 	/* Clean up nicely */
 	game_mode_context_destroy(game_mode_context_instance());
@@ -144,4 +146,5 @@ int main(int argc, char *argv[])
 
 	/* Log we're finished */
 	LOG_MSG("Quitting naturally...\n");
+	sd_notify(0,"STATUS=GameMode is quitting naturally...\n");
 }

+ 1 - 0
data/gamemoded.service.in

@@ -4,6 +4,7 @@ Description=gamemoded
 [Service]
 Type=dbus
 BusName=com.feralinteractive.GameMode
+NotifyAccess=main
 ExecStart=@BINDIR@/gamemoded -l
 
 [Install]