summarylogtreecommitdiffstats
path: root/os-prober-factor-out-logger.patch
blob: 52cb7ceabb0c3d4111a5beae168aab340e17969b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Index: os-prober/common.sh
===================================================================
--- os-prober.orig/common.sh
+++ os-prober/common.sh
@@ -62,10 +62,14 @@ cache_progname() {
   esac
 }
 
-log() {
-  cache_progname
-  logger -t "$progname" "$@"
-}
+# fd_logger: bind value now, possibly after assigning default. 
+eval '
+  log() {
+    cache_progname
+    echo "$progname: $@"  1>&'${fd_logger:=9}'
+  }
+'
+export fd_logger  # so subshells inherit current value by default
 
 error() {
   log "error: $@"
@@ -81,10 +85,14 @@ debug() {
   fi
 }
 
-result () {
-  log "result:" "$@"
-  echo "$@"
-}
+# fd_result: bind value now, possibly after assigning default.
+eval '
+  result() {
+    log "result:" "$@"
+    echo "$@"  1>&'${fd_result:=1}'
+  }
+'
+export fd_result  # so subshells inherit current value by default
 
 # shim to make it easier to use os-prober outside d-i
 if ! type mapdevfs >/dev/null 2>&1; then
Index: os-prober/linux-boot-prober
===================================================================
--- os-prober.orig/linux-boot-prober
+++ os-prober/linux-boot-prober
@@ -1,4 +1,12 @@
 #!/bin/sh
+
+# dash shell does not have "{varname}>&1" feature that bash shell has
+# for auto-assignment of new filedescriptors.
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
+# Therefore use fixed numbers.
+export fd_result=3  # file descriptor for external results
+export fd_logger=9  # file descriptor for input to logger
+
 . /usr/share/os-prober/common.sh
 
 set -e
@@ -19,6 +27,7 @@ bootuuid=
 
 grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true
 
+( (
 if [ -z "$1" ]; then
 	ERR=y
 elif [ "$1" = btrfs -a -z "$2" ]; then
@@ -186,3 +195,5 @@ else
 		fi
 	fi
 fi
+) 9>&1 | logger 1>&-  # fd_logger
+) 3>&1  # fd_result
Index: os-prober/os-prober
===================================================================
--- os-prober.orig/os-prober
+++ os-prober/os-prober
@@ -1,7 +1,14 @@
 #!/bin/sh
 set -e
 
-. /usr/share/os-prober/common.sh
+# dash shell does not have "{varname}>&1" feature that bash shell has
+# for auto-assignment of new filedescriptors.
+# It is cumbersome to write the 'eval' to use our own variables in redirections.
+# Therefore use fixed numbers.
+export fd_result=3  # file descriptor for external results
+export fd_logger=9  # file descriptor for input to logger
+
+ . /usr/share/os-prober/common.sh
 
 newns "$@"
 require_tmpdir
@@ -136,6 +143,7 @@ fi
 
 : >"$OS_PROBER_TMP/btrfs-vols"
 
+( (
 for partition in $(partitions); do
 	if ! mapped="$(mapdevfs "$partition")"; then
 		log "Device '$partition' does not exist; skipping"
@@ -200,3 +208,5 @@ for partition in $(partitions); do
 		fi
 	fi
 done
+) 9>&1 | logger 1>&-  # fd_logger
+) 3>&1  # fd_result