diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-08-07 11:11:40 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-01-04 09:45:59 -0500 |
commit | 52d95f50729b40628ae77d667d262c5235e50cb8 (patch) | |
tree | ef587b5834d13645b5997bd287f2acef66060f9f /libpod/lock/locks.go | |
parent | b489feff717a9976ee177acd4b239acf2dc9c326 (diff) | |
download | podman-52d95f50729b40628ae77d667d262c5235e50cb8.tar.gz podman-52d95f50729b40628ae77d667d262c5235e50cb8.tar.bz2 podman-52d95f50729b40628ae77d667d262c5235e50cb8.zip |
Propogate error codes from SHM lock creation and open
Also add a few more unit tests
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/lock/locks.go')
-rw-r--r-- | libpod/lock/locks.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libpod/lock/locks.go b/libpod/lock/locks.go index 14da7d6a7..c61bd78d2 100644 --- a/libpod/lock/locks.go +++ b/libpod/lock/locks.go @@ -27,16 +27,17 @@ type SHMLocks struct { // semaphores, and returns a struct that can be used to operate on those locks. // numLocks must be a multiple of the lock bitmap size (by default, 32). func CreateSHMLock(numLocks uint32) (*SHMLocks, error) { - if numLocks % bitmapSize != 0 { + if numLocks % bitmapSize != 0 || numLocks == 0 { return nil, errors.Wrapf(syscall.EINVAL, "number of locks must be a multiple of %d", C.bitmap_size_c) } locks := new(SHMLocks) - lockStruct := C.setup_lock_shm(C.uint32_t(numLocks)) + var errCode C.int = 0 + lockStruct := C.setup_lock_shm(C.uint32_t(numLocks), &errCode) if lockStruct == nil { // We got a null pointer, so something errored - return nil, errors.Wrapf(syscall.ENOENT, "error creating shared memory locks") + return nil, syscall.Errno(-1 * errCode) } locks.lockStruct = lockStruct @@ -51,16 +52,17 @@ func CreateSHMLock(numLocks uint32) (*SHMLocks, error) { // segment was created with and be a multiple of the lock bitmap size (default // 32) func OpenSHMLock(numLocks uint32) (*SHMLocks, error) { - if numLocks % bitmapSize != 0 { + if numLocks % bitmapSize != 0 || numLocks == 0 { return nil, errors.Wrapf(syscall.EINVAL, "number of locks must be a multiple of %d", C.bitmap_size_c) } locks := new(SHMLocks) - lockStruct := C.open_lock_shm(C.uint32_t(numLocks)) + var errCode C.int = 0 + lockStruct := C.open_lock_shm(C.uint32_t(numLocks), &errCode) if lockStruct == nil { // We got a null pointer, so something errored - return nil, errors.Wrapf(syscall.ENOENT, "error creating shared memory locks") + return nil, syscall.Errno(-1 * errCode) } locks.lockStruct = lockStruct |