// get the size of shm
if (shmctl(buf->shmid, IPC_STAT, &shm_buf))
{
- perror("SHM: shmctl");
- dlt_log(LOG_ERR,"SHM: shmctl");
-- return -1; /* ERROR */
++ dlt_log(LOG_ERR,"SHM: shmctl");
++ return -1; /* ERROR */
}
-- // Now we attach the segment to our data space.
-- if ((buf->shm = shmat(buf->shmid, NULL, 0)) == (char *) -1) {
- perror("shmat");
- dlt_log(LOG_ERR,"shmat");
-- return -1; /* ERROR */
-- }
++ // Now we attach the segment to our data space.
++ if ((buf->shm = shmat(buf->shmid, NULL, 0)) == (char *) -1) {
++ dlt_log(LOG_ERR,"shmat");
++ return -1; /* ERROR */
++ }
// Init semaphore
if( (buf->semid = semget(DLT_SHM_SEM,0,0)) == -1 ) {
- perror("SHM: semget");
- dlt_log(LOG_ERR,"SHM: semget");
-- return -1; /* ERROR */
++ dlt_log(LOG_ERR,"SHM: semget");
++ return -1; /* ERROR */
}
- DLT_SHM_SEM_FREE(buf->semid);
// Init pointers
-- buf->mem = (char*)(&(((int*)(buf->shm))[3]));
-- buf->size = shm_buf.shm_segsz - (buf->mem - buf->shm);
++ buf->mem = (char*)(&(((int*)(buf->shm))[3]));
++ buf->size = shm_buf.shm_segsz - (buf->mem - buf->shm);
//dlt_shm_status(buf);
-- //dlt_shm_info(buf);
++ //dlt_shm_info(buf);
return 0; /* OK */
}
// check status
if(status != 2 ) {
+ //printf("Buffer is not fully written\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"Buffer is not fully written\n");
return -1; // ERROR
}
// plausibility check of buffer size
if( (read+size) > buf->size) {
- printf("SHM: Buffers size bigger than shm buffer\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n");
+ dlt_shm_reset(buf);
return -1; // ERROR
}
// check max read size
if(size > max_size) {
- printf("SHM: Buffer is bigger than max size\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"SHM: Buffer is bigger than max size\n");
+ dlt_shm_reset(buf);
return -1; // ERROR
}
if(!buf->mem) {
// shm not initialised
- printf("SHM: SHM not initialised\n");
+ dlt_log(LOG_ERR,"SHM: SHM not initialised\n");
return -1; /* ERROR */
}
- DLT_SHM_SEM_FREE(buf->semid);
// get current write pointer
DLT_SHM_SEM_GET(buf->semid);
// check status
if(status != 2 ) {
- //printf("Buffer is not fully written\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"Buffer is not fully written\n");
return -1; // ERROR
}
// plausibility check of buffer size
if( (read+size) > buf->size) {
- printf("SHM: Buffers size bigger than shm buffer\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n");
+ dlt_shm_reset(buf);
return -1; // ERROR
}
// check max read size
if((size-sizeof(head)) > max_size) {
- printf("SHM: Buffer is bigger than max size\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"SHM: Buffer is bigger than max size\n");
+ dlt_shm_reset(buf);
return -1; // ERROR
}
// check status
if(status != 2 ) {
- //printf("Buffer is not fully written\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"Buffer is not fully written\n");
return -1; // ERROR
}
// plausibility check of buffer size
if( (read+size) > buf->size) {
- printf("SHM: Buffers size bigger than shm buffer\n");
+ DLT_SHM_SEM_FREE(buf->semid);
+ dlt_log(LOG_ERR,"SHM: Buffers size bigger than shm buffer\n");
+ dlt_shm_reset(buf);
return -1; // ERROR
}
/* reset pointers and counters */
DLT_SHM_SEM_GET(buf->semid);
-- ((int*)(buf->shm))[0] = 0; // pointer to write memory
-- ((int*)(buf->shm))[1] = 0; // pointer to read memory
-- ((int*)(buf->shm))[2] = 0; // number of packets
++ ((int*)(buf->shm))[0] = 0; // pointer to write memory
++ ((int*)(buf->shm))[1] = 0; // pointer to read memory
++ ((int*)(buf->shm))[2] = 0; // number of packets
DLT_SHM_SEM_FREE(buf->semid);
return 0; /* OK */