summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar lat9nq2022-11-23 21:57:28 -0500
committerGravatar lat9nq2022-11-23 21:59:24 -0500
commit35319ca3a5d6f6dd2b7619ca38d6f2b4696ff3dd (patch)
tree2b49ec37a8d176004d95d764414771b628da295c
parentstartup_checks: Use Windows flow for *nix (diff)
downloadyuzu-35319ca3a5d6f6dd2b7619ca38d6f2b4696ff3dd.tar.gz
yuzu-35319ca3a5d6f6dd2b7619ca38d6f2b4696ff3dd.tar.xz
yuzu-35319ca3a5d6f6dd2b7619ca38d6f2b4696ff3dd.zip
startup_checks: Use fmt::print, fix exec error handling
Uses fmt::print opposed to std::fprintf for error printing. Call exit instead of returning to caller to prevent a like issue the previous commit was trying to solve. Removes unneeded comment. Co-authored-by: liamwhite <liamwhite@users.noreply.github.com> Co-authored-by: Lioncash <mathew1800@gmail.com>
Diffstat (limited to '')
-rw-r--r--src/yuzu/startup_checks.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/yuzu/startup_checks.cpp b/src/yuzu/startup_checks.cpp
index 95c9fdecb..ccdcf10fa 100644
--- a/src/yuzu/startup_checks.cpp
+++ b/src/yuzu/startup_checks.cpp
@@ -4,11 +4,11 @@
4#include "video_core/vulkan_common/vulkan_wrapper.h" 4#include "video_core/vulkan_common/vulkan_wrapper.h"
5 5
6#ifdef _WIN32 6#ifdef _WIN32
7#include <cstring> // for memset, strncpy, strncmp 7#include <cstring>
8#include <processthreadsapi.h> 8#include <processthreadsapi.h>
9#include <windows.h> 9#include <windows.h>
10#elif defined(YUZU_UNIX) 10#elif defined(YUZU_UNIX)
11#include <cstring> // for strncmp 11#include <cstring>
12#include <errno.h> 12#include <errno.h>
13#include <spawn.h> 13#include <spawn.h>
14#include <sys/types.h> 14#include <sys/types.h>
@@ -16,7 +16,7 @@
16#include <unistd.h> 16#include <unistd.h>
17#endif 17#endif
18 18
19#include <cstdio> 19#include <fmt/core.h>
20#include "video_core/vulkan_common/vulkan_instance.h" 20#include "video_core/vulkan_common/vulkan_instance.h"
21#include "video_core/vulkan_common/vulkan_library.h" 21#include "video_core/vulkan_common/vulkan_library.h"
22#include "yuzu/startup_checks.h" 22#include "yuzu/startup_checks.h"
@@ -30,7 +30,7 @@ void CheckVulkan() {
30 Vulkan::CreateInstance(library, dld, VK_API_VERSION_1_0); 30 Vulkan::CreateInstance(library, dld, VK_API_VERSION_1_0);
31 31
32 } catch (const Vulkan::vk::Exception& exception) { 32 } catch (const Vulkan::vk::Exception& exception) {
33 std::fprintf(stderr, "Failed to initialize Vulkan: %s\n", exception.what()); 33 fmt::print(stderr, "Failed to initialize Vulkan: {}\n", exception.what());
34 } 34 }
35} 35}
36 36
@@ -52,8 +52,8 @@ bool CheckEnvVars(bool* is_child) {
52 *is_child = true; 52 *is_child = true;
53 return false; 53 return false;
54 } else if (!SetEnvironmentVariableA(IS_CHILD_ENV_VAR, ENV_VAR_ENABLED_TEXT)) { 54 } else if (!SetEnvironmentVariableA(IS_CHILD_ENV_VAR, ENV_VAR_ENABLED_TEXT)) {
55 std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %lu\n", 55 fmt::print(stderr, "SetEnvironmentVariableA failed to set {} with error {}\n",
56 IS_CHILD_ENV_VAR, GetLastError()); 56 IS_CHILD_ENV_VAR, GetLastError());
57 return true; 57 return true;
58 } 58 }
59#elif defined(YUZU_UNIX) 59#elif defined(YUZU_UNIX)
@@ -72,8 +72,8 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan, bool perform_vulka
72 // Set the startup variable for child processes 72 // Set the startup variable for child processes
73 const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, ENV_VAR_ENABLED_TEXT); 73 const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, ENV_VAR_ENABLED_TEXT);
74 if (!env_var_set) { 74 if (!env_var_set) {
75 std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %lu\n", 75 fmt::print(stderr, "SetEnvironmentVariableA failed to set {} with error {}\n",
76 STARTUP_CHECK_ENV_VAR, GetLastError()); 76 STARTUP_CHECK_ENV_VAR, GetLastError());
77 return false; 77 return false;
78 } 78 }
79 79
@@ -91,30 +91,30 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan, bool perform_vulka
91 DWORD exit_code = STILL_ACTIVE; 91 DWORD exit_code = STILL_ACTIVE;
92 const int err = GetExitCodeProcess(process_info.hProcess, &exit_code); 92 const int err = GetExitCodeProcess(process_info.hProcess, &exit_code);
93 if (err == 0) { 93 if (err == 0) {
94 std::fprintf(stderr, "GetExitCodeProcess failed with error %lu\n", GetLastError()); 94 fmt::print(stderr, "GetExitCodeProcess failed with error {}\n", GetLastError());
95 } 95 }
96 96
97 // Vulkan is broken if the child crashed (return value is not zero) 97 // Vulkan is broken if the child crashed (return value is not zero)
98 *has_broken_vulkan = (exit_code != 0); 98 *has_broken_vulkan = (exit_code != 0);
99 99
100 if (CloseHandle(process_info.hProcess) == 0) { 100 if (CloseHandle(process_info.hProcess) == 0) {
101 std::fprintf(stderr, "CloseHandle failed with error %lu\n", GetLastError()); 101 fmt::print(stderr, "CloseHandle failed with error {}\n", GetLastError());
102 } 102 }
103 if (CloseHandle(process_info.hThread) == 0) { 103 if (CloseHandle(process_info.hThread) == 0) {
104 std::fprintf(stderr, "CloseHandle failed with error %lu\n", GetLastError()); 104 fmt::print(stderr, "CloseHandle failed with error {}\n", GetLastError());
105 } 105 }
106 } 106 }
107 107
108 if (!SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, nullptr)) { 108 if (!SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, nullptr)) {
109 std::fprintf(stderr, "SetEnvironmentVariableA failed to clear %s with error %lu\n", 109 fmt::print(stderr, "SetEnvironmentVariableA failed to clear {} with error {}\n",
110 STARTUP_CHECK_ENV_VAR, GetLastError()); 110 STARTUP_CHECK_ENV_VAR, GetLastError());
111 } 111 }
112 112
113#elif defined(YUZU_UNIX) 113#elif defined(YUZU_UNIX)
114 const int env_var_set = setenv(STARTUP_CHECK_ENV_VAR, ENV_VAR_ENABLED_TEXT, 1); 114 const int env_var_set = setenv(STARTUP_CHECK_ENV_VAR, ENV_VAR_ENABLED_TEXT, 1);
115 if (env_var_set == -1) { 115 if (env_var_set == -1) {
116 const int err = errno; 116 const int err = errno;
117 std::fprintf(stderr, "setenv failed to set %s with error %d\n", STARTUP_CHECK_ENV_VAR, err); 117 fmt::print(stderr, "setenv failed to set {} with error {}\n", STARTUP_CHECK_ENV_VAR, err);
118 return false; 118 return false;
119 } 119 }
120 120
@@ -129,7 +129,7 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan, bool perform_vulka
129 const int r_val = waitpid(pid, &status, 0); 129 const int r_val = waitpid(pid, &status, 0);
130 if (r_val == -1) { 130 if (r_val == -1) {
131 const int err = errno; 131 const int err = errno;
132 std::fprintf(stderr, "wait failed with error %d\n", err); 132 fmt::print(stderr, "wait failed with error {}\n", err);
133 return false; 133 return false;
134 } 134 }
135 // Vulkan is broken if the child crashed (return value is not zero) 135 // Vulkan is broken if the child crashed (return value is not zero)
@@ -139,8 +139,8 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan, bool perform_vulka
139 const int env_var_cleared = unsetenv(STARTUP_CHECK_ENV_VAR); 139 const int env_var_cleared = unsetenv(STARTUP_CHECK_ENV_VAR);
140 if (env_var_cleared == -1) { 140 if (env_var_cleared == -1) {
141 const int err = errno; 141 const int err = errno;
142 std::fprintf(stderr, "unsetenv failed to clear %s with error %d\n", STARTUP_CHECK_ENV_VAR, 142 fmt::print(stderr, "unsetenv failed to clear {} with error {}\n", STARTUP_CHECK_ENV_VAR,
143 err); 143 err);
144 } 144 }
145#endif 145#endif
146 return false; 146 return false;
@@ -169,7 +169,7 @@ bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi, int flags) {
169 pi // lpProcessInformation 169 pi // lpProcessInformation
170 ); 170 );
171 if (!process_created) { 171 if (!process_created) {
172 std::fprintf(stderr, "CreateProcessA failed with error %lu\n", GetLastError()); 172 fmt::print(stderr, "CreateProcessA failed with error {}\n", GetLastError());
173 return false; 173 return false;
174 } 174 }
175 175
@@ -182,14 +182,14 @@ pid_t SpawnChild(const char* arg0) {
182 if (pid == -1) { 182 if (pid == -1) {
183 // error 183 // error
184 const int err = errno; 184 const int err = errno;
185 std::fprintf(stderr, "fork failed with error %d\n", err); 185 fmt::print(stderr, "fork failed with error {}\n", err);
186 return pid; 186 return pid;
187 } else if (pid == 0) { 187 } else if (pid == 0) {
188 // child 188 // child
189 execl(arg0, arg0, nullptr); 189 execl(arg0, arg0, nullptr);
190 const int err = errno; 190 const int err = errno;
191 std::fprintf(stderr, "execl failed with error %d\n", err); 191 fmt::print(stderr, "execl failed with error {}\n", err);
192 return -1; 192 _exit(0);
193 } 193 }
194 194
195 return pid; 195 return pid;