1 |
Author: ulm |
2 |
Date: 2009-12-29 10:54:46 +0000 (Tue, 29 Dec 2009) |
3 |
New Revision: 744 |
4 |
|
5 |
Modified: |
6 |
trunk/ChangeLog |
7 |
trunk/NEWS |
8 |
trunk/modules/env.eselect |
9 |
Log: |
10 |
Fix quoting and other modifications to make it whitespace safe, bug 298742. |
11 |
|
12 |
Modified: trunk/ChangeLog |
13 |
=================================================================== |
14 |
--- trunk/ChangeLog 2009-12-28 22:13:42 UTC (rev 743) |
15 |
+++ trunk/ChangeLog 2009-12-29 10:54:46 UTC (rev 744) |
16 |
@@ -2,6 +2,10 @@ |
17 |
|
18 |
* modules/env.eselect (create_profile_env): Exclude LDPATH from |
19 |
profile.env, fixes bug 298789. |
20 |
+ (is_envfile, update_envvar_classes, create_profile_env) |
21 |
+ (create_ld_so_conf, create_prelink_conf, need_links) |
22 |
+ (update_ldcache, do_update): Fix quoting and other modifications |
23 |
+ to make it whitespace safe, bug 298742. |
24 |
|
25 |
2009-12-04 Ulrich Mueller <ulm@g.o> |
26 |
|
27 |
|
28 |
Modified: trunk/NEWS |
29 |
=================================================================== |
30 |
--- trunk/NEWS 2009-12-28 22:13:42 UTC (rev 743) |
31 |
+++ trunk/NEWS 2009-12-29 10:54:46 UTC (rev 744) |
32 |
@@ -3,6 +3,7 @@ |
33 |
|
34 |
trunk: |
35 |
Bug fixes: |
36 |
+ - Fixed bug #298742: The env module was not whitespace safe. |
37 |
- Fixed bug #298789: Exclude LDPATH from profile.env in env module. |
38 |
|
39 |
1.2.8: |
40 |
|
41 |
Modified: trunk/modules/env.eselect |
42 |
=================================================================== |
43 |
--- trunk/modules/env.eselect 2009-12-28 22:13:42 UTC (rev 743) |
44 |
+++ trunk/modules/env.eselect 2009-12-29 10:54:46 UTC (rev 744) |
45 |
@@ -50,9 +50,9 @@ |
46 |
[[ -n ${envfile##*~} ]] || return 1 |
47 |
[[ ${envfile##*.} != bak ]] || return 1 |
48 |
|
49 |
- mime=$(POSIXLY_CORRECT=1 file -i ${envfile} \ |
50 |
+ mime=$(POSIXLY_CORRECT=1 file -i "${envfile}" \ |
51 |
| cut -d ' ' -f 2 | sed -e 's/;$//') |
52 |
- if ! has ${mime} ${MIME_WHITELIST} ; then |
53 |
+ if ! has ${mime} ${MIME_WHITELIST}; then |
54 |
echo "Skipping non-text file ${envfile}." |
55 |
return 1 |
56 |
fi |
57 |
@@ -67,19 +67,17 @@ |
58 |
local value |
59 |
envfiles=( "${EROOT}"/etc/env.d/* ) |
60 |
|
61 |
- for envfile in ${envfiles[@]} ; do |
62 |
- is_envfile ${envfile} || continue |
63 |
+ for envfile in "${envfiles[@]}"; do |
64 |
+ is_envfile "${envfile}" || continue |
65 |
|
66 |
- value=$(load_config ${envfile} COLON_SEPARATED) |
67 |
- for x in ${value} ; do |
68 |
- has ${x} ${PATH_CLASS} && continue |
69 |
- PATH_CLASS="${PATH_CLASS} ${x}" |
70 |
+ value=$(load_config "${envfile}" COLON_SEPARATED) |
71 |
+ for x in ${value}; do |
72 |
+ has ${x} ${PATH_CLASS} || PATH_CLASS="${PATH_CLASS} ${x}" |
73 |
done |
74 |
|
75 |
- value=$(load_config ${envfile} SPACE_SEPARATED) |
76 |
- for x in ${value} ; do |
77 |
- has ${x} ${SPACE_CLASS} && continue |
78 |
- SPACE_CLASS="${SPACE_CLASS} ${x}" |
79 |
+ value=$(load_config "${envfile}" SPACE_SEPARATED) |
80 |
+ for x in ${value}; do |
81 |
+ has ${x} ${SPACE_CLASS} || SPACE_CLASS="${SPACE_CLASS} ${x}" |
82 |
done |
83 |
done |
84 |
} |
85 |
@@ -88,19 +86,19 @@ |
86 |
# Create profile.env file |
87 |
create_profile_env() { |
88 |
local -a envfiles |
89 |
- local vars store items tmpprofile |
90 |
+ local vars store items tmpprofile ifs_save |
91 |
envfiles=( "${EROOT}"/etc/env.d/* ) |
92 |
|
93 |
# Blank the file first! |
94 |
- tmpprofile="$(mktemp ${ROOT}/tmp/profile.XXXXXX)" |
95 |
- [[ $? = 0 ]] || die "Couldn't create temporary file!" |
96 |
+ tmpprofile=$(mktemp "${ROOT}/tmp/profile.XXXXXX") |
97 |
+ [[ $? -eq 0 ]] || die "Couldn't create temporary file!" |
98 |
|
99 |
# Gather ye classes while ye may! |
100 |
update_envvar_classes |
101 |
|
102 |
# Parse all files in env.d |
103 |
- for envfile in ${envfiles[@]} ; do |
104 |
- is_envfile ${envfile} || continue |
105 |
+ for envfile in "${envfiles[@]}"; do |
106 |
+ is_envfile "${envfile}" || continue |
107 |
|
108 |
# Which vars are to be loaded? |
109 |
# TODO: Change to bash magic? |
110 |
@@ -109,60 +107,62 @@ |
111 |
-e 's/^export\s\+//' \ |
112 |
-e '/^[[:alpha:]_]\w*=/!d' \ |
113 |
-e 's/=.*//' \ |
114 |
- ${envfile}) |
115 |
- [[ -z ${vars} ]] && continue |
116 |
- for var in ${vars} ; do |
117 |
+ "${envfile}") |
118 |
+ |
119 |
+ for var in ${vars}; do |
120 |
if [[ ${var} = LDPATH ]]; then |
121 |
# Don't store LDPATH in profile.env |
122 |
- : |
123 |
+ continue |
124 |
elif has ${var} ${PATH_CLASS}; then |
125 |
# Colon separated |
126 |
- store=$(load_config ${tmpprofile} ${var}) |
127 |
- if [[ -z ${store} ]] ; then |
128 |
- store=$(load_config ${envfile} ${var}) |
129 |
+ store=$(load_config "${tmpprofile}" ${var}) |
130 |
+ if [[ -z ${store} ]]; then |
131 |
+ store=$(load_config "${envfile}" ${var}) |
132 |
else |
133 |
- items="$(load_config ${envfile} ${var})" |
134 |
- items=( ${items//:/ } ) |
135 |
- for item in ${items[@]} ; do |
136 |
- has ${item} ${store//:/ } && continue |
137 |
- store="${store}:${item}" |
138 |
+ items=$(load_config "${envfile}" ${var}) |
139 |
+ ifs_save=${IFS-$' \t\n'} |
140 |
+ IFS=":" |
141 |
+ for item in ${items}; do |
142 |
+ has ${item} ${store} \ |
143 |
+ || store="${store}${store:+:}${item}" |
144 |
done |
145 |
+ IFS=${ifs_save} |
146 |
fi |
147 |
- store_config ${tmpprofile} ${var} "${store#:}" |
148 |
elif has ${var} ${SPACE_CLASS}; then |
149 |
# Space separated |
150 |
- store=( $(load_config ${tmpprofile} ${var}) ) |
151 |
- if [[ -z ${store[@]} ]] ; then |
152 |
- store=( $(load_config ${envfile} ${var}) ) |
153 |
+ store=$(load_config "${tmpprofile}" ${var}) |
154 |
+ if [[ -z ${store} ]]; then |
155 |
+ store=$(load_config "${envfile}" ${var}) |
156 |
else |
157 |
- items=( $(load_config ${envfile} ${var}) ) |
158 |
- for item in ${items[@]} ; do |
159 |
- has ${item} ${store[@]} && continue |
160 |
- store=( ${store[@]} ${item} ) |
161 |
+ items=$(load_config "${envfile}" ${var}) |
162 |
+ for item in ${items}; do |
163 |
+ has ${item} ${store} \ |
164 |
+ || store="${store}${store:+ }${item}" |
165 |
done |
166 |
fi |
167 |
- store_config ${tmpprofile} ${var} "${store[@]}" |
168 |
else |
169 |
# Ok, just a non-cumulative var. |
170 |
- store_config ${tmpprofile} ${var} \ |
171 |
- "$(load_config ${envfile} ${var})" |
172 |
+ store=$(load_config "${envfile}" ${var}) |
173 |
fi |
174 |
+ store_config "${tmpprofile}" ${var} "${store}" |
175 |
done |
176 |
|
177 |
has LDPATH ${vars} || continue |
178 |
# Store LDPATH for later processing |
179 |
- items=$(load_config ${envfile} LDPATH) |
180 |
- items=( ${items//:/ } ) |
181 |
- for item in ${items[@]} ; do |
182 |
- has ${item} ${LDPATH[@]} && continue |
183 |
- ESELECT_LDPATH=( ${ESELECT_LDPATH[@]} ${item} ) |
184 |
+ items=$(load_config "${envfile}" LDPATH) |
185 |
+ ifs_save=${IFS-$' \t\n'} |
186 |
+ IFS=":" |
187 |
+ items=( ${items} ) |
188 |
+ IFS=${ifs_save} |
189 |
+ for item in "${items[@]}"; do |
190 |
+ has "${item}" "${ESELECT_LDPATH[@]}" \ |
191 |
+ || ESELECT_LDPATH=( "${ESELECT_LDPATH[@]}" "${item}" ) |
192 |
done |
193 |
done |
194 |
|
195 |
# Move new file onto old one |
196 |
- ENVPROFILE=$(canonicalise ${ENVPROFILE}) |
197 |
- chmod a+r ${tmpprofile} |
198 |
- mv ${tmpprofile} ${ENVPROFILE} \ |
199 |
+ chmod a+r "${tmpprofile}" |
200 |
+ mv "${tmpprofile}" "$(canonicalise "${ENVPROFILE}")" \ |
201 |
|| die "Couldn't move ${tmpprofile} to ${ENVPROFILE}!\n |
202 |
Original profile.env remains unchanged." |
203 |
} |
204 |
@@ -176,10 +176,10 @@ |
205 |
local str |
206 |
str="# ld.so.conf autogenerated by eselect\n" |
207 |
str="${str}# Make all changes to /etc/env.d files\n" |
208 |
- for x in ${ESELECT_LDPATH[@]} ; do |
209 |
+ for x in "${ESELECT_LDPATH[@]}"; do |
210 |
str="${str}${x}\n" |
211 |
done |
212 |
- echo -e "${str}" > $(canonicalise ${LDCONFIG}) |
213 |
+ echo -n -e "${str}" >"$(canonicalise "${LDCONFIG}")" |
214 |
} |
215 |
|
216 |
# create_prelink_conf() |
217 |
@@ -187,47 +187,47 @@ |
218 |
create_prelink_conf() { |
219 |
[[ -z ${ESELECT_LDPATH[@]} ]] \ |
220 |
&& die -q "No LDPATHs found in ${EROOT}/etc/env.d/*" |
221 |
- local str |
222 |
+ local str ifs_save |
223 |
str="# prelink.conf autogenerated by eselect\n" |
224 |
str="${str}# Make all changes to /etc/env.d files\n" |
225 |
# Add default items |
226 |
- for x in /bin /sbin /usr/bin /usr/sbin ; do |
227 |
+ for x in /bin /sbin /usr/bin /usr/sbin; do |
228 |
str="${str}-l ${EPREFIX}${x}\n" |
229 |
done |
230 |
- for x in $(list_libdirs) ; do |
231 |
+ for x in $(list_libdirs); do |
232 |
[[ -e ${EROOT}/${x} ]] && str="${str}-l ${EPREFIX}/${x}\n" |
233 |
[[ -e ${EROOT}/usr/${x} ]] && str="${str}-l ${EPREFIX}/usr/${x}\n" |
234 |
done |
235 |
- prelink_mask=$(load_config ${ENVPROFILE} PRELINK_PATH_MASK) |
236 |
+ prelink_mask=$(load_config "${ENVPROFILE}" PRELINK_PATH_MASK) |
237 |
prelink_mask=( ${prelink_mask//:/ } ) |
238 |
- prelink="$(load_config ${ENVPROFILE} PATH)" |
239 |
- prelink="${prelink} $(load_config ${ENVPROFILE} PRELINK_PATH)" |
240 |
- prelink=( ${prelink//:/ } ${ESELECT_LDPATH[@]} ) |
241 |
- for x in ${prelink[@]} ; do |
242 |
+ prelink=$(load_config "${ENVPROFILE}" PATH) |
243 |
+ prelink="${prelink} $(load_config "${ENVPROFILE}" PRELINK_PATH)" |
244 |
+ prelink=( ${prelink//:/ } "${ESELECT_LDPATH[@]}" ) |
245 |
+ for x in "${prelink[@]}"; do |
246 |
has ${x} ${prelink_mask} && continue |
247 |
[[ -z ${x##*/} ]] || x="${x}/" |
248 |
str="${str}-h ${x}\n" |
249 |
done |
250 |
- for x in ${prelink_mask[@]} ; do |
251 |
+ for x in "${prelink_mask[@]}"; do |
252 |
str="${str}-b ${x}\n" |
253 |
done |
254 |
- echo -e "${str}" > $(canonicalise ${PRELINK}) |
255 |
+ echo -n -e "${str}" >"$(canonicalise "${PRELINK}")" |
256 |
} |
257 |
|
258 |
# need_links() |
259 |
# Returns true if any item of ${LDPATH} has been modified. |
260 |
need_links() { |
261 |
local ret=1 |
262 |
- for x in ${ESELECT_LDPATH[@]} ; do |
263 |
+ for x in "${ESELECT_LDPATH[@]}"; do |
264 |
y=${x//\//_} |
265 |
y=${y//-/_} |
266 |
y=${y//./_} |
267 |
y=${y//+/_} |
268 |
- oldmtime=$(load_config ${LDMTIMEDB} "mtime${y}") |
269 |
+ oldmtime=$(load_config "${LDMTIMEDB}" "mtime${y}") |
270 |
newmtime=$(stat -c %Y ${x} 2> /dev/null) |
271 |
- if [[ ${oldmtime} != ${newmtime} ]] ; then |
272 |
+ if [[ ${oldmtime} != ${newmtime} ]]; then |
273 |
ret=0 |
274 |
- store_config ${LDMTIMEDB} "mtime${y}" ${newmtime} |
275 |
+ store_config "${LDMTIMEDB}" "mtime${y}" ${newmtime} |
276 |
fi |
277 |
done |
278 |
return ${ret} |
279 |
@@ -249,7 +249,7 @@ |
280 |
echo "Regenerating ${ROOT}/etc/ld.so.cache..." |
281 |
( |
282 |
cd / |
283 |
- ldconfig ${1} -r ${ROOT:-/} |
284 |
+ ldconfig ${1} -r "${ROOT:-/}" |
285 |
) |
286 |
;; |
287 |
esac |
288 |
@@ -272,7 +272,7 @@ |
289 |
|
290 |
do_update() { |
291 |
local makelinks ldconfig=1 |
292 |
- while [[ ${#@} -gt 0 ]] ; do |
293 |
+ while [[ $# -gt 0 ]]; do |
294 |
case ${1} in |
295 |
makelinks) |
296 |
makelinks="-X" |
297 |
@@ -287,16 +287,15 @@ |
298 |
shift |
299 |
done |
300 |
|
301 |
- if [[ -e ${EROOT}/etc/profile.env ]] ; then |
302 |
- [[ -w ${EROOT}/etc/profile.env ]] \ |
303 |
- || die -q "You need to be root!" |
304 |
+ if [[ -e ${ENVPROFILE} ]]; then |
305 |
+ [[ -w ${ENVPROFILE} ]] || die -q "You need to be root!" |
306 |
else |
307 |
- touch "${EROOT}/etc/profile.env" |
308 |
+ touch "${ENVPROFILE}" || die -q "You need to be root!" |
309 |
fi |
310 |
|
311 |
# Create configuration files |
312 |
create_profile_env |
313 |
- if [[ ${ldconfig} == 1 ]] ; then |
314 |
+ if [[ ${ldconfig} == 1 ]]; then |
315 |
create_ld_so_conf |
316 |
[[ -e ${EROOT}/usr/sbin/prelink ]] && create_prelink_conf |
317 |
need_links && makelinks="-X" |
318 |
@@ -304,11 +303,9 @@ |
319 |
fi |
320 |
|
321 |
# fix up ${ENVPROFILE} |
322 |
- cp ${ENVPROFILE} ${ENVPROFILE/.env/.csh} |
323 |
- sed -i \ |
324 |
- -e "s/^\(.*\)=\"\(.*\)\"/export \1='\2'/" \ |
325 |
- $(canonicalise ${ENVPROFILE}) |
326 |
- sed -i \ |
327 |
- -e "s/^\(.*\)=\"\(.*\)\"/setenv \1 '\2'/" \ |
328 |
- $(canonicalise ${ENVPROFILE/.env/.csh}) |
329 |
+ cp "${ENVPROFILE}" "${ENVPROFILE/.env/.csh}" |
330 |
+ sed -i -e "s/^\(.*\)=\"\(.*\)\"/export \1='\2'/" \ |
331 |
+ "$(canonicalise "${ENVPROFILE}")" |
332 |
+ sed -i -e "s/^\(.*\)=\"\(.*\)\"/setenv \1 '\2'/" \ |
333 |
+ "$(canonicalise "${ENVPROFILE/.env/.csh}")" |
334 |
} |