summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/ipcpd/local/CMakeLists.txt2
-rw-r--r--src/ipcpd/normal/CMakeLists.txt2
-rw-r--r--src/ipcpd/shim-eth-llc/CMakeLists.txt2
-rw-r--r--src/ipcpd/shim-udp/CMakeLists.txt2
-rw-r--r--src/irmd/CMakeLists.txt2
-rw-r--r--src/irmd/main.c28
-rw-r--r--src/lib/CMakeLists.txt2
-rw-r--r--src/lib/ipcp.c6
-rw-r--r--src/lib/shm_ap_rbuff.c11
-rw-r--r--src/lib/shm_du_map.c8
-rw-r--r--src/lib/sockets.c6
-rw-r--r--src/nsmd/CMakeLists.txt (renamed from src/dad/CMakeLists.txt)10
-rw-r--r--src/nsmd/main.c (renamed from src/dad/main.c)0
-rw-r--r--src/nsmd/tests/CMakeLists.txt (renamed from src/dad/tests/CMakeLists.txt)0
-rw-r--r--src/tools/cbr/CMakeLists.txt2
-rw-r--r--src/tools/echo/CMakeLists.txt2
-rw-r--r--src/tools/irm/CMakeLists.txt2
18 files changed, 65 insertions, 24 deletions
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)