public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/
@ 2011-06-08 16:48 Александр Берсенев
  0 siblings, 0 replies; 4+ messages in thread
From: Александр Берсенев @ 2011-06-08 16:48 UTC (permalink / raw
  To: gentoo-commits

commit:     3498865028063d381f35e05cc646c77dedaaa109
Author:     Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Wed Jun  8 22:48:19 2011 +0000
Commit:     Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Wed Jun  8 22:48:19 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=34988650

fixed bugs in multithreading in fuse, add some test for fuse, make unmount more reliable

---
 logger/src/autodep/logfs/logger_fusefs.py |   26 ++++++++++------
 logger/src/autodep/logfs/test_fstracer.py |   46 ++++++++++++++++++++++++++--
 logger/src/hook_fusefs/hookfs.c           |   11 +++++++
 3 files changed, 69 insertions(+), 14 deletions(-)

diff --git a/logger/src/autodep/logfs/logger_fusefs.py b/logger/src/autodep/logfs/logger_fusefs.py
index 76516bc..11a6f39 100644
--- a/logger/src/autodep/logfs/logger_fusefs.py
+++ b/logger/src/autodep/logfs/logger_fusefs.py
@@ -59,6 +59,18 @@ class logger:
 	#we will delete the object manually after execprog
 	pass
   
+  # launches command, if it returns not 0 waits for 1 second and launches again
+  # for various umounts
+  def smartcommandlauncher(self,args):
+	for waittime in (1,1,2):
+	  ret=subprocess.call(args)
+	  if ret==0:
+		return
+	  print "Auto-retrying after %d sec" % waittime
+	  time.sleep(waittime)
+	print "Giving up. Command %s failed" % args
+	
+  
   def execprog(self,prog_name,arguments):
 	pid=os.fork()
 	if pid==0:
@@ -78,18 +90,12 @@ class logger:
 	else:
 	  exitcode=os.wait()[1];
 	  try:
-		# unmount all manually
+		print "Unmounting partitions"
 		self.mountlist.reverse()
 		for mount in self.mountlist:
-		  ret=subprocess.call(['umount',self.rootmountpath+mount])
-		  if ret!=0:
-			print "failed to umount bind %s directory. Check messages above" % ( self.rootmountpath+mount)
-		ret=subprocess.call(['fusermount','-u',self.rootmountpath]);
-		if ret!=0:
-		  print "Error while unmounting fuse filesystem. Check messages above"
-		ret=subprocess.call(['umount',self.rootmountpath]);
-		if ret!=0:
-		  print "Error while unmounting %s Check messages above" % (self.rootmountpath)
+		  self.smartcommandlauncher(['umount',self.rootmountpath+mount])
+		self.smartcommandlauncher(['fusermount','-u',self.rootmountpath]);
+		self.smartcommandlauncher(['umount',self.rootmountpath]);
 		os.rmdir(self.rootmountpath)
 
 	  except OSError, e:

diff --git a/logger/src/autodep/logfs/test_fstracer.py b/logger/src/autodep/logfs/test_fstracer.py
index 9a3df67..c254bce 100644
--- a/logger/src/autodep/logfs/test_fstracer.py
+++ b/logger/src/autodep/logfs/test_fstracer.py
@@ -2,7 +2,7 @@ import unittest
 
 import fstracer
 
-class simple_tests(unittest.TestCase):
+class hooklib_simple_tests(unittest.TestCase):
   def test_open_unexists(self):
 	self.assertEqual(fstracer.getfsevents('/bin/cat',
 	                ['/bin/cat','f1','f2']),
@@ -46,11 +46,49 @@ class simple_tests(unittest.TestCase):
 	  for f in xrange(0,filesnum):
 		self.assertTrue(resultarray.count(['open', 'file_%d_%d' % (p,f)])==1)
 
-	#self.assertEqual(resultarray,
-	#                map(lambda x: ['open','file'+str(x)],range(0,filesnum)))
+class fusefs_simple_tests(unittest.TestCase):
+  def test_open_unexists(self):
+	eventslist=fstracer.getfsevents('/bin/cat', ['/bin/cat','/f1','/f2'],approach="fusefs")
+	self.assertTrue(eventslist.count(['stat', '/f1'])==1)
+	def test_open_exists(self):
+	  eventslist=fstracer.getfsevents('/bin/cat', ['/bin/cat','/etc/passwd'],approach="fusefs")
+	  self.assertTrue(eventslist.count(['stat', '/etc/passwd'])>=1)
+
+  def test_open_many(self):
+	filesnum=200
+	eventslist=fstracer.getfsevents('/bin/cat',['/bin/cat']+
+									map(lambda x: '/file'+str(x),range(0,filesnum)), approach="fusefs")
+	for f in map(lambda x: ['stat','/file'+str(x)],range(0,filesnum)):
+	  self.assertTrue(f in eventslist)
+
+  def test_parralel(self):
+	filesnum=200
+	procnum=6
+	
+	# create command
+	command=""
+	for p in xrange(0,procnum):
+  	  command+="/bin/cat "
+	  for f in xrange(0,filesnum):
+		command+="/file_%d_%d " % (p,f)
+	  command+="& "
+	command+=" >/dev/null 2>&1"
+	#command+=" "+"A"*65536
+	
+	resultarray=fstracer.getfsevents('/bin/sh', ['/bin/sh','-c',command],approach="fusefs")
+
+	#self.assertTrue(resultarray.count(['execve', '/bin/cat'])==procnum)
+
+	print resultarray
+
+	for p in xrange(0,procnum):
+	  for f in xrange(0,filesnum):
+		self.assertTrue(resultarray.count(['stat', '/file_%d_%d' % (p,f)])==1)
 
 
 
 
 if __name__ == '__main__':
-  unittest.main()
\ No newline at end of file
+  #unittest.main()
+  suite = unittest.TestLoader().loadTestsFromTestCase(fusefs_simple_tests)
+  unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file

diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hookfs.c
index 96d8958..af3e97a 100644
--- a/logger/src/hook_fusefs/hookfs.c
+++ b/logger/src/hook_fusefs/hookfs.c
@@ -36,6 +36,7 @@
 #endif
 #include <sys/socket.h>
 #include <sys/un.h>
+#include <pthread.h>
 
 
 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
@@ -47,6 +48,8 @@ struct hookfs_config {
 };
 
 
+pthread_mutex_t socketblock = PTHREAD_MUTEX_INITIALIZER;
+
 int mountpoint_fd = -1;
 char *mountpoint = NULL;
 FILE * log_file = NULL;
@@ -78,7 +81,9 @@ void __print_escaped(FILE *fh ,const char *s){
  * Format of log string: time event file flags result parents
 */
 void log_event(const char *event_type, const char *filename, char *result, int err, pid_t pid) {
+  pthread_mutex_lock( &socketblock );
 
+  
   fprintf(log_file,"%lld ",(unsigned long long)time(NULL));
 
   __print_escaped(log_file, event_type);
@@ -86,6 +91,9 @@ void log_event(const char *event_type, const char *filename, char *result, int e
   __print_escaped(log_file, filename);
   fprintf(log_file," %d %s\n", pid, result);
   fflush(log_file);
+
+  pthread_mutex_unlock( &socketblock );
+
 }
 
 /*
@@ -96,7 +104,10 @@ int is_event_allowed(const char *event_type,const char *filename, pid_t pid) {
   // sending asking log_event
   log_event(event_type,filename,"ASKING",0,pid);
   char answer[8];
+
+  pthread_mutex_lock( &socketblock );
   fscanf(log_file,"%7s",answer);
+  pthread_mutex_unlock( &socketblock );
   
   if(strcmp(answer,"ALLOW")==0)
 	return 1;



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/
@ 2011-06-18  8:27 Александр Берсенев
  0 siblings, 0 replies; 4+ messages in thread
From: Александр Берсенев @ 2011-06-18  8:27 UTC (permalink / raw
  To: gentoo-commits

commit:     17d67416cdb1addb6b77961686177520400a4d46
Author:     Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sat Jun 18 14:27:23 2011 +0000
Commit:     Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sat Jun 18 14:27:23 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=17d67416

small performance optimization

---
 logger/src/autodep/logfs/fstracer.py |   22 ++++++----------------
 logger/src/hook_fusefs/hookfs.c      |   13 +------------
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/logger/src/autodep/logfs/fstracer.py b/logger/src/autodep/logfs/fstracer.py
index 5ca8305..a632269 100644
--- a/logger/src/autodep/logfs/fstracer.py
+++ b/logger/src/autodep/logfs/fstracer.py
@@ -18,9 +18,9 @@ import logger_fusefs
 
 
 def unescape(s):
-  s=re.sub(r'\\r', '\r', s)
-  s=re.sub(r'\\n', '\n', s)
-  s=re.sub(r'\\(.)', r'\1', s)
+  s=s.replace(r'\\r', '\r')
+  s=s.replace(r'\\n', '\n')
+  s=s.replace(r'\\', '')
   return s
 
 def parse_message(message):
@@ -138,7 +138,7 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 	sock_listen=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 	sock_listen.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 	sock_listen.bind(socketname)
-	sock_listen.listen(65536*8)
+	sock_listen.listen(65536)
   except socket.error, e:
     print "Failed to create a socket for exchange data with the logger: %s" % e
     return []
@@ -168,7 +168,7 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 	  buffers = {}
 	  
 	  while input:
-		inputready,outputready,exceptready = select.select(input,[],[],5)
+		inputready,_,_ = select.select(input,[],[],5)
 		
 		for s in inputready:
 		  #print "!! len: %d" % len(buffers)
@@ -222,11 +222,8 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 					
 				else:
 				  eventname,filename,stage,result=message[1:5]
-				  #stage=get_stage_by_pid(int(messagepid),pid)
-				  print message;
+				  #print message;
 
-				  s.sendall("ALLOW\n"); # to continue execution
-				  
 				  if not stage in events:
 					events[stage]=[{},{}]
 				  
@@ -256,13 +253,6 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 
 				  else:
 					print "Error in logger module<->analyser protocol"
-				  # check previous five messages for possible repeats
-				  #for prevevent in events[-5:]:
-					#if prevevent[1:]==message[1:]:
-					#  break
-				  #else:
-					#pass
-					#events.append(message)
 				  
 			  except IndexError:
 				print "IndexError while parsing %s"%record

diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hookfs.c
index 23db13d..a633276 100644
--- a/logger/src/hook_fusefs/hookfs.c
+++ b/logger/src/hook_fusefs/hookfs.c
@@ -79,10 +79,6 @@ static void __print_escaped(FILE *fh ,const char *s){
 	for(;(*s)!=0; s++) {
 		if(*s==' ')
 		  fprintf(fh,"\\ ");
-		else if(*s==',')
-		  fprintf(fh,"\\,");
-		else if(*s=='\r')
-		  fprintf(fh,"\\r");
 		else if(*s=='\n')
 		  fprintf(fh,"\\n");
 		else if(*s=='\\')
@@ -231,11 +227,7 @@ static void raw_log_event(const char *event_type, const char *filename, char *re
 	fprintf(log_file,"%s",result);
 
   fprintf(log_file,"\n");
-  fflush(log_file);
-
-  // always wait for an answer
-//  fflush(log_file); // yes, it is here too
-  
+  fflush(log_file);  
 }
 
 /*
@@ -247,9 +239,6 @@ static void log_event(const char *event_type, const char *filename, char *result
   pthread_mutex_lock( &socketblock );
   raw_log_event(event_type,filename,result,err,stage);
 
-  char answer[8];
-  fscanf(log_file,"%7s",answer);
-
   pthread_mutex_unlock( &socketblock );
 }
 



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/
@ 2011-06-18 10:00 Александр Берсенев
  0 siblings, 0 replies; 4+ messages in thread
From: Александр Берсенев @ 2011-06-18 10:00 UTC (permalink / raw
  To: gentoo-commits

commit:     01807c6d423c98886fc71198f031adc7f38845bf
Author:     Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sat Jun 18 15:59:37 2011 +0000
Commit:     Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sat Jun 18 15:59:37 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=01807c6d

another performace improvements

---
 logger/src/autodep/logfs/fstracer.py |    2 +-
 logger/src/hook_fusefs/hookfs.c      |   11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/logger/src/autodep/logfs/fstracer.py b/logger/src/autodep/logfs/fstracer.py
index fec926c..95d64f5 100644
--- a/logger/src/autodep/logfs/fstracer.py
+++ b/logger/src/autodep/logfs/fstracer.py
@@ -173,7 +173,7 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 			  input.append(client)
 			  buffers[client]=""
 		  else:
-			data=s.recv(4096)
+			data=s.recv(65536)
 			
 			buffers[s]+=data
 			  

diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hookfs.c
index 3545151..9241a2a 100644
--- a/logger/src/hook_fusefs/hookfs.c
+++ b/logger/src/hook_fusefs/hookfs.c
@@ -46,6 +46,8 @@
 #define MAXSOCKETPATHLEN 108
 #define MAXFILEBUFFLEN 2048
 
+#define IOBUFSIZE 65536
+
 
 struct hookfs_config {
      int argv_debug;
@@ -202,7 +204,6 @@ static void raw_log_event(const char *event_type, const char *filename, char *re
 	fprintf(log_file,"%s",result);
 
   fprintf(log_file,"%c%c",0,0);
-  fflush(log_file);  
 }
 
 /*
@@ -229,10 +230,10 @@ static int is_event_allowed(const char *event_type,const char *filename, pid_t p
 
   // sending asking log_event
   raw_log_event(event_type,filename,"ASKING",0,stage);
+  fflush(log_file);
   char answer[8];
 
   fscanf(log_file,"%7s",answer);
-  fflush(log_file); // yes, it is here too
   pthread_mutex_unlock( &socketblock );
   
   if(strcmp(answer,"ALLOW")==0)
@@ -1113,6 +1114,12 @@ int main(int argc, char *argv[]) {
 	  fprintf(stderr,"Unable to open a socket for a steam writing: %s\n", strerror(errno));
 	  exit(1);
 	}
+	
+	ret=setvbuf(log_file,NULL,_IOFBF,IOBUFSIZE);
+	if(ret!=0){
+	  fprintf(stderr,"Unable to set a size of io buffer");
+	  exit(1);
+	} 
   }
   
   if (! try_chdir_to_mountpoint(args.argc, args.argv)) {



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/
@ 2011-06-24 20:17 Александр Берсенев
  0 siblings, 0 replies; 4+ messages in thread
From: Александр Берсенев @ 2011-06-24 20:17 UTC (permalink / raw
  To: gentoo-commits

commit:     d01cf77441dc9560b1b90b73d7df89e9423b4ef5
Author:     Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
AuthorDate: Sat Jun 25 02:16:42 2011 +0000
Commit:     Александр Берсенев <bay <AT> hackerdom <DOT> ru>
CommitDate: Sat Jun 25 02:16:42 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=d01cf774

better algorythm to log stage

---
 logger/src/autodep/logfs/fstracer.py      |    6 +-
 logger/src/autodep/logfs/logger_fusefs.py |    5 +-
 logger/src/hook_fusefs/hookfs.c           |  148 ++++++++++++++++++----------
 3 files changed, 102 insertions(+), 57 deletions(-)

diff --git a/logger/src/autodep/logfs/fstracer.py b/logger/src/autodep/logfs/fstracer.py
index 95d64f5..5842372 100644
--- a/logger/src/autodep/logfs/fstracer.py
+++ b/logger/src/autodep/logfs/fstracer.py
@@ -199,11 +199,12 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 			  #print "!"+"%d"%len(record)+"?"
 			  #print "datalen: %d" % len(data)
 			  message=record.split("\0")
-			  
+			  #print message
 			  
 			  try:
 				if message[4]=="ASKING":
 				  if filterproc(message[1],message[2],message[3]):
+					#print "Allowing an access to %s" % message[2]
 					s.sendall("ALLOW\n"); # TODO: think about flush here
 					
 				  else:
@@ -212,7 +213,8 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
 					
 				else:
 				  eventname,filename,stage,result=message[1:5]
-				  #print message;
+				  #if stage != "unknown":
+				  
 
 				  if not stage in events:
 					events[stage]=[{},{}]

diff --git a/logger/src/autodep/logfs/logger_fusefs.py b/logger/src/autodep/logfs/logger_fusefs.py
index c8d417d..9990ef9 100644
--- a/logger/src/autodep/logfs/logger_fusefs.py
+++ b/logger/src/autodep/logfs/logger_fusefs.py
@@ -21,7 +21,7 @@ class logger:
 
 	self.socketname=socketname
 	self.currpid=os.getpid()
-	
+
 	if accuracy==False:
 	  self.mountlist=self.mountlist+["/lib64/", "/lib32/","/var/tmp/portage/"]
 	
@@ -84,7 +84,7 @@ class logger:
 	if self.currpid!=os.getpid():
 	  print "Detected an attempt to execute execproc in other thread"
 	  sys.exit(1)
-	  
+
 	pid=os.fork()
 	if pid==0:
 	  try:
@@ -93,6 +93,7 @@ class logger:
 		os.chdir(cwd)
 		
 		env=os.environ.copy()
+		env["LOGGER_PROCESS_IS_INTERNAL"]="YES"
 
 		os.execvpe(prog_name, arguments, env)
 		sys.exit(1)

diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hookfs.c
index 6456bef..89c899a 100644
--- a/logger/src/hook_fusefs/hookfs.c
+++ b/logger/src/hook_fusefs/hookfs.c
@@ -46,6 +46,8 @@
 #define MAXSOCKETPATHLEN 108
 #define MAXFILEBUFFLEN 2048
 
+#define MAXSTAGELEN 20
+
 #define IOBUFSIZE 65536
 
 
@@ -72,6 +74,8 @@ char *stagenames[]={
 };
 int stagenameslength=sizeof(stagenames)/sizeof(char *);
 
+static void log_event(const char*, const char*, char *,int , char* );
+
 /*
  * Get a pid of the parent proccess
  * Parse the /proc/pid/stat
@@ -115,54 +119,91 @@ pid_t getparentpid(pid_t pid){
 }
 
 /*
- * Get a stage of building
+ * Get an environment variable of remote process
+ * result is an output arg(can be NULL)
 */
-static char * getstagebypid(pid_t pid, pid_t toppid) {
-  pid_t currpid;
-  for(currpid=getparentpid(pid); currpid!=0 && currpid!=1 && currpid!=toppid;currpid=getparentpid(currpid)) {
-	char filename[MAXPATHLEN];
-	snprintf(filename,MAXPATHLEN, "/proc/%d/cmdline",pid);
-	FILE *cmdline_file_handle=fopen(filename,"r");
-	
-	if(cmdline_file_handle==NULL)
-	  return "unknown";
-	
-	char read_buffer[MAXFILEBUFFLEN];
-	int readed;
-	readed=fread(read_buffer,sizeof(char),MAXFILEBUFFLEN,cmdline_file_handle);
+static int getenv_by_pid(pid_t pid, char *envname,char *result,int result_len) {
+  char filename[MAXPATHLEN];
+  snprintf(filename,MAXPATHLEN, "/proc/%d/environ",pid);
+  FILE *environ_file_handle=fopen(filename,"r");
+
+  if(environ_file_handle==NULL)
+	return 0;
+
+  char filebuff[IOBUFSIZE];
+  
+  int automata_state=0;
+  int offset;
+  int envname_len=strlen(envname);
+
+  for(;;) {
+	int readed=fread(filebuff,1,IOBUFSIZE,environ_file_handle);
 	
-	fclose(cmdline_file_handle);  
-
-	int off;
-	int null_bytes_num=0;
-	char *stage_name;
-	// small automata here. For readabilyity it is not in classic form
-	for(off=0;off<readed;off++) {
-		if(read_buffer[off]==0){
-		  null_bytes_num++;
-		  if(null_bytes_num==2) {
-			if(read_buffer+off-9<read_buffer) // 9 is a "ebuild.sh" string length
-			  break;
-			if(strcmp(read_buffer+off-9,"ebuild.sh")!=0)
-			  break;
-			stage_name=read_buffer+off+1;	
-		  } else if(null_bytes_num==3) {
-			// ugly, but memory allocation is not better
-			// there is better way to write this
-			int i;
-			for(i=0; i<stagenameslength;i++) {
-			  if(strcmp(stage_name,stagenames[i])==0)
-				return stagenames[i];
-			}
+	for(offset=0; offset<readed; offset++) {
+	  char c=filebuff[offset];
+
+	  if(automata_state<envname_len) {
+		if(c==0) { automata_state=0;}
+		else if(automata_state==-1) continue;
+		else if(c==envname[automata_state]) automata_state++;
+		else automata_state=-1;	  
+	  } else if(automata_state==envname_len) {
+		if(result==NULL) {
+		  fclose(environ_file_handle);
+		  return 1;
+		}
+		if(c=='=') automata_state++;
+		else automata_state=-1;	
+	  } else if(automata_state>envname_len){
+		int result_off=automata_state-1-envname_len;
+		if(result_off>=result_len) {
+		  result[result_len-1]=0; // force last byte to be 0
+		  fclose(environ_file_handle);
+		  return 1;		  
+		} else {
+		  result[result_off]=c;
+		  if(c==0) {
+			fclose(environ_file_handle);
+			return 1;		  			
 		  }
+		  automata_state++;
 		}
+	  }
 	}
+	if(feof(environ_file_handle))
+	  break;
+  }
+  fclose(environ_file_handle);
+  return 0;
+}
+
+/*
+ * Get a stage of building
+*/
+static char * getstagebypid(pid_t pid) {
+  char stage[MAXSTAGELEN];
+  if(!getenv_by_pid(getparentpid(pid),"EBUILD_PHASE",stage,MAXSTAGELEN))
+	return "unknown";
+
+  // ugly, but memory allocation is not better
+  // there is better way to write this, but this is fast
+  int i;
+  for(i=0; i<stagenameslength;i++) {
+	if(strcmp(stage,stagenames[i])==0)
+	  return stagenames[i];
   }
   
   return "unknown";
 }
 
 /*
+ * Check environment variable for process
+*/
+static int is_process_has_env(pid_t pid, char *envname) {
+  return getenv_by_pid(pid,envname,NULL,0);
+}
+
+/*
  * This is here because launching of a task is very slow without it
  */
 static int is_file_excluded(const char *filename) {
@@ -180,11 +221,18 @@ static int is_file_excluded(const char *filename) {
   return 0;
 }
 
+
 /*
  * Check external access - for example user's access to mount
 */ 
 static int is_process_external(pid_t pid) {
-  if(pid==1 || getparentpid(pid)==1)
+  pid_t ppid=getparentpid(pid);
+  if(pid==1 || ppid==1 || ppid==parent_pid)
+	return 0;
+
+  // ppid is here to bypass a deadlock on several kernels
+  // while trying to see environ but process is not executed yet
+  if( is_process_has_env(ppid,"LOGGER_PROCESS_IS_INTERNAL"))
 	return 0;
   
   for(;pid!=0;pid=getparentpid(pid))
@@ -270,7 +318,7 @@ static void give_to_creator_path(const char *path) {
 static int hookfs_getattr(const char *path, struct stat *stbuf)
 {
   	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 	
 	if(! is_event_allowed("stat",path,context->pid,stage)) {
 	  errno=2; // not found
@@ -303,7 +351,7 @@ static int hookfs_fgetattr(const char *path, struct stat *stbuf,
 	int res;
 
   	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	if(! is_event_allowed("stat",path,context->pid,stage)) {
 	  errno=2; // not found
@@ -599,7 +647,7 @@ static int hookfs_chown(const char *path, uid_t uid, gid_t gid)
 static int hookfs_truncate(const char *path, off_t size)
 {
 	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	char * rel_path = malloc_relative_path(path);
 	if (! rel_path) {
@@ -624,7 +672,7 @@ static int hookfs_ftruncate(const char *path, off_t size,
 	int res;
 
 	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	res = ftruncate(fi->fh, size);
 
@@ -640,20 +688,14 @@ static int hookfs_ftruncate(const char *path, off_t size,
 static int hookfs_utimens(const char *path, const struct timespec ts[2])
 {
 	int res;
-	struct timeval tv[2];
 	char * rel_path = NULL;
 
-	tv[0].tv_sec = ts[0].tv_sec;
-	tv[0].tv_usec = ts[0].tv_nsec / 1000;
-	tv[1].tv_sec = ts[1].tv_sec;
-	tv[1].tv_usec = ts[1].tv_nsec / 1000;
-
 	rel_path = malloc_relative_path(path);
 	if (! rel_path) {
 		return -errno;
 	}
 
-	res = utimes(rel_path, tv);
+	res = utimensat(AT_FDCWD,rel_path, ts, AT_SYMLINK_NOFOLLOW);
 	free(rel_path);
 	if (res == -1)
 		return -errno;
@@ -689,7 +731,7 @@ static int open_safely(const char *rel_path, int flags, mode_t mode) {
 static int hookfs_create(const char *path, mode_t mode, struct fuse_file_info *fi)
 {
 	struct fuse_context * context = fuse_get_context();
-  	char *stage=getstagebypid(context->pid,parent_pid);
+  	char *stage=getstagebypid(context->pid);
 
 	if(! is_event_allowed("create",path,context->pid,stage)) {
 	  errno=2; // not found
@@ -723,7 +765,7 @@ static int hookfs_open(const char *path, struct fuse_file_info *fi)
 	char * rel_path = NULL;
 
 	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	if(! is_event_allowed("open",path,context->pid,stage)) {
 	  errno=2; // not found
@@ -756,7 +798,7 @@ static int hookfs_read(const char *path, char *buf, size_t size, off_t offset,
 	int res;
 
 	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	res = pread(fi->fh, buf, size, offset);
 	if (res == -1) {
@@ -774,7 +816,7 @@ static int hookfs_write(const char *path, const char *buf, size_t size,
 	int res;
 
 	struct fuse_context * context = fuse_get_context();
-	char *stage=getstagebypid(context->pid,parent_pid);
+	char *stage=getstagebypid(context->pid);
 
 	res = pwrite(fi->fh, buf, size, offset);
 	if (res == -1) {



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-24 20:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-08 16:48 [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/ Александр Берсенев
  -- strict thread matches above, loose matches on Subject: below --
2011-06-18  8:27 Александр Берсенев
2011-06-18 10:00 Александр Берсенев
2011-06-24 20:17 Александр Берсенев

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox