This commit is contained in:
Andrea Fioraldi
2020-01-17 16:41:30 +01:00
parent f24135f1ed
commit b6c5974b37
10 changed files with 239 additions and 200 deletions

View File

@ -72,8 +72,8 @@ static s32 shm_id; /* ID of the SHM region */
static s32 cmplog_shm_id;
#endif
int cmplog_mode;
struct cmp_map* cmp_map;
int cmplog_mode;
struct cmp_map *cmp_map;
/* Get rid of shared memory (atexit handler). */
@ -96,8 +96,7 @@ void remove_shm(void) {
#else
shmctl(shm_id, IPC_RMID, NULL);
if (cmplog_mode)
shmctl(cmplog_shm_id, IPC_RMID, NULL);
if (cmplog_mode) shmctl(cmplog_shm_id, IPC_RMID, NULL);
#endif
}
@ -155,15 +154,16 @@ void setup_shm(unsigned char dumb_mode) {
shm_id = shmget(IPC_PRIVATE, MAP_SIZE, IPC_CREAT | IPC_EXCL | 0600);
if (shm_id < 0) PFATAL("shmget() failed");
if (cmplog_mode) {
cmplog_shm_id = shmget(IPC_PRIVATE, sizeof(struct cmp_map), IPC_CREAT | IPC_EXCL | 0600);
cmplog_shm_id = shmget(IPC_PRIVATE, sizeof(struct cmp_map),
IPC_CREAT | IPC_EXCL | 0600);
if (cmplog_shm_id < 0) PFATAL("shmget() failed");
}
atexit(remove_shm);
shm_str = alloc_printf("%d", shm_id);
@ -176,21 +176,20 @@ void setup_shm(unsigned char dumb_mode) {
if (!dumb_mode) setenv(SHM_ENV_VAR, shm_str, 1);
ck_free(shm_str);
if (cmplog_mode) {
shm_str = alloc_printf("%d", cmplog_shm_id);
if (!dumb_mode) setenv(CMPLOG_SHM_ENV_VAR, shm_str, 1);
ck_free(shm_str);
}
trace_bits = shmat(shm_id, NULL, 0);
if (cmplog_mode)
cmp_map = shmat(cmplog_shm_id, NULL, 0);
if (cmplog_mode) cmp_map = shmat(cmplog_shm_id, NULL, 0);
if (!trace_bits) PFATAL("shmat() failed");