Skip to content

Commit

Permalink
Improve ignoring return values (see #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphlange committed Jan 11, 2017
1 parent 5a92e05 commit 2326dc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
19 changes: 11 additions & 8 deletions clientFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "processClass.h"
#include "libtelnet.h"

// Wrapper to ignore return values
template<typename T>
inline void ignore_result(T /* unused result */) {}

static const telnet_telopt_t my_telopts[] = {
{ TELNET_TELOPT_ECHO, TELNET_WILL, 0 },
{ TELNET_TELOPT_LINEMODE, 0, TELNET_DO },
Expand Down Expand Up @@ -77,7 +81,6 @@ clientItem::clientItem(int socketIn, bool readonly) :
assert(socketIn>=0);
int optval = 1;
int i;
ssize_t ign;
struct tm procServStart_tm; // Time when this procServ started
char procServStart_buf[32]; // Time when this procServ started - as string
struct tm IOCStart_tm; // Time when the current IOC was started
Expand Down Expand Up @@ -137,17 +140,17 @@ clientItem::clientItem(int socketIn, bool readonly) :
_loggers++;
} else { // Regular (user) client
_users++;
ign = write( _fd, greeting1, strlen(greeting1) );
ign = write( _fd, greeting2, strlen(greeting2) );
ignore_result( write(_fd, greeting1, strlen(greeting1)) );
ignore_result( write(_fd, greeting2, strlen(greeting2)) );
}

ign = write( _fd, infoMessage1, strlen(infoMessage1) );
ign = write( _fd, infoMessage2, strlen(infoMessage2) );
ign = write( _fd, buf1, strlen(buf1) );
ignore_result( write(_fd, infoMessage1, strlen(infoMessage1)) );
ignore_result( write( _fd, infoMessage2, strlen(infoMessage2)) );
ignore_result( write( _fd, buf1, strlen(buf1)) );
if ( ! _readonly )
ign = write( _fd, buf2, strlen(buf2) );
ignore_result( write(_fd, buf2, strlen(buf2)) );
if ( ! processClass::exists() )
ign = write( _fd, infoMessage3, strlen(infoMessage3) );
ignore_result( write(_fd, infoMessage3, strlen(infoMessage3)) );

_telnet = telnet_init(my_telopts, telnet_eh, 0, this);

Expand Down
18 changes: 10 additions & 8 deletions procServ.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

#include "procServ.h"

// Wrapper to ignore return values
template<typename T>
inline void ignore_result(T /* unused result */) {}

#ifdef ALLOW_FROM_ANYWHERE
const bool enableAllow = true; // Enable --allow option
#else
Expand Down Expand Up @@ -675,7 +679,6 @@ void SendToAll(const char * message,
int len = 0;
time_t now;
struct tm now_tm;
ssize_t ign;

time(&now);
localtime_r(&now, &now_tm);
Expand All @@ -693,22 +696,22 @@ void SendToAll(const char * message,
int i = 0, j = 0;
for (i = 0; i < count; ++i) {
if (!log_stamp_sent) {
ign = write(logFileFD, stamp, len);
ignore_result( write(logFileFD, stamp, len) );
log_stamp_sent = true;
}
if (message[i] == '\n') {
ign = write(logFileFD, message+j, i-j+1);
ignore_result( write(logFileFD, message+j, i-j+1) );
j = i + 1;
log_stamp_sent = false;
}
}
ign = write(logFileFD, message+j, count-j); // finish off rest of line with no newline at end
ignore_result( write(logFileFD, message+j, count-j) ); // finish off rest of line with no newline at end
} else {
ign = write(logFileFD, message, count);
ignore_result( write(logFileFD, message, count) );
}
fsync(logFileFD);
}
if (inFgMode == false && debugFD > 0) ign = write(debugFD, message, count);
if (inFgMode == false && debugFD > 0) ignore_result( write(debugFD, message, count) );
}

while (p) {
Expand Down Expand Up @@ -831,7 +834,6 @@ void forkAndGo()
{
pid_t p;
int fh;
int ign;

if ((p = fork()) < 0) { // Fork failed
perror("Could not fork daemon process");
Expand All @@ -855,7 +857,7 @@ void forkAndGo()
fh = open(buf, O_RDWR);
if (fh < 0) { perror(buf); exit(-1); }
close(0); close(1); close(2);
ign = dup(fh); ign = dup(fh); ign = dup(fh);
ignore_result( dup(fh) ); ignore_result( dup(fh) ); ignore_result( dup(fh) );
close(fh);

// Make sure we are not attached to a terminal
Expand Down

0 comments on commit 2326dc4

Please sign in to comment.