More client fixes:
- Use an explicit cast to void to tell the compiler that we are intentionally ignoring return values.
- Delete the unused function GetPeerProcessId()
--
MOS_MIGRATED_REVID=132970162
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 9316a7f..018e64a 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -830,9 +830,7 @@
}
remaining -= bytes;
- if (write(output, server_output_buffer, bytes) != bytes) {
- // Not much we can do if this doesn't work, just placate the compiler.
- }
+ (void) write(output, server_output_buffer, bytes);
}
return 0;
@@ -1708,9 +1706,9 @@
// Ensure we have three open fds. Otherwise we can end up with
// bizarre things like stdout going to the lock file, etc.
- if (fcntl(0, F_GETFL) == -1) open("/dev/null", O_RDONLY);
- if (fcntl(1, F_GETFL) == -1) open("/dev/null", O_WRONLY);
- if (fcntl(2, F_GETFL) == -1) open("/dev/null", O_WRONLY);
+ if (fcntl(STDIN_FILENO, F_GETFL) == -1) open("/dev/null", O_RDONLY);
+ if (fcntl(STDOUT_FILENO, F_GETFL) == -1) open("/dev/null", O_WRONLY);
+ if (fcntl(STDERR_FILENO, F_GETFL) == -1) open("/dev/null", O_WRONLY);
}
static void CheckBinaryPath(const string& argv0) {
@@ -2073,17 +2071,13 @@
}
if (response.standard_output().size() > 0) {
- if (write(1, response.standard_output().c_str(),
- response.standard_output().size()) <= 0) {
- // Placate the compiler.
- }
+ (void) write(STDOUT_FILENO, response.standard_output().c_str(),
+ response.standard_output().size());
}
if (response.standard_error().size() > 0) {
- if (write(2, response.standard_error().c_str(),
- response.standard_error().size()) <= 0) {
- // Placate the compiler.
- }
+ (void) write(STDERR_FILENO, response.standard_error().c_str(),
+ response.standard_error().size());
}
if (!command_id_set && response.command_id().size() > 0) {
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 6ba27b5..7bf95cb 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -426,9 +426,7 @@
string msg = "owner=launcher\npid="
+ ToString(getpid()) + "\ntty=" + (tty ? tty : "") + "\n";
// The contents are currently meant only for debugging.
- if (write(lockfd, msg.data(), msg.size()) <= 0) {
- // Placate the compiler.
- }
+ (void) write(lockfd, msg.data(), msg.size());
blaze_lock->lockfd = lockfd;
return wait_time;
}
@@ -451,9 +449,7 @@
va_start(ap, format);
int r = vsnprintf(buf, sizeof buf, format, ap);
va_end(ap);
- if (write(STDERR_FILENO, buf, r) <= 0) {
- // We don't care, just placate the compiler.
- }
+ (void) write(STDERR_FILENO, buf, r);
}
} // namespace blaze
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index 0cadc41..1f0acbd 100644
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -114,16 +114,6 @@
}
}
-pid_t GetPeerProcessId(int socket) {
- pid_t pid = 0;
- socklen_t len = sizeof(pid_t);
- if (getsockopt(socket, SOL_LOCAL, LOCAL_PEERPID, &pid, &len) < 0) {
- pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "can't get server pid from connection");
- }
- return pid;
-}
-
string GetSelfPath() {
char pathbuf[PROC_PIDPATHINFO_MAXSIZE] = {};
int len = proc_pidpath(getpid(), pathbuf, sizeof(pathbuf));
diff --git a/src/main/cpp/blaze_util_freebsd.cc b/src/main/cpp/blaze_util_freebsd.cc
index 917a509..4429038 100644
--- a/src/main/cpp/blaze_util_freebsd.cc
+++ b/src/main/cpp/blaze_util_freebsd.cc
@@ -86,8 +86,6 @@
return string(buffer);
}
-pid_t GetPeerProcessId(int socket) { return -1; }
-
uint64_t MonotonicClock() {
struct timespec ts = {};
clock_gettime(CLOCK_MONOTONIC, &ts);
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc
index 4bc2224..bd5fc85 100644
--- a/src/main/cpp/blaze_util_linux.cc
+++ b/src/main/cpp/blaze_util_linux.cc
@@ -95,16 +95,6 @@
return string(buffer);
}
-pid_t GetPeerProcessId(int socket) {
- struct ucred creds = {};
- socklen_t len = sizeof creds;
- if (getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &creds, &len) == -1) {
- pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "can't get server pid from connection");
- }
- return creds.pid;
-}
-
uint64_t MonotonicClock() {
struct timespec ts = {};
clock_gettime(CLOCK_MONOTONIC, &ts);
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index 20d1ea6..069ce8b 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -83,16 +83,6 @@
}
}
-pid_t GetPeerProcessId(int socket) {
- struct ucred creds = {};
- socklen_t len = sizeof creds;
- if (getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &creds, &len) == -1) {
- pdie(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR,
- "can't get server pid from connection");
- }
- return creds.pid;
-}
-
uint64_t MonotonicClock() {
struct timespec ts = {};
clock_gettime(CLOCK_MONOTONIC, &ts);
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 1497a85..5f8b3bf 100644
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -27,9 +27,6 @@
// Returns the directory Bazel can use to store output.
std::string GetOutputRoot();
-// Returns the process id of the peer connected to this socket.
-pid_t GetPeerProcessId(int socket);
-
// Warn about dubious filesystem types, such as NFS, case-insensitive (?).
void WarnFilesystemType(const std::string& output_base);
diff --git a/src/main/cpp/blaze_util_posix.cc b/src/main/cpp/blaze_util_posix.cc
index 2203cb0..a7ba5d4 100644
--- a/src/main/cpp/blaze_util_posix.cc
+++ b/src/main/cpp/blaze_util_posix.cc
@@ -100,9 +100,7 @@
// In a daemon, no-one can hear you scream.
open("/dev/null", O_WRONLY);
}
- if (dup(STDOUT_FILENO)) { // stderr (2>&1)
- // Placate the compiler.
- }
+ (void) dup(STDOUT_FILENO); // stderr (2>&1)
}
class PipeBlazeServerStartup : public BlazeServerStartup {