Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.capone
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ for line in $imgret; do
linedecode=$(echo $line | base64 -d)
[[ -z $linedecode ]] && handleError "No image definition was found for $dmivalue ($0)\n Args Passed: $*"
let cnt+=1
awk_returned_vars=$(echo $linedecode | awk -F'|' "{printf(\"%s %s %s %s %s %s %s\",\$1,\$2,\$3,\$4,\$5,\$6,\$7)}")
read img osid imgType imgPartitionType imgFormat storage storageip <<< $awk_returned_vars
determineOS "$osid"
awk_returned_vars=$(echo $linedecode | awk -F'|' "{printf(\"%s %s %s %s %s %s %s %s\",\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8)}")
read img osid imgType imgPartitionType imgFormat storage storageip osfamily <<< $awk_returned_vars
determineOS "$osid" "$osfamily"
echo -n " ID $cnt) "
echo -n " OS: $osname"
echo -n " Image: "
Expand Down Expand Up @@ -92,9 +92,9 @@ case $cnt in
linedecode=$(echo $line | base64 -d)
let cnt+=1
if [[ $cnt -eq $imgchoice ]]; then
awk_returned_vars=$(echo $linedecode | awk -F'|' "{printf(\"%s %s %s %s %s %s %s\",\$1,\$2,\$3,\$4,\$5,\$6,\$7)}")
read img osid imgType imgPartitionType imgFormat storage storageip <<< $awk_returned_vars
determineOS "$osid"
awk_returned_vars=$(echo $linedecode | awk -F'|' "{printf(\"%s %s %s %s %s %s %s %s\",\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8)}")
read img osid imgType imgPartitionType imgFormat storage storageip osfamily <<< $awk_returned_vars
determineOS "$osid" "$osfamily"
break
fi
done
Expand All @@ -105,9 +105,10 @@ export type="down"
export mac=$(getMACAddresses)
export img
export osid
# The Capone menu sends no osfamily=, and fog.checkin reads it again on the
# way through fog -> fog.download. Clear it so a Capone image never inherits one.
export osfamily=""
# The family comes from the chosen Capone line (its eighth field). A plugin
# that sends seven fields leaves it empty, which determineOS treats as "not
# sent". fog.checkin reads it again on the way through fog -> fog.download.
export osfamily
export imgType
export imgPartitionType
export imgFormat
Expand Down
7 changes: 4 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ and add a new ADR for any similarly hard-to-reverse decision:
`osfamily=` and is optional: empty means a built-in fallback for the ids FOS
knows (8, 9-11, 50/51, 99), and a non-empty family from the server wins. The
family is an argument, not a global: `fog.checkin` and `fog.debug` pass it,
`fog.capone` does not and exports an empty `osfamily`, so a Capone image never
inherits one. Empty family plus unknown osid, or a bad family on a
non-frozen id, is fatal (ADR-0003). Do not add an osid comparison outside
`fog.capone` passes the eighth field of the chosen Capone line (empty from a
seven-field plugin) and exports it, so a Capone image never inherits
another's. Empty family plus unknown osid, or a bad family on a non-frozen
id, is fatal (ADR-0003). Do not add an osid comparison outside
`determineOS()`. Guarded by `tests/checks/os-class.sh`.

General conventions to preserve when editing `funcs.sh`/`partition-funcs.sh`:
Expand Down
18 changes: 11 additions & 7 deletions docs/adr/0022-os-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ branches on `osClass`.** `determineOS "$osid" "$family"` sets it.

## Why the family is an argument

`fog.checkin` and `fog.debug` pass `"$osfamily"`. `fog.capone` does not,
because its image comes from the Capone listing and not from the kernel
command line. `fog.capone` also exports an empty `osfamily`, because `fog` runs
`fog.download` and `fog.checkin` next, and they read `$osfamily` again. A
global read inside `determineOS()` would let a Capone image inherit a family
meant for another image. A new osid in a Capone listing still aborts. That
needs a server change to the Capone string, and is a follow-on.
`fog.checkin` and `fog.debug` pass `"$osfamily"`. `fog.capone` passes the
family from the eighth field of the chosen Capone line, because its image comes
from the Capone listing and not from the kernel command line. A plugin that
sends seven fields leaves `osfamily` empty, which `determineOS()` treats as
"not sent". `fog.capone` exports `osfamily`, because `fog` runs `fog.download`
and `fog.checkin` next, and they read `$osfamily` again. A global read inside
`determineOS()` would let a Capone image inherit a family meant for another
image. A new osid in a Capone listing resolves from its family when the plugin
sends the eighth field (fog-plugins v1.6.29 or later, on a core with
`Image::getOSFamily()`). From an older plugin the field is empty, and an
unknown osid still aborts (ADR-0003). See FOGProject/fog-plugins#43.

