Skip to content

Commit

Permalink
fix a bunch of compiler warnings due to -Wunused-result
Browse files Browse the repository at this point in the history
  • Loading branch information
mostynb committed Dec 7, 2014
1 parent 8076c0e commit 9649787
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 13 deletions.
5 changes: 3 additions & 2 deletions client/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "client.h"
#include "tempfile.h"
#include "md5.h"
#include "services/util.h"

#ifndef O_LARGEFILE
#define O_LARGEFILE 0
Expand Down Expand Up @@ -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())) {
Expand Down
14 changes: 12 additions & 2 deletions daemon/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "comm.h"
#include "exitcode.h"
#include "util.h"

using namespace std;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 9 additions & 4 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 9 additions & 2 deletions daemon/serve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "workit.h"
#include "logging.h"
#include "serve.h"
#include "util.h"

#include <sys/time.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions daemon/workit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#include "comm.h"
#include "platform.h"
#include "util.h"

using namespace std;

Expand All @@ -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));
}

}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
30 changes: 30 additions & 0 deletions services/util.h
Original file line number Diff line number Diff line change
@@ -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<typename T>
inline T ignore_result(T x __attribute__((unused)))
{
return x;
}

#endif

0 comments on commit 9649787

Please sign in to comment.