diff --git a/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp b/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
index a6c94ac..fb03b4a 100644
a
|
b
|
|
25 | 25 | #include <sys/stat.h> |
26 | 26 | #include <sys/shm.h> |
27 | 27 | |
| 28 | #if _POSIX_MAPPED_FILES > 0L |
| 29 | #include <sys/mman.h> |
| 30 | #endif |
| 31 | |
28 | 32 | #ifdef linux |
29 | 33 | # include <sys/vfs.h> |
30 | 34 | # include <sys/statvfs.h> |
… |
… |
ZMServer::ZMServer(int sock, bool debug) |
218 | 222 | cout << "Shared memory key is: " << buf << endl; |
219 | 223 | } |
220 | 224 | |
| 225 | // get the MMAP path |
| 226 | m_mmapPath = getZMSetting("ZM_PATH_MAP"); |
| 227 | if (m_debug) |
| 228 | { |
| 229 | cout << "Memory path directory is: " << m_mmapPath << endl; |
| 230 | } |
| 231 | |
221 | 232 | // get the event filename format |
222 | 233 | setting = getZMSetting("ZM_EVENT_IMAGE_DIGITS"); |
223 | 234 | int eventDigits = atoi(setting.c_str()); |
… |
… |
void ZMServer::getMonitorList(void) |
1286 | 1297 | |
1287 | 1298 | void ZMServer::initMonitor(MONITOR *monitor) |
1288 | 1299 | { |
1289 | | void *shm_ptr; |
| 1300 | void *shm_ptr = NULL; |
1290 | 1301 | |
1291 | 1302 | monitor->shared_data = NULL; |
1292 | 1303 | monitor->shared_images = NULL; |
… |
… |
void ZMServer::initMonitor(MONITOR *monitor) |
1309 | 1320 | ((monitor->image_buffer_count) * (sizeof(struct timeval))) + |
1310 | 1321 | ((monitor->image_buffer_count) * monitor->frame_size); |
1311 | 1322 | |
1312 | | int shmid; |
1313 | 1323 | |
1314 | | if ((shmid = shmget((m_shmKey & 0xffffff00) | monitor->mon_id, |
1315 | | shared_data_size, SHM_R)) == -1) |
| 1324 | #if _POSIX_MAPPED_FILES > 0L |
| 1325 | /* |
| 1326 | * Try to open the mmap file first if the architecture supports it. |
| 1327 | * Otherwise, legacy shared memory will be used below. |
| 1328 | */ |
| 1329 | stringstream mmap_filename; |
| 1330 | mmap_filename << m_mmapPath << "/zm.mmap." << monitor->mon_id; |
| 1331 | |
| 1332 | int mapFile = open(mmap_filename.str().c_str(), O_RDONLY, 0x0); |
| 1333 | if (mapFile >= 0) |
1316 | 1334 | { |
1317 | | cout << "Failed to shmget for monitor: " << monitor->mon_id << endl; |
1318 | | monitor->status = "Error"; |
1319 | | switch(errno) |
| 1335 | if (m_debug) |
| 1336 | cout << "Opened mmap file: " << mmap_filename << endl; |
| 1337 | |
| 1338 | shm_ptr = mmap(NULL, shared_data_size, PROT_READ, |
| 1339 | MAP_SHARED, mapFile, 0x0); |
| 1340 | if (shm_ptr == NULL) |
1320 | 1341 | { |
1321 | | case EACCES: cout << "EACCES - no rights to access segment\n"; break; |
1322 | | case EEXIST: cout << "EEXIST - segment already exists\n"; break; |
1323 | | case EINVAL: cout << "EINVAL - size < SHMMIN or size > SHMMAX\n"; break; |
1324 | | case ENFILE: cout << "ENFILE - limit on open files has been reached\n"; break; |
1325 | | case ENOENT: cout << "ENOENT - no segment exists for the given key\n"; break; |
1326 | | case ENOMEM: cout << "ENOMEM - couldn't reserve memory for segment\n"; break; |
1327 | | case ENOSPC: cout << "ENOSPC - shmmni or shmall limit reached\n"; break; |
| 1342 | cout << "Failed to map shared memory from file [" << |
| 1343 | mmap_filename << "] " << |
| 1344 | "for monitor: " << |
| 1345 | monitor->mon_id << |
| 1346 | endl; |
| 1347 | monitor->status = "Error"; |
| 1348 | return; |
1328 | 1349 | } |
1329 | | |
1330 | | return; |
1331 | 1350 | } |
1332 | | |
1333 | | shm_ptr = shmat(shmid, 0, SHM_RDONLY); |
1334 | | |
| 1351 | #endif |
1335 | 1352 | |
1336 | 1353 | if (shm_ptr == NULL) |
1337 | 1354 | { |
1338 | | cout << "Failed to shmat for monitor: " << monitor->mon_id << endl; |
1339 | | monitor->status = "Error"; |
1340 | | return; |
| 1355 | // fail back to shmget() functionality if mapping memory above failed. |
| 1356 | int shmid; |
| 1357 | |
| 1358 | if ((shmid = shmget((m_shmKey & 0xffffff00) | monitor->mon_id, |
| 1359 | shared_data_size, SHM_R)) == -1) |
| 1360 | { |
| 1361 | cout << "Failed to shmget for monitor: " << monitor->mon_id << endl; |
| 1362 | monitor->status = "Error"; |
| 1363 | switch(errno) |
| 1364 | { |
| 1365 | case EACCES: cout << "EACCES - no rights to access segment\n"; break; |
| 1366 | case EEXIST: cout << "EEXIST - segment already exists\n"; break; |
| 1367 | case EINVAL: cout << "EINVAL - size < SHMMIN or size > SHMMAX\n"; break; |
| 1368 | case ENFILE: cout << "ENFILE - limit on open files has been reached\n"; break; |
| 1369 | case ENOENT: cout << "ENOENT - no segment exists for the given key\n"; break; |
| 1370 | case ENOMEM: cout << "ENOMEM - couldn't reserve memory for segment\n"; break; |
| 1371 | case ENOSPC: cout << "ENOSPC - shmmni or shmall limit reached\n"; break; |
| 1372 | } |
| 1373 | |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | shm_ptr = shmat(shmid, 0, SHM_RDONLY); |
| 1378 | |
| 1379 | |
| 1380 | if (shm_ptr == NULL) |
| 1381 | { |
| 1382 | cout << "Failed to shmat for monitor: " << monitor->mon_id << endl; |
| 1383 | monitor->status = "Error"; |
| 1384 | return; |
| 1385 | } |
1341 | 1386 | } |
1342 | 1387 | |
1343 | 1388 | monitor->shared_data = (SharedData*)shm_ptr; |
diff --git a/mythplugins/mythzoneminder/mythzmserver/zmserver.h b/mythplugins/mythzoneminder/mythzmserver/zmserver.h
index 849f4ec..8d0dc4b 100644
a
|
b
|
class ZMServer |
191 | 191 | string m_eventFileFormat; |
192 | 192 | string m_analyseFileFormat; |
193 | 193 | key_t m_shmKey; |
| 194 | string m_mmapPath; |
194 | 195 | }; |
195 | 196 | |
196 | 197 | |