diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-07-04 11:52:18 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-07-04 11:52:18 +0000 |
| commit | 2d9b8adec28cfb02eb9fb18be1f411070d560a78 (patch) | |
| tree | d9fd9fc8f6a85b167a8fa5c6c6b4105cb7b16ce0 /src/zabbix_agent | |
| parent | 87284087f0b676cf85589eab268bfd69d290f968 (diff) | |
| download | zabbix-2d9b8adec28cfb02eb9fb18be1f411070d560a78.tar.gz zabbix-2d9b8adec28cfb02eb9fb18be1f411070d560a78.tar.xz zabbix-2d9b8adec28cfb02eb9fb18be1f411070d560a78.zip | |
- fixed shared memory allocation (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@4426 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_agent')
| -rw-r--r-- | src/zabbix_agent/stats.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c index 6082d118..4e2371bc 100644 --- a/src/zabbix_agent/stats.c +++ b/src/zabbix_agent/stats.c @@ -76,19 +76,43 @@ void init_collector_data(void) #else /* not _WINDOWS */ +#define ZBX_MAX_ATTEMPTS 10 + int attempts = 0; + key_t shm_key; int shm_id; ZBX_GET_SHM_KEY(shm_key); - shm_id = shmget(shm_key, sizeof(ZBX_COLLECTOR_DATA), IPC_CREAT | 0666); - - if (-1 == shm_id) +lbl_create: + if ( -1 == (shm_id = shmget(shm_key, sizeof(ZBX_COLLECTOR_DATA), IPC_CREAT | IPC_EXCL | 0666 /* 0022 */)) ) { - zabbix_log(LOG_LEVEL_CRIT, "Can't allocate shared memory for collector. [%s]",strerror(errno)); - exit(1); + if( EEXIST == errno ) + { + zabbix_log(LOG_LEVEL_DEBUG, "Shared memory already exists for collector, trying to recreate."); + + shm_id = shmget(shm_key, 0 /* get reference */, 0666 /* 0022 */); + + shmctl(shm_id, IPC_RMID, 0); + if ( ++attempts > ZBX_MAX_ATTEMPTS ) + { + zabbix_log(LOG_LEVEL_CRIT, "Can't recreate shared memory for collector. [too many attempts]"); + exit(1); + } + if ( attempts > (ZBX_MAX_ATTEMPTS / 2) ) + { + zabbix_log(LOG_LEVEL_DEBUG, "Wait 1 sec for next attemtion of collector shared memory allocation."); + zbx_sleep(1); + } + goto lbl_create; + } + else + { + zabbix_log(LOG_LEVEL_CRIT, "Can't allocate shared memory for collector. [%s]",strerror(errno)); + exit(1); + } } - + collector = shmat(shm_id, 0, 0); if ((void*)(-1) == collector) |
