Add Windows automatic discovery support with WSDD#4491
Add Windows automatic discovery support with WSDD#4491madbrain76 wants to merge 9 commits intohome-assistant:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Windows automatic discovery support by installing wsdd, bumps addon version to 12.7.0, and adds s6-overlay service files, run/finish scripts, and a network-interfaces helper to select enabled interfaces for wsdd. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant s6 as s6 (supervisor)
participant init as init-smbd/run
participant helper as network-interfaces.sh
participant bashio as bashio (config/network)
participant wsdd as wsdd daemon
s6->>init: start init-smbd/run
init->>helper: source + get_enabled_interfaces()
helper->>bashio: query interfaces & enabled state
bashio-->>helper: enabled interfaces list
helper-->>init: return interfaces array
init->>s6: continue startup (prepare wsdd args)
s6->>wsdd: exec wsdd with -i (interfaces), -n (hostname), -w (workgroup)
wsdd-->>s6: exit (code, signal)
s6->>s6: run wsdd/finish logic (log, maybe halt)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/finish`:
- Around line 17-20: The finish script currently propagates a non-zero exit code
for signaled wsdd exits even when the container exit was previously healthy;
change the conditional that writes to
/run/s6-linux-init-container-results/exitcode so it only sets the propagated
signal exit (echo $((128 + exit_code_signal))) when other services already
indicated a non-zero container exit (i.e., require exit_code_container -ne 0) or
otherwise skip writing entirely for wsdd signal exits; update the conditional
around exit_code_service/exit_code_container/exit_code_signal in the wsdd finish
script accordingly so optional wsdd signal exits don’t taint the addon’s final
exit status.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b64f7bdb-1d82-410d-bded-eafb5b86ec3f
📒 Files selected for processing (8)
samba/CHANGELOG.mdsamba/Dockerfilesamba/config.yamlsamba/rootfs/etc/s6-overlay/s6-rc.d/user/contents.d/wsddsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/dependencies.d/init-smbdsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/finishsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/runsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/type
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Co-authored-by: Stefan Agner <stefan@agner.ch>
There was a problem hiding this comment.
🧹 Nitpick comments (2)
samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run (1)
20-21: Add a defensive fallback for empty workgroup.If Line 20 resolves to an empty value,
wsddstarts with-w "". Consider a safe default to avoid misconfiguration-driven startup issues.Proposed hardening
workgroup=$(bashio::config 'workgroup') +if bashio::var.is_empty "${workgroup}"; then + bashio::log.warning "Can't read workgroup, using default." + workgroup="WORKGROUP" +fi🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run` around lines 20 - 21, The workgroup variable read via workgroup=$(bashio::config 'workgroup') can be empty and produce a wsdd invocation like -w ""—add a defensive fallback after that assignment: check if variable is empty (e.g., test -z "$workgroup") and if so assign a sensible default (e.g., WORKGROUP or a configurable DEFAULT_WORKGROUP), then use that variable when starting wsdd; update the run script's wsdd invocation to rely on this validated workgroup variable (reference: workgroup variable and the wsdd start invocation in the run script).samba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/network-interfaces.sh (1)
12-12: Prefer line-safe iteration over word-splitting for interface enumeration.Line 12 iterates using
for interface in $(...), which applies word-splitting and globbing to the output. While Linux interface names typically don't contain problematic characters, usingwhile IFS= read -ris safer and follows Bash best practices.Refactor suggestion
- for interface in $(bashio::network.interfaces); do - interface_enabled=$(bashio::network.enabled "${interface}") - if bashio::var.true "${interface_enabled}"; then - _out_interfaces+=("${interface}") - fi - done + while IFS= read -r interface; do + interface_enabled=$(bashio::network.enabled "${interface}") + if bashio::var.true "${interface_enabled}"; then + _out_interfaces+=("${interface}") + fi + done < <(bashio::network.interfaces)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@samba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/network-interfaces.sh` at line 12, The for-loop using command substitution over bashio::network.interfaces should be replaced with a line-safe reader loop: read each interface into the variable interface using a while IFS= read -r loop that consumes the output of bashio::network.interfaces (via a pipe or process substitution) to avoid word-splitting and globbing; update the loop that references interface so its body behavior remains identical (keep any commands that follow unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@samba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/network-interfaces.sh`:
- Line 12: The for-loop using command substitution over
bashio::network.interfaces should be replaced with a line-safe reader loop: read
each interface into the variable interface using a while IFS= read -r loop that
consumes the output of bashio::network.interfaces (via a pipe or process
substitution) to avoid word-splitting and globbing; update the loop that
references interface so its body behavior remains identical (keep any commands
that follow unchanged).
In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run`:
- Around line 20-21: The workgroup variable read via workgroup=$(bashio::config
'workgroup') can be empty and produce a wsdd invocation like -w ""—add a
defensive fallback after that assignment: check if variable is empty (e.g., test
-z "$workgroup") and if so assign a sensible default (e.g., WORKGROUP or a
configurable DEFAULT_WORKGROUP), then use that variable when starting wsdd;
update the run script's wsdd invocation to rely on this validated workgroup
variable (reference: workgroup variable and the wsdd start invocation in the run
script).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bb280353-25b6-44a0-8fd6-ed6b9b3a01a5
📒 Files selected for processing (6)
samba/CHANGELOG.mdsamba/config.yamlsamba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/network-interfaces.shsamba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/runsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/finishsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run
✅ Files skipped from review due to trivial changes (2)
- samba/config.yaml
- samba/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
- samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/finish
There was a problem hiding this comment.
🧹 Nitpick comments (2)
samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run (2)
35-37: Simplify log formatting to avoid trailing whitespace
$(printf '%s ' ...)leaves a trailing space and splits message construction across two args. A single string is cleaner and more predictable.Proposed diff
-bashio::log.info \ - "Starting the WSDD daemon on interfaces: $(printf '%s ' "${interfaces[@]}")" \ - "for ${workgroup}/${hostname}" +bashio::log.info \ + "Starting the WSDD daemon on interfaces: ${interfaces[*]} for ${workgroup}/${hostname}"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run` around lines 35 - 37, The log call splits the message across two arguments and uses printf '%s ' which leaves a trailing space; replace the two-argument call and the printf with a single quoted string that joins the interfaces without trailing whitespace (e.g. use "${interfaces[*]}") so update the bashio::log.info invocation to a single string like: bashio::log.info "Starting the WSDD daemon on interfaces: ${interfaces[*]} for ${workgroup}/${hostname}".
21-21: Add an empty-value guard forworkgroupto matchhostnamevalidationLine 21 reads
workgroupfrom config without validating it, unlikehostnamewhich has a guard on lines 17–20. If a user setsworkgroupto an empty string, line 39 will invokewsddwith-w "", which is invalid and can trigger restart churn. The schema does not enforce a non-empty value (it is defined as plainstr). Add a guard defaulting toWORKGROUPwhen empty, consistent with thehostnamefallback pattern.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run` at line 21, The workgroup value read into the variable workgroup via bashio::config should be guarded for empty strings like the hostname handling: detect if workgroup is empty or unset and default it to the constant WORKGROUP before use, so that the wsdd invocation (which passes -w "$workgroup") never receives an empty argument; update the run script's workgroup assignment to perform the empty-value check and assignment similar to the hostname guard to prevent invalid `-w ""` calls and restart churn.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@samba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run`:
- Around line 35-37: The log call splits the message across two arguments and
uses printf '%s ' which leaves a trailing space; replace the two-argument call
and the printf with a single quoted string that joins the interfaces without
trailing whitespace (e.g. use "${interfaces[*]}") so update the bashio::log.info
invocation to a single string like: bashio::log.info "Starting the WSDD daemon
on interfaces: ${interfaces[*]} for ${workgroup}/${hostname}".
- Line 21: The workgroup value read into the variable workgroup via
bashio::config should be guarded for empty strings like the hostname handling:
detect if workgroup is empty or unset and default it to the constant WORKGROUP
before use, so that the wsdd invocation (which passes -w "$workgroup") never
receives an empty argument; update the run script's workgroup assignment to
perform the empty-value check and assignment similar to the hostname guard to
prevent invalid `-w ""` calls and restart churn.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e9cb2dc1-5a62-4066-a265-f26566a1a51b
📒 Files selected for processing (2)
samba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/runsamba/rootfs/etc/s6-overlay/s6-rc.d/wsdd/run
🚧 Files skipped from review as they are similar to previous changes (1)
- samba/rootfs/etc/s6-overlay/s6-rc.d/init-smbd/run
| if [[ "${exit_code_container}" -eq 0 ]]; then | ||
| echo $((128 + exit_code_signal)) > /run/s6-linux-init-container-results/exitcode | ||
| fi | ||
| exec /run/s6/basedir/bin/halt |
There was a problem hiding this comment.
This part feels a bit overengineered to me, but I am fine with it. I mostly meant we should not shutdown the container on regular failure, but what coderabbit suggested was a bit more elaborate 😅
| exec /run/s6/basedir/bin/halt | ||
| elif [[ "${exit_code_service}" -eq 256 ]]; then | ||
| bashio::log.warning \ | ||
| "Optional service ${service} exited by signal ${exit_code_signal}; continuing without Windows discovery." |
| "Optional service ${service} exited by signal ${exit_code_signal}; continuing without Windows discovery." | ||
| elif [[ "${exit_code_service}" -ne 0 ]]; then | ||
| bashio::log.warning \ | ||
| "Optional service ${service} failed; continuing without Windows discovery." |
There was a problem hiding this comment.
... and this case s6 will simply restart the service again. If we want it to remain stopped we need to exit the finish script with exit code 125 (permanent failure). And I'd make use of that here, since that is what the warning suggests is what we want to happen.
This patch allows the HAOS system to automatically show up in the "Network" tab on Windows hosts.
To minimize impact, I chose to make the the new service startup failure non-fatal. It will just log a warning in this case. I can change it back. I could make it fatal if that's preferred.
Summary by CodeRabbit
New Features
Chores
Stability