Gentoo Archives: gentoo-commits

From: "Александр Берсенев" <bay@×××××××××.ru>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/autodep:master commit in: logger/src/autodep/logfs/, logger/src/autodep/, logger/src/hook_lib/
Date: Sun, 03 Jul 2011 19:40:57
Message-Id: a1d60fa6ca3bf5fc264b68d88e6769bf35f7a51e.bay@gentoo
1 commit: a1d60fa6ca3bf5fc264b68d88e6769bf35f7a51e
2 Author: Alexander Bersenev <bay <AT> hackerdom <DOT> ru>
3 AuthorDate: Sun Jul 3 19:40:37 2011 +0000
4 Commit: Александр Берсенев <bay <AT> hackerdom <DOT> ru>
5 CommitDate: Sun Jul 3 19:40:37 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/autodep.git;a=commit;h=a1d60fa6
7
8 work with usersandbox feature, futher work for outout
9
10 ---
11 logger/src/autodep/logfs/__init__.pyc | Bin 138 -> 0 bytes
12 logger/src/autodep/logfs/fstracer.py | 5 +++--
13 logger/src/autodep/showfsevents.py | 33 ++++++++++++++++++++++++---------
14 logger/src/hook_lib/file_hook.c | 27 ++++++++++++++++++++-------
15 4 files changed, 47 insertions(+), 18 deletions(-)
16
17 diff --git a/logger/src/autodep/logfs/__init__.pyc b/logger/src/autodep/logfs/__init__.pyc
18 deleted file mode 100644
19 index ae3151f..0000000
20 Binary files a/logger/src/autodep/logfs/__init__.pyc and /dev/null differ
21
22 diff --git a/logger/src/autodep/logfs/fstracer.py b/logger/src/autodep/logfs/fstracer.py
23 index 66b1de3..c724b61 100644
24 --- a/logger/src/autodep/logfs/fstracer.py
25 +++ b/logger/src/autodep/logfs/fstracer.py
26 @@ -74,7 +74,7 @@ def getparentpid(pid):
27 if match==None:
28 print "Failed to get parent process. Format of /proc/<pid>/stat is incorrect. Did you change a kernel?"
29 return 1
30 -
31 +
32 return int(match.group(1))
33
34 except IOError,e:
35 @@ -200,9 +200,10 @@ def getfsevents(prog_name,arguments,approach="hooklib",filterproc=defaultfilter)
36 continue
37
38 message=record.split("\0")
39 - #if message[3]!="unknown":
40 + #if message[3]=="compile": #and message[1]=="debug":
41 #print message
42
43 +
44 try:
45 if message[4]=="ASKING":
46 if filterproc(message[1],message[2],message[3]):
47
48 diff --git a/logger/src/autodep/showfsevents.py b/logger/src/autodep/showfsevents.py
49 index cc4bec6..b738a76 100755
50 --- a/logger/src/autodep/showfsevents.py
51 +++ b/logger/src/autodep/showfsevents.py
52 @@ -9,23 +9,30 @@ import logfs.fstracer
53 import logfs.portage_utils
54
55 args_parser=optparse.OptionParser("%prog [options] <command>")
56 +args_parser.add_option("-b", "--block",action="store", type="string",
57 + dest="packages", default="", help="block an access to files from this packages")
58 args_parser.add_option("-v", action="store_true", dest="verbose",
59 default=False, help="show accessed files")
60 args_parser.add_option("-u", "--unknown", action="store_true", dest="show_unknown_stage",
61 default=False, help="show unknown stage")
62 -args_parser.add_option("-b", "--block",action="store", type="string",
63 - dest="packages", default="", help="block an access to files from this packages")
64 +
65 +args_parser.add_option("--hooklib",action="store_const", dest="approach",
66 + const="hooklib", help="use ld_preload logging approach(default)")
67 +args_parser.add_option("--fusefs",action="store_const", dest="approach",
68 + const="fusefs", help="use fuse logging approach(slow, but reliable)")
69 +args_parser.set_defaults(approach="hooklib")
70 +
71 args_parser.epilog="Example: %s -b lsof,cowsay emerge bash" % (os.path.basename(sys.argv[0]))
72
73 args_parser.disable_interspersed_args()
74
75 (options, args) = args_parser.parse_args()
76 +#print options
77 +#print args
78
79 if len(args)==0:
80 args_parser.print_help()
81 exit(1)
82 -#print args
83 -#print options
84
85 filter_function=lambda eventname,filename,stage: True
86
87 @@ -45,7 +52,7 @@ if options.packages:
88 return not filename in files_to_block
89 filter_function=filter
90
91 -events=logfs.fstracer.getfsevents(args[0], args,approach="fusefs",filterproc=filter_function)
92 +events=logfs.fstracer.getfsevents(args[0], args,approach=options.approach,filterproc=filter_function)
93 print "Program finished, analyzing dependencies"
94
95 # get unique filenames
96 @@ -114,7 +121,15 @@ for stage in sorted(events):
97 filesinfo[filename]["notfound"]=fail_events[filename]
98
99 #print events_converted_for_output
100 -
101 +
102 +# explicit check for launching with non-emerge application
103 +was_emerge_process=False
104 +for package in packagesinfo:
105 + if len(packagesinfo[package].keys())>1:
106 + was_emerge_process=True
107 + break
108 +
109 +# generating output
110 stagesorder={"clean":1,"setup":2,"unpack":3,"prepare":4,"configure":5,"compile":6,"test":7,
111 "install":8,"preinst":9,"postinst":10,"prerm":11,"postrm":12,"unknown":13}
112
113 @@ -126,7 +141,7 @@ for package in sorted(packagesinfo):
114
115 stages=[]
116 for stage in sorted(packagesinfo[package].keys(), key=stagesorder.get):
117 - if stage!="unknown" or options.show_unknown_stage:
118 + if stage!="unknown" or options.show_unknown_stage or not was_emerge_process:
119 stages.append(stage)
120
121 if len(stages)!=0:
122 @@ -159,7 +174,7 @@ for package in sorted(packagesinfo):
123
124 """
125 for stage in sorted(events, key=stagesorder.get):
126 - succ_events=events[stage][0]-
127 + succ_events=events[stage][0]
128 fail_events=events[stage][1]
129 print "On stage %s:" % stage
130 for filename in sorted(succ_events, key=file_to_package.get):
131 @@ -195,4 +210,4 @@ for stage in sorted(events, key=stagesorder.get):
132 print file_to_package[filename],
133 print
134 """
135 -##logfs.fstracer.getfsevents("emerge", ["emerge","--info"])
136 \ No newline at end of file
137 +##logfs.fstracer.getfsevents("emerge", ["emerge","--info"])
138
139 diff --git a/logger/src/hook_lib/file_hook.c b/logger/src/hook_lib/file_hook.c
140 index 4ad6b97..9012b20 100644
141 --- a/logger/src/hook_lib/file_hook.c
142 +++ b/logger/src/hook_lib/file_hook.c
143 @@ -53,6 +53,7 @@ int (*_close)(int fd); // we hooking this, because some programs closes our sock
144 int log_socket=-1;
145
146 char log_socket_name[MAXSOCKETPATHLEN];
147 +char ld_preload_orig[MAXPATHLEN];
148
149 void __doconnect(){
150 if(strlen(log_socket_name)>=MAXSOCKETPATHLEN) {
151 @@ -104,8 +105,16 @@ void _init() {
152 fprintf(stderr,"Unable to create a unix-socket %s: socket name is too long,exiting\n", log_socket_name);
153 exit(1);
154 }
155 +
156 strcpy(log_socket_name,log_socket_env);
157
158 + if(getenv("LD_PRELOAD")==NULL) {
159 + fprintf(stderr,"Unable to find LD_PRELOAD environment variable. "
160 + "Library will load only with this variable defined");
161 + exit(1);
162 + }
163 +
164 + strcpy(ld_preload_orig,getenv("LD_PRELOAD"));
165
166 _open = (int (*)(const char * pathname, int flags, ...)) dlsym(RTLD_NEXT, "open");
167 _open64 = (int (*)(const char * pathname, int flags, ...)) dlsym(RTLD_NEXT, "open64");
168 @@ -247,8 +256,8 @@ int open(const char * path, int flags, mode_t mode) {
169 realpath(path,fullpath);
170 char *stage=__get_stage();
171 if(! __is_event_allowed("open",fullpath,stage)) {
172 - errno=2; // not found
173 __log_event("open",fullpath,"DENIED",errno,stage);
174 + errno=2; // not found
175 return -1;
176 }
177
178 @@ -270,8 +279,8 @@ int open64(const char * path, int flags, mode_t mode) {
179 realpath(path,fullpath);
180 char *stage=__get_stage();
181 if(! __is_event_allowed("open",fullpath,stage)) {
182 - errno=2; // not found
183 __log_event("open",path,"DENIED",errno,stage);
184 + errno=2; // not found
185 return -1;
186 }
187
188 @@ -294,8 +303,8 @@ FILE *fopen(const char *path, const char *mode) {
189
190 char *stage=__get_stage();
191 if(! __is_event_allowed("open",fullpath,stage)) {
192 - errno=2; // not found
193 __log_event("open",path,"DENIED",errno,stage);
194 + errno=2; // not found
195 return NULL;
196 }
197
198 @@ -316,8 +325,8 @@ FILE *fopen64(const char *path, const char *mode) {
199
200 char *stage=__get_stage();
201 if(! __is_event_allowed("open",fullpath,stage)) {
202 - errno=2; // not found
203 __log_event("open",fullpath,"DENIED",errno,stage);
204 + errno=2; // not found
205 return NULL;
206 }
207
208 @@ -346,6 +355,9 @@ ssize_t read(int fd, void *buf, size_t count){
209 else
210 __log_event("read",fullpath,"OK",0,stage);
211 }
212 +
213 + //__log_event("debug",fullpath,"ERR",getpid(),stage);
214 +
215 errno=saved_errno;
216 return ret;
217 }
218 @@ -372,7 +384,8 @@ pid_t fork(void) {
219
220 //int succ=
221 _setenv("LOG_SOCKET",log_socket_name,1);
222 -
223 + _setenv("LD_PRELOAD",ld_preload_orig,1);
224 + //ld_preload_orig
225 //fprintf(stderr,"prefork %s%p%p%d %s\n",getenv("LOG_SOCKET"),_setenv,setenv,succ,log_socket_orig);
226
227 int ret=_fork();
228 @@ -407,14 +420,14 @@ int execve(const char *filename, char *const argv[],
229 int i;
230 for(i=0;envp[i];i++){
231 if(strncmp(envp[i],"LD_PRELOAD=",11)==0)
232 - if(strcmp(envp[i]+11,getenv("LD_PRELOAD"))==0)
233 + if(strcmp(envp[i]+11,ld_preload_orig)==0)
234 ld_preload_valid=1;
235 if(strncmp(envp[i],"LOG_SOCKET=",11)==0)
236 if(strcmp(envp[i]+11,log_socket_name)==0)
237 log_socket_valid=1;
238 }
239 if(!ld_preload_valid || !log_socket_valid) {
240 - snprintf(new_ld_preload,MAXENVITEMSIZE,"LD_PRELOAD=%s",getenv("LD_PRELOAD"));
241 + snprintf(new_ld_preload,MAXENVITEMSIZE,"LD_PRELOAD=%s",ld_preload_orig);
242 snprintf(new_log_socket,MAXENVITEMSIZE,"LOG_SOCKET=%s",log_socket_name);
243 for(i=0; envp[i] && i<MAXENVSIZE-3; i++) {
244 if(strncmp(envp[i],"LD_PRELOAD=",11)==0) {