diff --git a/common/common-governors.c b/common/common-governors.c index 56a03ba..83bb627 100644 --- a/common/common-governors.c +++ b/common/common-governors.c @@ -122,22 +122,29 @@ const char *get_gov_state(void) long length = ftell(f); fseek(f, 0, SEEK_SET); - char contents[length]; + if (length == -1) + { + LOG_ERROR("Failed to seek file %s\n", gov); + } + else + { + char contents[length]; - if (fread(contents, 1, (size_t)length, f) > 0) { - /* Files have a newline */ - strtok(contents, "\n"); - if (strlen(governor) > 0 && strncmp(governor, contents, 64) != 0) { - /* Don't handle the mixed case, this shouldn't ever happen - * But it is a clear sign we shouldn't carry on */ - LOG_ERROR("Governors malformed: got \"%s\", expected \"%s\"", contents, governor); - fclose(f); - return "malformed"; + if (fread(contents, 1, (size_t)length, f) > 0) { + /* Files have a newline */ + strtok(contents, "\n"); + if (strlen(governor) > 0 && strncmp(governor, contents, 64) != 0) { + /* Don't handle the mixed case, this shouldn't ever happen + * But it is a clear sign we shouldn't carry on */ + LOG_ERROR("Governors malformed: got \"%s\", expected \"%s\"", contents, governor); + fclose(f); + return "malformed"; + } + + strncpy(governor, contents, sizeof(governor) - 1); + } else { + LOG_ERROR("Failed to read contents of %s\n", gov); } - - strncpy(governor, contents, sizeof(governor) - 1); - } else { - LOG_ERROR("Failed to read contents of %s\n", gov); } fclose(f); diff --git a/daemon/gamemode-wine.c b/daemon/gamemode-wine.c index 11a6920..056b50a 100644 --- a/daemon/gamemode-wine.c +++ b/daemon/gamemode-wine.c @@ -224,7 +224,8 @@ char *game_mode_resolve_wine_preloader(const char *exe, const pid_t pid) goto fail; error_cleanup: - game_mode_close_proc(proc_fd); + if (proc_fd != INVALID_PROCFD) + game_mode_close_proc(proc_fd); free(wineprefix); return wine_exe; diff --git a/daemon/gamemoded.c b/daemon/gamemoded.c index 58ebd5b..fd2be1a 100644 --- a/daemon/gamemoded.c +++ b/daemon/gamemoded.c @@ -132,11 +132,19 @@ static void daemonize(const char *name) /* replace standard file descriptors by /dev/null */ int devnull_r = open("/dev/null", O_RDONLY); int devnull_w = open("/dev/null", O_WRONLY); - dup2(devnull_r, STDIN_FILENO); - dup2(devnull_w, STDOUT_FILENO); - dup2(devnull_w, STDERR_FILENO); - close(devnull_r); - close(devnull_w); + + if (devnull_r == -1 || devnull_w == -1) + { + LOG_ERROR("Failed to redirect standard input and output to /dev/null\n"); + } + else + { + dup2(devnull_r, STDIN_FILENO); + dup2(devnull_w, STDOUT_FILENO); + dup2(devnull_w, STDERR_FILENO); + close(devnull_r); + close(devnull_w); + } } /**