diff options
26 files changed, 85 insertions, 39 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d31262d..9875bd7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,10 @@ SET(CMAKE_SKIP_BUILD_RPATH FALSE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) +LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES + "${CMAKE_INSTALL_PREFIX}usr/lib" isSystemDir) IF("${isSystemDir}" STREQUAL "-1") - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/usr/lib") ENDIF("${isSystemDir}" STREQUAL "-1") message(STATUS "Package name is: ${PACKAGE_NAME}") @@ -49,7 +50,7 @@ configure_file( "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ouroboros.pc" - DESTINATION "lib/pkgconfig") + DESTINATION "usr/lib/pkgconfig") enable_testing() add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) @@ -71,7 +72,8 @@ set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_VERSION_MAJOR "${PACKAGE_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PACKAGE_VERSION_MINOR}") -set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") +set(CPACK_PACKAGE_INSTALL_DIRECTORY + "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") set(CPACK_GENERATOR "TGZ") set(CPACK_SOURCE_GENERATOR "TGZ") diff --git a/compile_debug.sh b/compile_debug.sh index 3ea1e039..9f7da176 100755 --- a/compile_debug.sh +++ b/compile_debug.sh @@ -4,7 +4,7 @@ ME=compile_debug if (($# == 1 )) then - PREFIX=`echo "$1"|sed -e "s,\/$,,"` + PREFIX=$1 else PREFIX="/usr/local/ouroboros" fi diff --git a/compile_release.sh b/compile_release.sh index 0dad6c91..d2400ec2 100755 --- a/compile_release.sh +++ b/compile_release.sh @@ -4,9 +4,9 @@ ME=compile_release if (($# == 1 )) then - PREFIX=`echo "$1"|sed -e "s,\/$,,"` + PREFIX=$1 else - PREFIX="/usr/local/ouroboros" + PREFIX="/" fi BUILDDIR=build diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 245187e9..8347f928 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -14,4 +14,4 @@ set(HEADER_FILES time_utils.h ) -install(FILES ${HEADER_FILES} DESTINATION include/ouroboros) +install(FILES ${HEADER_FILES} DESTINATION usr/include/ouroboros) diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index be5ae651..b765b55b 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -36,10 +36,13 @@ typedef IrmMsg irm_msg_t; #include "ipcpd_messages.pb-c.h" typedef IpcpMsg ipcp_msg_t; -#define IRM_SOCK_PATH "/tmp/irm_sock" +#define SOCK_PATH INSTALL_DIR "var/run/ouroboros/" +#define SOCK_PATH_SUFFIX ".sock" + +#define IRM_SOCK_PATH SOCK_PATH "irm" SOCK_PATH_SUFFIX #define IRM_MSG_BUF_SIZE 256 -#define IPCP_SOCK_PATH_PREFIX "/tmp/ipcp_sock" +#define IPCP_SOCK_PATH_PREFIX SOCK_PATH "ipcp" #define IPCP_MSG_BUF_SIZE IRM_MSG_BUF_SIZE /* Returns the full socket path of an IPCP */ diff --git a/install_debug.sh b/install_debug.sh index ef6b8a30..020677a0 100755 --- a/install_debug.sh +++ b/install_debug.sh @@ -4,7 +4,7 @@ ME=install_debug if (($# == 1 )) then - PREFIX=`echo "$1"|sed -e "s,\/$,,"` + PREFIX=$1 else PREFIX="/usr/local/ouroboros" fi diff --git a/install_release.sh b/install_release.sh index cbba45ff..383c3f9b 100755 --- a/install_release.sh +++ b/install_release.sh @@ -4,9 +4,9 @@ ME=install_release if (($# == 1 )) then - PREFIX=`echo "$1"|sed -e "s,\/$,,"` + PREFIX=$1 else - PREFIX="/usr" + PREFIX="/" fi BUILDDIR=build diff --git a/ouroboros.pc.in b/ouroboros.pc.in index b10ce9a4..44da4b91 100644 --- a/ouroboros.pc.in +++ b/ouroboros.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=${exec_prefix}/lib@LIB_SUFFIX@ -includedir=${prefix}/include +libdir=${exec_prefix}/usr/lib +includedir=${prefix}/usr/include Name: @PROJECT_NAME@ Description: @PACKAGE_DESCRIPTION@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0732f08..0037d437 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(ipcpd) add_subdirectory(irmd) -add_subdirectory(dad) +add_subdirectory(nsmd) add_subdirectory(lib) add_subdirectory(tools) diff --git a/src/ipcpd/local/CMakeLists.txt b/src/ipcpd/local/CMakeLists.txt index 4d05d474..cc19aad0 100644 --- a/src/ipcpd/local/CMakeLists.txt +++ b/src/ipcpd/local/CMakeLists.txt @@ -26,7 +26,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ipcpd-local -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS ipcpd-local RUNTIME DESTINATION bin) +install(TARGETS ipcpd-local RUNTIME DESTINATION sbin) # Enable once ipcp-local has tests # add_subdirectory(tests) diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index 58584e20..74bd19ec 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -28,7 +28,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ipcpd-normal -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS ipcpd-normal RUNTIME DESTINATION bin) +install(TARGETS ipcpd-normal RUNTIME DESTINATION sbin) # Enable once ipcp-normal has tests # add_subdirectory(tests) diff --git a/src/ipcpd/shim-eth-llc/CMakeLists.txt b/src/ipcpd/shim-eth-llc/CMakeLists.txt index 14441113..a3f96735 100644 --- a/src/ipcpd/shim-eth-llc/CMakeLists.txt +++ b/src/ipcpd/shim-eth-llc/CMakeLists.txt @@ -34,4 +34,4 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ipcpd-shim-eth-llc -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS ipcpd-shim-eth-llc RUNTIME DESTINATION bin) +install(TARGETS ipcpd-shim-eth-llc RUNTIME DESTINATION sbin) diff --git a/src/ipcpd/shim-udp/CMakeLists.txt b/src/ipcpd/shim-udp/CMakeLists.txt index 79d7b72f..6430661c 100644 --- a/src/ipcpd/shim-udp/CMakeLists.txt +++ b/src/ipcpd/shim-udp/CMakeLists.txt @@ -84,7 +84,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(ipcpd-shim-udp -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS ipcpd-shim-udp RUNTIME DESTINATION bin) +install(TARGETS ipcpd-shim-udp RUNTIME DESTINATION sbin) # Enable once ipcp-shim-udp has tests # add_subdirectory(tests) diff --git a/src/irmd/CMakeLists.txt b/src/irmd/CMakeLists.txt index 75d65ba3..a402b242 100644 --- a/src/irmd/CMakeLists.txt +++ b/src/irmd/CMakeLists.txt @@ -19,7 +19,7 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) MACRO_ADD_COMPILE_FLAGS(irmd -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS irmd RUNTIME DESTINATION bin) +install(TARGETS irmd RUNTIME DESTINATION sbin) # Enable once irmd has tests # add_subdirectory(tests) diff --git a/src/irmd/main.c b/src/irmd/main.c index 7ad7a23a..68789e94 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -49,6 +49,7 @@ #include <string.h> #include <limits.h> #include <pthread.h> +#include <sys/stat.h> #ifndef IRMD_MAX_FLOWS #define IRMD_MAX_FLOWS 4096 @@ -1571,11 +1572,13 @@ void * mainloop() static struct irm * irm_create() { + struct stat st = {0}; + struct irm * i = malloc(sizeof(*i)); if (i == NULL) return NULL; - if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { + if (access(INSTALL_DIR "dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) { struct shm_du_map * dum = shm_du_map_open(); if (dum == NULL) { LOG_ERR("Could not examine existing shm file."); @@ -1592,6 +1595,11 @@ static struct irm * irm_create() } } + if (rw_lock_init(&i->state_lock)) { + irm_destroy(i); + return NULL; + } + i->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE); if (i->threadpool == NULL) { irm_destroy(i); @@ -1613,13 +1621,22 @@ static struct irm * irm_create() return NULL; } + if (stat(SOCK_PATH, &st) == -1) { + if (mkdir(SOCK_PATH, 0777)) { + LOG_ERR("Failed to create sockets directory."); + irm_destroy(i); + return NULL; + } + } + i->sockfd = server_socket_open(IRM_SOCK_PATH); if (i->sockfd < 0) { irm_destroy(i); return NULL; } - if (rw_lock_init(&i->state_lock)) { + if (chmod(IRM_SOCK_PATH, 0666)) { + LOG_ERR("Failed to chmod socket."); irm_destroy(i); return NULL; } @@ -1643,6 +1660,11 @@ int main() int t = 0; + if (geteuid() != 0) { + LOG_ERR("IPC Resource Manager must be run as root."); + exit(EXIT_FAILURE); + } + /* init sig_act */ memset(&sig_act, 0, sizeof sig_act); @@ -1661,7 +1683,7 @@ int main() instance = irm_create(); if (instance == NULL) - return 1; + exit(EXIT_FAILURE); pthread_create(&instance->cleanup_flows, NULL, irm_flow_cleaner, NULL); 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 <ouroboros/shm_ap_rbuff.h> +#include <ouroboros/config.h> + #define OUROBOROS_PREFIX "shm_ap_rbuff" #include <ouroboros/logs.h> +#include <ouroboros/shm_ap_rbuff.h> #include <pthread.h> #include <sys/mman.h> @@ -34,6 +36,7 @@ #include <unistd.h> #include <stdbool.h> #include <errno.h> +#include <sys/stat.h> #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 <ouroboros/config.h> #include <ouroboros/shm_du_map.h> #include <pthread.h> #include <sys/mman.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #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 <ouroboros/config.h> #include <ouroboros/logs.h> #include <ouroboros/common.h> #include <ouroboros/sockets.h> @@ -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); diff --git a/src/dad/CMakeLists.txt b/src/nsmd/CMakeLists.txt index 1f9f4f42..b916170b 100644 --- a/src/dad/CMakeLists.txt +++ b/src/nsmd/CMakeLists.txt @@ -9,16 +9,16 @@ set(SOURCE_FILES main.c ) -add_executable (dad ${SOURCE_FILES}) +add_executable (nsmd ${SOURCE_FILES}) -target_link_libraries (dad LINK_PUBLIC ouroboros) +target_link_libraries (nsmd LINK_PUBLIC ouroboros) include(MacroAddCompileFlags) if (CMAKE_BUILD_TYPE MATCHES Debug) - MACRO_ADD_COMPILE_FLAGS(dad -DCONFIG_OUROBOROS_DEBUG) + MACRO_ADD_COMPILE_FLAGS(nsmd -DCONFIG_OUROBOROS_DEBUG) endif (CMAKE_BUILD_TYPE MATCHES Debug) -install(TARGETS dad RUNTIME DESTINATION bin) +install(TARGETS nsmd RUNTIME DESTINATION sbin) -# Enable once dad has tests +# Enable once nsmd has tests # add_subdirectory(tests) diff --git a/src/dad/main.c b/src/nsmd/main.c index e2971dca..e2971dca 100644 --- a/src/dad/main.c +++ b/src/nsmd/main.c diff --git a/src/dad/tests/CMakeLists.txt b/src/nsmd/tests/CMakeLists.txt index 68bd762d..68bd762d 100644 --- a/src/dad/tests/CMakeLists.txt +++ b/src/nsmd/tests/CMakeLists.txt diff --git a/src/tools/cbr/CMakeLists.txt b/src/tools/cbr/CMakeLists.txt index 7c3f93f8..232bea36 100644 --- a/src/tools/cbr/CMakeLists.txt +++ b/src/tools/cbr/CMakeLists.txt @@ -13,4 +13,4 @@ add_executable(cbr ${SOURCE_FILES}) target_link_libraries(cbr LINK_PUBLIC ouroboros) -install(TARGETS cbr RUNTIME DESTINATION bin) +install(TARGETS cbr RUNTIME DESTINATION usr/bin) diff --git a/src/tools/echo/CMakeLists.txt b/src/tools/echo/CMakeLists.txt index b3d88089..42bcdbfe 100644 --- a/src/tools/echo/CMakeLists.txt +++ b/src/tools/echo/CMakeLists.txt @@ -13,4 +13,4 @@ add_executable(echo-app ${SOURCE_FILES}) target_link_libraries(echo-app LINK_PUBLIC ouroboros) -install(TARGETS echo-app RUNTIME DESTINATION bin) +install(TARGETS echo-app RUNTIME DESTINATION usr/bin) diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index eb385908..d1f227a8 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -20,4 +20,4 @@ add_executable (irm ${SOURCE_FILES}) target_link_libraries (irm LINK_PUBLIC ouroboros) -install(TARGETS irm RUNTIME DESTINATION bin) +install(TARGETS irm RUNTIME DESTINATION sbin) |