remove ROBUST, this is taken care of by NDEBUG (thanks to Petr Uzel)
This commit is contained in:
@@ -64,8 +64,7 @@ u_int32_t PackList::sumanddel (timeval t)
|
|||||||
/* packet may be deleted by caller */
|
/* packet may be deleted by caller */
|
||||||
Connection::Connection (Packet * packet)
|
Connection::Connection (Packet * packet)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert (packet != NULL);
|
||||||
assert (packet != NULL);
|
|
||||||
connections = new ConnList (this, connections);
|
connections = new ConnList (this, connections);
|
||||||
sent_packets = new PackList ();
|
sent_packets = new PackList ();
|
||||||
recv_packets = new PackList ();
|
recv_packets = new PackList ();
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ public:
|
|||||||
}
|
}
|
||||||
PackList (Packet * m_val)
|
PackList (Packet * m_val)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert (m_val != NULL);
|
||||||
assert (m_val != NULL);
|
|
||||||
content = new PackListNode(m_val);
|
content = new PackListNode(m_val);
|
||||||
}
|
}
|
||||||
~PackList ()
|
~PackList ()
|
||||||
|
|||||||
79
cui.cpp
79
cui.cpp
@@ -36,20 +36,14 @@ class Line
|
|||||||
public:
|
public:
|
||||||
Line (const char * name, double n_recv_value, double n_sent_value, pid_t pid, uid_t uid, const char * n_devicename)
|
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;
|
m_name = name;
|
||||||
sent_value = n_sent_value;
|
sent_value = n_sent_value;
|
||||||
recv_value = n_recv_value;
|
recv_value = n_recv_value;
|
||||||
devicename = n_devicename;
|
devicename = n_devicename;
|
||||||
m_pid = pid;
|
m_pid = pid;
|
||||||
m_uid = uid;
|
m_uid = uid;
|
||||||
if (!ROBUST)
|
assert (m_pid >= 0);
|
||||||
{
|
|
||||||
assert (m_pid >= 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void show (int row);
|
void show (int row);
|
||||||
@@ -72,10 +66,7 @@ char * uid2username (uid_t uid)
|
|||||||
|
|
||||||
if (pwd == NULL)
|
if (pwd == NULL)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert(false);
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
return strdup ("unlisted");
|
return strdup ("unlisted");
|
||||||
} else {
|
} else {
|
||||||
return strdup(pwd->pw_name);
|
return strdup(pwd->pw_name);
|
||||||
@@ -85,11 +76,8 @@ char * uid2username (uid_t uid)
|
|||||||
|
|
||||||
void Line::show (int row)
|
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)
|
if (DEBUG || tracemode)
|
||||||
{
|
{
|
||||||
@@ -336,24 +324,21 @@ void do_refresh()
|
|||||||
double sent_global = 0;
|
double sent_global = 0;
|
||||||
double recv_global = 0;
|
double recv_global = 0;
|
||||||
|
|
||||||
if (!ROBUST)
|
#ifndef NDEBUG
|
||||||
{
|
// initialise to null pointers
|
||||||
// initialise to null pointers
|
for (int i = 0; i < nproc; i++)
|
||||||
for (int i = 0; i < nproc; i++)
|
lines[i] = NULL;
|
||||||
lines[i] = NULL;
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
while (curproc != NULL)
|
while (curproc != NULL)
|
||||||
{
|
{
|
||||||
// walk though its connections, summing up their data, and
|
// walk though its connections, summing up their data, and
|
||||||
// throwing away connections that haven't received a package
|
// throwing away connections that haven't received a package
|
||||||
// in the last PROCESSTIMEOUT seconds.
|
// in the last PROCESSTIMEOUT seconds.
|
||||||
if (!ROBUST)
|
assert (curproc != NULL);
|
||||||
{
|
assert (curproc->getVal() != NULL);
|
||||||
assert (curproc != NULL);
|
assert (nproc == processes->size());
|
||||||
assert (curproc->getVal() != NULL);
|
|
||||||
assert (nproc == processes->size());
|
|
||||||
}
|
|
||||||
/* remove timed-out processes (unless it's one of the the unknown process) */
|
/* remove timed-out processes (unless it's one of the the unknown process) */
|
||||||
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <= curtime.tv_sec)
|
if ((curproc->getVal()->getLastPacket() + PROCESSTIMEOUT <= curtime.tv_sec)
|
||||||
&& (curproc->getVal() != unknowntcp)
|
&& (curproc->getVal() != unknowntcp)
|
||||||
@@ -408,30 +393,28 @@ void do_refresh()
|
|||||||
forceExit("Invalid viewmode");
|
forceExit("Invalid viewmode");
|
||||||
}
|
}
|
||||||
uid_t uid = curproc->getVal()->getUid();
|
uid_t uid = curproc->getVal()->getUid();
|
||||||
if (!ROBUST)
|
#ifndef NDEBUG
|
||||||
{
|
struct passwd * pwuid = getpwuid(uid);
|
||||||
struct passwd * pwuid = getpwuid(uid);
|
assert (pwuid != NULL);
|
||||||
assert (pwuid != NULL);
|
// value returned by pwuid should not be freed, according to
|
||||||
// value returned by pwuid should not be freed, according to
|
// Petr Uzel.
|
||||||
// Petr Uzel.
|
//free (pwuid);
|
||||||
//free (pwuid);
|
#endif
|
||||||
assert (curproc->getVal()->pid >= 0);
|
assert (curproc->getVal()->pid >= 0);
|
||||||
assert (n < nproc);
|
assert (n < nproc);
|
||||||
}
|
|
||||||
lines[n] = new Line (curproc->getVal()->name, value_recv, value_sent,
|
lines[n] = new Line (curproc->getVal()->name, value_recv, value_sent,
|
||||||
curproc->getVal()->pid, uid, curproc->getVal()->devicename);
|
curproc->getVal()->pid, uid, curproc->getVal()->devicename);
|
||||||
previousproc = curproc;
|
previousproc = curproc;
|
||||||
curproc = curproc->next;
|
curproc = curproc->next;
|
||||||
n++;
|
n++;
|
||||||
if (!ROBUST)
|
#ifndef NDEBUG
|
||||||
{
|
assert (nproc == processes->size());
|
||||||
assert (nproc == processes->size());
|
if (curproc == NULL)
|
||||||
if (curproc == NULL)
|
assert (n-1 < nproc);
|
||||||
assert (n-1 < nproc);
|
else
|
||||||
else
|
assert (n < nproc);
|
||||||
assert (n < nproc);
|
#endif
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,8 +154,7 @@ void get_info_for_pid(char * pid) {
|
|||||||
free (fromname);
|
free (fromname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!ROBUST)
|
assert (usedlen < linklen);
|
||||||
assert (usedlen < linklen);
|
|
||||||
linkname[usedlen] = '\0';
|
linkname[usedlen] = '\0';
|
||||||
//std::cout << "Linking to: " << linkname << std::endl;
|
//std::cout << "Linking to: " << linkname << std::endl;
|
||||||
get_info_by_linkname (pid, linkname);
|
get_info_by_linkname (pid, linkname);
|
||||||
|
|||||||
@@ -32,12 +32,6 @@
|
|||||||
|
|
||||||
#define DEBUG 0
|
#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
|
#define REVERSEHACK 0
|
||||||
|
|
||||||
// 2 times: 32 characters, 7 ':''s, a ':12345'.
|
// 2 times: 32 characters, 7 ':''s, a ':12345'.
|
||||||
@@ -95,8 +89,7 @@ public:
|
|||||||
|
|
||||||
int result = inet_pton (AF_INET6, address, &addr6);
|
int result = inet_pton (AF_INET6, address, &addr6);
|
||||||
|
|
||||||
if (!ROBUST)
|
assert (result > 0);
|
||||||
assert (result > 0);
|
|
||||||
sa_family = AF_INET6;
|
sa_family = AF_INET6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ void getLocal (const char *device, bool tracemode)
|
|||||||
char address [33];
|
char address [33];
|
||||||
char ifname [9];
|
char ifname [9];
|
||||||
int n_results = sscanf (buffer, "%32[0-9a-f] %*d %*d %*d %*d %8[0-9a-zA-Z]", address, ifname);
|
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)
|
if (strcmp (stripspaces(ifname), device) == 0)
|
||||||
{
|
{
|
||||||
@@ -182,8 +181,7 @@ bool Packet::isOlderThan (timeval t) {
|
|||||||
|
|
||||||
bool Packet::Outgoing () {
|
bool Packet::Outgoing () {
|
||||||
/* must be initialised with getLocal("eth0:1");) */
|
/* must be initialised with getLocal("eth0:1");) */
|
||||||
if (!ROBUST)
|
assert (local_addrs != NULL);
|
||||||
assert (local_addrs != NULL);
|
|
||||||
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case dir_outgoing:
|
case dir_outgoing:
|
||||||
|
|||||||
16
process.cpp
16
process.cpp
@@ -65,11 +65,8 @@ int Process::getLastPacket()
|
|||||||
ConnList * curconn=connections;
|
ConnList * curconn=connections;
|
||||||
while (curconn != NULL)
|
while (curconn != NULL)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert (curconn != NULL);
|
||||||
{
|
assert (curconn->getVal() != NULL);
|
||||||
assert (curconn != NULL);
|
|
||||||
assert (curconn->getVal() != NULL);
|
|
||||||
}
|
|
||||||
if (curconn->getVal()->getLastPacket() > lastpacket)
|
if (curconn->getVal()->getLastPacket() > lastpacket)
|
||||||
lastpacket = curconn->getVal()->getLastPacket();
|
lastpacket = curconn->getVal()->getLastPacket();
|
||||||
curconn = curconn->getNext();
|
curconn = curconn->getNext();
|
||||||
@@ -83,8 +80,7 @@ Process * findProcess (struct prg_node * node)
|
|||||||
while (current != NULL)
|
while (current != NULL)
|
||||||
{
|
{
|
||||||
Process * currentproc = current->getVal();
|
Process * currentproc = current->getVal();
|
||||||
if (!ROBUST)
|
assert (currentproc != NULL);
|
||||||
assert (currentproc != NULL);
|
|
||||||
|
|
||||||
if (node->pid == currentproc->pid)
|
if (node->pid == currentproc->pid)
|
||||||
return current->getVal();
|
return current->getVal();
|
||||||
@@ -127,8 +123,10 @@ void reviewUnknown ()
|
|||||||
if (DEBUG || bughuntmode)
|
if (DEBUG || bughuntmode)
|
||||||
std::cout << "FIXME: Previously unknown inode " << inode << " now got process - apparently it makes sense to review unknown connections\n";
|
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? */
|
/* 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)
|
if (previous_conn != NULL)
|
||||||
{
|
{
|
||||||
previous_conn->setNext (curr_conn->getNext());
|
previous_conn->setNext (curr_conn->getNext());
|
||||||
|
|||||||
10
process.h
10
process.h
@@ -15,8 +15,7 @@ class ConnList
|
|||||||
public:
|
public:
|
||||||
ConnList (Connection * m_val, ConnList * m_next)
|
ConnList (Connection * m_val, ConnList * m_next)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert (m_val != NULL);
|
||||||
assert (m_val != NULL);
|
|
||||||
val = m_val; next = m_next;
|
val = m_val; next = m_next;
|
||||||
}
|
}
|
||||||
~ConnList ()
|
~ConnList ()
|
||||||
@@ -63,9 +62,7 @@ public:
|
|||||||
uid = 0;
|
uid = 0;
|
||||||
}
|
}
|
||||||
void check () {
|
void check () {
|
||||||
if (!ROBUST) {
|
assert (pid >= 0);
|
||||||
assert (pid >= 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Process ()
|
~Process ()
|
||||||
@@ -101,8 +98,7 @@ class ProcList
|
|||||||
public:
|
public:
|
||||||
ProcList (Process * m_val, ProcList * m_next)
|
ProcList (Process * m_val, ProcList * m_next)
|
||||||
{
|
{
|
||||||
if (!ROBUST)
|
assert (m_val != NULL);
|
||||||
assert (m_val != NULL);
|
|
||||||
val = m_val; next = m_next;
|
val = m_val; next = m_next;
|
||||||
}
|
}
|
||||||
int size ();
|
int size ();
|
||||||
|
|||||||
Reference in New Issue
Block a user