s3:utils:mdsearch go to cmdline_messaging_context_free, fix 15284

mdsearch utility would exit earlier with failure in several cases like: a. samba server is not running yet,

[~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"'
main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED

b. spotlight backend service is not ready yet,

[~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"'
Failed to connect mdssvc

c. mdsearch utility paramters is not as expecred,

[~] # mdsearch -Uuser%password1 ${server} share_not_exist '*=="Samba"'
mdscli_search failed

And in the mean while once mdsearch utility exit earlier with failure, the lock files are left behind in the directory 'msg.sock' and 'msg.lock'. If a script to run mdsearch utility in a loop, this might result in used space slowly growing-up on underlying filesystem.

Supposed to add a new label 'fail_free_messaging', make it go through the cmdline_messaging_context_free() which deletes the lock files in the directory msg.sock and msg.lock before mdsearch utility is exiting with failure.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15284

  1. Before patch: mdsearch utility would exit earlier if server is not running yet, the lock entries '12827' are left behind in the 'msg.sock' and 'msg.lock'.
[~] # strace mdsearch -Uuser%password1 ${server} Public '*=="Samba"' 2>&1 | grep -E "msg..ock/|Cannot connect"
open("/var/lock/.samba/lock/msg.lock/12827", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 5
unlink("/usr/local/samba/private/msg.sock/12827") = -1 ENOENT (No such file or directory)
bind(6, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/12827"}, 110) = 0
write(2, "main: Cannot connect to server: "..., 61main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED
[~] #
[~] # ls /var/lock/.samba/lock/msg.lock/ /usr/local/samba/private/msg.sock/
/usr/local/samba/private/msg.sock/:
12827=

/var/lock/.samba/lock/msg.lock/:
12827
[~] #
  1. After patch: strace shows that the lock entries are created and then deleted before mdsearch utility is exiting.
[~] # strace mdsearch -Uuser%password1 ${server} Public '*=="Samba"' 2>&1 | grep -E "msg..ock/|Cannot connect"
open("/var/lock/.samba/lock/msg.lock/14401", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 5
unlink("/usr/local/samba/private/msg.sock/14401") = -1 ENOENT (No such file or directory)
bind(6, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/14401"}, 110) = 0
write(2, "main: Cannot connect to server: "..., 61main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED
unlink("/usr/local/samba/private/msg.sock/14401") = 0
unlink("/var/lock/.samba/lock/msg.lock/14401") = 0
[~] #

strace with '-k' shows that the destructor is triggered.

unlink("/usr/local/samba/private/msg.sock/15817") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x12a) [0x370a]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x51dbc]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(main+0x4b6) [0x4286]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(_start+0x29) [0x4509]
unlink("/var/lock/.samba/lock/msg.lock/15817") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x155) [0x3735]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x51dbc]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(main+0x4b6) [0x4286]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(_start+0x29) [0x4509]

Checklist

  • Commits have Signed-off-by: with name/author being identical to the commit author
  • (optional) This MR is just one part towards a larger feature.
  • (optional, if backport required) Bugzilla bug filed and BUG: tag added
  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Documentation updated
  • CI timeout is 3h or higher (see Settings/CICD/General pipelines/ Timeout)

Reviewer's checklist:

  • There is a test suite reasonably covering new functionality or modifications
  • Function naming, parameters, return values, types, etc., are consistent and according to README.Coding.md
  • This feature/change has adequate documentation added
  • No obvious mistakes in the code

Merge request reports

Loading