Example #1
0
// Remove marks the shared memory segment for removal.
// It will be removed when all attachments have been closed.
func (shm *SharedMem) Remove() error {
	rc, err := C.shmctl(C.int(shm.id), C.IPC_RMID, nil)
	if rc == -1 {
		return err
	}
	return nil
}
Example #2
0
// Stat produces meta information about the shared memory segment.
func (shm *SharedMem) Stat() (*SHMInfo, error) {
	shmds := C.struct_shmid_ds{}

	rc, err := C.shmctl(C.int(shm.id), C.IPC_STAT, &shmds)
	if rc == -1 {
		return nil, err
	}

	shminf := SHMInfo{
		Perms: IpcPerms{
			OwnerUID:   int(shmds.shm_perm.uid),
			OwnerGID:   int(shmds.shm_perm.gid),
			CreatorUID: int(shmds.shm_perm.cuid),
			CreatorGID: int(shmds.shm_perm.cgid),
			Mode:       uint16(shmds.shm_perm.mode),
		},
		SegmentSize:     uint(shmds.shm_segsz),
		LastAttach:      time.Unix(int64(shmds.shm_atime), 0),
		LastDetach:      time.Unix(int64(shmds.shm_dtime), 0),
		LastChange:      time.Unix(int64(shmds.shm_ctime), 0),
		CreatorPID:      int(shmds.shm_cpid),
		LastUserPID:     int(shmds.shm_lpid),
		CurrentAttaches: uint(shmds.shm_nattch),
	}

	return &shminf, nil
}
Example #3
0
// Set updates parameters of the shared memory segment.
func (shm *SharedMem) Set(info *SHMInfo) error {
	shmds := &C.struct_shmid_ds{
		shm_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(info.Perms.OwnerUID),
			gid:  C.__gid_t(info.Perms.OwnerGID),
			mode: C.ushort(info.Perms.Mode & 0x1FF),
		},
	}

	rc, err := C.shmctl(C.int(shm.id), C.IPC_SET, shmds)
	if rc == -1 {
		return err
	}
	return nil
}