/[gentoo-src]/rc-scripts/src/awk/cachedepends.awk
Gentoo

Contents of /rc-scripts/src/awk/cachedepends.awk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Fri Apr 16 03:50:21 2004 UTC (16 years, 2 months ago) by agriffis
Branch: MAIN
Changes since 1.15: +69 -58 lines
rc-scripts-1.4.9 -- Fix bug 47111 (severe depcache problems) with tons of help from dswhite42 and the rest of the crew in that bug.  Thanks guys!

1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # Author: Martin Schlemmer <azarah@gentoo.org>
4 # $Header: /home/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.15 2004/02/26 17:29:43 azarah Exp $
5
6 function print_start() {
7 print "source /sbin/functions.sh" >> TMPCACHE
8 print "" >> TMPCACHE
9 print "need() {" >> TMPCACHE
10 print " echo \"NEED $*\"; return 0" >> TMPCACHE
11 print "}" >> TMPCACHE
12 print "" >> TMPCACHE
13 print "use() {" >> TMPCACHE
14 print " echo \"USE $*\"; return 0" >> TMPCACHE
15 print "}" >> TMPCACHE
16 print "" >> TMPCACHE
17 print "before() {" >> TMPCACHE
18 print " echo \"BEFORE $*\"; return 0" >> TMPCACHE
19 print "}" >> TMPCACHE
20 print "" >> TMPCACHE
21 print "after() {" >> TMPCACHE
22 print " echo \"AFTER $*\"; return 0" >> TMPCACHE
23 print "}" >> TMPCACHE
24 print "" >> TMPCACHE
25 print "provide() {" >> TMPCACHE
26 print " echo \"PROVIDE $*\"; return 0" >> TMPCACHE
27 print "}" >> TMPCACHE
28 print "" >> TMPCACHE
29 print "parallel() {" >> TMPCACHE
30 print " echo \"PARALLEL $*\"; return 0" >> TMPCACHE
31 print "}" >> TMPCACHE
32 print "" >> TMPCACHE
33 }
34
35 function print_header1(mtime) {
36 print "#*** " MYFILENAME " ***" >> TMPCACHE
37 print "" >> TMPCACHE
38 print "myservice=\"" MYFILENAME "\"" >> TMPCACHE
39 print "myservice=\"${myservice##*/}\"" >> TMPCACHE
40 print "echo \"RCSCRIPT ${myservice}\"" >> TMPCACHE
41 print "" >> TMPCACHE
42 print "echo \"MTIME " mtime "\"" >> TMPCACHE
43 print "" >> TMPCACHE
44 }
45
46 function print_header2(mtime) {
47 print "(" >> TMPCACHE
48 print " # Get settings for rc-script ..." >> TMPCACHE
49 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> TMPCACHE
50 print "" >> TMPCACHE
51 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> TMPCACHE
52 print "" >> TMPCACHE
53 print " [ -e /etc/conf.d/net ] && \\" >> TMPCACHE
54 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> TMPCACHE
55 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> TMPCACHE
56 print "" >> TMPCACHE
57 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> TMPCACHE
58 print "" >> TMPCACHE
59 print " depend() {" >> TMPCACHE
60 print " return 0" >> TMPCACHE
61 print " }" >> TMPCACHE
62 print "" >> TMPCACHE
63 }
64
65 function print_end() {
66 print "" >> TMPCACHE
67 print " depend" >> TMPCACHE
68 print ")" >> TMPCACHE
69 print "" >> TMPCACHE
70 }
71
72 BEGIN {
73
74 extension("/lib/rcscripts/filefuncs.so", "dlload")
75
76 # Get our environment variables
77 SVCDIR = ENVIRON["SVCDIR"]
78 if (SVCDIR == "") {
79 eerror("Could not get SVCDIR!")
80 exit 1
81 }
82
83 # Since this could be called more than once simultaneously, use a
84 # temporary cache and rename when finished. See bug 47111
85 ("/bin/mktemp "SVCDIR"/depcache.XXXXXXX") | getline TMPCACHE
86 if (TMPCACHE == "") {
87 eerror("Failed to create temporary cache!")
88 exit 1
89 }
90
91 pipe = "ls /etc/init.d/*"
92 while ((pipe | getline tmpstring) > 0)
93 scripts = scripts " " tmpstring
94 close(pipe)
95
96 split(scripts, TMPRCSCRIPTS)
97
98 # Make sure that its a file we are working with,
99 # and do not process scripts, source or backup files.
100 for (x in TMPRCSCRIPTS)
101 if (((isfile(TMPRCSCRIPTS[x])) || (islink(TMPRCSCRIPTS[x]))) &&
102 (TMPRCSCRIPTS[x] !~ /((\.(c|bak))|\~)$/)) {
103
104 RCCOUNT++
105
106 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
107 }
108
109 if (RCCOUNT == 0) {
110 eerror("No scripts to process!")
111 system("rm -f "TMPCACHE)
112 exit 1
113 }
114
115 print_start()
116
117 for (count = 1;count <= RCCOUNT;count++) {
118
119 MYFNR = 1
120 MYFILENAME = RCSCRIPTS[count]
121 STAT_DATA[1] = 1
122
123 while (((getline < (RCSCRIPTS[count])) > 0) && (!NEXTFILE)) {
124
125 # If line start with a '#' and is the first line
126 if (($0 ~ /^[[:space:]]*#/) && (MYFNR == 1)) {
127
128 # Remove any spaces and tabs
129 gsub(/[[:space:]]+/, "")
130
131 if ($0 == "#!/sbin/runscript") {
132
133 if (RCSCRIPTS[count] ~ /\.sh$/) {
134
135 ewarn(RCSCRIPTS[count] " is invalid (should not end with '.sh')")
136 NEXTFILE = 1
137 continue
138 }
139
140 if (stat(MYFILENAME, STAT_DATA) != 0)
141 ewarn("Could not stat \"" MYFILENAME "\"")
142
143 ISRCSCRIPT = 1
144 print_header1(STAT_DATA["mtime"])
145 } else {
146
147 NEXTFILE = 1
148 continue
149 }
150 }
151
152 # Filter out comments and only process if its a rcscript
153 if (($0 !~ /^[[:space:]]*#/) && (ISRCSCRIPT)) {
154
155 # If line contain 'depend()', set GOTDEPEND to 1
156 if ($0 ~ /depend[[:space:]]*\(\)/) {
157
158 GOTDEPEND = 1
159
160 print_header2()
161 print " # Actual depend() function ..." >> TMPCACHE
162 }
163
164 # We have the depend function...
165 if (GOTDEPEND) {
166
167 # Basic theory is that COUNT will be 0 when we
168 # have matching '{' and '}'
169 COUNT += gsub(/{/, "{")
170 COUNT -= gsub(/}/, "}")
171
172 # This is just to verify that we have started with
173 # the body of depend()
174 SBCOUNT += gsub(/{/, "{")
175
176 # Make sure depend() contain something, else bash
177 # errors out (empty function).
178 if ((SBCOUNT > 0) && (COUNT == 0))
179 print " \treturn 0" >> TMPCACHE
180
181 # Print the depend() function
182 print " " $0 >> TMPCACHE
183
184 # If COUNT=0, and SBCOUNT>0, it means we have read
185 # all matching '{' and '}' for depend(), so stop.
186 if ((SBCOUNT > 0) && (COUNT == 0)) {
187
188 GOTDEPEND = 0
189 COUNT = 0
190 SBCOUNT = 0
191 ISRCSCRIPT = 0
192
193 print_end()
194
195 NEXTFILE = 1
196 continue
197 }
198 }
199 }
200
201 MYFNR++
202 }
203
204 close(RCSCRIPTS[count])
205
206 NEXTFILE = 0
207
208 }
209
210 system("mv "TMPCACHE" "SVCDIR"/depcache")
211 }
212
213
214 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20