cpp: convert ServerPidFile() and ServerPidSymlink() into constants
These two functions have no logic inside it, they just return a string, and a
string that does not change, so they might be better expressed as real C/C++
constants. This might as well generate some better (and less) code anyway.
--
Change-Id: I78673c537c17c2665a74c5778e45a4d41a5f7b50
Reviewed-on: https://bazel-review.googlesource.com/#/c/6114
MOS_MIGRATED_REVID=133805201
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 65e1522..b5a330a 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1000,8 +1000,8 @@
// TODO(lberki): Remove the readlink() call when there is no chance of an old
// server lingering around. Probably safe after 2016.06.01.
int len;
- string pid_file = blaze_util::JoinPath(server_dir, ServerPidFile());
- string pid_symlink = blaze_util::JoinPath(server_dir, ServerPidSymlink());
+ string pid_file = blaze_util::JoinPath(server_dir, kServerPidFile);
+ string pid_symlink = blaze_util::JoinPath(server_dir, kServerPidSymlink);
len = readlink(pid_symlink.c_str(), buf, sizeof(buf) - 1);
if (len < 0) {
int fd = open(pid_file.c_str(), O_RDONLY);
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index a1cf14a..648c0d4 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -45,13 +45,8 @@
namespace blaze {
-string ServerPidFile() {
- return "server.pid.txt";
-}
-
-string ServerPidSymlink() {
- return "server.pid";
-}
+const char kServerPidFile[] = "server.pid.txt";
+const char kServerPidSymlink[] = "server.pid";
string GetUserName() {
const char *user = getenv("USER");
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 0472ddc..5fe17ae 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -29,9 +29,8 @@
using std::string;
-string ServerPidFile();
-
-string ServerPidSymlink();
+extern const char kServerPidFile[];
+extern const char kServerPidSymlink[];
string GetUserName();
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index 4807df4..9136c61 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -394,7 +394,7 @@
CloseHandle(pipe_read);
string pid_string = ToString(processInfo.dwProcessId);
- string pid_file = blaze_util::JoinPath(server_dir, ServerPidFile());
+ string pid_file = blaze_util::JoinPath(server_dir, kServerPidFile);
if (!WriteFile(pid_string, pid_file)) {
// Not a lot we can do if this fails
fprintf(stderr, "Cannot write PID file %s\n", pid_file.c_str());
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index a7ba5d4..0022da3 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -153,9 +153,8 @@
Daemonize(daemon_output);
string pid_string = ToString(getpid());
- string pid_file = blaze_util::JoinPath(server_dir, ServerPidFile());
- string pid_symlink_file =
- blaze_util::JoinPath(server_dir, ServerPidSymlink());
+ string pid_file = blaze_util::JoinPath(server_dir, kServerPidFile);
+ string pid_symlink_file = blaze_util::JoinPath(server_dir, kServerPidSymlink);
if (!WriteFile(pid_string, pid_file)) {
// The exit code does not matter because we are already in the daemonized