aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Thiago Farina <tfarina@chromium.org>2016-09-21 08:20:41 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-09-21 08:26:18 +0000
commit048bbfc46b9bc19538d57710a8d106e8206f0b47 (patch)
tree102adc6f489cf3c1dc2f839ef399d3f8f654b5fa /src
parentc07af7aba8734a0690fa769e482f080ddd447b78 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/main/cpp/blaze.cc4
-rw-r--r--src/main/cpp/blaze_util.cc9
-rw-r--r--src/main/cpp/blaze_util.h5
-rw-r--r--src/main/cpp/blaze_util_mingw.cc2
-rw-r--r--src/main/cpp/blaze_util_posix.cc5
5 files changed, 9 insertions, 16 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 65e1522dc3..b5a330a2f8 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1000,8 +1000,8 @@ static int GetServerPid(const string &server_dir) {
// 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 a1cf14a225..648c0d4a01 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -45,13 +45,8 @@ using std::vector;
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 0472ddc9ec..5fe17aec0a 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -29,9 +29,8 @@ namespace blaze {
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 4807df4f8c..9136c61a5b 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -394,7 +394,7 @@ void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
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 a7ba5d4f4d..0022da3da9 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -153,9 +153,8 @@ void ExecuteDaemon(const string& exe,
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