Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,46 @@ static void init_core_client(int argc, char** argv) {
setbuf(stdout, 0);
setbuf(stderr, 0);

// Manually extract --dir argument and change directory before config read
bool dir_specified = false;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-dir") || !strcmp(argv[i], "--dir")) {
if (i + 1 < argc) {
char* dir_path = argv[i+1];
// Remove the two arguments
for (int j = i; j < argc - 2; j++) {
argv[j] = argv[j+2];
}
argc -= 2;
if (boinc_chdir(dir_path)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Behavior regression in --dir error handling. The previous -dir branch in parse_cmdline did if (chdir(argv[++i])) { perror("chdir"); exit(1); }, so a bad directory terminated the client. The new code only logs an error and continues, and it sets dir_specified = true even when the chdir failed. As a result, on Windows the chdir_to_data_dir() fallback is also skipped (because dir_specified is true), and the client runs on with an unexpected working directory instead of failing fast as before.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At client/main.cpp, line 194:

<comment>Behavior regression in `--dir` error handling. The previous `-dir` branch in `parse_cmdline` did `if (chdir(argv[++i])) { perror("chdir"); exit(1); }`, so a bad directory terminated the client. The new code only logs an error and continues, and it sets `dir_specified = true` even when the chdir failed. As a result, on Windows the `chdir_to_data_dir()` fallback is also skipped (because `dir_specified` is true), and the client runs on with an unexpected working directory instead of failing fast as before.</comment>

<file context>
@@ -180,17 +180,46 @@ static void init_core_client(int argc, char** argv) {
+                    argv[j] = argv[j+2];
+                }
+                argc -= 2;
+                if (boinc_chdir(dir_path)) {
+                    log_message_error("Failed to chdir to specified directory");
+                }
</file context>

log_message_error("Failed to chdir to specified directory");
}
dir_specified = true;
break;
}
}
}

cc_config.defaults();
nvc_config.defaults();

// Parse command line without --dir command
gstate.parse_cmdline(argc, argv);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
gstate.now = dtime();

#ifdef _WIN32
if (!cc_config.allow_multiple_clients && !gstate.cmdline_dir) {
// On Windows, switch to default data directory if no --dir and not allowing multiple clients
if (!dir_specified && !cc_config.allow_multiple_clients && !gstate.cmdline_dir) {
chdir_to_data_dir();
}
#endif

// Read config file from current working directory
read_config_file(true);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.

// Parse command line again to override config file settings
gstate.parse_cmdline(argc, argv);

#ifndef _WIN32
if (g_use_sandbox) {
// Set file creation mask to be writable by both user and group and
Expand Down Expand Up @@ -237,8 +266,6 @@ static void init_core_client(int argc, char** argv) {
//_CrtSetBreakAlloc(654);
#endif

read_config_file(true);

// NOTE: this must be called BEFORE newer_version_startup_check()
// Only branded builds of BOINC should have an nvc_config.xml file
// in the BOINC Data directory. See comments in current_version.cpp.
Expand Down Expand Up @@ -273,6 +300,7 @@ static void do_gpu_detection(int argc, char** argv) {
vector<string> warnings;

boinc_install_signal_handlers();
read_config_file(true);
gstate.parse_cmdline(argc, argv);
gstate.now = dtime();

Expand All @@ -285,8 +313,6 @@ static void do_gpu_detection(int argc, char** argv) {

diagnostics_init(flags, "stdoutgpudetect", "stderrgpudetect");

read_config_file(true);

coprocs.detect_gpus(warnings);
coprocs.write_coproc_info_file(warnings);
warnings.clear();
Expand Down Expand Up @@ -354,7 +380,6 @@ static int initialize() {
}
}


// Initialize WinSock
#if defined(_WIN32) && defined(USE_WINSOCK)
if (WinsockInitialize() != 0) {
Expand Down
Loading