2 * --- T2-COPYRIGHT-NOTE-BEGIN ---
3 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 * T2 SDE: misc/tools-source/fl_stparse.c
6 * Copyright (C) 2004 - 2005 The T2 SDE Project
7 * Copyright (C) 1998 - 2003 ROCK Linux Project
9 * More information can be found in the files COPYING and README.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License. A copy of the
14 * GNU General Public License can be found in the file COPYING.
15 * --- T2-COPYRIGHT-NOTE-END ---
32 void newproc(int pid
, char * cwd
) {
34 for (c
=0; c
<MAXPROCS
; c
++)
35 if (procs
[c
].pid
== 0) {
41 fprintf(stderr
, "fl_stparse: No more free procs in list!\n");
45 struct procs_t
* getproc(int pid
) {
47 for (c
=0; c
<MAXPROCS
; c
++)
48 if (procs
[c
].pid
== pid
) {
52 fprintf(stderr
, "fl_stparse: Can't find proc %d!\n", pid
);
56 void setproc(int pid
, char * cwd
) {
58 for (c
=0; c
<MAXPROCS
; c
++)
59 if (procs
[c
].pid
== pid
) {
65 fprintf(stderr
, "fl_stparse: Can't set proc %d!\n", pid
);
69 void freeproc(int pid
) {
71 for (c
=0; c
<MAXPROCS
; c
++)
72 if (procs
[c
].pid
== pid
) {
79 fprintf(stderr
, "fl_stparse: Can't free proc %d!\n", pid
);
83 int main(int argc
, char ** argv
) {
90 FILE *wlog
= fopen("/dev/null", "w");
91 FILE *rlog
= fopen("/dev/null", "w");
95 while ( (opt
= getopt(argc
, argv
, "w:r:")) != -1 ) {
99 wlog
= fopen(optarg
, "w");
104 rlog
= fopen(optarg
, "w");
108 fprintf(stderr
, "Usage: %s [-w wlog-file] "
109 "[-r rlog-file]\n", argv
[0]);
114 if (fgets(line
, 1024, stdin
) &&
115 sscanf(line
, "%d", &pid
) == 1 ) {
116 newproc(pid
, getcwd((char *) NULL
, 0) );
118 fprintf(stderr
, "fl_stparse: Can't init using first line "
125 if ( sscanf(line
, "%d fork() = %d", &pid
, &newpid
) == 2 ||
126 sscanf(line
, "%d vfork() = %d", &pid
, &newpid
) == 2 ||
127 sscanf(line
, "%d <... fork resumed> ) = %d",
128 &pid
, &newpid
) == 2 ||
129 sscanf(line
, "%d <... vfork resumed> ) = %d",
130 &pid
, &newpid
) == 2) {
131 sp1
= getproc(pid
)->cwd
;
132 sp2
= malloc( strlen(sp1
) + 1);
134 newproc(newpid
, sp2
);
138 if ( sscanf(line
, "%d _exit(%d", &pid
, &newpid
) == 2 ||
139 sscanf(line
, "%d exit_group(%d", &pid
, &newpid
) == 2 ) {
144 if ( sscanf(line
, "%d chdir(\"%[^\"]", &pid
, buf1
) == 2 ) {
145 chdir( getproc(pid
)->cwd
); chdir( buf1
);
146 setproc(pid
, getcwd((char *) NULL
, 0) );
150 if ( sscanf(line
, "%d open(\"%[^\"]\", %s",
151 &pid
, buf1
, buf2
) == 3 ) {
153 if (strstr(buf2
, "O_RDONLY") == NULL
) logfile
= wlog
;
156 if (strstr(buf2
, "O_DIRECTORY") != NULL
) continue;
158 if (buf1
[0] == '/') {
159 fprintf(logfile
, "%d: %s\n", pid
, buf1
);
161 sp1
= getproc(pid
)->cwd
;
162 if (!strcmp(sp1
, "/")) sp1
="";
163 fprintf(logfile
, "%d: %s/%s\n",
169 if ( sscanf(line
, "%d mkdir(\"%[^\"]\", ", &pid
, buf1
) == 2 ||
170 sscanf(line
, "%d utime(\"%[^\"]\", ", &pid
, buf1
) == 2 ||
171 sscanf(line
, "%d link(\"%[^\"]\", \"%[^\"]\"",
172 &pid
, buf2
, buf1
) == 3 ||
173 sscanf(line
, "%d symlink(\"%[^\"]\", \"%[^\"]\"",
174 &pid
, buf2
, buf1
) == 3 ||
175 sscanf(line
, "%d rename(\"%[^\"]\", \"%[^\"]\"",
176 &pid
, buf2
, buf1
) == 3 ) {
177 if (buf1
[0] == '/') {
178 fprintf(wlog
, "%d: %s\n", pid
, buf1
);
180 sp1
= getproc(pid
)->cwd
;
181 if (!strcmp(sp1
, "/")) sp1
="";
182 fprintf(wlog
, "%d: %s/%s\n",
188 } while (fgets(line
, 1024, stdin
) != NULL
);