From 16323dcc9df15020e368d4324cf1c1d9dceac805 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Mon, 20 Jun 2016 20:57:25 +0200 Subject: build: Change install directories and set correct permissions This sets the correct install directories for all the binaries, library and header files. It also sets the right permissions on the sockets and shared memory so that regular users can also use the ouroboros library. Root privileges are required to run the irmd. Fixes #7 --- src/lib/CMakeLists.txt | 2 +- src/lib/ipcp.c | 6 ++---- src/lib/shm_ap_rbuff.c | 11 ++++++++++- src/lib/shm_du_map.c | 8 ++++++++ src/lib/sockets.c | 6 +++++- 5 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src/lib') diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 796a0b7c..7db083b6 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -51,7 +51,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ouroboros -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS ouroboros LIBRARY DESTINATION lib) +install(TARGETS ouroboros LIBRARY DESTINATION usr/lib) target_include_directories(ouroboros PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 89756235..fcaf9f83 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -105,7 +105,7 @@ pid_t ipcp_create(char * ipcp_name, pid_t pid = 0; char irmd_pid[10]; size_t len = 0; - char * ipcp_dir = "bin"; + char * ipcp_dir = "sbin/"; char * full_name = NULL; char * exec_name = NULL; @@ -135,7 +135,7 @@ pid_t ipcp_create(char * ipcp_name, len += strlen(INSTALL_DIR); len += strlen(ipcp_dir); len += strlen(exec_name); - len += 3; + len += 1; full_name = malloc(len + 1); if (full_name == NULL) { @@ -144,9 +144,7 @@ pid_t ipcp_create(char * ipcp_name, } strcpy(full_name, INSTALL_DIR); - strcat(full_name, "/"); strcat(full_name, ipcp_dir); - strcat(full_name, "/"); strcat(full_name, exec_name); full_name[len] = '\0'; diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index a855ed8f..6ee2936c 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -20,10 +20,12 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include +#include + #define OUROBOROS_PREFIX "shm_ap_rbuff" #include +#include #include #include @@ -34,6 +36,7 @@ #include #include #include +#include #define SHM_RBUFF_FILE_SIZE (SHM_RBUFF_SIZE * sizeof(struct rb_entry) \ + 2 * sizeof(size_t) + sizeof(pthread_mutex_t) \ @@ -80,6 +83,12 @@ struct shm_ap_rbuff * shm_ap_rbuff_create() return NULL; } + if (fchmod(shm_fd, 0666)) { + LOG_DBGF("Failed to chmod shared memory."); + free(rb); + return NULL; + } + if (lseek(shm_fd, SHM_RBUFF_FILE_SIZE - 1, SEEK_SET) < 0) { LOG_DBGF("Failed to extend ringbuffer."); free(rb); diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index 0ce6bdcd..5f935d3f 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -21,12 +21,14 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include #include #include #include +#include #define OUROBOROS_PREFIX "shm_du_map" @@ -95,6 +97,12 @@ struct shm_du_map * shm_du_map_create() return NULL; } + if (fchmod(shm_fd, 0666)) { + LOG_DBGF("Failed to chmod shared memory map."); + free(dum); + return NULL; + } + if (lseek(shm_fd, SHM_FILE_SIZE - 1, SEEK_SET) < 0) { LOG_DBGF("Failed to extend shared memory map."); free(dum); diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 6c51e916..403d2833 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "libouroboros-sockets" +#include #include #include #include @@ -153,7 +154,7 @@ char * ipcp_sock_path(pid_t pid) char * full_name = NULL; char * pid_string = NULL; size_t len = 0; - char * delim = "-"; + char * delim = "_"; len = n_digits(pid); pid_string = malloc(len + 1); @@ -164,6 +165,8 @@ char * ipcp_sock_path(pid_t pid) len += strlen(IPCP_SOCK_PATH_PREFIX); len += strlen(delim); + len += strlen(SOCK_PATH_SUFFIX); + full_name = malloc(len + 1); if (full_name == NULL) { free(pid_string); @@ -173,6 +176,7 @@ char * ipcp_sock_path(pid_t pid) strcpy(full_name, IPCP_SOCK_PATH_PREFIX); strcat(full_name, delim); strcat(full_name, pid_string); + strcat(full_name, SOCK_PATH_SUFFIX); free(pid_string); -- cgit v1.2.3