## Consequences

Expand Down
41 changes: 34 additions & 7 deletions tests/checks/os-class.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,40 @@ grep -qF 'determineOS "$osid" "$osfamily"' "$BIN/fog.checkin"
eq "fog.checkin passes the family" $? 0
grep -qF 'determineOS "$osid" "$osfamily"' "$BIN/fog.debug"
eq "fog.debug passes the family" $? 0
# Capone has no family: its image comes from the Capone listing.
eq "fog.capone passes no family" "$(grep -c 'determineOS "\$osid" ' "$BIN/fog.capone")" 0
eq "fog.capone calls determineOS" "$(grep -c 'determineOS "\$osid"$' "$BIN/fog.capone")" 2
# The handoff to fog -> fog.download -> fog.checkin must not inherit a family.
grep -qxF 'export osfamily=""' "$BIN/fog.capone"
eq "fog.capone exports an empty osfamily" $? 0
exp="$(grep -nxF 'export osfamily=""' "$BIN/fog.capone" | cut -d: -f1)"
# Capone sends the family as the eighth field of each image line.
eq "fog.capone read lines name osfamily eighth" \
"$(grep -cE '^\s*read img osid imgType imgPartitionType imgFormat storage storageip osfamily <<< ' "$BIN/fog.capone")" 2
eq "fog.capone passes the family to determineOS" "$(grep -cF 'determineOS "$osid" "$osfamily"' "$BIN/fog.capone")" 2
eq "fog.capone has no bare determineOS" "$(grep -cE 'determineOS "\$osid"\s*$' "$BIN/fog.capone")" 0
# Run the awk and read text from fog.capone itself, not a copy.
CAPONE="$BIN/fog.capone"
capone_pipe() { # capone_pipe <n> <decoded line>: the nth awk/read pair, prints the eight variables
(
linedecode="$2"
awkline="$(grep '^\s*awk_returned_vars=' "$CAPONE" | awk -v n="$1" 'NR == n')"
readline="$(grep '^\s*read img osid' "$CAPONE" | awk -v n="$1" 'NR == n')"
[[ -n $awkline && -n $readline ]] || { echo "NOEXTRACT"; exit 1; }
eval "$awkline"
eval "$readline"
echo "$img|$osid|$imgType|$imgPartitionType|$imgFormat|$storage|$storageip|$osfamily"
)
}
# Both the listing loop and the selection loop carry their own awk and read.
eq "fog.capone awk lines carrying \$8" "$(grep -cE '^\s*awk_returned_vars=.*\\\$8' "$CAPONE")" 2
for n in 1 2; do
awkno="$(grep -n '^\s*awk_returned_vars=' "$CAPONE" | awk -v n="$n" 'NR == n' | cut -d: -f1)"
if [[ -z $awkno ]]; then fail "extract awk_returned_vars pair $n from fog.capone"; continue; fi
eq "capone line with eight fields (pair $n, fog.capone:$awkno)" \
"$(capone_pipe "$n" 'win11|10|n|1|2|10.0.0.1:/images|10.0.0.1|windows')" \
'win11|10|n|1|2|10.0.0.1:/images|10.0.0.1|windows'
eq "capone line with seven fields (pair $n, fog.capone:$awkno)" \
"$(capone_pipe "$n" 'win11|10|n|1|2|10.0.0.1:/images|10.0.0.1')" \
'win11|10|n|1|2|10.0.0.1:/images|10.0.0.1|'
done
# The handoff to fog -> fog.download -> fog.checkin carries the chosen family.
grep -qxF 'export osfamily' "$BIN/fog.capone"
eq "fog.capone exports osfamily" $? 0
exp="$(grep -nxF 'export osfamily' "$BIN/fog.capone" | cut -d: -f1)"
run="$(grep -nE '^\s*(exec )?fog( |$)|/bin/fog( |$)' "$BIN/fog.capone" | tail -1 | cut -d: -f1)"
if [[ -n $exp && -n $run && $exp -lt $run ]]; then pass; else fail "fog.capone exports osfamily before it runs fog" "export line '$exp', fog line '$run'"; fi

Expand Down
Loading