mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 03:06:10 +00:00
More debug messages in ahalib
This commit is contained in:
parent
e5442b7ccb
commit
cdb9e2970b
3 changed files with 27 additions and 25 deletions
|
@ -34,10 +34,11 @@ class AHAActions:
|
||||||
except OSError,e:
|
except OSError,e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#Can trow IOError
|
#Can trow IOError
|
||||||
def create_message(self,filename,block,exitcode,substitue,insult):
|
def create_message(self,filename,block,exitcode,substitue,insult):
|
||||||
print "CREATE_MESSAGE ",filename,"block=",block
|
print "CREATE_MESSAGE ",filename,"block=",block, "insult=",insult,\
|
||||||
|
"substitue=",substitue
|
||||||
try:
|
try:
|
||||||
reply = ReplyMessage(block=block,exitcode=exitcode,substitue=substitue,
|
reply = ReplyMessage(block=block,exitcode=exitcode,substitue=substitue,
|
||||||
insult = insult)
|
insult = insult)
|
||||||
|
@ -123,7 +124,7 @@ class ProcessTrees:
|
||||||
# Retuns None if ssh related information was not found
|
# Retuns None if ssh related information was not found
|
||||||
sys.stderr.write('ERROR: No child provided SSH information\n')
|
sys.stderr.write('ERROR: No child provided SSH information\n')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Record additional information about processes like SSH parameters
|
# Record additional information about processes like SSH parameters
|
||||||
# and timestamps etc
|
# and timestamps etc
|
||||||
#TODO annotate SSH_LOGNAME
|
#TODO annotate SSH_LOGNAME
|
||||||
|
@ -152,7 +153,7 @@ class ProcessTrees:
|
||||||
# Is there a timestamp?
|
# Is there a timestamp?
|
||||||
if msg.has_key('timestamp'):
|
if msg.has_key('timestamp'):
|
||||||
self.aplist[pid]['timestamp'] = msg['timestamp']
|
self.aplist[pid]['timestamp'] = msg['timestamp']
|
||||||
|
|
||||||
except ValueError,e:
|
except ValueError,e:
|
||||||
print e
|
print e
|
||||||
pass
|
pass
|
||||||
|
@ -204,8 +205,8 @@ class ProcessTrees:
|
||||||
return
|
return
|
||||||
#Go through the children list and do a recursion
|
#Go through the children list and do a recursion
|
||||||
for p in children:
|
for p in children:
|
||||||
self.__get_children(p)
|
self.__get_children(p)
|
||||||
|
|
||||||
def get_children(self,pid):
|
def get_children(self,pid):
|
||||||
#Empty the list; do not want duplicates
|
#Empty the list; do not want duplicates
|
||||||
self.children = dict()
|
self.children = dict()
|
||||||
|
@ -225,14 +226,14 @@ class ProcessTrees:
|
||||||
def does_user_disconnects(self,pid):
|
def does_user_disconnects(self,pid):
|
||||||
if self.userList.has_key(pid):
|
if self.userList.has_key(pid):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
# Describe the root process
|
# Describe the root process
|
||||||
# f is file object
|
# f is file object
|
||||||
# pid is the root process
|
# pid is the root process
|
||||||
def desc_root_process(self,f,pid):
|
def desc_root_process(self,f,pid):
|
||||||
vec = self.recover_process_vector(pid)
|
vec = self.recover_process_vector(pid)
|
||||||
#Sometimes SSHD clones processes that are not related
|
#Sometimes SSHD clones processes that are not related
|
||||||
#to users, small trees about a length of 2
|
#to users, small trees about a length of 2
|
||||||
if (len(vec) == 0):
|
if (len(vec) == 0):
|
||||||
return
|
return
|
||||||
|
@ -251,9 +252,9 @@ class ProcessTrees:
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
def exportUserListTxt(self,filename):
|
def exportUserListTxt(self,filename):
|
||||||
try:
|
try:
|
||||||
#Opens the file in append mode aiming to keep the history
|
#Opens the file in append mode aiming to keep the history
|
||||||
f = open(filename, 'a')
|
f = open(filename, 'a')
|
||||||
ts = time.strftime("%Y-%m-%d %H:%M:%S")
|
ts = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
f.write("*** UserList created on %s ***\n"%(str(ts)))
|
f.write("*** UserList created on %s ***\n"%(str(ts)))
|
||||||
for pid in self.userList.keys():
|
for pid in self.userList.keys():
|
||||||
#Each sshd clone is not necessarly related to a user
|
#Each sshd clone is not necessarly related to a user
|
||||||
|
@ -264,7 +265,7 @@ class ProcessTrees:
|
||||||
f.close()
|
f.close()
|
||||||
except IOError,e:
|
except IOError,e:
|
||||||
#TODO implement logging of internal errors
|
#TODO implement logging of internal errors
|
||||||
#User should notice that there is something wrong when
|
#User should notice that there is something wrong when
|
||||||
#user lists are outdated or corrupted
|
#user lists are outdated or corrupted
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -299,7 +300,7 @@ class ProcessTrees:
|
||||||
if vector.has_key(its) == False:
|
if vector.has_key(its) == False:
|
||||||
vector[its] = []
|
vector[its] = []
|
||||||
vector[its].append(file)
|
vector[its].append(file)
|
||||||
#Now sort the vector
|
#Now sort the vector
|
||||||
tab = vector.keys()
|
tab = vector.keys()
|
||||||
tab.sort()
|
tab.sort()
|
||||||
ret = []
|
ret = []
|
||||||
|
@ -308,8 +309,8 @@ class ProcessTrees:
|
||||||
ret.append(c)
|
ret.append(c)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
#Recursively get the children of a process. This time from the annotated
|
#Recursively get the children of a process. This time from the annotated
|
||||||
#list.
|
#list.
|
||||||
#Internal function
|
#Internal function
|
||||||
def __get_aplist_children(self,pid):
|
def __get_aplist_children(self,pid):
|
||||||
#Establish a list of children for a process
|
#Establish a list of children for a process
|
||||||
|
@ -324,8 +325,8 @@ class ProcessTrees:
|
||||||
return
|
return
|
||||||
#Go through the children list and do a recursion
|
#Go through the children list and do a recursion
|
||||||
for p in children:
|
for p in children:
|
||||||
self.__get_aplist_children(p)
|
self.__get_aplist_children(p)
|
||||||
|
|
||||||
def get__aplist_children(self,pid):
|
def get__aplist_children(self,pid):
|
||||||
#Empty the list; do not want duplicates
|
#Empty the list; do not want duplicates
|
||||||
self.children = dict()
|
self.children = dict()
|
||||||
|
@ -338,7 +339,7 @@ class ProcessTrees:
|
||||||
print "Removal candidates"
|
print "Removal candidates"
|
||||||
for pid in children:
|
for pid in children:
|
||||||
self.aplist.pop(pid)
|
self.aplist.pop(pid)
|
||||||
|
|
||||||
class TestProcessTree(unittest.TestCase):
|
class TestProcessTree(unittest.TestCase):
|
||||||
def testSearchRegular0(self):
|
def testSearchRegular0(self):
|
||||||
x = ProcessTrees()
|
x = ProcessTrees()
|
||||||
|
@ -430,7 +431,7 @@ class TestProcessTree(unittest.TestCase):
|
||||||
|
|
||||||
ret = x.searchTree(334,123)
|
ret = x.searchTree(334,123)
|
||||||
self.assertEqual(ret,1)
|
self.assertEqual(ret,1)
|
||||||
|
|
||||||
#First child has onother child
|
#First child has onother child
|
||||||
ret = x.searchTree(555,333)
|
ret = x.searchTree(555,333)
|
||||||
self.assertEqual(ret,1)
|
self.assertEqual(ret,1)
|
||||||
|
@ -442,8 +443,8 @@ class TestProcessTree(unittest.TestCase):
|
||||||
ret = x.searchTree(1001,1000)
|
ret = x.searchTree(1001,1000)
|
||||||
self.assertEqual(ret,1)
|
self.assertEqual(ret,1)
|
||||||
children = x.get_children(123)
|
children = x.get_children(123)
|
||||||
#[666, 555, 333, 334]
|
#[666, 555, 333, 334]
|
||||||
self.assertEqual(len(children), 4)
|
self.assertEqual(len(children), 4)
|
||||||
self.assertEqual(children[0],666)
|
self.assertEqual(children[0],666)
|
||||||
self.assertEqual(children[1],555)
|
self.assertEqual(children[1],555)
|
||||||
self.assertEqual(children[2],333)
|
self.assertEqual(children[2],333)
|
||||||
|
@ -452,7 +453,7 @@ class TestProcessTree(unittest.TestCase):
|
||||||
x= ProcessTrees()
|
x= ProcessTrees()
|
||||||
children = x.get_children(999)
|
children = x.get_children(999)
|
||||||
self.assertEqual(len(children),0)
|
self.assertEqual(len(children),0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "linux/delay.h"
|
#include "linux/delay.h"
|
||||||
#include "aha-defs.h"
|
#include "aha-defs.h"
|
||||||
#define MAX_DUMP_BUF 512
|
#define MAX_DUMP_BUF 1024
|
||||||
struct ReplyMessage{
|
struct ReplyMessage{
|
||||||
int block;
|
int block;
|
||||||
int exitcode;
|
int exitcode;
|
||||||
|
@ -17,7 +17,7 @@ struct ReplyMessage{
|
||||||
|
|
||||||
#define EXECVE_MESSAGE 1
|
#define EXECVE_MESSAGE 1
|
||||||
#define CLONE_MESSAGE 2
|
#define CLONE_MESSAGE 2
|
||||||
#define EXIT_MESSAGE 3
|
#define EXIT_MESSAGE 3
|
||||||
#ifdef AHA_DEBUG
|
#ifdef AHA_DEBUG
|
||||||
#define AHA_PRINTK(args...) printk(args)
|
#define AHA_PRINTK(args...) printk(args)
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -32,7 +32,8 @@ inline void __aha_os_write_file_ck(int fd, char* buf, int size, int cnt)
|
||||||
if ((cnt > 0) & (cnt < size)){
|
if ((cnt > 0) & (cnt < size)){
|
||||||
os_write_file(fd,buf,cnt);
|
os_write_file(fd,buf,cnt);
|
||||||
} else {
|
} else {
|
||||||
AHA_PRINTK("Failed to write information\n");
|
AHA_PRINTK("Cannot write. buffer is too small size = %d cnt=%d, \
|
||||||
|
fd=%d\n", size, cnt,fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue