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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 Revision 1.20
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.15 2004/02/26 17:29:43 azarah Exp $ 3# $Header: /var/cvsroot/gentoo-src/rc-scripts/src/awk/cachedepends.awk,v 1.20 2005/02/23 17:47:43 azarah Exp $
5 4
6function print_start() { 5function print_start() {
7 print "source /sbin/functions.sh" >> (SVCDIR "/depcache") 6 print "source /sbin/functions.sh" >> TMPCACHE
8 print "" >> (SVCDIR "/depcache") 7 print "" >> TMPCACHE
9 print "need() {" >> (SVCDIR "/depcache") 8 print "need() {" >> TMPCACHE
10 print " echo \"NEED $*\"; return 0" >> (SVCDIR "/depcache") 9 print " echo \"NEED $*\"; return 0" >> TMPCACHE
11 print "}" >> (SVCDIR "/depcache") 10 print "}" >> TMPCACHE
12 print "" >> (SVCDIR "/depcache") 11 print "" >> TMPCACHE
13 print "use() {" >> (SVCDIR "/depcache") 12 print "use() {" >> TMPCACHE
14 print " echo \"USE $*\"; return 0" >> (SVCDIR "/depcache") 13 print " echo \"USE $*\"; return 0" >> TMPCACHE
15 print "}" >> (SVCDIR "/depcache") 14 print "}" >> TMPCACHE
16 print "" >> (SVCDIR "/depcache") 15 print "" >> TMPCACHE
17 print "before() {" >> (SVCDIR "/depcache") 16 print "before() {" >> TMPCACHE
18 print " echo \"BEFORE $*\"; return 0" >> (SVCDIR "/depcache") 17 print " echo \"BEFORE $*\"; return 0" >> TMPCACHE
19 print "}" >> (SVCDIR "/depcache") 18 print "}" >> TMPCACHE
20 print "" >> (SVCDIR "/depcache") 19 print "" >> TMPCACHE
21 print "after() {" >> (SVCDIR "/depcache") 20 print "after() {" >> TMPCACHE
22 print " echo \"AFTER $*\"; return 0" >> (SVCDIR "/depcache") 21 print " echo \"AFTER $*\"; return 0" >> TMPCACHE
23 print "}" >> (SVCDIR "/depcache") 22 print "}" >> TMPCACHE
24 print "" >> (SVCDIR "/depcache") 23 print "" >> TMPCACHE
25 print "provide() {" >> (SVCDIR "/depcache") 24 print "provide() {" >> TMPCACHE
26 print " echo \"PROVIDE $*\"; return 0" >> (SVCDIR "/depcache") 25 print " echo \"PROVIDE $*\"; return 0" >> TMPCACHE
27 print "}" >> (SVCDIR "/depcache") 26 print "}" >> TMPCACHE
28 print "" >> (SVCDIR "/depcache") 27 print "" >> TMPCACHE
29 print "parallel() {" >> (SVCDIR "/depcache") 28 print "parallel() {" >> TMPCACHE
30 print " echo \"PARALLEL $*\"; return 0" >> (SVCDIR "/depcache") 29 print " echo \"PARALLEL $*\"; return 0" >> TMPCACHE
31 print "}" >> (SVCDIR "/depcache") 30 print "}" >> TMPCACHE
32 print "" >> (SVCDIR "/depcache") 31 print "" >> TMPCACHE
33} 32}
34 33
35function print_header1(mtime) { 34function print_header1(mtime) {
36 print "#*** " MYFILENAME " ***" >> (SVCDIR "/depcache") 35 print "#*** " MYFILENAME " ***" >> TMPCACHE
37 print "" >> (SVCDIR "/depcache") 36 print "" >> TMPCACHE
38 print "myservice=\"" MYFILENAME "\"" >> (SVCDIR "/depcache") 37 print "myservice=\"" MYFILENAME "\"" >> TMPCACHE
39 print "myservice=\"${myservice##*/}\"" >> (SVCDIR "/depcache") 38 print "myservice=\"${myservice##*/}\"" >> TMPCACHE
40 print "echo \"RCSCRIPT ${myservice}\"" >> (SVCDIR "/depcache") 39 print "echo \"RCSCRIPT ${myservice}\"" >> TMPCACHE
41 print "" >> (SVCDIR "/depcache") 40 print "" >> TMPCACHE
42 print "echo \"MTIME " mtime "\"" >> (SVCDIR "/depcache") 41 print "echo \"MTIME " mtime "\"" >> TMPCACHE
43 print "" >> (SVCDIR "/depcache") 42 print "" >> TMPCACHE
44} 43}
45 44
46function print_header2(mtime) { 45function print_header2(mtime) {
47 print "(" >> (SVCDIR "/depcache") 46 print "(" >> TMPCACHE
48 print " # Get settings for rc-script ..." >> (SVCDIR "/depcache") 47 print " # Get settings for rc-script ..." >> TMPCACHE
49 print " [ -e /etc/conf.d/basic ] && source /etc/conf.d/basic" >> (SVCDIR "/depcache") 48 print "" >> TMPCACHE
50 print "" >> (SVCDIR "/depcache")
51 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> (SVCDIR "/depcache") 49 print " [ -e \"/etc/conf.d/${myservice}\" ] && source \"/etc/conf.d/${myservice}\"" >> TMPCACHE
52 print "" >> (SVCDIR "/depcache") 50 print "" >> TMPCACHE
53 print " [ -e /etc/conf.d/net ] && \\" >> (SVCDIR "/depcache") 51 print " [ -e /etc/conf.d/net ] && \\" >> TMPCACHE
54 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> (SVCDIR "/depcache") 52 print " [ \"${myservice%%.*}\" = \"net\" ] && \\" >> TMPCACHE
55 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> (SVCDIR "/depcache") 53 print " [ \"${myservice##*.}\" != \"${myservice}\" ] && source /etc/conf.d/net" >> TMPCACHE
56 print "" >> (SVCDIR "/depcache") 54 print "" >> TMPCACHE
57 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> (SVCDIR "/depcache") 55 print " [ -e /etc/rc.conf ] && source /etc/rc.conf" >> TMPCACHE
58 print "" >> (SVCDIR "/depcache") 56 print "" >> TMPCACHE
59 print " depend() {" >> (SVCDIR "/depcache") 57 print " depend() {" >> TMPCACHE
60 print " return 0" >> (SVCDIR "/depcache") 58 print " return 0" >> TMPCACHE
61 print " }" >> (SVCDIR "/depcache") 59 print " }" >> TMPCACHE
62 print "" >> (SVCDIR "/depcache") 60 print "" >> TMPCACHE
63} 61}
64 62
65function print_end() { 63function print_end() {
66 print "" >> (SVCDIR "/depcache") 64 print "" >> TMPCACHE
67 print " depend" >> (SVCDIR "/depcache") 65 print " depend" >> TMPCACHE
68 print ")" >> (SVCDIR "/depcache") 66 print ")" >> TMPCACHE
69 print "" >> (SVCDIR "/depcache") 67 print "" >> TMPCACHE
70} 68}
71 69
72BEGIN { 70BEGIN {
73 71
74 extension("/lib/rcscripts/filefuncs.so", "dlload") 72 extension("/lib/rcscripts/filefuncs.so", "dlload")
78 if (SVCDIR == "") { 76 if (SVCDIR == "") {
79 eerror("Could not get SVCDIR!") 77 eerror("Could not get SVCDIR!")
80 exit 1 78 exit 1
81 } 79 }
82 80
81 # Since this could be called more than once simultaneously, use a
82 # temporary cache and rename when finished. See bug 47111
83 ("/bin/mktemp "SVCDIR"/depcache.XXXXXXX") | getline TMPCACHE
84 if (TMPCACHE == "") {
85 eerror("Failed to create temporary cache!")
86 exit 1
87 }
88
83 pipe = "ls /etc/init.d/*" 89 pipe = "ls /etc/init.d/*"
84 while ((pipe | getline tmpstring) > 0) 90 while ((pipe | getline tmpstring) > 0)
85 scripts = scripts " " tmpstring 91 scripts = scripts " " tmpstring
86 close(pipe) 92 close(pipe)
87 93
98 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x] 104 RCSCRIPTS[RCCOUNT] = TMPRCSCRIPTS[x]
99 } 105 }
100 106
101 if (RCCOUNT == 0) { 107 if (RCCOUNT == 0) {
102 eerror("No scripts to process!") 108 eerror("No scripts to process!")
109 system("rm -f "TMPCACHE)
103 exit 1 110 exit 1
104 } 111 }
105 112
106 print_start() 113 print_start()
107 114
147 if ($0 ~ /depend[[:space:]]*\(\)/) { 154 if ($0 ~ /depend[[:space:]]*\(\)/) {
148 155
149 GOTDEPEND = 1 156 GOTDEPEND = 1
150 157
151 print_header2() 158 print_header2()
152 print " # Actual depend() function ..." >> (SVCDIR "/depcache") 159 print " # Actual depend() function ..." >> TMPCACHE
153 } 160 }
154 161
155 # We have the depend function... 162 # We have the depend function...
156 if (GOTDEPEND) { 163 if (GOTDEPEND) {
157 164
165 SBCOUNT += gsub(/{/, "{") 172 SBCOUNT += gsub(/{/, "{")
166 173
167 # Make sure depend() contain something, else bash 174 # Make sure depend() contain something, else bash
168 # errors out (empty function). 175 # errors out (empty function).
169 if ((SBCOUNT > 0) && (COUNT == 0)) 176 if ((SBCOUNT > 0) && (COUNT == 0))
170 print " \treturn 0" >> (SVCDIR "/depcache") 177 print " \treturn 0" >> TMPCACHE
171 178
172 # Print the depend() function 179 # Print the depend() function
173 print " " $0 >> (SVCDIR "/depcache") 180 print " " $0 >> TMPCACHE
174 181
175 # If COUNT=0, and SBCOUNT>0, it means we have read 182 # If COUNT=0, and SBCOUNT>0, it means we have read
176 # all matching '{' and '}' for depend(), so stop. 183 # all matching '{' and '}' for depend(), so stop.
177 if ((SBCOUNT > 0) && (COUNT == 0)) { 184 if ((SBCOUNT > 0) && (COUNT == 0)) {
178 185
195 close(RCSCRIPTS[count]) 202 close(RCSCRIPTS[count])
196 203
197 NEXTFILE = 0 204 NEXTFILE = 0
198 205
199 } 206 }
207
208
209 assert(system("rm -f "SVCDIR"/depcache"), "system(rm -f "SVCDIR"/depcache)")
210 assert(system("mv "TMPCACHE" "SVCDIR"/depcache"), "system(mv "TMPCACHE" "SVCDIR"/depcache)")
200} 211}
201 212
202 213
203# vim:ts=4 214# vim:ts=4

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20