Skip to content

Commit

Permalink
Don't fail if a tun device can not be configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb James DeLisle committed Jun 20, 2012
1 parent 347b680 commit c90f624
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 8 additions & 3 deletions cjdroute.c
Expand Up @@ -25,6 +25,7 @@
#include "dht/dhtcore/RouterModule_admin.h" #include "dht/dhtcore/RouterModule_admin.h"
#include "exception/ExceptionHandler.h" #include "exception/ExceptionHandler.h"
#include "exception/AbortHandler.h" #include "exception/AbortHandler.h"
#include "exception/Jmp.h"
#include "interface/Interface.h" #include "interface/Interface.h"
#include "interface/TUNInterface.h" #include "interface/TUNInterface.h"
#include "interface/TUNConfigurator.h" #include "interface/TUNConfigurator.h"
Expand Down Expand Up @@ -322,9 +323,13 @@ static void registerRouter(Dict* config, struct Address* addr, struct Context* c
assignedTunName, assignedTunName,
context->logger, context->logger,
AbortHandler_INSTANCE); AbortHandler_INSTANCE);

struct Jmp jmp;
TUNConfigurator_setIpAddress( Jmp_try(jmp) {
assignedTunName, addr->ip6.bytes, 8, context->logger, AbortHandler_INSTANCE); TUNConfigurator_setIpAddress(
assignedTunName, addr->ip6.bytes, 8, context->logger, &jmp.handler);
} Jmp_catch {
Log_warn(context->logger, "Unable to configure ip address [%s]", jmp.message);
}


struct TUNInterface* tun = TUNInterface_new(tunPtr, context->base, context->allocator); struct TUNInterface* tun = TUNInterface_new(tunPtr, context->base, context->allocator);
context->tunInterface = TUNInterface_asGeneric(tun); context->tunInterface = TUNInterface_asGeneric(tun);
Expand Down
17 changes: 10 additions & 7 deletions exception/Except.h
Expand Up @@ -15,28 +15,31 @@
#ifndef Except_H #ifndef Except_H
#define Except_H #define Except_H


#include "exception/ExceptionHandler.h"
#include "util/Gcc.h" #include "util/Gcc.h"


#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>


#define Except ExceptionHandler #define Except_BUFFER_SZ 1024

struct Except
{
void (* exception)(char* message, int code, struct Except* handler);

char message[Except_BUFFER_SZ];
};


Gcc_NORETURN Gcc_NORETURN
Gcc_PRINTF(3, 4) Gcc_PRINTF(3, 4)
static inline void Except_raise(struct Except* eh, int code, char* format, ...) static inline void Except_raise(struct Except* eh, int code, char* format, ...)
{ {
#define Except_BUFFER_SZ 1024
char buff[Except_BUFFER_SZ];

va_list args; va_list args;
va_start(args, format); va_start(args, format);
vsnprintf(buff, Except_BUFFER_SZ, format, args); vsnprintf(eh->message, Except_BUFFER_SZ, format, args);


eh->exception(buff, code, eh); eh->exception(eh->message, code, eh);
abort(); abort();
} }


Expand Down
7 changes: 2 additions & 5 deletions exception/ExceptionHandler.h
Expand Up @@ -15,11 +15,8 @@
#ifndef ExceptionHandler_H #ifndef ExceptionHandler_H
#define ExceptionHandler_H #define ExceptionHandler_H


struct ExceptionHandler #include "exception/Except.h"
{
void (* exception)(char* message, int code, struct ExceptionHandler* handler);


void* context; #define ExceptionHandler Except
};


#endif #endif

0 comments on commit c90f624

Please sign in to comment.