1 |
This allows us to spawn 'tee' as separate process while keeping |
2 |
the function code executed in the main shell. |
3 |
--- |
4 |
gx86/eclass/multibuild.eclass | 29 +++++++++++++++-------------- |
5 |
1 file changed, 15 insertions(+), 14 deletions(-) |
6 |
|
7 |
diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass |
8 |
index 716d34f..d66d069 100644 |
9 |
--- a/gx86/eclass/multibuild.eclass |
10 |
+++ b/gx86/eclass/multibuild.eclass |
11 |
@@ -108,18 +108,20 @@ multibuild_foreach() { |
12 |
local MULTIBUILD_VARIANT=${v} |
13 |
local MULTIBUILD_ID=${prev_id}${v} |
14 |
local BUILD_DIR=${bdir%%/}-${v} |
15 |
- |
16 |
- einfo "${v}: running ${@}" \ |
17 |
- | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
18 |
- |
19 |
- # _multibuild_parallel() does redirection internally. |
20 |
- # this is a hidden API to avoid writing multilib_foreach twice. |
21 |
- if [[ ${1} == _multibuild_parallel ]]; then |
22 |
- "${@}" |
23 |
- else |
24 |
- "${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
25 |
- fi |
26 |
- lret=${?} |
27 |
+ local log_fd |
28 |
+ |
29 |
+ # redirect_alloc_fd accepts files only. so we need to open |
30 |
+ # a random file and then reuse the fd for logger process. |
31 |
+ redirect_alloc_fd log_fd /dev/null |
32 |
+ # bash can't handle ${log_fd} in redirections, |
33 |
+ # we need to use eval to pass fd numbers directly. |
34 |
+ eval " |
35 |
+ exec ${log_fd}> >(exec tee -a \"\${T}/build-\${MULTIBUILD_ID}.log\") |
36 |
+ einfo \"\${v}: running \${@}\" >&${log_fd} 2>&1 |
37 |
+ \"\${@}\" >&${log_fd} 2>&1 |
38 |
+ lret=\${?} |
39 |
+ exec ${log_fd}>&- |
40 |
+ " |
41 |
done |
42 |
[[ ${ret} -eq 0 && ${lret} -ne 0 ]] && ret=${lret} |
43 |
|
44 |
@@ -145,8 +147,7 @@ multibuild_parallel_foreach() { |
45 |
_multibuild_parallel() { |
46 |
( |
47 |
multijob_child_init |
48 |
- "${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
49 |
- exit ${PIPESTATUS[0]} |
50 |
+ "${@}" |
51 |
) & |
52 |
multijob_post_fork |
53 |
} |
54 |
-- |
55 |
1.8.1.4 |