From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QaCoj-0004vA-FL for garchives@archives.gentoo.org; Fri, 24 Jun 2011 20:17:29 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 622841C01D; Fri, 24 Jun 2011 20:17:12 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 072F31C01D for ; Fri, 24 Jun 2011 20:17:11 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7E6B41B401D for ; Fri, 24 Jun 2011 20:17:10 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id DAD428003C for ; Fri, 24 Jun 2011 20:17:09 +0000 (UTC) From: "Александр Берсенев" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Александр Берсенев" Message-ID: Subject: [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/hook_fusefs/ X-VCS-Repository: proj/autodep X-VCS-Files: logger/src/autodep/logfs/fstracer.py logger/src/autodep/logfs/logger_fusefs.py logger/src/hook_fusefs/hookfs.c X-VCS-Directories: logger/src/autodep/logfs/ logger/src/hook_fusefs/ X-VCS-Committer: bay X-VCS-Committer-Name: Александр Берсенев X-VCS-Revision: d01cf77441dc9560b1b90b73d7df89e9423b4ef5 Date: Fri, 24 Jun 2011 20:17:09 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: e37ac550c8090675358c6cbd0f322c22 commit: d01cf77441dc9560b1b90b73d7df89e9423b4ef5 Author: Alexander Bersenev hackerdom ru> AuthorDate: Sat Jun 25 02:16:42 2011 +0000 Commit: =D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80 =D0=91= =D0=B5=D1=80=D1=81=D0=B5=D0=BD=D0=B5=D0=B2 hackerdom ru> CommitDate: Sat Jun 25 02:16:42 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/autodep.git;a= =3Dcommit;h=3Dd01cf774 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/lo= gfs/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=3D"hoo= klib",filterproc=3Ddefaultfilter) #print "!"+"%d"%len(record)+"?" #print "datalen: %d" % len(data) message=3Drecord.split("\0") - =20 + #print message =20 try: if message[4]=3D=3D"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 =09 else: @@ -212,7 +213,8 @@ def getfsevents(prog_name,arguments,approach=3D"hookl= ib",filterproc=3Ddefaultfilter) =09 else: eventname,filename,stage,result=3Dmessage[1:5] - #print message; + #if stage !=3D "unknown": + =20 =20 if not stage in events: events[stage]=3D[{},{}] diff --git a/logger/src/autodep/logfs/logger_fusefs.py b/logger/src/autod= ep/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: =20 self.socketname=3Dsocketname self.currpid=3Dos.getpid() -=09 + if accuracy=3D=3DFalse: self.mountlist=3Dself.mountlist+["/lib64/", "/lib32/","/var/tmp/porta= ge/"] =09 @@ -84,7 +84,7 @@ class logger: if self.currpid!=3Dos.getpid(): print "Detected an attempt to execute execproc in other thread" sys.exit(1) - =20 + pid=3Dos.fork() if pid=3D=3D0: try: @@ -93,6 +93,7 @@ class logger: os.chdir(cwd) =09 env=3Dos.environ.copy() + env["LOGGER_PROCESS_IS_INTERNAL"]=3D"YES" =20 os.execvpe(prog_name, arguments, env) sys.exit(1) diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hoo= kfs.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 =20 +#define MAXSTAGELEN 20 + #define IOBUFSIZE 65536 =20 =20 @@ -72,6 +74,8 @@ char *stagenames[]=3D{ }; int stagenameslength=3Dsizeof(stagenames)/sizeof(char *); =20 +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){ } =20 /* - * 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=3Dgetparentpid(pid); currpid!=3D0 && currpid!=3D1 && currp= id!=3Dtoppid;currpid=3Dgetparentpid(currpid)) { - char filename[MAXPATHLEN]; - snprintf(filename,MAXPATHLEN, "/proc/%d/cmdline",pid); - FILE *cmdline_file_handle=3Dfopen(filename,"r"); -=09 - if(cmdline_file_handle=3D=3DNULL) - return "unknown"; -=09 - char read_buffer[MAXFILEBUFFLEN]; - int readed; - readed=3Dfread(read_buffer,sizeof(char),MAXFILEBUFFLEN,cmdline_file_han= dle); +static int getenv_by_pid(pid_t pid, char *envname,char *result,int resul= t_len) { + char filename[MAXPATHLEN]; + snprintf(filename,MAXPATHLEN, "/proc/%d/environ",pid); + FILE *environ_file_handle=3Dfopen(filename,"r"); + + if(environ_file_handle=3D=3DNULL) + return 0; + + char filebuff[IOBUFSIZE]; + =20 + int automata_state=3D0; + int offset; + int envname_len=3Dstrlen(envname); + + for(;;) { + int readed=3Dfread(filebuff,1,IOBUFSIZE,environ_file_handle); =09 - fclose(cmdline_file_handle); =20 - - int off; - int null_bytes_num=3D0; - char *stage_name; - // small automata here. For readabilyity it is not in classic form - for(off=3D0;offenvname_len){ + int result_off=3Dautomata_state-1-envname_len; + if(result_off>=3Dresult_len) { + result[result_len-1]=3D0; // force last byte to be 0 + fclose(environ_file_handle); + return 1; =20 + } else { + result[result_off]=3Dc; + if(c=3D=3D0) { + fclose(environ_file_handle); + return 1; =09 } + 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=3D0; ipid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =09 if(! is_event_allowed("stat",path,context->pid,stage)) { errno=3D2; // not found @@ -303,7 +351,7 @@ static int hookfs_fgetattr(const char *path, struct s= tat *stbuf, int res; =20 struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 if(! is_event_allowed("stat",path,context->pid,stage)) { errno=3D2; // 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 =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 char * rel_path =3D malloc_relative_path(path); if (! rel_path) { @@ -624,7 +672,7 @@ static int hookfs_ftruncate(const char *path, off_t s= ize, int res; =20 struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 res =3D ftruncate(fi->fh, size); =20 @@ -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 =3D NULL; =20 - tv[0].tv_sec =3D ts[0].tv_sec; - tv[0].tv_usec =3D ts[0].tv_nsec / 1000; - tv[1].tv_sec =3D ts[1].tv_sec; - tv[1].tv_usec =3D ts[1].tv_nsec / 1000; - rel_path =3D malloc_relative_path(path); if (! rel_path) { return -errno; } =20 - res =3D utimes(rel_path, tv); + res =3D utimensat(AT_FDCWD,rel_path, ts, AT_SYMLINK_NOFOLLOW); free(rel_path); if (res =3D=3D -1) return -errno; @@ -689,7 +731,7 @@ static int open_safely(const char *rel_path, int flag= s, mode_t mode) { static int hookfs_create(const char *path, mode_t mode, struct fuse_file= _info *fi) { struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 if(! is_event_allowed("create",path,context->pid,stage)) { errno=3D2; // not found @@ -723,7 +765,7 @@ static int hookfs_open(const char *path, struct fuse_= file_info *fi) char * rel_path =3D NULL; =20 struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 if(! is_event_allowed("open",path,context->pid,stage)) { errno=3D2; // not found @@ -756,7 +798,7 @@ static int hookfs_read(const char *path, char *buf, s= ize_t size, off_t offset, int res; =20 struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 res =3D pread(fi->fh, buf, size, offset); if (res =3D=3D -1) { @@ -774,7 +816,7 @@ static int hookfs_write(const char *path, const char = *buf, size_t size, int res; =20 struct fuse_context * context =3D fuse_get_context(); - char *stage=3Dgetstagebypid(context->pid,parent_pid); + char *stage=3Dgetstagebypid(context->pid); =20 res =3D pwrite(fi->fh, buf, size, offset); if (res =3D=3D -1) {