Steps to reproduce:
- Install zabbix_sender with Ports or pkg on FreeBSD or emerge on Gentoo Linux.
- Use the same configuration(zabbix_agentd.conf or zabbix_agent2.conf) with no problem on Zabbix 5.4.11.
- Execute "ipcs -s" before executing zabbix_sender command below.
- Execute "zabbix_sender -c ... -k test -o 1", where it is ok that key and value are random one.
- Execute "ipcs -s" after executing zabbix_sender command above.
- Not released semaphore owned by root is added.
Zabbix_sender in Zabbix 6 exits without releasing the semaphore it used on my FreeBSD 13.0 system.
Zabbix_sender in Zabbix 5.4.11 or below exits normally after releasing the semaphore it used.
I experienced the same situation on my Gentoo Linux system too.
But, zabbix_sender in Zabbix 6 exit with no problem on my Fedora 35, Ubuntu 20.04, Debian 11 or Arch Linux system.
I found the Asymmetric usage of zbx_locks_* in zabbix_sender.c.
- Initializing locks uses zbx_locks_create(&error) #ifndef _WINDOWS on l.1508 and l.1509
- Finalizing locks uses zbx_locks_disable() #if !defined(_WINDOWS) && defined(HAVE_PTHREAD_PROCESS_SHARED) on l.1868 and l.1869
HAVE_PTHREAD_PROCESS_SHARED appears only at finalizing, and zabbix_sender.c uses zabbix_locks_create() and zabbix_locks_disable().
In mutex.h, zbx_locks_enable() seems to be paired with zbx_locks_disable(), and zbx_locks_create() seems to be paired with zbx_locks_destroy().
So, I changed the zabbix_sender.c like the appended patch, and patched zabbix_sender just exits normally after releasing the semaphore it used
on my both FreeBSD 13.0 and Gentoo Linux systems.