From 966c207a333f3f4528e3cf271be2835b3e7d506f Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 25 Apr 2018 13:16:27 +0100 Subject: [PATCH] Teach gamemoded the '-r' option This allows for easy requesting of gamemode and pausing for any signal Primarily useful for simple tests, but also functionally to allow enterning and exiting gamemode manually --- daemon/main.c | 17 ++++++++++++++++- daemon/meson.build | 2 ++ data/gamemoded.1 | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/daemon/main.c b/daemon/main.c index c725f1d..2116486 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "daemonize.h" #include "dbus_messaging.h" #include "gamemode.h" +#include "gamemode_client.h" #include "logging.h" #include @@ -65,6 +66,7 @@ POSSIBILITY OF SUCH DAMAGE. "Usage: %s [-d] [-l] [-h] [-v]\n\n" \ " -d daemonize self after launch\n" \ " -l log to syslog\n" \ + " -r request gamemode and pause\n" \ " -h print this help\n" \ " -v print version\n" \ "\n" \ @@ -94,7 +96,7 @@ int main(int argc, char *argv[]) bool daemon = false; bool use_syslog = false; int opt = 0; - while ((opt = getopt(argc, argv, "dlvh")) != -1) { + while ((opt = getopt(argc, argv, "dlrvh")) != -1) { switch (opt) { case 'd': daemon = true; @@ -102,6 +104,19 @@ int main(int argc, char *argv[]) case 'l': use_syslog = true; break; + case 'r': + if (gamemode_request_start() < 0) { + fprintf(stderr, "gamemode request failed: %s\n", gamemode_error_string()); + exit(EXIT_FAILURE); + } + + fprintf(stdout, "gamemode request succeeded...\n"); + + // Simply pause and wait for any signal + pause(); + + exit(EXIT_SUCCESS); + break; case 'v': fprintf(stdout, VERSION_TEXT); exit(EXIT_SUCCESS); diff --git a/daemon/meson.build b/daemon/meson.build index 7b6790e..b845417 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -32,9 +32,11 @@ executable( dep_threads, dep_systemd, inih_dependency, + libdl, ], include_directories: [ config_h_dir, + libgamemode_includes, ], install: true, ) diff --git a/data/gamemoded.1 b/data/gamemoded.1 index 0e896ef..fa78ac9 100644 --- a/data/gamemoded.1 +++ b/data/gamemoded.1 @@ -19,6 +19,9 @@ Run the daemon as a separate process (daemonize it) .B \-l Log to syslog .TP 8 +.B \-r +Request gamemode and wait for any signal +.TP 8 .B \-h Print help text .TP 8