From 964978733462511832d08ec9670a93b1867a018f Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Sun, 7 Dec 2014 14:33:02 +0100 Subject: [PATCH] fix a bunch of compiler warnings due to -Wunused-result --- client/remote.cpp | 5 +++-- daemon/environment.cpp | 14 ++++++++++++-- daemon/main.cpp | 13 +++++++++---- daemon/serve.cpp | 11 +++++++++-- daemon/workit.cpp | 9 ++++++--- services/util.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 services/util.h diff --git a/client/remote.cpp b/client/remote.cpp index a36542a8f..46c5e86bf 100644 --- a/client/remote.cpp +++ b/client/remote.cpp @@ -51,6 +51,7 @@ #include "client.h" #include "tempfile.h" #include "md5.h" +#include "services/util.h" #ifndef O_LARGEFILE #define O_LARGEFILE 0 @@ -559,12 +560,12 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_ throw(102); } - write(STDOUT_FILENO, crmsg->out.c_str(), crmsg->out.size()); + ignore_result(write(STDOUT_FILENO, crmsg->out.c_str(), crmsg->out.size())); if (colorify_wanted(job)) { colorify_output(crmsg->err); } else { - write(STDERR_FILENO, crmsg->err.c_str(), crmsg->err.size()); + ignore_result(write(STDERR_FILENO, crmsg->err.c_str(), crmsg->err.size())); } if (status && (crmsg->err.length() || crmsg->out.length())) { diff --git a/daemon/environment.cpp b/daemon/environment.cpp index e3109e1f0..a054419ce 100644 --- a/daemon/environment.cpp +++ b/daemon/environment.cpp @@ -38,6 +38,7 @@ #include "comm.h" #include "exitcode.h" +#include "util.h" using namespace std; @@ -344,7 +345,10 @@ int start_create_env(const string &basedir, uid_t user_uid, gid_t user_gid, flush_debug(); int pipes[2]; - pipe(pipes); + if (pipe(pipes) == -1) { + log_error() << "failed to create pipe: " << strerror(errno) << endl; + _exit(147); + } pid_t pid = fork(); if (pid) { @@ -577,9 +581,15 @@ size_t finalize_install_environment(const std::string &basename, const std::stri } string dirname = basename + "/target=" + target; + + errno = 0; mkdir((dirname + "/tmp").c_str(), 01775); - chown((dirname + "/tmp").c_str(), user_uid, user_gid); + ignore_result(chown((dirname + "/tmp").c_str(), user_uid, user_gid)); chmod((dirname + "/tmp").c_str(), 01775); + if (errno == -1) { + log_error() << "failed to setup " << dirname << "/tmp :" + << strerror(errno) << endl; + } return sumup_dir(dirname); } diff --git a/daemon/main.cpp b/daemon/main.cpp index 51676e00a..c66215bce 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -100,6 +100,7 @@ #include "load.h" #include "environment.h" #include "platform.h" +#include "util.h" static std::string pidFilePath; static volatile sig_atomic_t exit_main_loop = 0; @@ -375,7 +376,7 @@ static void dcc_daemon_terminate(int whichsig) // The > 1 is because we get one more signal from the kill(0,...) below. // hmm, we got killed already twice. try better static const char msg[] = "forced exit.\n"; - write(STDERR_FILENO, msg, strlen( msg )); + ignore_result(write(STDERR_FILENO, msg, strlen( msg ))); _exit(1); } @@ -2173,13 +2174,13 @@ int main(int argc, char **argv) if (!logfile.length() && detach) { mkdir("/var/log/icecc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); chmod("/var/log/icecc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - chown("/var/log/icecc", d.user_uid, d.user_gid); + ignore_result(chown("/var/log/icecc", d.user_uid, d.user_gid)); logfile = "/var/log/icecc/iceccd.log"; } mkdir("/var/run/icecc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); chmod("/var/run/icecc", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - chown("/var/run/icecc", d.user_uid, d.user_gid); + ignore_result(chown("/var/run/icecc", d.user_uid, d.user_gid)); #ifdef HAVE_LIBCAP_NG capng_clear(CAPNG_SELECT_BOTH); @@ -2214,7 +2215,11 @@ int main(int argc, char **argv) d.determine_system(); - chdir("/"); + if (chdir("/") != 0) { + log_error() << "failed to switch to root directory: " + << strerror(errno) << endl; + exit(EXIT_DISTCC_FAILED); + } if (detach) if (daemon(0, 0)) { diff --git a/daemon/serve.cpp b/daemon/serve.cpp index f1348c4b5..4afcfac76 100644 --- a/daemon/serve.cpp +++ b/daemon/serve.cpp @@ -51,6 +51,7 @@ #include "workit.h" #include "logging.h" #include "serve.h" +#include "util.h" #include @@ -158,7 +159,13 @@ int handle_connection(const string &basedir, CompileJob *job, /* internal communication channel, don't inherit to gcc */ fcntl(out_fd, F_SETFD, FD_CLOEXEC); - nice(nice_level); + errno = 0; + int niceval = nice(nice_level); + (void) niceval; + if (errno != 0) { + log_warning() << "failed to set nice value: " << strerror(errno) + << endl; + } Msg *msg = 0; // The current read message unsigned int job_id = 0; @@ -228,7 +235,7 @@ int handle_connection(const string &basedir, CompileJob *job, /* wake up parent and tell him that compile finished */ /* if the write failed, well, doesn't matter */ - write(out_fd, job_stat, sizeof(job_stat)); + ignore_result(write(out_fd, job_stat, sizeof(job_stat))); close(out_fd); if (rmsg.status == 0) { diff --git a/daemon/workit.cpp b/daemon/workit.cpp index 393378424..7630a95ce 100644 --- a/daemon/workit.cpp +++ b/daemon/workit.cpp @@ -62,6 +62,7 @@ #include "comm.h" #include "platform.h" +#include "util.h" using namespace std; @@ -72,7 +73,7 @@ extern "C" { static void theSigCHLDHandler(int) { char foo = 0; - write(death_pipe[1], &foo, 1); + ignore_result(write(death_pipe[1], &foo, 1)); } } @@ -236,7 +237,9 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, } // HACK: If in / , Clang records DW_AT_name with / prepended . - chdir("/tmp/"); + if (chdir("/tmp/") != 0) { + error_client(client, "/tmp dir missing?"); + } bool hasPipe = false; @@ -311,7 +314,7 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, perror("ICECC: execv"); char resultByte = 1; - write(main_sock[1], &resultByte, 1); + ignore_result(write(main_sock[1], &resultByte, 1)); _exit(-1); } diff --git a/services/util.h b/services/util.h new file mode 100644 index 000000000..43b5242dd --- /dev/null +++ b/services/util.h @@ -0,0 +1,30 @@ +/* -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 99; -*- */ +/* vim: set ts=4 sw=4 et tw=99: */ +/* + This file is part of Icecream. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#ifndef UTIL_H +#define UTIL_H + +template +inline T ignore_result(T x __attribute__((unused))) +{ + return x; +} + +#endif