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 1QUMgq-0004ME-P2 for garchives@archives.gentoo.org; Wed, 08 Jun 2011 17:37:13 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8F7781C1CF; Wed, 8 Jun 2011 17:37:00 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 4EEFB1C1CF for ; Wed, 8 Jun 2011 17:37:00 +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 886021B4031 for ; Wed, 8 Jun 2011 17:36:59 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 00AE98003C for ; Wed, 8 Jun 2011 17:36:59 +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: <9275b79dab7f4856352cf0ab7830915c6930f7d1.bay@gentoo> Subject: [gentoo-commits] proj/autodep:master commit in: logger/src/hook_fusefs/ X-VCS-Repository: proj/autodep X-VCS-Files: logger/src/hook_fusefs/hookfs.c X-VCS-Directories: logger/src/hook_fusefs/ X-VCS-Committer: bay X-VCS-Committer-Name: Александр Берсенев X-VCS-Revision: 9275b79dab7f4856352cf0ab7830915c6930f7d1 Date: Wed, 8 Jun 2011 17:36:59 +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: d18cf181bf149d01780aee1931acbfe2 commit: 9275b79dab7f4856352cf0ab7830915c6930f7d1 Author: Alexander Bersenev hackerdom ru> AuthorDate: Wed Jun 8 23:36:34 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: Wed Jun 8 23:36:34 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/autodep.git;a= =3Dcommit;h=3D9275b79d better logging system. Finalize format of logs --- logger/src/hook_fusefs/hookfs.c | 158 +++++++++++++++++----------------= ------ 1 files changed, 70 insertions(+), 88 deletions(-) diff --git a/logger/src/hook_fusefs/hookfs.c b/logger/src/hook_fusefs/hoo= kfs.c index af3e97a..16b9a46 100644 --- a/logger/src/hook_fusefs/hookfs.c +++ b/logger/src/hook_fusefs/hookfs.c @@ -80,20 +80,24 @@ 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 *resul= t, int err, pid_t pid) { +void log_event(const char *event_type, const char *filename, char *resul= t,int err, pid_t pid) { pthread_mutex_lock( &socketblock ); =20 - =20 fprintf(log_file,"%lld ",(unsigned long long)time(NULL)); =20 __print_escaped(log_file, event_type); fprintf(log_file," "); __print_escaped(log_file, filename); - fprintf(log_file," %d %s\n", pid, result); + =20 + fprintf(log_file," %d ", pid); + if(strcmp(result,"ERR")=3D=3D0) + fprintf(log_file,"%s/%d",result,err); + else + fprintf(log_file,"%s",result); + fprintf(log_file,"\n"); fflush(log_file); =20 pthread_mutex_unlock( &socketblock ); - } =20 /* @@ -118,59 +122,6 @@ int is_event_allowed(const char *event_type,const ch= ar *filename, pid_t pid) { return 0; } =20 -static int post_getattr(const char *path, int res) { - struct fuse_context * context =3D fuse_get_context(); - log_event("stat",path,"OK",errno,context->pid); - return 0; -} - -static int post_read(const char *path, int res) { - struct fuse_context * context =3D fuse_get_context(); - log_event("read",path,"OK",errno,context->pid); - return 0; -} - -static int post_write(const char *path, int res) { - struct fuse_context * context =3D fuse_get_context(); - log_event("write",path,"OK",errno,context->pid); - return 0; -} - -static int post_open(const char *path, int fd) { - struct fuse_context * context =3D fuse_get_context(); - log_event("open",path,"OK",errno,context->pid); - return 0; -} - -static int post_truncate(const char *path, int res) { - struct fuse_context * context =3D fuse_get_context(); - log_event("write",path,"OK",errno,context->pid); - return 0; -} - -struct hook_operations { - int (*post_read)(const char *path, int res); - int (*post_write)(const char *path, int res); - int (*post_open)(const char *path, int fd); - //int (*post_rename)(const char *from, const char *to, int res); - int (*post_getattr)(const char *path, int res); - int (*post_truncate)(const char *path, int res); -}; - -static struct hook_operations hooks =3D { - .post_read =3D post_read, - .post_write =3D post_write, - .post_open =3D post_open, - //.post_unlink =3D post_unlink, - //.post_rename =3D post_rename, - .post_getattr =3D post_getattr, - .post_truncate =3D post_truncate, -}; - -#define NOTIFY(function, ...) \ - if (hooks.function) { \ - hooks.function(__VA_ARGS__); \ - } =20 static char * malloc_relative_path(const char *path) { int len =3D strlen(path); @@ -196,6 +147,8 @@ static void give_to_creator_path(const char *path) { =20 static int hookfs_getattr(const char *path, struct stat *stbuf) { + struct fuse_context * context =3D fuse_get_context(); + char * rel_path =3D malloc_relative_path(path); if (! rel_path) { return -errno; @@ -203,11 +156,12 @@ static int hookfs_getattr(const char *path, struct = stat *stbuf) =20 int res =3D lstat(rel_path, stbuf); free(rel_path); - - NOTIFY(post_getattr, path, res); =09 - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("stat",path,"ERR",errno,context->pid); return -errno; + } + log_event("stat",path,"OK",errno,context->pid); =20 return 0; } @@ -217,20 +171,23 @@ static int hookfs_fgetattr(const char *path, struct= stat *stbuf, { int res; =20 - (void) path; + struct fuse_context * context =3D fuse_get_context(); =20 res =3D fstat(fi->fh, stbuf); =09 - NOTIFY(post_getattr, path, res); - - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("stat",path,"ERR",errno,context->pid); return -errno; - + } + log_event("stat",path,"OK",errno,context->pid); +=09 return 0; } =20 static int hookfs_access(const char *path, int mask) { + struct fuse_context * context =3D fuse_get_context(); + char * rel_path =3D malloc_relative_path(path); if (! rel_path) { return -errno; @@ -239,11 +196,12 @@ static int hookfs_access(const char *path, int mask= ) int res =3D access(rel_path, mask); free(rel_path); =09 - NOTIFY(post_getattr, path, res); - - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("stat",path,"ERR",errno,context->pid); return -errno; - + } + log_event("stat",path,"OK",errno,context->pid); +=09 return 0; } =20 @@ -506,6 +464,8 @@ static int hookfs_chown(const char *path, uid_t uid, = gid_t gid) =20 static int hookfs_truncate(const char *path, off_t size) { + struct fuse_context * context =3D fuse_get_context(); + char * rel_path =3D malloc_relative_path(path); if (! rel_path) { return -errno; @@ -514,10 +474,12 @@ static int hookfs_truncate(const char *path, off_t = size) int res =3D truncate(rel_path, size); free(rel_path); =20 - NOTIFY(post_truncate, path, res); - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("write",path,"ERR",errno,context->pid); return -errno; - + } + log_event("write",path,"OK",errno,context->pid); +=09 return 0; } =20 @@ -526,13 +488,15 @@ static int hookfs_ftruncate(const char *path, off_t= size, { int res; =20 - (void) path; + struct fuse_context * context =3D fuse_get_context(); =20 res =3D ftruncate(fi->fh, size); - NOTIFY(post_truncate, path, res); =20 - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("write",path,"ERR",errno,context->pid); return -errno; + } + log_event("write",path,"OK",errno,context->pid); =20 return 0; } @@ -588,16 +552,27 @@ static int open_safely(const char *rel_path, int fl= ags, mode_t mode) { =20 static int hookfs_create(const char *path, mode_t mode, struct fuse_file= _info *fi) { + struct fuse_context * context =3D fuse_get_context(); + =20 + if(! is_event_allowed("create",path,context->pid)) { + errno=3D2; // not found + return -errno; + } + char * rel_path =3D malloc_relative_path(path); +=09 if (! rel_path) { return -errno; } =20 int fd =3D open_safely(rel_path, fi->flags, mode); free(rel_path); - NOTIFY(post_open, path, fd); - if (fd =3D=3D -1) + + if (fd =3D=3D -1) { + log_event("create",path,"ERR",errno,context->pid); return -errno; + }=20 + log_event("create",path,"OK",errno,context->pid); =20 fi->fh =3D fd; return 0; @@ -610,9 +585,8 @@ static int hookfs_open(const char *path, struct fuse_= file_info *fi) =20 struct fuse_context * context =3D fuse_get_context(); =20 -=09 if(! is_event_allowed("open",path,context->pid)) { - errno=3D2; + errno=3D2; // not found return -errno; } =09 @@ -623,11 +597,13 @@ static int hookfs_open(const char *path, struct fus= e_file_info *fi) =20 fd =3D open_safely(rel_path, fi->flags, 0000); free(rel_path); - NOTIFY(post_open, path, fd); =20 - if (fd =3D=3D -1) + if (fd =3D=3D -1) { + log_event("open",path,"ERR",errno,context->pid); return -errno; - + } +=09 + log_event("open",path,"OK",errno,context->pid); fi->fh =3D fd; return 0; } @@ -637,12 +613,15 @@ static int hookfs_read(const char *path, char *buf,= size_t size, off_t offset, { int res; =20 - (void) path; + struct fuse_context * context =3D fuse_get_context(); +=09 res =3D pread(fi->fh, buf, size, offset); - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("read",path,"ERR",errno,context->pid); res =3D -errno; + } =20 - NOTIFY(post_read, path, res); + log_event("read",path,"OK",errno,context->pid); return res; } =20 @@ -651,12 +630,15 @@ static int hookfs_write(const char *path, const cha= r *buf, size_t size, { int res; =20 - (void) path; + struct fuse_context * context =3D fuse_get_context(); + res =3D pwrite(fi->fh, buf, size, offset); - if (res =3D=3D -1) + if (res =3D=3D -1) { + log_event("write",path,"ERR",errno,context->pid); res =3D -errno; + } =20 - NOTIFY(post_write, path, res); + log_event("write",path,"OK",errno,context->pid); =20 return res; }