From db0cf7963b971ebb393d105a0a29fa7bd926521c Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Tue, 31 May 2016 14:05:46 -0400 Subject: VPP-83 Allow non-privileged clients to use the vpp binary API. Use the command line argument "api-segment { uid gid }" to configure shared memory segment file ownership. Defaults to uid = gid = 0. Shared-memory segments are explicitly set to 0770 mode, aka "rwxrwx---". Change-Id: Ic5d596b68139add61e7de6ace035c57dfd030111 Signed-off-by: Dave Barach --- vlib-api/vlibmemory/memory_shared.c | 43 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'vlib-api/vlibmemory/memory_shared.c') diff --git a/vlib-api/vlibmemory/memory_shared.c b/vlib-api/vlibmemory/memory_shared.c index a32194310a4..71150fdc9cb 100644 --- a/vlib-api/vlibmemory/memory_shared.c +++ b/vlib-api/vlibmemory/memory_shared.c @@ -197,9 +197,23 @@ void vl_set_memory_root_path (char *name) am->root_path = name; } +void vl_set_memory_uid (int uid) +{ + api_main_t *am = &api_main; + + am->api_uid = uid; +} + +void vl_set_memory_gid (int gid) +{ + api_main_t *am = &api_main; + + am->api_gid = gid; +} + int vl_map_shmem (char *region_name, int is_vlib) { - svm_map_region_args_t *a = 0; + svm_map_region_args_t _a, *a = &_a; svm_region_t *vlib_rp, *root_rp; void *oldheap; vl_shmem_hdr_t *shmem_hdr=0; @@ -210,16 +224,16 @@ int vl_map_shmem (char *region_name, int is_vlib) if (is_vlib == 0) svm_region_init_chroot(am->root_path); - vec_validate (a, 0); + memset (a, 0, sizeof (*a)); a->name = region_name; a->size = 16<<20; a->flags = SVM_FLAGS_MHEAP; + a->uid = am->api_uid; + a->gid = am->api_gid; vlib_rp = svm_region_find_or_create (a); - vec_free (a); - if (vlib_rp == 0) return (-2); @@ -273,25 +287,8 @@ int vl_map_shmem (char *region_name, int is_vlib) /* Clean up the root region client list */ pthread_mutex_lock (&root_rp->mutex); svm_client_scan_this_region_nolock (root_rp); - pthread_mutex_unlock (&root_rp->mutex); - } else { - pthread_mutex_unlock (&vlib_rp->mutex); - /* - * Make sure the vlib app is really there... - * Wait up to 100 seconds... - */ - for (i = 0; i < 10000; i++) { - /* Yup, it's there, off we go... */ - if (kill (am->shmem_hdr->vl_pid, 0) >= 0) - break; - - ts.tv_sec = 0; - ts.tv_nsec = 10000*1000; /* 10 ms */ - while (nanosleep(&ts, &tsrem) < 0) - ts = tsrem; - } - } - + } + pthread_mutex_unlock (&vlib_rp->mutex); am->vlib_rp = vlib_rp; vec_add1(am->mapped_shmem_regions, vlib_rp); return 0; -- cgit 1.2.3-korg