|
root / base / usr / src / zyginit / services / devfs
devfs Plain Text 73 lines 2.9 KB
 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
# devfs — populate /dev (devfsadm) and configure sockfs protocol modules
# (soconfig). Without soconfig, socket(AF_INET) returns EAFNOSUPPORT and
# every later ifconfig call — including lo0 plumb — fails.

[service]
name = "devfs"
description = "Device and socket protocol configuration"
type = "oneshot"

[exec]
start = "/etc/zyginit/services/devfs/start.sh"

[runlevel]
# Essential — /dev nodes (incl. /dev/dld for dlmgmtd) and sockfs
# protocol map are needed for any meaningful userland operation.
mode = "always"

[dependencies]
requires = ["root-fs"]

[restart]
on = "never"
#!/bin/zsh
# devfs/start.sh — populate /dev and configure socket protocol modules
#
# Mirrors SMF's system/device/local method (lib/svc/method/devices-local).
# devfsadm configures hardware; soconfig loads /etc/sock2path.d into kernel
# sockfs so socket(AF_INET, ...) and socket(AF_INET6, ...) actually return
# a valid fd. Without soconfig, every socket() of those families fails
# EAFNOSUPPORT and ifconfig cannot configure any interface — including lo0.

set -e
set -u

# Hardware device configuration. Hammerhead's SMF runs this unconditionally
# (upstream illumos only runs it on reconfigure boots, which leaves PCI
# NICs unattached on fresh deploys); we follow Hammerhead's convention.
/usr/sbin/devfsadm

# Load minor_perm + device_policy (/etc/security/device_policy) into the
# kernel. WITHOUT this, the kernel keeps its restrictive built-in default
# (DEFAULT read_priv_set=all / write_priv_set=all), so a NON-root process
# can't even open() /dev/null or /dev/zero — open() returns EACCES. That
# breaks the non-root (zygaena) build (perl/OCaml/reefc all redirect to
# /dev/null) and any non-root program. `devfsadm -P` is the only devfsadm
# mode that loads these tables (illumos did it in SMF's devices-local
# method; the zyginit port dropped it). Absolute path per the zyginit
# boot-script convention.
/usr/sbin/devfsadm -P

# Clear the first-boot reconfigure flag. hh-deploy drops /reconfigure so a
# fresh deploy does a full device enumeration on its first boot; the kernel
# reads the flag at boot and performs a reconfigure boot (rebuilding the
# device tree, ~15s to write /etc/devices/pci_unitaddr_persistent). illumos's
# devices-local method removes the flag afterwards — the zyginit port dropped
# that step, so WITHOUT this every boot reconfigures: slow boot + a long delay
# before the console login prompt appears. devfsadm above has now processed
# this boot's reconfigure, so it is safe to clear for subsequent boots.
# Absolute path per the zyginit boot-script convention.
/bin/rm -f /reconfigure

# Force PCI bus enumeration in case devfsadm alone didn't trigger it.
/usr/bin/ls /devices/pci@0,0/ > /dev/null 2>&1 || true

# Load AF_* → STREAMS-module mappings into the kernel sockfs. THIS is the
# step that makes socket(AF_INET, ...) work.
/sbin/soconfig -d /etc/sock2path.d

# Refresh kernel driver.conf cache.
/usr/sbin/devfsadm -I

exit 0