Skip to content

Commit cb33da3

Browse files
committed
open_ipc_handle should use shm from handle
1 parent e6ff45e commit cb33da3

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

src/provider/provider_os_memory.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ typedef struct os_ipc_data_t {
11461146
int fd;
11471147
size_t fd_offset;
11481148
size_t size;
1149-
char shm_name[NAME_MAX]; // optional - can be used or not (see below)
1149+
char shm_name[NAME_MAX]; // optional
11501150
} os_ipc_data_t;
11511151

11521152
static umf_result_t os_get_ipc_handle_size(void *provider, size_t *size) {
@@ -1160,13 +1160,9 @@ static umf_result_t os_get_ipc_handle_size(void *provider, size_t *size) {
11601160
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
11611161
}
11621162

1163-
if (os_provider->shm_name[0]) {
1164-
// os_ipc_data_t->shm_name will be used
1165-
*size = sizeof(os_ipc_data_t);
1166-
} else {
1167-
// os_ipc_data_t->shm_name will NOT be used
1168-
*size = sizeof(os_ipc_data_t) - NAME_MAX;
1169-
}
1163+
// for simplicity, always return size of the full structure even if we
1164+
// don't use named shared memory object
1165+
*size = sizeof(os_ipc_data_t);
11701166

11711167
return UMF_RESULT_SUCCESS;
11721168
}
@@ -1251,14 +1247,14 @@ static umf_result_t os_open_ipc_handle(void *provider, void *providerIpcData,
12511247
umf_result_t ret = UMF_RESULT_SUCCESS;
12521248
int fd;
12531249

1254-
if (os_provider->shm_name[0]) {
1255-
fd = utils_shm_open(os_provider->shm_name);
1250+
if (os_ipc_data->shm_name[0]) {
1251+
fd = utils_shm_open(os_ipc_data->shm_name);
12561252
if (fd <= 0) {
12571253
LOG_PERR("opening a shared memory file (%s) failed",
1258-
os_provider->shm_name);
1254+
os_ipc_data->shm_name);
12591255
return UMF_RESULT_ERROR_UNKNOWN;
12601256
}
1261-
(void)utils_shm_unlink(os_provider->shm_name);
1257+
(void)utils_shm_unlink(os_ipc_data->shm_name);
12621258
} else {
12631259
umf_result_t umf_result =
12641260
utils_duplicate_fd(os_ipc_data->pid, os_ipc_data->fd, &fd);

test/ipc_os_prov_consumer.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "ipc_os_prov_common.h"
1515

1616
int main(int argc, char *argv[]) {
17-
if (argc < 2) {
18-
fprintf(stderr, "usage: %s <port> [shm_name]\n", argv[0]);
17+
if (argc < 1) {
18+
fprintf(stderr, "usage: %s <port>\n", argv[0]);
1919
return -1;
2020
}
2121

@@ -25,9 +25,6 @@ int main(int argc, char *argv[]) {
2525

2626
os_params = umfOsMemoryProviderParamsDefault();
2727
os_params.visibility = UMF_MEM_MAP_SHARED;
28-
if (argc >= 3) {
29-
os_params.shm_name = argv[2];
30-
}
3128

3229
return run_consumer(port, umfOsMemoryProviderOps(), &os_params, memcopy,
3330
NULL);

test/ipc_os_prov_shm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ UMF_LOG_VAL="level:debug;flush:debug;output:stderr;pid:yes"
2020
rm -f /dev/shm/${SHM_NAME}
2121

2222
echo "Starting ipc_os_prov_shm CONSUMER on port $PORT ..."
23-
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_os_prov_consumer $PORT $SHM_NAME &
23+
UMF_LOG=$UMF_LOG_VAL ./umf_test-ipc_os_prov_consumer $PORT &
2424

2525
echo "Waiting 1 sec ..."
2626
sleep 1

0 commit comments

Comments
 (0)