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

View File

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

79
cui.cpp
View File

@@ -36,20 +36,14 @@ 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);
}
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);
}
assert (m_pid >= 0);
}
void show (int row);
@@ -72,10 +66,7 @@ char * uid2username (uid_t uid)
if (pwd == NULL)
{
if (!ROBUST)
{
assert(false);
}
assert(false);
return strdup ("unlisted");
} else {
return strdup(pwd->pw_name);
@@ -85,11 +76,8 @@ char * uid2username (uid_t uid)
void Line::show (int row)
{
if (!ROBUST)
{
assert (m_pid >= 0);
assert (m_pid <= 100000);
}
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)
{
// initialise to null pointers
for (int i = 0; i < nproc; i++)
lines[i] = NULL;
}
#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());
}
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)
{
struct passwd * pwuid = getpwuid(uid);
assert (pwuid != NULL);
// value returned by pwuid should not be freed, according to
// Petr Uzel.
//free (pwuid);
assert (curproc->getVal()->pid >= 0);
assert (n < nproc);
}
#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)
{
assert (nproc == processes->size());
if (curproc == NULL)
assert (n-1 < nproc);
else
assert (n < nproc);
}
#ifndef NDEBUG
assert (nproc == processes->size());
if (curproc == NULL)
assert (n-1 < nproc);
else
assert (n < nproc);
#endif
}
}

View File

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

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,8 +89,7 @@ public:
int result = inet_pton (AF_INET6, address, &addr6);
if (!ROBUST)
assert (result > 0);
assert (result > 0);
sa_family = AF_INET6;
}

View File

@@ -64,8 +64,7 @@ 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);
assert (n_results = 2);
if (strcmp (stripspaces(ifname), device) == 0)
{
@@ -182,8 +181,7 @@ bool Packet::isOlderThan (timeval t) {
bool Packet::Outgoing () {
/* must be initialised with getLocal("eth0:1");) */
if (!ROBUST)
assert (local_addrs != NULL);
assert (local_addrs != NULL);
switch (dir) {
case dir_outgoing:

View File

@@ -65,11 +65,8 @@ int Process::getLastPacket()
ConnList * curconn=connections;
while (curconn != NULL)
{
if (!ROBUST)
{
assert (curconn != NULL);
assert (curconn->getVal() != NULL);
}
assert (curconn != NULL);
assert (curconn->getVal() != NULL);
if (curconn->getVal()->getLastPacket() > lastpacket)
lastpacket = curconn->getVal()->getLastPacket();
curconn = curconn->getNext();
@@ -83,8 +80,7 @@ Process * findProcess (struct prg_node * node)
while (current != NULL)
{
Process * currentproc = current->getVal();
if (!ROBUST)
assert (currentproc != NULL);
assert (currentproc != NULL);
if (node->pid == currentproc->pid)
return current->getVal();
@@ -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);
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,8 +15,7 @@ class ConnList
public:
ConnList (Connection * m_val, ConnList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
assert (m_val != NULL);
val = m_val; next = m_next;
}
~ConnList ()
@@ -63,9 +62,7 @@ public:
uid = 0;
}
void check () {
if (!ROBUST) {
assert (pid >= 0);
}
assert (pid >= 0);
}
~Process ()
@@ -101,8 +98,7 @@ class ProcList
public:
ProcList (Process * m_val, ProcList * m_next)
{
if (!ROBUST)
assert (m_val != NULL);
assert (m_val != NULL);
val = m_val; next = m_next;
}
int size ();