1 /* 2 ** Zabbix 3 ** Copyright (C) 2001-2021 Zabbix SIA 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ** GNU General Public License for more details. 14 ** 15 ** You should have received a copy of the GNU General Public License 16 ** along with this program; if not, write to the Free Software 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 **/ 19 20 #ifndef ZABBIX_IPC_H 21 #define ZABBIX_IPC_H 22 23 #if defined(_WINDOWS) 24 # error "This module allowed only for Unix OS" 25 #endif 26 27 #include "mutexs.h" 28 29 #define ZBX_NONEXISTENT_SHMID (-1) 30 31 #define ZBX_IPC_CONFIG_ID 'g' 32 #define ZBX_IPC_HISTORY_ID 'h' 33 #define ZBX_IPC_HISTORY_INDEX_ID 'H' 34 #define ZBX_IPC_TREND_ID 't' 35 #define ZBX_IPC_STRPOOL_ID 's' 36 #define ZBX_IPC_COLLECTOR_ID 'l' 37 #define ZBX_IPC_COLLECTOR_DISKSTAT 'm' 38 #define ZBX_IPC_SELFMON_ID 'S' 39 #define ZBX_IPC_VALUECACHE_ID 'v' 40 #define ZBX_IPC_VMWARE_ID 'w' 41 #define ZBX_IPC_COLLECTOR_PROC_ID 'p' 42 43 key_t zbx_ftok(char *path, int id); 44 int zbx_shmget(key_t key, size_t size); 45 46 /* data copying callback function prototype */ 47 typedef void (*zbx_shm_copy_func_t)(void *dst, size_t size_dst, const void *src); 48 49 /* dynamic shared memory data structure */ 50 typedef struct 51 { 52 /* shared memory segment identifier */ 53 int shmid; 54 55 /* project id used to generate shared memory key */ 56 int proj_id; 57 58 /* allocated size */ 59 size_t size; 60 61 /* callback function to copy data after shared memory reallocation */ 62 zbx_shm_copy_func_t copy_func; 63 64 ZBX_MUTEX lock; 65 } 66 zbx_dshm_t; 67 68 /* local process reference to dynamic shared memory data */ 69 typedef struct 70 { 71 /* shared memory segment identifier */ 72 int shmid; 73 74 /* shared memory base address */ 75 void *addr; 76 } 77 zbx_dshm_ref_t; 78 79 int zbx_dshm_create(zbx_dshm_t *shm, int proj_id, size_t shm_size, ZBX_MUTEX_NAME mutex, 80 zbx_shm_copy_func_t copy_func, char **errmsg); 81 82 int zbx_dshm_destroy(zbx_dshm_t *shm, char **errmsg); 83 84 int zbx_dshm_realloc(zbx_dshm_t *shm, size_t size, char **errmsg); 85 86 int zbx_dshm_validate_ref(const zbx_dshm_t *shm, zbx_dshm_ref_t *shm_ref, char **errmsg); 87 88 void zbx_dshm_lock(zbx_dshm_t *shm); 89 void zbx_dshm_unlock(zbx_dshm_t *shm); 90 91 #endif 92