mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-08-05 20:58:29 +02:00
Add gamemode_query_status and teach gamemoded '-s'
This allows the client to query the daemon about the status of gamemode. Returns the following: 0 if gamemode is inactive 1 if gamemode is active 2 if gamemode is active and this client is registered -1 if the query failed Passing -s to gamemoded will simply query and print the current status. Allows for more comprehensive testing when using 'gamemoded -r' as well as more reactionary program behaviour
This commit is contained in:
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
|
||||
bool daemon = false;
|
||||
bool use_syslog = false;
|
||||
int opt = 0;
|
||||
while ((opt = getopt(argc, argv, "dlrvh")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "dlsrvh")) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
daemon = true;
|
||||
@@ -104,13 +104,38 @@ int main(int argc, char *argv[])
|
||||
case 'l':
|
||||
use_syslog = true;
|
||||
break;
|
||||
case 's': {
|
||||
int status;
|
||||
|
||||
if ((status = gamemode_query_status()) < 0) {
|
||||
fprintf(stderr, "gamemode status request failed: %s\n", gamemode_error_string());
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (status > 0) {
|
||||
fprintf(stdout, "gamemode is active\n");
|
||||
} else {
|
||||
fprintf(stdout, "gamemode is inactive\n");
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
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");
|
||||
int status = gamemode_query_status();
|
||||
if (status == 2) {
|
||||
fprintf(stdout, "gamemode request succeeded and is active\n");
|
||||
} else if (status == 1) {
|
||||
fprintf(stderr,
|
||||
"gamemode request succeeded and is active but registration failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
fprintf(stderr, "gamemode request succeeded but is not active\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Simply pause and wait for any signal
|
||||
pause();
|
||||
|
Reference in New Issue
Block a user