Пример #1
0
void instance_free (struct instance *o)
{
    // free timer
    BReactor_RemoveTimer(o->i->params->iparams->reactor, &o->timer);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #2
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // remove route
    int res = 0; // to remove warning
    switch (o->type) {
        case TYPE_NORMAL:
            res = NCDIfConfig_remove_ipv6_route(o->dest, &o->gateway, o->metric, o->ifname_nts.data);
            break;
        case TYPE_IFONLY:
            res = NCDIfConfig_remove_ipv6_route(o->dest, NULL, o->metric, o->ifname_nts.data);
            break;
        case TYPE_BLACKHOLE:
            res = NCDIfConfig_remove_ipv6_blackhole_route(o->dest, o->metric);
            break;
        default: ASSERT(0);
    }
    if (!res) {
        ModuleLog(o->i, BLOG_ERROR, "failed to remove route");
    }
    
    // free ifname nts
    NCDValNullTermString_Free(&o->ifname_nts);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #3
0
static void func_new_from_value (NCDModuleInst *i)
{
    // read arguments
    NCDValue *arg_value;
    if (!NCDValue_ListRead(i->args, 1, &arg_value)) {
        ModuleLog(i, BLOG_ERROR, "wrong arity");
        goto fail0;
    }
    if (NCDValue_Type(arg_value) != NCDVALUE_STRING) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // parse value
    uintmax_t value;
    if (!parse_unsigned_integer(NCDValue_StringValue(arg_value), &value)) {
        ModuleLog(i, BLOG_ERROR, "wrong value");
        goto fail0;
    }
    
    // check overflow
    if (value > SIZE_MAX) {
        ModuleLog(i, BLOG_ERROR, "value too large");
        goto fail0;
    }
    
    func_new_templ(i, value);
    return;
    
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #4
0
static void rprint_func_die (void *vo)
{
    struct rprint_instance *o = vo;
    
    do_print(o->i, o->args, o->ln);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #5
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    AliasNames_FreeNames(o);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #6
0
static void read_func_die (void *vo)
{
    struct read_instance *o = vo;
    
    // free data
    free(o->file_data);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #7
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // free monitor
    NCDRfkillMonitor_Free(&o->monitor);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #8
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // free mem
    NCDValMem_Free(&o->mem);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #9
0
static void instance_free (struct instance *o)
{
    NCDModuleInst *i = o->i;
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #10
0
static void replace_func_die (void *vo)
{
    struct replace_instance *o = vo;
    
    // free output
    BFree((char *)o->output.ptr);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #11
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // free result
    free(o->result);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #12
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    NCDModuleInst *i = o->i;
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #13
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    while (o->num-- > 0) {
        BFree(((struct substring *)o->arr.v)[o->num].data);
    }
    free(o->arr.v);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #14
0
static void instance_free (struct instance *o, int is_error)
{
    // free arpprobe
    BArpProbe_Free(&o->arpprobe);
    
    if (is_error) {
        NCDModuleInst_Backend_DeadError(o->i);
    } else {
        NCDModuleInst_Backend_Dead(o->i);
    }
}
Пример #15
0
static void instance_free (struct instance *o, int is_error)
{
    // free DHCP
    BDHCPClient_Free(&o->dhcp);
    
    if (is_error) {
        NCDModuleInst_Backend_DeadError(o->i);
    } else {
        NCDModuleInst_Backend_Dead(o->i);
    }
}
Пример #16
0
void instance_free (struct instance *o)
{
    NCDModuleInst *i = o->i;
    
    // free process
    NCDModuleProcess_Free(&o->process);
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #17
0
static void func_new (NCDModuleInst *i)
{
    // allocate instance
    struct instance *o = malloc(sizeof(*o));
    if (!o) {
        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
        goto fail0;
    }
    NCDModuleInst_Backend_SetUser(i, o);
    
    // init arguments
    o->i = i;
    
    // check arguments
    NCDValue *template_name_arg;
    NCDValue *args_arg;
    if (!NCDValue_ListRead(o->i->args, 2, &template_name_arg, &args_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail1;
    }
    if (NCDValue_Type(template_name_arg) != NCDVALUE_STRING || NCDValue_Type(args_arg) != NCDVALUE_LIST) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail1;
    }
    
    // signal up.
    // Do it before creating the process so that the process starts initializing before our own process continues.
    NCDModuleInst_Backend_Up(o->i);
    
    // copy arguments
    NCDValue args;
    if (!NCDValue_InitCopy(&args, args_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitCopy failed");
        goto fail1;
    }
    
    // create process
    if (!NCDModuleProcess_Init(&o->process, o->i, NCDValue_StringValue(template_name_arg), args, o, (NCDModuleProcess_handler_event)process_handler_event)) {
        ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
        NCDValue_Free(&args);
        goto fail1;
    }
    
    // set state working
    o->state = STATE_WORKING;
    return;
    
fail1:
    free(o);
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #18
0
static void func_new (NCDModuleInst *i)
{
    // allocate instance
    struct instance *o = malloc(sizeof(*o));
    if (!o) {
        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
        goto fail0;
    }
    NCDModuleInst_Backend_SetUser(i, o);
    
    // init arguments
    o->i = i;
    
    // init string
    ExpString s;
    if (!ExpString_Init(&s)) {
        ModuleLog(i, BLOG_ERROR, "ExpString_Init failed");
        goto fail1;
    }
    
    // append arguments
    NCDValue *arg = NCDValue_ListFirst(o->i->args);
    while (arg) {
        if (NCDValue_Type(arg) != NCDVALUE_STRING) {
            ModuleLog(i, BLOG_ERROR, "wrong type");
            goto fail2;
        }
        
        if (!ExpString_Append(&s, NCDValue_StringValue(arg))) {
            ModuleLog(i, BLOG_ERROR, "ExpString_Append failed");
            goto fail2;
        }
        
        arg = NCDValue_ListNext(o->i->args, arg);
    }
    
    // set string
    o->string = ExpString_Get(&s);
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    
    return;
    
fail2:
    ExpString_Free(&s);
fail1:
    free(o);
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #19
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // remove address
    if (!NCDIfConfig_remove_ipv4_addr(o->ifname_nts.data, o->ifaddr)) {
        ModuleLog(o->i, BLOG_ERROR, "failed to remove IP address");
    }
    
    // free ifname nts
    NCDValNullTermString_Free(&o->ifname_nts);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #20
0
static void instance_free (struct instance *o)
{
    ASSERT(LinkedList1_IsEmpty(&o->users))
    
    // break any rdownups
    LinkedList0Node *ln;
    while (ln = LinkedList0_GetFirst(&o->rdownups_list)) {
        struct rdownup_instance *rdu = UPPER_OBJECT(ln, struct rdownup_instance, rdownups_list_node);
        ASSERT(rdu->blocker == o)
        LinkedList0_Remove(&o->rdownups_list, &rdu->rdownups_list_node);
        rdu->blocker = NULL;
    }
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #21
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    struct global *g = ModuleGlobal(o->i);
    
    // remove from instances
    LinkedList1_Remove(&g->instances, &o->instances_node);
    
    // set servers
    set_servers(g);
    
    // free servers
    remove_entries(o);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #22
0
static void func_new_from_index (NCDModuleInst *i)
{
    struct instance *index = ((NCDModuleInst *)i->method_user)->inst_user;
    
    // check overflow
    if (index->value == SIZE_MAX) {
        ModuleLog(i, BLOG_ERROR, "overflow");
        goto fail0;
    }
    
    func_new_templ(i, index->value + 1);
    return;
    
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #23
0
static void func_die (void *vo)
{
    struct instance *o = vo;
    
    // free devpath
    if (o->devpath) {
        free(o->devpath);
    }
    
    // free regex
    regfree(&o->reg);
    
    // free client
    NCDUdevClient_Free(&o->client);
    
    NCDModuleInst_Backend_Dead(o->i);
}
Пример #24
0
static void callrefhere_func_die (void *vo)
{
    struct callrefhere_instance *o = vo;
    NCDModuleInst *i = o->i;
    
    // disconnect calls
    while (!LinkedList0_IsEmpty(&o->calls_list)) {
        struct instance *inst = UPPER_OBJECT(LinkedList0_GetFirst(&o->calls_list), struct instance, calls_list_node);
        ASSERT(inst->crh == o)
        LinkedList0_Remove(&o->calls_list, &inst->calls_list_node);
        inst->crh = NULL;
    }
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #25
0
static void rgo_func_die (void *vo)
{
    struct rgo_instance *o = vo;
    
    // deref backtrack_point
    NCDModuleInst *backtrack_point_inst = NCDModuleRef_Deref(&o->bp_ref);
    
    // free object reference
    NCDModuleRef_Free(&o->bp_ref);
    
    // die
    NCDModuleInst_Backend_Dead(o->i);
    
    // toggle backtrack_point
    if (backtrack_point_inst) {
        NCDModuleInst_Backend_DownUp(backtrack_point_inst);
    }
}
Пример #26
0
void instance_free (struct instance *o)
{
    NCDModuleInst *i = o->i;
    
    if (o->state != STATE_NONE) {
        // remove from callrefhere's calls list
        if (o->crh) {
            LinkedList0_Remove(&o->crh->calls_list, &o->calls_list_node);
        }
        
        // free process
        NCDModuleProcess_Free(&o->process);
    }
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #27
0
static void func_new_templ (NCDModuleInst *i, size_t value)
{
    // allocate instance
    struct instance *o = malloc(sizeof(*o));
    if (!o) {
        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
        goto fail0;
    }
    NCDModuleInst_Backend_SetUser(i, o);
    
    // init arguments
    o->i = i;
    o->value = value;
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #28
0
void instance_free (struct instance *o)
{
    ASSERT(!o->started)
    NCDModuleInst *i = o->i;
    
    // free timer
    BReactor_RemoveTimer(o->i->params->reactor, &o->timer);
    
    // set device down
    if (!NCDIfConfig_set_down(o->ifname)) {
        ModuleLog(o->i, BLOG_ERROR, "failed to set device down");
    }
    
    // free TAP device
    if (!NCDIfConfig_remove_tuntap(o->ifname, 0)) {
        ModuleLog(o->i, BLOG_ERROR, "failed to remove TAP device");
    }
    
    // free instance
    free(o);
    
    NCDModuleInst_Backend_Dead(i);
}
Пример #29
0
static void callrefhere_func_new (NCDModuleInst *i)
{
    // allocate instance
    struct callrefhere_instance *o = malloc(sizeof(*o));
    if (!o) {
        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
        goto fail0;
    }
    NCDModuleInst_Backend_SetUser(i, o);
    
    // set arguments
    o->i = i;
    
    // init calls list
    LinkedList0_Init(&o->calls_list);
    
    // signal up
    NCDModuleInst_Backend_Up(o->i);
    return;
    
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}
Пример #30
0
static void func_new (NCDModuleInst *i)
{
    // allocate instance
    struct instance *o = malloc(sizeof(*o));
    if (!o) {
        ModuleLog(i, BLOG_ERROR, "failed to allocate instance");
        goto fail0;
    }
    NCDModuleInst_Backend_SetUser(i, o);
    
    // init arguments
    o->i = i;
    
    // check arguments
    NCDValue *template_name_arg;
    NCDValue *args_arg;
    if (!NCDValue_ListRead(o->i->args, 2, &template_name_arg, &args_arg)) {
        ModuleLog(o->i, BLOG_ERROR, "wrong arity");
        goto fail1;
    }
    if (NCDValue_Type(template_name_arg) != NCDVALUE_STRING || NCDValue_Type(args_arg) != NCDVALUE_LIST) {
        ModuleLog(o->i, BLOG_ERROR, "wrong type");
        goto fail1;
    }
    char *template_name = NCDValue_StringValue(template_name_arg);
    
    // calling none?
    if (!strcmp(template_name, "<none>")) {
        // signal up
        NCDModuleInst_Backend_Up(o->i);
        
        // set state none
        o->state = STATE_NONE;
    } else {
        // copy arguments
        NCDValue args;
        if (!NCDValue_InitCopy(&args, args_arg)) {
            ModuleLog(o->i, BLOG_ERROR, "NCDValue_InitCopy failed");
            goto fail1;
        }
        
        // create process
        if (!NCDModuleProcess_Init(&o->process, o->i, template_name, args, o, (NCDModuleProcess_handler_event)process_handler_event)) {
            ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
            NCDValue_Free(&args);
            goto fail1;
        }
        
        // set special functions
        NCDModuleProcess_SetSpecialFuncs(&o->process,
                                        (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
        
        // set callrefhere
        o->crh = (o->i->method_user ? ((NCDModuleInst *)i->method_user)->inst_user : NULL);
        
        // add to callrefhere's calls list
        if (o->crh) {
            LinkedList0_Prepend(&o->crh->calls_list, &o->calls_list_node);
        }
        
        // set state working
        o->state = STATE_WORKING;
    }
    return;
    
fail1:
    free(o);
fail0:
    NCDModuleInst_Backend_SetError(i);
    NCDModuleInst_Backend_Dead(i);
}