Skip to content

Enhancement: Capture and display stderr from 'net usershare' on sharesmb failure #18987

Description

@c3ph3us

Is your feature request related to a problem? Please describe.

Yes. When zfs set sharesmb=on fails due to Samba configuration constraints (e.g., usershare max shares = 0), ZFS only outputs a generic, unhelpful error message:
cannot share 'pool/dataset': system error: SMB share creation failed

Samba system logs (log.smbd / journalctl) remain completely silent because the failure happens at the CLI utility level (/usr/bin/net), leaving the administrator completely blind during debugging.

Describe the solution you'd like

The ZFS utility should capture the stderr output from the spawned child process (/usr/bin/net usershare add ...) when it exits with a non-zero status, and append that specific error message to the ZFS command output instead of masking it.

Additional context (Logs and Reproducer)

Running strace -f reveals that ZFS forks a child process executing /usr/bin/net, which exits with status 255 (WEXITSTATUS(s) == 255):

clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fe7538d1950) = 127211
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
wait4(127211, [{WIFEXITED(s) && WEXITSTATUS(s) == 255}], 0, NULL) = 127211
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=127211, si_uid=0, si_status=255, si_utime=9 /* 0.09 s */, si_stime=1 /* 0.01 s */} ---
write(2, "cannot share 'rpool/media: syste"..., 68cannot share 'rpool/media: system error': SMB share creation failed
) = 68

When executing the exact underlying command manually as root, the actual root cause is instantly revealed by Samba:

ceph3us@scarabeus:~/\$ /usr/bin/net usershare add rpool_media /rpool/media "" "Everyone:F" guest_ok=n
net usershare: usershares are currently disabled

If ZFS simply passed this stderr output to the console instead of masking it behind a generic system error, it would save administrators hours of blind troubleshooting, especially after OS upgrades where default package maintainer configs change.

zfs-2.4.3-2
zfs-kmod-2.4.3-2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: FeatureFeature request or new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions