Skip to content

Commit

Permalink
Run the formatter over some files.
Browse files Browse the repository at this point in the history
This should be a no-op.

PiperOrigin-RevId: 713981634
Change-Id: I3df4926f00c92104a9aa5d66950374ad9eb4d4d0
  • Loading branch information
bigelephant29 authored and copybara-github committed Jan 10, 2025
1 parent b4f02e5 commit b8f048c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 58 deletions.
5 changes: 2 additions & 3 deletions src/main/cpp/blaze_util_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class StartupOptions;

class SignalHandler {
public:
typedef void (* Callback)();
typedef void (*Callback)();

static SignalHandler& Get() { return INSTANCE; }
const ServerProcessInfo* GetServerProcessInfo() const {
Expand All @@ -106,7 +106,7 @@ class SignalHandler {
};

// A signal-safe version of fprintf(stderr, ...).
void SigPrintf(const char *format, ...);
void SigPrintf(const char* format, ...);

std::string GetProcessIdAsString();

Expand Down Expand Up @@ -177,7 +177,6 @@ class BlazeServerStartup {
virtual bool IsStillAlive() = 0;
};


// Starts a daemon process with its standard output and standard error
// redirected (and conditionally appended) to the file "daemon_output". Sets
// server_startup to an object that can be used to query if the server is
Expand Down
42 changes: 16 additions & 26 deletions src/main/cpp/blaze_util_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ ATTRIBUTE_NORETURN void SignalHandler::PropagateSignalOrExit(int exit_code) {
}
}

string GetProcessIdAsString() {
return blaze_util::ToString(getpid());
}
string GetProcessIdAsString() { return blaze_util::ToString(getpid()); }

string GetHomeDir() { return GetPathEnv("HOME"); }

Expand Down Expand Up @@ -305,9 +303,7 @@ class CharPP {
}

// Obtains the raw pointer to the array of strings.
char** get() {
return charpp_;
}
char** get() { return charpp_; }

// Prevent copies as we manually manage memory.
CharPP(const CharPP&) = delete;
Expand Down Expand Up @@ -368,13 +364,9 @@ class SocketBlazeServerStartup : public BlazeServerStartup {
int fd;
};

SocketBlazeServerStartup::SocketBlazeServerStartup(int fd)
: fd(fd) {
}
SocketBlazeServerStartup::SocketBlazeServerStartup(int fd) : fd(fd) {}

SocketBlazeServerStartup::~SocketBlazeServerStartup() {
close(fd);
}
SocketBlazeServerStartup::~SocketBlazeServerStartup() { close(fd); }

bool SocketBlazeServerStartup::IsStillAlive() {
struct pollfd pfd;
Expand All @@ -399,7 +391,7 @@ bool SocketBlazeServerStartup::IsStillAlive() {
// Returns zero on success or -1 on error, in which case errno is set to the
// corresponding error details.
int ConfigureDaemonProcess(posix_spawnattr_t* attrp,
const StartupOptions &options);
const StartupOptions& options);

void WriteSystemSpecificProcessIdentifier(const blaze_util::Path& server_dir,
pid_t server_pid);
Expand Down Expand Up @@ -440,11 +432,13 @@ int ExecuteDaemon(
posix_spawn_file_actions_t file_actions;
if (posix_spawn_file_actions_init(&file_actions) != 0) {
BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
<< "Failed to create posix_spawn_file_actions: " << GetLastErrorString();
<< "Failed to create posix_spawn_file_actions: "
<< GetLastErrorString();
}
if (posix_spawn_file_actions_addclose(&file_actions, fds[0]) != 0) {
BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
<< "Failed to modify posix_spawn_file_actions: "<< GetLastErrorString();
<< "Failed to modify posix_spawn_file_actions: "
<< GetLastErrorString();
}

posix_spawnattr_t attrp;
Expand All @@ -461,8 +455,8 @@ int ExecuteDaemon(
if (posix_spawn(&transient_pid, daemonize.c_str(), &file_actions, &attrp,
CharPP(daemonize_args).get(), CharPP(env).get()) != 0) {
BAZEL_DIE(blaze_exit_code::INTERNAL_ERROR)
<< "Failed to execute JVM via " << daemonize
<< ": " << GetLastErrorString();
<< "Failed to execute JVM via " << daemonize << ": "
<< GetLastErrorString();
}
close(fds[1]);

Expand Down Expand Up @@ -568,9 +562,7 @@ void SetEnv(const string& name, const string& value) {
setenv(name.c_str(), value.c_str(), 1);
}

void UnsetEnv(const string& name) {
unsetenv(name.c_str());
}
void UnsetEnv(const string& name) { unsetenv(name.c_str()); }

bool WarnIfStartedFromDesktop() { return false; }

Expand Down Expand Up @@ -601,7 +593,7 @@ void SetupStdStreams() {
// Blaze server.
// Also, it's a good idea to start each message with a newline,
// in case the Blaze server has written a partial line.
void SigPrintf(const char *format, ...) {
void SigPrintf(const char* format, ...) {
char buf[1024];
va_list ap;
va_start(ap, format);
Expand Down Expand Up @@ -785,7 +777,7 @@ string GetUserName() {
return user;
}
errno = 0;
passwd *pwent = getpwuid(getuid()); // NOLINT (single-threaded)
passwd* pwent = getpwuid(getuid()); // NOLINT (single-threaded)
if (pwent == nullptr || pwent->pw_name == nullptr) {
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
<< "$USER is not set, and unable to look up name of current user: "
Expand Down Expand Up @@ -869,7 +861,7 @@ static bool UnlimitResource(const int resource, const bool allow_infinity) {
rl.rlim_cur = rl.rlim_max;
} else {
if ((rl.rlim_max == RLIM_INFINITY && !allow_infinity) ||
rl.rlim_max > explicit_limit) {
rl.rlim_max > explicit_limit) {
rl.rlim_cur = explicit_limit;
} else {
rl.rlim_cur = rl.rlim_max;
Expand All @@ -893,9 +885,7 @@ bool UnlimitResources() {
return success;
}

bool UnlimitCoredumps() {
return UnlimitResource(RLIMIT_CORE, true);
}
bool UnlimitCoredumps() { return UnlimitResource(RLIMIT_CORE, true); }

void EnsurePythonPathOption(vector<string>* options) {
// do nothing.
Expand Down
39 changes: 20 additions & 19 deletions src/main/cpp/startup_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ bool StartupOptions::MaybeCheckValidNullary(const string &arg, bool *result,

void StartupOptions::AddExtraOptions(vector<string> *result) const {}

blaze_exit_code::ExitCode StartupOptions::ProcessArg(
const string &argstr, const string &next_argstr, const string &rcfile,
bool *is_space_separated, string *error) {
blaze_exit_code::ExitCode StartupOptions::ProcessArg(const string &argstr,
const string &next_argstr,
const string &rcfile,
bool *is_space_separated,
string *error) {
// We have to parse a specific option syntax, so GNU getopts won't do. All
// options begin with "--" or "-". Values are given together with the option
// delimited by '=' or in the next option.
const char* arg = argstr.c_str();
const char *arg = argstr.c_str();
const char *next_arg = next_argstr.empty() ? nullptr : next_argstr.c_str();
const char *value = nullptr;

Expand Down Expand Up @@ -276,20 +278,19 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
option_sources["host_jvm_args"] = rcfile; // NB: This is incorrect
} else if ((value = GetUnaryOption(arg, next_arg, "--io_nice_level")) !=
nullptr) {
if (!blaze_util::safe_strto32(value, &io_nice_level) ||
io_nice_level > 7) {
blaze_util::StringPrintf(error,
if (!blaze_util::safe_strto32(value, &io_nice_level) || io_nice_level > 7) {
blaze_util::StringPrintf(
error,
"Invalid argument to --io_nice_level: '%s'. Must not exceed 7.",
value);
return blaze_exit_code::BAD_ARGV;
}
option_sources["io_nice_level"] = rcfile;
} else if ((value = GetUnaryOption(arg, next_arg, "--max_idle_secs")) !=
nullptr) {
if (!blaze_util::safe_strto32(value, &max_idle_secs) ||
max_idle_secs < 0) {
blaze_util::StringPrintf(error,
"Invalid argument to --max_idle_secs: '%s'.", value);
if (!blaze_util::safe_strto32(value, &max_idle_secs) || max_idle_secs < 0) {
blaze_util::StringPrintf(
error, "Invalid argument to --max_idle_secs: '%s'.", value);
return blaze_exit_code::BAD_ARGV;
}
option_sources["max_idle_secs"] = rcfile;
Expand Down Expand Up @@ -348,12 +349,12 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
option_sources["unix_digest_hash_attribute_name"] = rcfile;
} else if ((value = GetUnaryOption(arg, next_arg, "--command_port")) !=
nullptr) {
if (!blaze_util::safe_strto32(value, &command_port) ||
command_port < 0 || command_port > 65535) {
if (!blaze_util::safe_strto32(value, &command_port) || command_port < 0 ||
command_port > 65535) {
blaze_util::StringPrintf(error,
"Invalid argument to --command_port: '%s'.\n"
"Must be a valid port number or 0.\n",
value);
"Invalid argument to --command_port: '%s'.\n"
"Must be a valid port number or 0.\n",
value);
return blaze_exit_code::BAD_ARGV;
}
option_sources["command_port"] = rcfile;
Expand All @@ -364,7 +365,8 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
invocation_policy = value;
option_sources["invocation_policy"] = rcfile;
} else {
*error = "The startup flag --invocation_policy cannot be specified "
*error =
"The startup flag --invocation_policy cannot be specified "
"multiple times.";
return blaze_exit_code::BAD_ARGV;
}
Expand Down Expand Up @@ -396,8 +398,7 @@ blaze_exit_code::ExitCode StartupOptions::ProcessArg(
}

blaze_exit_code::ExitCode StartupOptions::ProcessArgs(
const std::vector<RcStartupFlag>& rcstartup_flags,
std::string *error) {
const std::vector<RcStartupFlag> &rcstartup_flags, std::string *error) {
std::vector<RcStartupFlag>::size_type i = 0;
while (i < rcstartup_flags.size()) {
bool is_space_separated = false;
Expand Down
18 changes: 8 additions & 10 deletions src/main/cpp/startup_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ namespace blaze {
struct RcStartupFlag {
const std::string source;
const std::string value;
RcStartupFlag(const std::string& source_arg,
const std::string& value_arg)
RcStartupFlag(const std::string &source_arg, const std::string &value_arg)
: source(source_arg), value(value_arg) {}
};

Expand All @@ -63,8 +62,7 @@ class StartupOptions {

// Process an ordered list of RcStartupFlags using ProcessArg.
blaze_exit_code::ExitCode ProcessArgs(
const std::vector<RcStartupFlag>& rcstartup_flags,
std::string *error);
const std::vector<RcStartupFlag> &rcstartup_flags, std::string *error);

// Adds any other options needed to result.
//
Expand Down Expand Up @@ -122,7 +120,7 @@ class StartupOptions {

// Checks whether the argument is a valid unary option.
// E.g. --blazerc=foo, --blazerc foo.
bool IsUnary(const std::string& arg) const;
bool IsUnary(const std::string &arg) const;

std::string GetLowercaseProductName() const;

Expand Down Expand Up @@ -342,7 +340,7 @@ class StartupOptions {

virtual std::string GetRcFileBaseName() const = 0;

void RegisterUnaryStartupFlag(const std::string& flag_name);
void RegisterUnaryStartupFlag(const std::string &flag_name);

// Register a nullary startup flag.
// Both '--flag_name' and '--noflag_name' will be registered as valid nullary
Expand All @@ -368,10 +366,10 @@ class StartupOptions {
// Prevent copying and moving the object to avoid invalidating pointers to
// members (in all_nullary_startup_flags_ for example).
StartupOptions() = delete;
StartupOptions(const StartupOptions&) = delete;
StartupOptions& operator=(const StartupOptions&) = delete;
StartupOptions(StartupOptions&&) = delete;
StartupOptions& operator=(StartupOptions&&) = delete;
StartupOptions(const StartupOptions &) = delete;
StartupOptions &operator=(const StartupOptions &) = delete;
StartupOptions(StartupOptions &&) = delete;
StartupOptions &operator=(StartupOptions &&) = delete;

// Parses a single argument, either from the command line or from the .blazerc
// "startup" options.
Expand Down

0 comments on commit b8f048c

Please sign in to comment.