Source
zabbix_log(LOG_LEVEL_DEBUG, "In %s() shmid:%d size:" ZBX_FS_SIZE_T, __func__, shm->shmid, (zbx_fs_size_t)size);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/******************************************************************************
* *
* Purpose: creates dynamic shared memory segment *
* *
* Parameters: shm - [OUT] the dynamic shared memory data *
* shm_size - [IN] the initial size (can be 0) *
* mutex - [IN] the name of mutex used to synchronize memory *
* access *
* copy_func - [IN] the function used to copy shared memory *
* contents during reallocation *
* errmsg - [OUT] the error message *
* *
* Return value: SUCCEED - the dynamic shared memory segment was created *
* successfully. *
* FAIL - otherwise. The errmsg contains error message and *
* must be freed by the caller. *
* *
******************************************************************************/
int zbx_dshm_create(zbx_dshm_t *shm, size_t shm_size, zbx_mutex_name_t mutex,
zbx_shm_copy_func_t copy_func, char **errmsg)
{
int ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() size:" ZBX_FS_SIZE_T, __func__, (zbx_fs_size_t)shm_size);
if (SUCCEED != zbx_mutex_create(&shm->lock, mutex, errmsg))
goto out;
if (0 < shm_size)
{
if (-1 == (shm->shmid = zbx_shm_create(shm_size)))
{
*errmsg = zbx_strdup(*errmsg, "cannot allocate shared memory");
goto out;
}
}
else
shm->shmid = ZBX_NONEXISTENT_SHMID;
shm->size = shm_size;
shm->copy_func = copy_func;
ret = SUCCEED;
out:
zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s shmid:%d", __func__, zbx_result_string(ret), shm->shmid);