Skip to content

fix: respect $WATCHMAN_SOCK env variable for spawned service #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
16 changes: 14 additions & 2 deletions watchman/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static SpawnResult spawn_via_launchd() {
"--foreground",
fmt::format("--logfile={}", logging::log_name),
fmt::format("--log-level={}", logging::log_level),
fmt::format("--sockname={}", get_unix_sock_name()),
fmt::format("--unix-listener-path={}", get_unix_sock_name()),
fmt::format("--statefile={}", flags.watchman_state_file),
fmt::format("--pidfile={}", flags.pid_file)};
std::string watchman_spawning_command;
Expand Down Expand Up @@ -837,7 +837,19 @@ static void setup_sock_name() {
flags.named_pipe_path = fmt::format("\\\\.\\pipe\\watchman-{}", user);
}
#endif
compute_file_name(flags.unix_sock_name, user, "sock", "sockname");
auto sock = getenv("WATCHMAN_SOCK");
if (sock && flags.unix_sock_name.empty()) {
if (mkdir(dirname(sock), 0700) == 0 || errno == EEXIST) {
flags.unix_sock_name = sock;
} else {
log(FATAL,
"failed to create base directory specified by $WATCHMAN_SOCK: ",
folly::errnoStr(errno),
"\n");
}
} else {
compute_file_name(flags.unix_sock_name, user, "sock", "sockname");
}

compute_file_name(flags.watchman_state_file, user, "state", "statefile");
compute_file_name(
Expand Down