remove ROBUST, this is taken care of by NDEBUG (thanks to Petr Uzel)

This commit is contained in:
Arnout Engelen
2008-12-31 15:52:26 +00:00
parent 8b7a51c57d
commit 3d6ac8bdd3
8 changed files with 47 additions and 82 deletions

View File

@@ -64,7 +64,6 @@ u_int32_t PackList::sumanddel (timeval t)
/* packet may be deleted by caller */
Connection::Connection (Packet * packet)
{
if (!ROBUST)
assert (packet != NULL);
connections = new ConnList (this, connections);
sent_packets = new PackList ();

View File

@@ -31,7 +31,6 @@ public:
}
PackList (Packet * m_val)
{
if (!ROBUST)
assert (m_val != NULL);
content = new PackListNode(m_val);
}

33
cui.cpp
View File

@@ -35,22 +35,16 @@ class Line
{
public:
Line (const char * name, double n_recv_value, double n_sent_value, pid_t pid, uid_t uid, const char * n_devicename)
{
if (!ROBUST)
{
assert (pid >= 0);
}
m_name = name;
sent_value = n_sent_value;
recv_value = n_recv_value;
devicename = n_devicename;
m_pid = pid;
m_uid = uid;
if (!ROBUST)
{
assert (m_pid >= 0);
}
}
void show (int row);
@@ -71,11 +65,8 @@ char * uid2username (uid_t uid)
pwd = getpwuid(uid);
if (pwd == NULL)
{
if (!ROBUST)
{
assert(false);
}
return strdup ("unlisted");
} else {
return strdup(pwd->pw_name);
@@ -84,12 +75,9 @@ char * uid2username (uid_t uid)
void Line::show (int row)
{
if (!ROBUST)
{
assert (m_pid >= 0);
assert (m_pid <= 100000);
}
if (DEBUG || tracemode)
{
@@ -336,24 +324,21 @@ void do_refresh()
double sent_global = 0;
double recv_global = 0;
if (!ROBUST)
{
#ifndef NDEBUG
// initialise to null pointers
for (int i = 0; i < nproc; i++)
lines[i] = NULL;
}
#endif
while (curproc != NULL)
{
// walk though its connections, summing up their data, and
// throwing away connections that haven't received a package
// in the last PROCESSTIMEOUT seconds.
if (!ROBUST)
{
assert (curproc != NULL);
assert (curproc->getVal() != NULL);
assert (nproc == processes->size());
}
/* remove timed-out processes (unless it's one of the the unknown process) */
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <= curtime.tv_sec)
&& (curproc->getVal() != unknowntcp)
@@ -408,30 +393,28 @@ void do_refresh()
forceExit("Invalid viewmode");
}
uid_t uid = curproc->getVal()->getUid();
if (!ROBUST)
{
#ifndef NDEBUG
struct passwd * pwuid = getpwuid(uid);
assert (pwuid != NULL);
// value returned by pwuid should not be freed, according to
// Petr Uzel.
//free (pwuid);
#endif
assert (curproc->getVal()->pid >= 0);
assert (n < nproc);
}
lines[n] = new Line (curproc->getVal()->name, value_recv, value_sent,
curproc->getVal()->pid, uid, curproc->getVal()->devicename);
previousproc = curproc;
curproc = curproc->next;
n++;
if (!ROBUST)
{
#ifndef NDEBUG
assert (nproc == processes->size());
if (curproc == NULL)
assert (n-1 < nproc);
else
assert (n < nproc);
}
#endif
}
}

View File

@@ -154,7 +154,6 @@ void get_info_for_pid(char * pid) {
free (fromname);
continue;
}
if (!ROBUST)
assert (usedlen < linklen);
linkname[usedlen] = '\0';
//std::cout << "Linking to: " << linkname << std::endl;

View File

@@ -32,12 +32,6 @@
#define DEBUG 0
// if '0', do extra checks and
// assertions. good for finding bugs
// at an early stage of development.
// for production, should be 1.
#define ROBUST 1
#define REVERSEHACK 0
// 2 times: 32 characters, 7 ':''s, a ':12345'.
@@ -95,7 +89,6 @@ public:
int result = inet_pton (AF_INET6, address, &addr6);
if (!ROBUST)
assert (result > 0);
sa_family = AF_INET6;
}

View File

@@ -64,7 +64,6 @@ void getLocal (const char *device, bool tracemode)
char address [33];
char ifname [9];
int n_results = sscanf (buffer, "%32[0-9a-f] %*d %*d %*d %*d %8[0-9a-zA-Z]", address, ifname);
if (!ROBUST)
assert (n_results = 2);
if (strcmp (stripspaces(ifname), device) == 0)
@@ -182,7 +181,6 @@ bool Packet::isOlderThan (timeval t) {
bool Packet::Outgoing () {
/* must be initialised with getLocal("eth0:1");) */
if (!ROBUST)
assert (local_addrs != NULL);
switch (dir) {

View File

@@ -64,12 +64,9 @@ int Process::getLastPacket()
int lastpacket=0;
ConnList * curconn=connections;
while (curconn != NULL)
{
if (!ROBUST)
{
assert (curconn != NULL);
assert (curconn->getVal() != NULL);
}
if (curconn->getVal()->getLastPacket() > lastpacket)
lastpacket = curconn->getVal()->getLastPacket();
curconn = curconn->getNext();
@@ -83,7 +80,6 @@ Process * findProcess (struct prg_node * node)
while (current != NULL)
{
Process * currentproc = current->getVal();
if (!ROBUST)
assert (currentproc != NULL);
if (node->pid == currentproc->pid)
@@ -127,8 +123,10 @@ void reviewUnknown ()
if (DEBUG || bughuntmode)
std::cout << "FIXME: Previously unknown inode " << inode << " now got process - apparently it makes sense to review unknown connections\n";
/* Yay! - but how can this happen? */
if (!ROBUST)
assert(false);
/* TODO: this needs some investigation/refactoring - we should never get here due to assert(false) */
if (previous_conn != NULL)
{
previous_conn->setNext (curr_conn->getNext());

View File

@@ -15,7 +15,6 @@ class ConnList
public:
ConnList (Connection * m_val, ConnList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
val = m_val; next = m_next;
}
@@ -63,10 +62,8 @@ public:
uid = 0;
}
void check () {
if (!ROBUST) {
assert (pid >= 0);
}
}
~Process ()
{
@@ -101,7 +98,6 @@ class ProcList
public:
ProcList (Process * m_val, ProcList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
val = m_val; next = m_next;
}