summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ssm/pool.c34
-rw-r--r--src/lib/ssm/tests/CMakeLists.txt3
-rw-r--r--src/lib/ssm/tests/pool_sharding_test.c12
-rw-r--r--src/lib/ssm/tests/pool_test.c43
4 files changed, 39 insertions, 53 deletions
diff --git a/src/lib/ssm/pool.c b/src/lib/ssm/pool.c
index e938f644..a388742d 100644
--- a/src/lib/ssm/pool.c
+++ b/src/lib/ssm/pool.c
@@ -477,7 +477,6 @@ static ssize_t alloc_from_sc_b(struct ssm_pool * pool,
static char * pool_filename(uid_t uid)
{
char * str;
- char * test_suffix;
char base[64];
if (IS_GSPP(uid))
@@ -485,15 +484,7 @@ static char * pool_filename(uid_t uid)
else
snprintf(base, sizeof(base), SSM_PUP_NAME_FMT, (int) uid);
- test_suffix = getenv("OUROBOROS_TEST_POOL_SUFFIX");
- if (test_suffix != NULL) {
- str = malloc(strlen(base) + strlen(test_suffix) + 1);
- if (str == NULL)
- return NULL;
- sprintf(str, "%s%s", base, test_suffix);
- } else {
- str = strdup(base);
- }
+ str = strdup(base);
return str;
}
@@ -540,6 +531,7 @@ void ssm_pool_destroy(struct ssm_pool * pool)
static struct ssm_pool * __pool_create(const char * name,
int flags,
uid_t uid,
+ gid_t gid,
mode_t mode)
{
struct ssm_pool * pool;
@@ -559,8 +551,14 @@ static struct ssm_pool * __pool_create(const char * name,
if (fd == -1)
goto fail_open;
- if ((flags & O_CREAT) && ftruncate(fd, (off_t) file_size) < 0)
- goto fail_truncate;
+ if (flags & O_CREAT) {
+ if (ftruncate(fd, (off_t) file_size) < 0)
+ goto fail_truncate;
+ if (uid != geteuid())
+ (void) fchown(fd, uid, gid);
+ if (fchmod(fd, mode) < 0)
+ goto fail_truncate;
+ }
shm_base = mmap(NULL, file_size, MM_FLAGS, MAP_SHARED, fd, 0);
if (shm_base == MAP_FAILED)
@@ -598,7 +596,6 @@ struct ssm_pool * ssm_pool_create(uid_t uid,
mode_t mode;
pthread_mutexattr_t mattr;
pthread_condattr_t cattr;
- int fd;
fn = pool_filename(uid);
if (fn == NULL)
@@ -607,20 +604,13 @@ struct ssm_pool * ssm_pool_create(uid_t uid,
mode = IS_GSPP(uid) ? 0660 : 0600;
mask = umask(0);
- pool = __pool_create(fn, O_CREAT | O_EXCL | O_RDWR, uid, mode);
+ pool = __pool_create(fn, O_CREAT | O_EXCL | O_RDWR, uid, gid, mode);
umask(mask);
if (pool == NULL)
goto fail_pool;
- fd = shm_open(fn, O_RDWR, 0);
- if (fd >= 0) {
- fchown(fd, uid, gid);
- fchmod(fd, mode);
- close(fd);
- }
-
if (pthread_mutexattr_init(&mattr))
goto fail_mattr;
@@ -676,7 +666,7 @@ struct ssm_pool * ssm_pool_open(uid_t uid)
if (fn == NULL)
return NULL;
- pool = __pool_create(fn, O_RDWR, uid, 0);
+ pool = __pool_create(fn, O_RDWR, uid, 0, 0);
if (pool != NULL)
init_size_classes(pool);
diff --git a/src/lib/ssm/tests/CMakeLists.txt b/src/lib/ssm/tests/CMakeLists.txt
index 5cac70d1..d622d41c 100644
--- a/src/lib/ssm/tests/CMakeLists.txt
+++ b/src/lib/ssm/tests/CMakeLists.txt
@@ -18,5 +18,4 @@ target_link_libraries(${PARENT_DIR}_test ouroboros-common)
add_dependencies(build_tests ${PARENT_DIR}_test)
-ouroboros_register_tests(TARGET ${PARENT_DIR}_test TESTS ${${PARENT_DIR}_tests}
- ENVIRONMENT "OUROBOROS_TEST_POOL_SUFFIX=.test")
+ouroboros_register_tests(TARGET ${PARENT_DIR}_test TESTS ${${PARENT_DIR}_tests})
diff --git a/src/lib/ssm/tests/pool_sharding_test.c b/src/lib/ssm/tests/pool_sharding_test.c
index 46eecd8d..4ecd2b9c 100644
--- a/src/lib/ssm/tests/pool_sharding_test.c
+++ b/src/lib/ssm/tests/pool_sharding_test.c
@@ -68,7 +68,7 @@ static int test_lazy_distribution(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL) {
printf("Failed to create pool.\n");
goto fail;
@@ -141,7 +141,7 @@ static int test_shard_migration(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL) {
printf("Failed to create pool.\n");
goto fail;
@@ -213,7 +213,7 @@ static int test_fallback_stealing(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL) {
printf("Failed to create pool.\n");
goto fail;
@@ -326,7 +326,7 @@ static int test_multiprocess_sharding(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL) {
printf("Failed to create pool.\n");
goto fail;
@@ -348,7 +348,7 @@ static int test_multiprocess_sharding(void)
ssize_t off;
int my_shard;
- child_pool = ssm_pool_open(0);
+ child_pool = ssm_pool_open(getuid());
if (child_pool == NULL)
exit(EXIT_FAILURE);
@@ -442,7 +442,7 @@ static int test_exhaustion_with_fallback(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL) {
printf("Failed to create pool.\n");
goto fail;
diff --git a/src/lib/ssm/tests/pool_test.c b/src/lib/ssm/tests/pool_test.c
index 53f7f541..87d4d71c 100644
--- a/src/lib/ssm/tests/pool_test.c
+++ b/src/lib/ssm/tests/pool_test.c
@@ -61,7 +61,7 @@ static int test_ssm_pool_basic_allocation(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -119,7 +119,7 @@ static int test_ssm_pool_multiple_allocations(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -212,7 +212,7 @@ static int test_ssm_pool_no_fallback_for_large(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -248,7 +248,7 @@ static int test_ssm_pool_blocking_vs_nonblocking(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -295,7 +295,7 @@ static int test_ssm_pool_stress_test(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -305,14 +305,14 @@ static int test_ssm_pool_stress_test(void)
goto fail_alloc;
}
- for (i = 0; i < 100; i++) {
+ for (i = 0; i < 50; i++) {
size_t j;
size_t num;
size_t size;
- num = (i % 100) + 1;
+ num = (i % 50) + 1;
- for (j = 0; j < num && count < 100; j++) {
+ for (j = 0; j < num && count < 50; j++) {
switch (i % 4) {
case 0:
/* FALLTHRU */
@@ -392,7 +392,7 @@ static int test_ssm_pool_open_initializes_ssm(void)
TEST_START();
- creator = ssm_pool_create(0, getgid());
+ creator = ssm_pool_create(getuid(), getgid());
if (creator == NULL)
goto fail_create;
@@ -403,7 +403,7 @@ static int test_ssm_pool_open_initializes_ssm(void)
}
ssm_pool_remove(creator, ret);
- opener = ssm_pool_open(0);
+ opener = ssm_pool_open(getuid());
if (opener == NULL) {
printf("Open failed.\n");
goto fail_creator;
@@ -439,7 +439,7 @@ static int test_ssm_pool_bounds_checking(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -502,7 +502,7 @@ static int test_ssm_pool_inter_process_communication(void)
len = strlen(msg) + 1;
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -606,7 +606,7 @@ static int test_ssm_pool_read_operation(void)
len = strlen(data) + 1;
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -656,7 +656,7 @@ static int test_ssm_pool_mlock_operation(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -690,7 +690,7 @@ static int test_ssm_pk_buff_operations(void)
dlen = strlen(data);
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -772,7 +772,6 @@ static int test_ssm_pool_size_class_boundaries(void)
struct ssm_pk_buff * spb;
uint8_t * ptr;
size_t sizes[] = {
- 1,
POOL_512 - OVERHEAD,
POOL_512 - OVERHEAD + 1,
POOL_1K - OVERHEAD,
@@ -786,19 +785,17 @@ static int test_ssm_pool_size_class_boundaries(void)
POOL_64K - OVERHEAD,
POOL_64K - OVERHEAD + 1,
POOL_256K - OVERHEAD,
- POOL_256K - OVERHEAD + 1,
- POOL_1M - OVERHEAD,
};
size_t expected_classes[] = {
- 512, 512, 1024, 1024, 2048, 2048, 4096, 4096, 16384,
- 16384, 65536, 65536, 262144, 262144, 1048576, 1048576
+ 512, 1024, 1024, 2048, 2048, 4096, 4096, 16384,
+ 16384, 65536, 65536, 262144, 262144
};
size_t i;
ssize_t idx;
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -859,7 +856,7 @@ static int test_ssm_pool_exhaustion(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;
@@ -937,7 +934,7 @@ static int test_ssm_pool_reclaim_orphans(void)
TEST_START();
- pool = ssm_pool_create(0, getgid());
+ pool = ssm_pool_create(getuid(), getgid());
if (pool == NULL)
goto fail_create;