summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorJan (janneke) Nieuwenhuizen <janneke@gnu.org>2020-06-08 13:02:13 +0200
committerJan Nieuwenhuizen <janneke@gnu.org>2020-06-19 10:38:26 +0200
commit951847ee3792f8fa57d2bd38d84d9fa9c276c0fa (patch)
treefb932bb4bc3792d5328680c6f1cb3b63a17aaa98 /gnu
parent42ed562691640fc38a08e2269379fc181bdfe0f9 (diff)
hurd-boot: Create individual translators instead of running MAKEDEV.
* gnu/build/hurd-boot.scm (make-hurd-device-nodes): Do not create dev/{null,zero,full,random,urandom} mount points. (passive-translator-xattr?, passive-translator-installed?, translated?, set-translator, set-hurd-device-translators): New procedures. (false-if-EEXIST): New macro. (boot-hurd-system): Use them instead of running MAKEDEV.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/build/hurd-boot.scm190
1 files changed, 143 insertions, 47 deletions
diff --git a/gnu/build/hurd-boot.scm b/gnu/build/hurd-boot.scm
index 09326233d21..f4b6dc734db 100644
--- a/gnu/build/hurd-boot.scm
+++ b/gnu/build/hurd-boot.scm
@@ -80,16 +80,8 @@ Return the value associated with OPTION, or #f on failure."
80 (string-append root (if (string-suffix? "/" root) "" "/") dir)) 80 (string-append root (if (string-suffix? "/" root) "" "/") dir))
81 81
82 (mkdir (scope "dev")) 82 (mkdir (scope "dev"))
83 (for-each (lambda (file) 83 ;; Don't create /dev/null etc just yet; the store
84 (call-with-output-file (scope file) 84 ;; messes-up the permission bits.
85 (lambda (port)
86 (display file port) ;avoid hard-linking
87 (chmod port #o666))))
88 '("dev/null"
89 "dev/zero"
90 "dev/full"
91 "dev/random"
92 "dev/urandom"))
93 ;; Don't create /dev/console, /dev/vcs, etc.: they are created by 85 ;; Don't create /dev/console, /dev/vcs, etc.: they are created by
94 ;; console-run on first boot. 86 ;; console-run on first boot.
95 87
@@ -115,6 +107,143 @@ Return the value associated with OPTION, or #f on failure."
115 ;; settings? 107 ;; settings?
116 ) 108 )
117 109
110(define (passive-translator-xattr? file-name)
111 "Return true if FILE-NAME has an extended @code{gnu.translator} attribute
112set."
113 (catch 'system-error
114 (lambda _ (not (string-null? (getxattr file-name "gnu.translator"))))
115 (lambda args
116 (if (= ENODATA (system-error-errno args))
117 #f
118 (apply throw args)))))
119
120(define (passive-translator-installed? file-name)
121 "Return true if @file{showtrans} finds a translator installed on FILE-NAME."
122 (with-output-to-port (%make-void-port "w")
123 (lambda _
124 (with-error-to-port (%make-void-port "w")
125 (lambda _
126 (zero? (system* "showtrans" "--silent" file-name)))))))
127
128(define (translated? file-name)
129 "Return true if a translator is installed on FILE-NAME."
130 (if (string-contains %host-type "linux-gnu")
131 (passive-translator-xattr? file-name)
132 (passive-translator-installed? file-name)))
133
134(define* (set-translator file-name command #:optional (mode #o600))
135 "Setup translator COMMAND on FILE-NAME."
136 (unless (translated? file-name)
137 (let ((dir (dirname file-name)))
138 (unless (directory-exists? dir)
139 (mkdir-p dir))
140 (unless (file-exists? file-name)
141 (call-with-output-file file-name
142 (lambda (port)
143 (display file-name port) ;avoid hard-linking
144 (chmod port mode)))))
145 (catch 'system-error
146 (lambda _
147 (apply invoke "settrans" "--create" file-name command))
148 (lambda (key . args)
149 (let ((errno (system-error-errno (cons key args))))
150 (format (current-error-port) "~a: ~a\n"
151 (strerror errno) file-name)
152 (format (current-error-port) "Ignoring...Good Luck!\n"))))))
153
154(define-syntax-rule (false-if-EEXIST exp)
155 "Evaluate EXP but return #f if it raises to 'system-error with EEXIST."
156 (catch 'system-error
157 (lambda () exp)
158 (lambda args
159 (if (= EEXIST (system-error-errno args))
160 #f
161 (apply throw args)))))
162
163(define* (set-hurd-device-translators #:optional (root "/"))
164 "Make some of the device nodes needed on GNU/Hurd."
165
166 (define (scope dir)
167 (string-append root (if (string-suffix? "/" root) "" "/") dir))
168
169 (define scope-set-translator
170 (match-lambda
171 ((file-name command)
172 (scope-set-translator (list file-name command #o600)))
173 ((file-name command mode)
174 (let ((mount-point (scope file-name)))
175 (set-translator mount-point command mode)))))
176
177 (define (mkdir* dir)
178 (let ((dir (scope dir)))
179 (unless (file-exists? dir)
180 (mkdir-p dir))))
181
182 (define servers
183 '(("servers/crash-dump-core" ("/hurd/crash" "--dump-core"))
184 ("servers/crash-kill" ("/hurd/crash" "--kill"))
185 ("servers/crash-suspend" ("/hurd/crash" "--suspend"))
186 ("servers/password" ("/hurd/password"))
187 ("servers/socket/1" ("/hurd/pflocal"))
188 ("servers/socket/2" ("/hurd/pfinet"
189 "--interface" "eth0"
190 "--address"
191 "10.0.2.15" ;the default QEMU guest IP
192 "--netmask" "255.255.255.0"
193 "--gateway" "10.0.2.2"
194 "--ipv6" "/servers/socket/16"))))
195
196 (define devices
197 '(("dev/full" ("/hurd/null" "--full") #o666)
198 ("dev/null" ("/hurd/null") #o666)
199 ("dev/random" ("/hurd/random" "--seed-file" "/var/lib/random-seed")
200 #o644)
201 ("dev/zero" ("/hurd/storeio" "--store-type=zero") #o666)
202
203 ("dev/console" ("/hurd/term" "/dev/console" "device" "console"))
204
205 ("dev/klog" ("/hurd/streamio" "kmsg"))
206 ("dev/mem" ("/hurd/storeio" "--no-cache" "mem") #o660)
207 ("dev/shm" ("/hurd/tmpfs" "--mode=1777" "50%") #o644)
208 ("dev/time" ("/hurd/storeio" "--no-cache" "time") #o644)
209
210 ("dev/vcs" ("/hurd/console"))
211 ("dev/tty" ("/hurd/magic" "tty") #o666)
212
213 ("dev/tty1" ("/hurd/term" "/dev/tty1" "hurdio" "/dev/vcs/1/console")
214 #o666)
215 ("dev/tty2" ("/hurd/term" "/dev/tty2" "hurdio" "/dev/vcs/2/console")
216 #o666)
217 ("dev/tty3" ("/hurd/term" "/dev/tty3" "hurdio" "/dev/vcs/3/console")
218 #o666)
219
220 ("dev/ptyp0" ("/hurd/term" "/dev/ptyp0" "pty-master" "/dev/ttyp0")
221 #o666)
222 ("dev/ptyp1" ("/hurd/term" "/dev/ptyp1" "pty-master" "/dev/ttyp1")
223 #o666)
224 ("dev/ptyp2" ("/hurd/term" "/dev/ptyp2" "pty-master" "/dev/ttyp2")
225 #o666)
226
227 ("dev/ttyp0" ("/hurd/term" "/dev/ttyp0" "pty-slave" "/dev/ptyp0")
228 #o666)
229 ("dev/ttyp1" ("/hurd/term" "/dev/ttyp1" "pty-slave" "/dev/ptyp1")
230 #o666)
231 ("dev/ttyp2" ("/hurd/term" "/dev/ttyp2" "pty-slave" "/dev/ptyp2")
232 #o666)))
233
234 (for-each scope-set-translator servers)
235 (mkdir* (scope "dev/vcs/1"))
236 (mkdir* (scope "dev/vcs/2"))
237 (mkdir* (scope "dev/vcs/2"))
238 (rename-file (scope "/dev/console") (scope "/dev/console-"))
239 (for-each scope-set-translator devices)
240
241 (false-if-EEXIST (symlink "/dev/random" (scope "dev/urandom")))
242 (mkdir* (scope "dev/fd"))
243 (false-if-EEXIST (symlink "/dev/fd/0" (scope "dev/stdin")))
244 (false-if-EEXIST (symlink "/dev/fd/1" (scope "dev/stdout")))
245 (false-if-EEXIST (symlink "/dev/fd/2" (scope "dev/stderr"))))
246
118 247
119(define* (boot-hurd-system #:key (on-error 'debug)) 248(define* (boot-hurd-system #:key (on-error 'debug))
120 "This procedure is meant to be called from an early RC script. 249 "This procedure is meant to be called from an early RC script.
@@ -126,20 +255,9 @@ starting the Shepherd.
126XXX TODO: see linux-boot.scm:boot-system. 255XXX TODO: see linux-boot.scm:boot-system.
127XXX TODO: add proper file-system checking, mounting 256XXX TODO: add proper file-system checking, mounting
128XXX TODO: move bits to (new?) (hurd?) (activation?) services 257XXX TODO: move bits to (new?) (hurd?) (activation?) services
129XXX TODO: use settrans/setxattr instead of MAKEDEV 258XXX TODO: use Linux xattr/setxattr to remove (settrans in) /libexec/RUNSYSTEM
130 259
131" 260"
132 (define translators
133 '(("/servers/crash-dump-core" ("/hurd/crash" "--dump-core"))
134 ("/servers/crash-kill" ("/hurd/crash" "--kill"))
135 ("/servers/crash-suspend" ("/hurd/crash" "--suspend"))
136 ("/servers/password" ("/hurd/password"))
137 ("/servers/socket/1" ("/hurd/pflocal"))
138 ("/servers/socket/2" ("/hurd/pfinet" "--interface" "eth0"
139 "--address" "10.0.2.15" ;the default QEMU guest IP
140 "--netmask" "255.255.255.0"
141 "--gateway" "10.0.2.2"
142 "--ipv6" "/servers/socket/16"))))
143 261
144 (display "Welcome, this is GNU's early boot Guile.\n") 262 (display "Welcome, this is GNU's early boot Guile.\n")
145 (display "Use '--repl' for an initrd REPL.\n\n") 263 (display "Use '--repl' for an initrd REPL.\n\n")
@@ -147,35 +265,13 @@ XXX TODO: use settrans/setxattr instead of MAKEDEV
147 (call-with-error-handling 265 (call-with-error-handling
148 (lambda () 266 (lambda ()
149 267
150 (define (translated? node)
151 ;; Return true if a translator is installed on NODE.
152 (with-output-to-port (%make-void-port "w")
153 (lambda ()
154 (with-error-to-port (%make-void-port "w")
155 (lambda ()
156 (zero? (system* "showtrans" "--silent" node)))))))
157
158 (let* ((args (command-line)) 268 (let* ((args (command-line))
159 (system (find-long-option "--system" args)) 269 (system (find-long-option "--system" args))
160 (to-load (find-long-option "--load" args))) 270 (to-load (find-long-option "--load" args)))
161 271
162 (format #t "Creating essential servers...\n") 272 (format #t "Setting-up essential translators...\n")
163 (setenv "PATH" (string-append system "/profile/bin" 273 (setenv "PATH" (string-append system "/profile/bin"))
164 ":" system "/profile/sbin")) 274 (set-hurd-device-translators)
165 (for-each (match-lambda
166 ((node command)
167 (unless (translated? node)
168 (mkdir-p (dirname node))
169 (apply invoke "settrans" "--create" node command))))
170 translators)
171
172 (format #t "Creating essential device nodes...\n")
173 (with-directory-excursion "/dev"
174 (invoke "MAKEDEV" "--devdir=/dev" "std")
175 (invoke "MAKEDEV" "--devdir=/dev" "vcs")
176 (invoke "MAKEDEV" "--devdir=/dev" "tty1""tty2" "tty3" "tty4" "tty5" "tty6")
177 (invoke "MAKEDEV" "--devdir=/dev" "ptyp0" "ptyp1" "ptyp2")
178 (invoke "MAKEDEV" "--devdir=/dev" "console"))
179 275
180 (false-if-exception (delete-file "/hurd")) 276 (false-if-exception (delete-file "/hurd"))
181 (let ((hurd/hurd (readlink* (string-append system "/profile/hurd")))) 277 (let ((hurd/hurd (readlink* (string-append system "/profile/hurd"))))