Source
zabbix_log(LOG_LEVEL_DEBUG, "In %s() shmid:%d size:" ZBX_FS_SIZE_T, __func__, shm->shmid, (zbx_fs_size_t)size);
/*
** Zabbix
** 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 General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
extern char *CONFIG_FILE;
/******************************************************************************
* *
* 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;