summaryrefslogtreecommitdiff
path: root/src/irmd/reg/ipcp.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2024-02-17 10:19:46 +0100
committerSander Vrijders <sander@ouroboros.rocks>2024-02-19 11:49:07 +0100
commit06ee3370998f965b469d1c2859e3e34159c71e20 (patch)
tree93881747a4f1e99f6932231b0cb2358941cb9741 /src/irmd/reg/ipcp.c
parent7bb8aed15c7f29de4d9719acf8db7fdf73731af5 (diff)
downloadouroboros-06ee3370998f965b469d1c2859e3e34159c71e20.tar.gz
ouroboros-06ee3370998f965b469d1c2859e3e34159c71e20.zip
irmd: Revise IRMd internals
This is a full revision of the IRMd internal implementation. The registry is now a proper subcomponent managing its own internal lock (a single mutex). Some tests are added for the registry and its data structures. Some macros for tests are added in <ouroboros/test.h>. Flow allocation is now more symmetric between the client side (alloc) and server size (accept). Each will create a flow in pending state (ALLOC_PENDING/ACCEPT_PENDING) that is potentially fulfilled by an IPCP using respond_alloc and respond_accept primitives. Deallocation is split in flow_dealloc (application side) and ipcp_flow_dealloc (IPCP side) to get the flow in DEALLOC_PENDING and DEALLOCATED state. Cleanup of failed flow allocation is now properly handled instead of relying on the sanitizer thread. The new sanitizer only needs to monitor crashed processes. On shutdown, the IRMd will now detect hanging processes and SIGKILL them and clean up their fuse mountpoints if needed. A lot of other things have been cleaned up and shuffled around a bit. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/irmd/reg/ipcp.c')
-rw-r--r--src/irmd/reg/ipcp.c111
1 files changed, 29 insertions, 82 deletions
diff --git a/src/irmd/reg/ipcp.c b/src/irmd/reg/ipcp.c
index c1d06d94..6580cb5b 100644
--- a/src/irmd/reg/ipcp.c
+++ b/src/irmd/reg/ipcp.c
@@ -20,126 +20,73 @@
* Foundation, Inc., http://www.fsf.org/about/contact/.
*/
-#if defined(__linux__) || defined(__CYGWIN__)
-#define _DEFAULT_SOURCE
-#else
#define _POSIX_C_SOURCE 200809L
-#endif
-#include "config.h"
+#define OUROBOROS_PREFIX "reg/ipcp"
-#include <ouroboros/errno.h>
-#include <ouroboros/hash.h>
-#include <ouroboros/ipcp.h>
-#include <ouroboros/pthread.h>
-#include <ouroboros/time_utils.h>
+#include <ouroboros/logs.h>
+#include <ouroboros/time.h>
#include "ipcp.h"
#include <assert.h>
-#include <signal.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
struct reg_ipcp * reg_ipcp_create(const struct ipcp_info * info)
{
- struct reg_ipcp * ipcp;
- pthread_condattr_t cattr;
+ struct reg_ipcp * ipcp;
+
+ assert(info != NULL);
+ assert(info->state == IPCP_BOOT);
ipcp = malloc(sizeof(*ipcp));
- if (ipcp == NULL)
+ if (ipcp == NULL) {
+ log_err("Failed to malloc ipcp.");
goto fail_malloc;
+ }
- if (pthread_mutex_init(&ipcp->mtx, NULL))
- goto fail_mutex;
-
- if (pthread_condattr_init(&cattr))
- goto fail_cattr;
-#ifndef __APPLE__
- pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
-#endif
- if (pthread_cond_init(&ipcp->cond, &cattr))
- goto fail_cond;
-
- memcpy(&ipcp->info, info, sizeof(*info));
+ memset(ipcp, 0, sizeof(*ipcp));
+ memset(&ipcp->layer, 0, sizeof(ipcp->layer));
- pthread_condattr_destroy(&cattr);
+ list_head_init(&ipcp->next);
- ipcp->layer = NULL;
- ipcp->state = IPCP_BOOT;
+ ipcp->info = *info;
+ ipcp->info.state = IPCP_BOOT;
- list_head_init(&ipcp->next);
+ strcpy(ipcp->layer.name, "Not enrolled.");
return ipcp;
- fail_cond:
- pthread_condattr_destroy(&cattr);
- fail_cattr:
- pthread_mutex_destroy(&ipcp->mtx);
- fail_mutex:
- free(ipcp);
fail_malloc:
return NULL;
}
void reg_ipcp_destroy(struct reg_ipcp * ipcp)
{
- assert(ipcp);
-
- pthread_mutex_lock(&ipcp->mtx);
-
- while (ipcp->state == IPCP_BOOT)
- pthread_cond_wait(&ipcp->cond, &ipcp->mtx);
-
- free(ipcp->layer);
+ assert(ipcp != NULL);
- pthread_mutex_unlock(&ipcp->mtx);
-
- pthread_cond_destroy(&ipcp->cond);
- pthread_mutex_destroy(&ipcp->mtx);
+ assert(list_is_empty(&ipcp->next));
free(ipcp);
}
-void reg_ipcp_set_state(struct reg_ipcp * ipcp,
- enum ipcp_state state)
+void reg_ipcp_update(struct reg_ipcp * ipcp,
+ const struct ipcp_info * info)
{
- pthread_mutex_lock(&ipcp->mtx);
-
- ipcp->state = state;
- pthread_cond_broadcast(&ipcp->cond);
+ assert(ipcp != NULL);
+ assert(info->state != IPCP_INIT);
- pthread_mutex_unlock(&ipcp->mtx);
+ ipcp->info = *info;
}
-int reg_ipcp_wait_boot(struct reg_ipcp * ipcp)
+void reg_ipcp_set_layer(struct reg_ipcp * ipcp,
+ const struct layer_info * info)
{
- int ret = 0;
- struct timespec dl;
- struct timespec to = {SOCKET_TIMEOUT / 1000,
- (SOCKET_TIMEOUT % 1000) * MILLION};
-
- clock_gettime(PTHREAD_COND_CLOCK, &dl);
- ts_add(&dl, &to, &dl);
-
- pthread_mutex_lock(&ipcp->mtx);
-
- while (ipcp->state == IPCP_BOOT && ret != ETIMEDOUT)
- ret = pthread_cond_timedwait(&ipcp->cond, &ipcp->mtx, &dl);
-
- if (ret == ETIMEDOUT) {
- kill(ipcp->pid, SIGTERM);
- ipcp->state = IPCP_NULL;
- pthread_cond_signal(&ipcp->cond);
- }
-
- if (ipcp->state != IPCP_OPERATIONAL) {
- pthread_mutex_unlock(&ipcp->mtx);
- return -1;
- }
-
- pthread_mutex_unlock(&ipcp->mtx);
+ assert(ipcp != NULL);
+ assert(ipcp->info.state == IPCP_OPERATIONAL);
- return 0;
+ ipcp->layer = *info;
}